X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=event.c;h=4357eaee441d98c687a0359336d0622d70ca3077;hb=28a52197c43136945defebe1e8be82812a0e53cf;hp=c3169aa7001c3434f214028d6371c38985f048c4;hpb=92e55c7c53cb808b584982ac8f6d69112d713fab;p=dwm.git diff --git a/event.c b/event.c index c3169aa..4357eae 100644 --- a/event.c +++ b/event.c @@ -58,6 +58,7 @@ static void resizemouse(Client *c) { int ocx, ocy; + int nw, nh; Corner sticky; XEvent ev; @@ -76,8 +77,10 @@ resizemouse(Client *c) break; case MotionNotify: XSync(dpy, False); - c->w = abs(ocx - ev.xmotion.x); - c->h = abs(ocy - ev.xmotion.y); + if((nw = abs(ocx - ev.xmotion.x))) + c->w = abs(ocx - ev.xmotion.x); + if((nh = abs(ocy - ev.xmotion.y))) + c->h = abs(ocy - ev.xmotion.y); 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) @@ -102,23 +105,16 @@ buttonpress(XEvent *e) XButtonPressedEvent *ev = &e->xbutton; if(barwin == ev->window) { - switch(ev->button) { - default: - x = 0; - for(a.i = 0; a.i < ntags; a.i++) { - x += textw(tags[a.i]); - if(ev->x < x) { + x = 0; + for(a.i = 0; a.i < ntags; a.i++) { + x += textw(tags[a.i]); + if(ev->x < x) { + if(ev->button == Button3) + toggleview(&a); + else view(&a); - break; - } + return; } - break; - case Button4: - viewnext(&a); - break; - case Button5: - viewprev(&a); - break; } } else if((c = getclient(ev->window))) { @@ -128,16 +124,16 @@ buttonpress(XEvent *e) break; case Button1: if(!c->ismax && (arrange == dofloat || c->isfloat)) { - higher(c); + restack(c); movemouse(c); } break; case Button2: - lower(c); + zoom(NULL); break; case Button3: if(!c->ismax && (arrange == dofloat || c->isfloat)) { - higher(c); + restack(c); resizemouse(c); } break; @@ -146,18 +142,6 @@ buttonpress(XEvent *e) } static void -clientmessage(XEvent *e) -{ - Client *c; - XClientMessageEvent *ev = &e->xclient; - - if(ev->message_type == netatom[NetActiveWindow]) { - if((c = getclient(ev->window)) && c->tags[tsel]) - focus(c); - } -} - -static void configurerequest(XEvent *e) { Client *c; @@ -235,13 +219,16 @@ enternotify(XEvent *e) Client *c; XCrossingEvent *ev = &e->xcrossing; - if(ev->detail == NotifyInferior) + if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) return; if((c = getclient(ev->window)) || (c = getctitle(ev->window))) focus(c); - else if(ev->window == root) + else if(ev->window == root) { issel = True; + XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + drawall(); + } } static void @@ -281,8 +268,10 @@ leavenotify(XEvent *e) { XCrossingEvent *ev = &e->xcrossing; - if((ev->window == root) && !ev->same_screen) - issel = True; + if((ev->window == root) && !ev->same_screen) { + issel = False; + drawall(); + } } static void @@ -351,7 +340,6 @@ unmapnotify(XEvent *e) void (*handler[LASTEvent]) (XEvent *) = { [ButtonPress] = buttonpress, - [ClientMessage] = clientmessage, [ConfigureRequest] = configurerequest, [DestroyNotify] = destroynotify, [EnterNotify] = enternotify, @@ -382,3 +370,19 @@ grabkeys() GrabModeAsync, GrabModeAsync); } } + +void +ungrabkeys() +{ + static unsigned int len = sizeof(key) / sizeof(key[0]); + unsigned int i; + KeyCode code; + + for(i = 0; i < len; i++) { + code = XKeysymToKeycode(dpy, key[i].keysym); + XUngrabKey(dpy, code, key[i].mod, root); + XUngrabKey(dpy, code, key[i].mod | LockMask, root); + XUngrabKey(dpy, code, key[i].mod | NUMLOCKMASK, root); + XUngrabKey(dpy, code, key[i].mod | NUMLOCKMASK | LockMask, root); + } +}