]> git.mdlowis.com Git - proto/anvil.git/commitdiff
tweaked mouse handling on resize and added different cursors for frame and root windows
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 13 Mar 2020 16:34:43 +0000 (12:34 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 13 Mar 2020 16:34:43 +0000 (12:34 -0400)
anvil.c
anvil.h
client.c

diff --git a/anvil.c b/anvil.c
index 0540e1e2e082af7081824672046587371c83a2c1..bf0647daa3861a33e2e6547b3291f47e56be6579 100644 (file)
--- a/anvil.c
+++ b/anvil.c
@@ -16,6 +16,16 @@ static inline int PRESSED(int mods, int btn)
     return ((mods & (1 << (btn + 7))) == (1 << (btn + 7)));
 }
 
+static void warp_mouse(Client* c)
+{
+    XWarpPointer(X.disp, None, c->frame, 0, 0, 0, 0,
+        c->w + 2*BORDER_WIDTH - BORDER_WIDTH/2,
+        c->h + 2*BORDER_WIDTH + TITLE_HEIGHT - BORDER_WIDTH/2
+    );
+    X.start_x = c->x + c->w + 4;
+    X.start_y = c->y + c->h + 4;
+}
+
 static void xbtnpress(XEvent* e)
 {
     XButtonEvent* ev = &(e->xbutton);
@@ -29,12 +39,7 @@ static void xbtnpress(XEvent* e)
             if (ev->y > (TITLE_HEIGHT + BORDER_WIDTH))
             {
                 X.reshaping = 1;
-                XWarpPointer(X.disp, None, ev->window, 0, 0, 0, 0,
-                    c->w + 2*BORDER_WIDTH,
-                    c->h + 2*BORDER_WIDTH + TITLE_HEIGHT
-                );
-                X.start_x = c->x + c->w + 2*BORDER_WIDTH;
-                X.start_y = c->y + c->h + 2*BORDER_WIDTH + TITLE_HEIGHT;
+                warp_mouse(c);
             }
         } else if (ev->button == Button2) {
             client_close(c);
@@ -52,16 +57,12 @@ static void xbtnrelease(XEvent* e)
 
 static void xbtnmotion(XEvent* e)
 {
+    /* make sure we get just the latest event */
     XMotionEvent *ev = &e->xmotion;
-    while (XCheckTypedWindowEvent(X.disp, ev->window, ev->type, e))
-    {
-        /* Keep grabbing them till we have no more to grab */
-    }
-
+    while (XCheckTypedWindowEvent(X.disp, ev->window, ev->type, e));
     Client* c = client_get(ev->window);
     if (c && (ev->window == c->frame))
     {
-        /* TODO: only move window if Button1 held */
         if (PRESSED(ev->state, Button1))
         {
             if (!X.reshaping)
@@ -96,6 +97,10 @@ static void xconfigrequest(XEvent* e)
         c->w = wc.width;
         c->h = wc.height;
         client_resize(c, 0, 0);
+        if (X.reshaping && Focused == c)
+        {
+            warp_mouse(c);
+        }
     }
 }
 
@@ -170,8 +175,7 @@ static void xkeypress(XEvent* e)
 
 int main(void)
 {
-    XColor color, exact;
-
+    XColor color, red, white, exact;
     /* Initialize X server*/
     check( (X.disp = XOpenDisplay(0)) != NULL,
         "could not open display");
@@ -186,6 +190,15 @@ int main(void)
     client_initall();
     keys_init();
 
+    /* configure mouse cursors */
+    Colormap cmap = DefaultColormap(X.disp, X.screen);
+    X.csr_root = XCreateFontCursor(X.disp, XC_left_ptr);
+    XAllocNamedColor(X.disp, cmap, "red", &red, &exact);
+    XAllocNamedColor(X.disp, cmap, "white", &white, &exact);
+    X.csr_point = XCreateFontCursor(X.disp, XC_left_ptr);
+    XRecolorCursor(X.disp, X.csr_point, &red, &white);
+    XDefineCursor(X.disp, X.root, X.csr_root);
+
     /* setup event handlers */
     X.eventfns[ButtonPress] = xbtnpress;
     X.eventfns[ButtonRelease] = xbtnrelease;
diff --git a/anvil.h b/anvil.h
index 6812b1108d11321cc15a3dfeed4dcf49120c798e..7b454a0ce6ec09c832fc455c6cf1083d917a1160 100644 (file)
--- a/anvil.h
+++ b/anvil.h
@@ -2,6 +2,7 @@
 #include <X11/Xlib.h>
 #include <X11/keysym.h>
 #include <X11/XKBlib.h>
+#include <X11/cursorfont.h>
 #include <X11/extensions/Xinerama.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -27,6 +28,7 @@ typedef struct {
     unsigned long black, white, gray;
     int start_x, start_y;
     int reshaping;
+    Cursor csr_root, csr_point;
     void (*eventfns[LASTEvent])(XEvent*);
 } XConf;
 
index 09bfc14a53bf8be5d2a0416f8116692157d0662a..99a4c1440ae7e79f7ae17fe9e24d4c56867d9ecf 100644 (file)
--- a/client.c
+++ b/client.c
@@ -74,6 +74,7 @@ void client_draw(Client* c)
     {
         XSetWindowBackground(X.disp, c->frame, (Focused == c) ? X.black : X.gray);
         XClearWindow(X.disp, c->frame);
+        XDefineCursor(X.disp, c->frame, X.csr_point);
 
     //    int quarter = (border + titleHeight()) / 4;
     //    /* Draw window title. */