X-Git-Url: https://git.xinqibao.xyz/dwm.git/blobdiff_plain/fee8df6ccf3ab1494421d422af252f7b3da3a811..82fed986f9f09ddf973f182b30946bed9c2424cd:/event.c

diff --git a/event.c b/event.c
index 83e1b86..418e986 100644
--- a/event.c
+++ b/event.c
@@ -1,5 +1,4 @@
-/*
- * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
+/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
  * See LICENSE file for license details.
  */
 #include "dwm.h"
@@ -19,6 +18,7 @@ typedef struct {
 KEYS
 
 #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
+#define MOUSEMASK		(BUTTONMASK | PointerMotionMask)
 
 static void
 movemouse(Client *c) {
@@ -35,20 +35,30 @@ movemouse(Client *c) {
 	c->ismax = False;
 	XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
 	for(;;) {
-		XMaskEvent(dpy, MOUSEMASK | ExposureMask, &ev);
+		XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
 		switch (ev.type) {
 		case ButtonRelease:
-			resize(c, True, TopLeft);
+			resize(c, True);
 			XUngrabPointer(dpy, CurrentTime);
 			return;
+		case ConfigureRequest:
 		case Expose:
-			handler[Expose](&ev);
+		case MapRequest:
+			handler[ev.type](&ev);
 			break;
 		case MotionNotify:
 			XSync(dpy, False);
 			c->x = ocx + (ev.xmotion.x - x1);
 			c->y = ocy + (ev.xmotion.y - y1);
-			resize(c, False, TopLeft);
+			if(abs(wax + c->x) < SNAP)
+				c->x = wax;
+			else if(abs((wax + waw) - (c->x + c->w + 2 * c->border)) < SNAP)
+				c->x = wax + waw - c->w - 2 * c->border;
+			if(abs(way - c->y) < SNAP)
+				c->y = way;
+			else if(abs((way + wah) - (c->y + c->h + 2 * c->border)) < SNAP)
+				c->y = way + wah - c->h - 2 * c->border;
+			resize(c, False);
 			break;
 		}
 	}
@@ -58,39 +68,34 @@ static void
 resizemouse(Client *c) {
 	int ocx, ocy;
 	int nw, nh;
-	Corner sticky;
 	XEvent ev;
 
 	ocx = c->x;
 	ocy = c->y;
 	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
-				None, cursor[CurResize], CurrentTime) != GrabSuccess)
+			None, cursor[CurResize], CurrentTime) != GrabSuccess)
 		return;
 	c->ismax = False;
-	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
+	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
 	for(;;) {
-		XMaskEvent(dpy, MOUSEMASK | ExposureMask, &ev);
+		XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask , &ev);
 		switch(ev.type) {
 		case ButtonRelease:
-			resize(c, True, TopLeft);
+			resize(c, True);
 			XUngrabPointer(dpy, CurrentTime);
 			return;
+		case ConfigureRequest:
 		case Expose:
-			handler[Expose](&ev);
+		case MapRequest:
+			handler[ev.type](&ev);
 			break;
 		case MotionNotify:
 			XSync(dpy, False);
-			if((nw = abs(ocx - ev.xmotion.x)))
-				c->w = nw;
-			if((nh = abs(ocy - ev.xmotion.y)))
-				c->h = nh;
-			c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
-			c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
-			if(ocx <= ev.xmotion.x)
-				sticky = (ocy <= ev.xmotion.y) ? TopLeft : BotLeft;
-			else
-				sticky = (ocy <= ev.xmotion.y) ? TopRight : BotRight;
-			resize(c, True, sticky);
+			nw = ev.xmotion.x - ocx - 2 * c->border + 1;
+			c->w = nw > 0 ? nw : 1;
+			nh = ev.xmotion.y - ocy - 2 * c->border + 1;
+			c->h = nh > 0 ? nh : 1;
+			resize(c, True);
 			break;
 		}
 	}
@@ -123,10 +128,20 @@ buttonpress(XEvent *e) {
 				return;
 			}
 		}
