summary refs log tree commit diff
diff options
context:
space:
mode:
authorokan <okan>2016-10-03 13:52:17 +0000
committerokan <okan>2016-10-03 13:52:17 +0000
commit792f85cde97742d0c580ee2354044870d0f8754f (patch)
treead31325524b656d1232bd3b2f50cad837bb38548
parenta8a111dffd2752fc5be7773a67d03306dd92d05e (diff)
downloadcwm-792f85cde97742d0c580ee2354044870d0f8754f.tar.gz
cwm-792f85cde97742d0c580ee2354044870d0f8754f.tar.xz
cwm-792f85cde97742d0c580ee2354044870d0f8754f.zip
For both kb and mouse move, it is possible to grab a client and move it
completely off the screen/region; instead, if the pointer is outside of
the client bounds, warp the pointer to the closest edge before moving.
-rw-r--r--kbfunc.c14
-rw-r--r--mousefunc.c18
2 files changed, 27 insertions, 5 deletions
diff --git a/kbfunc.c b/kbfunc.c
index c5b0083..fc2bc8b 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -95,12 +95,24 @@ kbfunc_client_move(struct client_ctx *cc, union arg *arg)
 {
 	struct screen_ctx	*sc = cc->sc;
 	struct geom		 area;
-	int			 x, y;
+	int			 x, y, px, py;
 	unsigned int		 mx = 0, my = 0;
 
 	if (cc->flags & CLIENT_FREEZE)
 		return;
 
+	xu_ptr_getpos(cc->win, &px, &py);
+	if (px < 0)
+		px = 0;
+	else if (px > cc->geom.w)
+		px = cc->geom.w;
+	if (py < 0)
+		py = 0;
+	else if (py > cc->geom.h)
+		py = cc->geom.h;
+
+	xu_ptr_setpos(cc->win, px, py);
+
 	kbfunc_amount(arg->i, Conf.mamount, &mx, &my);
 
 	cc->geom.x += mx;
diff --git a/mousefunc.c b/mousefunc.c
index cd7a897..2bf19db 100644
--- a/mousefunc.c
+++ b/mousefunc.c
@@ -45,13 +45,13 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg)
 	client_raise(cc);
 	client_ptrsave(cc);
 
+	xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h);
+
 	if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
 	    GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE],
 	    CurrentTime) != GrabSuccess)
 		return;
 
-	xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h);
-
 	for (;;) {
 		XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev);
 
@@ -101,13 +101,23 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg)
 	if (cc->flags & CLIENT_FREEZE)
 		return;
 
+	xu_ptr_getpos(cc->win, &px, &py);
+	if (px < 0) 
+		px = 0;
+	else if (px > cc->geom.w)
+		px = cc->geom.w;
+	if (py < 0)
+		py = 0;
+	else if (py > cc->geom.h)
+		py = cc->geom.h;
+
+	xu_ptr_setpos(cc->win, px, py);
+
 	if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
 	    GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE],
 	    CurrentTime) != GrabSuccess)
 		return;
 
-	xu_ptr_getpos(cc->win, &px, &py);
-
 	for (;;) {
 		XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev);