From e4770d93955aea01a7f2ccd0e95462fa5de21732 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 5 Apr 2020 14:54:17 -0400 Subject: [PATCH] moved mouse warping functions to mouse.c --- anvil.c | 2 +- anvil.h | 4 ++-- client.c | 6 ------ mons.c | 3 ++- mouse.c | 18 +++++++++++++++++- tile.c | 2 +- util.c | 9 --------- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/anvil.c b/anvil.c index b5d6cf1..f533c85 100644 --- a/anvil.c +++ b/anvil.c @@ -95,7 +95,7 @@ static void xconfigrequest(XEvent* e) client_adjust(loc.client); if (X.mode == M_RESIZE && Focused == loc.client) { - warp_mouse(loc.client); + mouse_tocorner(loc.client); } } else diff --git a/anvil.h b/anvil.h index db02775..4cf1199 100644 --- a/anvil.h +++ b/anvil.h @@ -169,12 +169,13 @@ void client_show(Client* c, int show); void client_readprops(Client* c); void client_shade(Client* c); void client_setshade(Client* c, int shade); -void client_warpmouse(Client* c); /* mouse.c */ void mouse_down(XButtonEvent* ev, Location* loc); void mouse_up(XButtonEvent* ev, Location* loc); void mouse_drag(XMotionEvent* ev, Location* loc); +void mouse_tocorner(Client* c); +void mouse_totitle(Client* c); /* tile.c */ void monocled_add(Monitor* mon, Column* col, Client* c); @@ -198,5 +199,4 @@ void* ecalloc(size_t n, size_t sz); void xfree(void* p); Atom atom(char* str); void sendmsg(Window win, Atom proto, Atom type); -void warp_mouse(Client* c); void get_mouse(int* ptrx, int* ptry); diff --git a/client.c b/client.c index 3be4022..ccc8dc9 100644 --- a/client.c +++ b/client.c @@ -204,9 +204,3 @@ void client_setshade(Client* c, int shade) XUnmapWindow(X.disp, c->win); } } - -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)); -} diff --git a/mons.c b/mons.c index 93002dd..acb1132 100644 --- a/mons.c +++ b/mons.c @@ -94,7 +94,7 @@ void mons_addclient(Client* c) { Monitor* mon = pickmon(); add_client(mon, c, PtrX); - client_warpmouse(c); + mouse_totitle(c); } void mons_delclient(Location* loc) @@ -346,6 +346,7 @@ void mons_tilemove(Location* loc, int hdiff) { stacked_addheight(loc->monitor, loc->column, loc->client, hdiff); } + mouse_totitle(loc->client); } void mons_activate(Window win) diff --git a/mouse.c b/mouse.c index 548a77d..e666709 100644 --- a/mouse.c +++ b/mouse.c @@ -15,7 +15,7 @@ static void float_click(XButtonEvent* ev, Location* loc) if ((ev->button == Button1) && (ev->y > MIN_HEIGHT)) { X.mode = M_RESIZE; - warp_mouse(loc->client); + mouse_tocorner(loc->client); } else if (ev->button == Button2) { @@ -165,3 +165,19 @@ void mouse_drag(XMotionEvent* ev, Location* loc) float_drag(ev, loc); } } + +void mouse_tocorner(Client* c) +{ + int new_w = c->w - BORDER_WIDTH/2; + int new_h = c->h - BORDER_WIDTH/2; + XWarpPointer(X.disp, None, c->frame, 0, 0, 0, 0, new_w, new_h); + X.last_x = c->x + new_w; + X.last_y = c->y + new_h; +} + +void mouse_totitle(Client* c) +{ + XWarpPointer(X.disp, None, X.root, 0, 0, 0, 0, (c->x + c->w/2), c->y + (MIN_HEIGHT/2)); +} + + diff --git a/tile.c b/tile.c index af2b205..742d031 100644 --- a/tile.c +++ b/tile.c @@ -156,7 +156,7 @@ void stacked_addheight(Monitor* mon, Column* col, Client* c, int amount) client_setshade(prev, (prev->h <= MIN_HEIGHT)); client_setshade(c, (c->h <= MIN_HEIGHT)); client_adjust(prev); - client_warpmouse(c); + mouse_totitle(c); client_adjust(c); } } diff --git a/util.c b/util.c index 08c6989..8b0b77c 100644 --- a/util.c +++ b/util.c @@ -51,15 +51,6 @@ void sendmsg(Window win, Atom proto, Atom type) XSync(X.disp, False); } -void warp_mouse(Client* c) -{ - int new_w = c->w - BORDER_WIDTH/2; - int new_h = c->h - BORDER_WIDTH/2; - XWarpPointer(X.disp, None, c->frame, 0, 0, 0, 0, new_w, new_h); - X.last_x = c->x + new_w; - X.last_y = c->y + new_h; -} - void get_mouse(int* ptrx, int* ptry) { Window root = 0, child = 0; -- 2.52.0