about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--client.c58
-rw-r--r--event.c2
2 files changed, 32 insertions, 28 deletions
diff --git a/client.c b/client.c
index dff398a..cb5334e 100644
--- a/client.c
+++ b/client.c
@@ -11,6 +11,19 @@
 /* static functions */
 
 static void
+grabbutton(Client *c, unsigned int button, unsigned int modifier)
+{
+	XGrabButton(dpy, button, modifier, c->win, False, BUTTONMASK,
+			GrabModeAsync, GrabModeSync, None, None);
+	XGrabButton(dpy, button, modifier | LockMask, c->win, False, BUTTONMASK,
+			GrabModeAsync, GrabModeSync, None, None);
+	XGrabButton(dpy, button, modifier | numlockmask, c->win, False, BUTTONMASK,
+			GrabModeAsync, GrabModeSync, None, None);
+	XGrabButton(dpy, button, modifier | numlockmask | LockMask, c->win, False, BUTTONMASK,
+			GrabModeAsync, GrabModeSync, None, None);
+}
+
+static void
 resizetitle(Client *c)
 {
 	int i;
@@ -31,6 +44,15 @@ resizetitle(Client *c)
 
 }
 
+static void
+ungrabbutton(Client *c, unsigned int button, unsigned int modifier)
+{
+	XUngrabButton(dpy, button, modifier, c->win);
+	XUngrabButton(dpy, button, modifier | LockMask, c->win);
+	XUngrabButton(dpy, button, modifier | numlockmask, c->win);
+	XUngrabButton(dpy, button, modifier | numlockmask | LockMask, c->win);
+}
+
 static int
 xerrordummy(Display *dsply, XErrorEvent *ee)
 {
@@ -53,11 +75,14 @@ focus(Client *c)
 
 	if (!issel)
 		return;
-	if(sel && sel->ismax)
+	if(sel && sel->ismax && sel != c)
 		togglemax(NULL);
 	sel = c;
-	if(old && old != c)
+	if(old && old != c) {
+		grabbutton(old, AnyButton, 0);
 		drawtitle(old);
+	}
+	ungrabbutton(c, AnyButton, 0);
 	drawtitle(c);
 	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
 }
@@ -230,32 +255,9 @@ manage(Window w, XWindowAttributes *wa)
 	c->next = clients;
 	clients = c;
 
-	XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
-			GrabModeAsync, GrabModeSync, None, None);
-	XGrabButton(dpy, Button1, MODKEY | LockMask, c->win, False, BUTTONMASK,
-			GrabModeAsync, GrabModeSync, None, None);
-	XGrabButton(dpy, Button1, MODKEY | numlockmask, c->win, False, BUTTONMASK,
-			GrabModeAsync, GrabModeSync, None, None);
-	XGrabButton(dpy, Button1, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
-			GrabModeAsync, GrabModeSync, None, None);
-
-	XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
-			GrabModeAsync, GrabModeSync, None, None);
-	XGrabButton(dpy, Button2, MODKEY | LockMask, c->win, False, BUTTONMASK,
-			GrabModeAsync, GrabModeSync, None, None);
-	XGrabButton(dpy, Button2, MODKEY | numlockmask, c->win, False, BUTTONMASK,
-			GrabModeAsync, GrabModeSync, None, None);
-	XGrabButton(dpy, Button2, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
-			GrabModeAsync, GrabModeSync, None, None);
-
-	XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
-			GrabModeAsync, GrabModeSync, None, None);
-	XGrabButton(dpy, Button3, MODKEY | LockMask, c->win, False, BUTTONMASK,
-			GrabModeAsync, GrabModeSync, None, None);
-	XGrabButton(dpy, Button3, MODKEY | numlockmask, c->win, False, BUTTONMASK,
-			GrabModeAsync, GrabModeSync, None, None);
-	XGrabButton(dpy, Button3, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
-			GrabModeAsync, GrabModeSync, None, None);
+	grabbutton(c, Button1, MODKEY);
+	grabbutton(c, Button2, MODKEY);
+	grabbutton(c, Button3, MODKEY);
 
 	settags(c);
 	if(!c->isfloat)
diff --git a/event.c b/event.c
index 5209be3..c2288f4 100644
--- a/event.c
+++ b/event.c
@@ -119,6 +119,8 @@ buttonpress(XEvent *e)
 	}
 	else if((c = getclient(ev->window))) {
 		focus(c);
+		if(CLEANMASK(ev->state) == 0)
+			return;
 		switch(ev->button) {
 		default:
 			break;
='#n108'>108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160