-		if(ev->x < x + bmw) {
-			if(ev->button == Button1)
+		if(ev->x < x + bmw)
+			switch(ev->button) {
+			case Button1:
 				togglemode(NULL);
-		}
+				break;
+			case Button4:
+				a.i = 1;
+				incnmaster(&a);
+				break;
+			case Button5:
+				a.i = -1;
+				incnmaster(&a);
+				break;
+			}
 	}
 	else if((c = getclient(ev->window))) {
 		focus(c);
@@ -138,7 +153,8 @@ buttonpress(XEvent *e) {
 		}
 		else if(ev->button == Button2)
 			zoom(NULL);
-		else if(ev->button == Button3 && (arrange == dofloat || c->isfloat)) {
+		else if(ev->button == Button3 && (arrange == dofloat || c->isfloat) &&
+				!c->isfixed) {
 			restack();
 			resizemouse(c);
 		}
@@ -154,7 +170,6 @@ configurerequest(XEvent *e) {
 
 	if((c = getclient(ev->window))) {
 		c->ismax = False;
-		gravitate(c, True);
 		if(ev->value_mask & CWX)
 			c->x = ev->x;
 		if(ev->value_mask & CWY)
@@ -165,7 +180,6 @@ configurerequest(XEvent *e) {
 			c->h = ev->height;
 		if(ev->value_mask & CWBorderWidth)
 			c->border = ev->border_width;
-		gravitate(c, False);
 		wc.x = c->x;
 		wc.y = c->y;
 		wc.width = c->w;
@@ -177,12 +191,12 @@ configurerequest(XEvent *e) {
 			configure(c);
 		XSync(dpy, False);
 		if(c->isfloat) {
-			resize(c, False, TopLeft);
+			resize(c, False);
 			if(!isvisible(c))
-				ban(c);
+				XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
 		}
 		else
-			arrange(NULL);
+			arrange();
 	}
 	else {
 		wc.x = ev->x;
@@ -213,32 +227,28 @@ enternotify(XEvent *e) {
 
 	if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
 		return;
-
-	if(((c = getclient(ev->window)) || (c = getctitle(ev->window))) && isvisible(c))
+	if((c = getclient(ev->window)) && isvisible(c))
 		focus(c);
 	else if(ev->window == root) {
-		issel = True;
-		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
-		drawall();
+		selscreen = True;
+		for(c = stack; c && !isvisible(c); c = c->snext);
+		focus(c);
 	}
 }
 
 static void
 expose(XEvent *e) {
-	Client *c;
 	XExposeEvent *ev = &e->xexpose;
 
 	if(ev->count == 0) {
 		if(barwin == ev->window)
 			drawstatus();
-		else if((c = getctitle(ev->window)))
-			drawtitle(c);
 	}
 }
 
 static void
 keypress(XEvent *e) {
-	static unsigned int len = sizeof(key) / sizeof(key[0]);
+	static unsigned int len = sizeof key / sizeof key[0];
 	unsigned int i;
 	KeySym keysym;
 	XKeyEvent *ev = &e->xkey;
@@ -250,7 +260,6 @@ keypress(XEvent *e) {
 		{
 			if(key[i].func)
 				key[i].func(&key[i].arg);
-			return;
 		}
 	}
 }
@@ -260,8 +269,8 @@ leavenotify(XEvent *e) {
 	XCrossingEvent *ev = &e->xcrossing;
 
 	if((ev->window == root) && !ev->same_screen) {
-		issel = False;
-		drawall();
+		selscreen = False;
+		focus(NULL);
 	}
 }
 
@@ -281,13 +290,11 @@ maprequest(XEvent *e) {
 
 	if(!XGetWindowAttributes(dpy, ev->window, &wa))
 		return;
-
 	if(wa.override_redirect) {
 		XSelectInput(dpy, ev->window,
 				(StructureNotifyMask | PropertyChangeMask));
 		return;
 	}
-
 	if(!getclient(ev->window))
 		manage(ev->window, &wa);
 }
@@ -300,7 +307,6 @@ propertynotify(XEvent *e) {
 
 	if(ev->state == PropertyDelete)
 		return; /* ignore */
-
 	if((c = getclient(ev->window))) {
 		if(ev->atom == wmatom[WMProtocols]) {
 			c->proto = getproto(c->win);
@@ -311,16 +317,16 @@ propertynotify(XEvent *e) {
 			case XA_WM_TRANSIENT_FOR:
 				XGetTransientForHint(dpy, c->win, &trans);
 				if(!c->isfloat && (c->isfloat = (trans != 0)))
-					arrange(NULL);
+					arrange();
 				break;
 			case XA_WM_NORMAL_HINTS:
-				updatesize(c);
+				updatesizehints(c);
 				break;
 		}
 		if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
 			updatetitle(c);
-			resizetitle(c);
-			drawtitle(c);
+			if(c == sel)
+				drawstatus();
 		}
 	}
 }
@@ -352,7 +358,7 @@ void (*handler[LASTEvent]) (XEvent *) = {
 
 void
 grabkeys(void) {
-	static unsigned int len = sizeof(key) / sizeof(key[0]);
+	static unsigned int len = sizeof key / sizeof key[0];
 	unsigned int i;
 	KeyCode code;