]> git.mdlowis.com Git - projs/tide.git/commitdiff
added cursor handling to button handler
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 11 Jun 2019 02:34:56 +0000 (22:34 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 11 Jun 2019 02:34:56 +0000 (22:34 -0400)
src/anvil.c

index f36baab1b627ce822981f89d4d117e5eebba52de..a9c100c4d27403bea9fcf99bd769144c6c396ff7 100644 (file)
@@ -6,6 +6,7 @@
 #include <draw.h>
 #include <locale.h>
 #include <sys/wait.h>
+#include <X11/cursorfont.h>
 
 #define INCLUDE_DEFS
 #include "config.h"
@@ -21,6 +22,7 @@ typedef struct Client {
 
 XConf X = {0};
 Client* Clients = NULL;
+Cursor Move_Cursor;
 
 /* configuration */
 uint32_t BorderWidth = 1;
@@ -45,11 +47,14 @@ void* xfree(void* p) {
 
 /* Client Handling
  *****************************************************************************/
-void client_add(XConf* x, Client* c) {
+void client_add(Client* parent, Client* c) {
+    c->next = parent->next;
+    c->prev = parent;
+    parent->next = c;
+    if (c->next) c->next->prev = c;
 }
 
-void client_del(XConf* x, Client* c) {
-    /* first remove it from the list */
+void client_del(Client* c) {
     if (c->prev) c->prev->next = c->next;
     if (c->next) c->next->prev = c->prev;
     if (Clients == c) Clients = c->next;
@@ -101,12 +106,7 @@ void client_create(XConf* x, Window win) {
         biggy->h /= 2;
         c->y = biggy->y + biggy->h;
         client_config(x, biggy, biggy->x, biggy->y, biggy->w, biggy->h);
-
-        /* add the new client to the list after the biggest */
-        c->next = biggy->next;
-        c->prev = biggy;
-        biggy->next = c;
-        if (c->next) c->next->prev = c;
+        client_add(biggy, c);
     } else {
         Clients = c;
     }
@@ -115,11 +115,10 @@ void client_create(XConf* x, Window win) {
 
     XSync(x->display, False);
     XUngrabServer(x->display);
-
 }
 
 void client_destroy(XConf* x, Client* c) {
-    client_del(x, c);
+    client_del(c);
     XGrabServer(x->display);
     XftDrawDestroy(c->xft);
     XDestroyWindow(x->display, c->frame);
@@ -140,6 +139,7 @@ Client* client_find(Window win) {
 void client_redraw(XConf* x, Client* c) {
     puts("redraw");
     XftColor clr;
+    if (!c->name) return;
     xftcolor(x, &clr, -1);
     XftDrawStringUtf8(c->xft, &clr, x->font, 0, x->font->ascent, (const FcChar8*)c->name, strlen(c->name));
     XftColorFree(x->display, x->visual, x->colormap, &clr);
@@ -150,7 +150,7 @@ void client_redraw(XConf* x, Client* c) {
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wunused-parameter"
-
+Cursor cursor;
 static void xbtnpress(XConf* x, XEvent* e) {
     printf("btn\n");
     /*
@@ -162,6 +162,14 @@ static void xbtnpress(XConf* x, XEvent* e) {
         * Shift+B1: Move one column to the left
         * Shift+B1: Move one column to the right
     */
+    Client* c = client_find(e->xbutton.window);
+    if (c && c->frame == e->xbutton.window) {
+        if (ButtonPress == e->type)
+            XDefineCursor(X.display, e->xbutton.window, Move_Cursor);
+        else
+            XUndefineCursor(X.display, e->xbutton.window);
+    }
+    XSync(X.display, False);
 }
 
 static void xconfigrequest(XConf* x, XEvent* e) {
@@ -257,7 +265,10 @@ int main(void) {
     XSync(X.display, False);
     if (x11_error_get())
         die("Could not start. Is another WM running?\n");
+
+    Move_Cursor = XCreateFontCursor(X.display, XC_draped_box);
     X.eventfns[ButtonPress] = xbtnpress;
+    X.eventfns[ButtonRelease] = xbtnpress;
     X.eventfns[ConfigureRequest] = xconfigrequest;
     X.eventfns[MapRequest] = xmaprequest;
     X.eventfns[UnmapNotify] = xunmapnotify;