From 65d80d7fcec33b0d18512c8b092b10177eb51a76 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sat, 28 Mar 2020 15:06:59 -0400 Subject: [PATCH] added grab pointer to change cursor and control event delivery --- anvil.c | 8 +++++++- anvil.h | 4 +--- client.c | 2 +- mouse.c | 1 - 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/anvil.c b/anvil.c index ed0b085..e13db64 100644 --- a/anvil.c +++ b/anvil.c @@ -14,6 +14,9 @@ static void check_for_wm(void) static void xbtnpress(XEvent* e) { XButtonEvent* ev = &(e->xbutton); + XGrabPointer(X.disp, ev->window, False, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, + GrabModeAsync, GrabModeAsync, None, X.csr_move, CurrentTime); printf("BTN_DN(w: 0x%lx x: %d y: %d rx: %d ry: %d)\n", ev->window, ev->x, ev->y, ev->x_root, ev->y_root); X.start_x = ev->x_root, X.start_y = ev->y_root; X.last_x = ev->x_root, X.last_y = ev->y_root; @@ -56,6 +59,7 @@ static void xbtnrelease(XEvent* e) mouse_up(ev, &loc); } X.mode = M_IDLE; + XUngrabPointer(X.disp, CurrentTime); } static void xbtnmotion(XEvent* e) @@ -170,9 +174,9 @@ static void xenternotify(XEvent* e) static void xexpose(XEvent* e) { XExposeEvent* ev = &(e->xexpose); -// printf("EXPOSE(w: 0x%lx)\n", ev->window); if (ev->count == 0) { + printf("EXPOSE(w: 0x%lx)\n", ev->window); Client* c = client_get(ev->window, NULL); if (c) { @@ -197,6 +201,8 @@ static void init_cursors(void) XAllocNamedColor(X.disp, cmap, "white", &white, &exact); X.csr_point = XCreateFontCursor(X.disp, XC_left_ptr); XRecolorCursor(X.disp, X.csr_point, &red, &white); + X.csr_move = XCreateFontCursor(X.disp, XC_fleur); + XRecolorCursor(X.disp, X.csr_move, &red, &white); XDefineCursor(X.disp, X.root, X.csr_root); } diff --git a/anvil.h b/anvil.h index 1433f22..c485a57 100644 --- a/anvil.h +++ b/anvil.h @@ -17,8 +17,6 @@ #define max(a,b) (a > b ? a : b) /* TODO: warp mouse pointer to title bars on new windows */ -/* TODO: implement mouse handling for tiling methods */ -/* TODO: add logic to add/del columns and retile */ enum { M_INIT, @@ -41,7 +39,7 @@ typedef struct { int screen, mode, edge, start_x, start_y, last_x, last_y; Window root; unsigned long black, white, gray; - Cursor csr_root, csr_point; + Cursor csr_root, csr_point, csr_move; XFontSet font; XFontSetExtents *font_ext; GC graphics; diff --git a/client.c b/client.c index 56f2802..7e23284 100644 --- a/client.c +++ b/client.c @@ -220,5 +220,5 @@ void client_setshade(Client* c, int shade) void client_warpmouse(Client* c) { (void)c; -// XWarpPointer(X.disp, None, X.root, 0, 0, 0, 0, (c->x + c->w/2), c->y + (MIN_HEIGHT/2)); + //XWarpPointer(X.disp, None, X.root, 0, 0, 0, 0, (c->x + c->w/2), c->y + (MIN_HEIGHT/2)); } diff --git a/mouse.c b/mouse.c index 6a3e51f..c781af3 100644 --- a/mouse.c +++ b/mouse.c @@ -116,7 +116,6 @@ static void float_drag(XMotionEvent* ev, Location* loc) void mouse_up(XButtonEvent* ev, Location* loc) { - /* TODO: handle button 1 drag to resize, reposition, and move windows */ if (X.mode == M_TILE_RESIZE) { mons_tilemove(loc, ev->y_root - X.start_y); -- 2.52.0