X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=event.c;h=ecbb8d285d7109caa0591a1d49ff39296f82a23d;hp=59c9bb947cf500c0e5570e52d102706516701204;hb=901b3ed9b7e3e4c7542797301ae2442938bcea20;hpb=dba23062bad40afb1a90f60b6897cf9e1ca5035b diff --git a/event.c b/event.c index 59c9bb9..ecbb8d2 100644 --- a/event.c +++ b/event.c @@ -2,25 +2,20 @@ * (C)opyright MMVI Anselm R. Garbe * See LICENSE file for license details. */ +#include "dwm.h" -#include -#include #include -#include -#include #include #include -#include "dwm.h" - #define ButtonMask (ButtonPressMask | ButtonReleaseMask) #define MouseMask (ButtonMask | PointerMotionMask) /********** CUSTOMIZE **********/ const char *term[] = { - "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn", - "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL + "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-cr", "white", + "-fn", "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", NULL }; const char *browse[] = { "firefox", NULL }; const char *xlock[] = { "xlock", NULL }; @@ -54,89 +49,34 @@ Key key[] = { /********** CUSTOMIZE **********/ -/* local functions */ -static void buttonpress(XEvent *e); -static void configurerequest(XEvent *e); -static void destroynotify(XEvent *e); -static void enternotify(XEvent *e); -static void leavenotify(XEvent *e); -static void expose(XEvent *e); -static void keypress(XEvent *e); -static void maprequest(XEvent *e); -static void propertynotify(XEvent *e); -static void unmapnotify(XEvent *e); - -void (*handler[LASTEvent]) (XEvent *) = { - [ButtonPress] = buttonpress, - [ConfigureRequest] = configurerequest, - [DestroyNotify] = destroynotify, - [EnterNotify] = enternotify, - [LeaveNotify] = leavenotify, - [Expose] = expose, - [KeyPress] = keypress, - [MapRequest] = maprequest, - [PropertyNotify] = propertynotify, - [UnmapNotify] = unmapnotify -}; - -void -grabkeys() -{ - static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 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); - XGrabKey(dpy, code, key[i].mod, root, True, - GrabModeAsync, GrabModeAsync); - } -} - -static void -keypress(XEvent *e) -{ - XKeyEvent *ev = &e->xkey; - static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; - unsigned int i; - KeySym keysym; - - keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); - for(i = 0; i < len; i++) - if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { - if(key[i].func) - key[i].func(&key[i].arg); - return; - } -} +/* static functions */ static void -resizemouse(Client *c) +movemouse(Client *c) { XEvent ev; - int ocx, ocy; + int x1, y1, ocx, ocy, di; + unsigned int dui; + Window dummy; ocx = c->x; ocy = c->y; if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, - None, cursor[CurResize], CurrentTime) != GrabSuccess) + None, cursor[CurMove], CurrentTime) != GrabSuccess) return; - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); + XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); for(;;) { XMaskEvent(dpy, MouseMask | ExposureMask, &ev); - switch(ev.type) { + switch (ev.type) { default: break; case Expose: handler[Expose](&ev); break; case MotionNotify: - XFlush(dpy); - c->w = abs(ocx - ev.xmotion.x); - 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; - resize(c, True); + XSync(dpy, False); + c->x = ocx + (ev.xmotion.x - x1); + c->y = ocy + (ev.xmotion.y - y1); + resize(c, False); break; case ButtonRelease: XUngrabPointer(dpy, CurrentTime); @@ -146,31 +86,31 @@ resizemouse(Client *c) } static void -movemouse(Client *c) +resizemouse(Client *c) { XEvent ev; - int x1, y1, ocx, ocy, di; - unsigned int dui; - Window dummy; + int ocx, ocy; ocx = c->x; ocy = c->y; if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, - None, cursor[CurMove], CurrentTime) != GrabSuccess) + None, cursor[CurResize], CurrentTime) != GrabSuccess) return; - XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); for(;;) { XMaskEvent(dpy, MouseMask | ExposureMask, &ev); - switch (ev.type) { + switch(ev.type) { default: break; case Expose: handler[Expose](&ev); break; case MotionNotify: - XFlush(dpy); - c->x = ocx + (ev.xmotion.x - x1); - c->y = ocy + (ev.xmotion.y - y1); - resize(c, False); + XSync(dpy, False); + c->w = abs(ocx - ev.xmotion.x); + 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; + resize(c, True); break; case ButtonRelease: XUngrabPointer(dpy, CurrentTime); @@ -188,18 +128,34 @@ buttonpress(XEvent *e) Client *c; if(barwin == ev->window) { - x = (arrange == dofloat) ? textw("~") : 0; - for(a.i = 0; a.i < TLast; a.i++) { - x += textw(tags[a.i]); - if(ev->x < x) { - view(&a); - break; + switch(ev->button) { + default: + x = 0; + for(a.i = 0; a.i < TLast; a.i++) { + x += textw(tags[a.i]); + if(ev->x < x) { + view(&a); + break; + } } + break; + case Button4: + a.i = (tsel + 1 < TLast) ? tsel + 1 : 0; + view(&a); + break; + case Button5: + a.i = (tsel - 1 >= 0) ? tsel - 1 : TLast - 1; + view(&a); + break; } } else if((c = getclient(ev->window))) { - if(arrange == dotile && !c->dofloat) + if(arrange == dotile && !c->isfloat) { + if((ev->state & ControlMask) && (ev->button == Button1)) + zoom(NULL); return; + } + /* floating windows */ higher(c); switch(ev->button) { default: @@ -251,7 +207,7 @@ configurerequest(XEvent *e) ev->value_mask &= ~CWStackMode; ev->value_mask |= CWBorderWidth; XConfigureWindow(dpy, ev->window, ev->value_mask, &wc); - XFlush(dpy); + XSync(dpy, False); } static void @@ -280,15 +236,6 @@ enternotify(XEvent *e) } static void -leavenotify(XEvent *e) -{ - XCrossingEvent *ev = &e->xcrossing; - - if((ev->window == root) && !ev->same_screen) - issel = True; -} - -static void expose(XEvent *e) { XExposeEvent *ev = &e->xexpose; @@ -303,6 +250,32 @@ expose(XEvent *e) } static void +keypress(XEvent *e) +{ + XKeyEvent *ev = &e->xkey; + static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; + unsigned int i; + KeySym keysym; + + keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); + for(i = 0; i < len; i++) + if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { + if(key[i].func) + key[i].func(&key[i].arg); + return; + } +} + +static void +leavenotify(XEvent *e) +{ + XCrossingEvent *ev = &e->xcrossing; + + if((ev->window == root) && !ev->same_screen) + issel = True; +} + +static void maprequest(XEvent *e) { XMapRequestEvent *ev = &e->xmaprequest; @@ -332,7 +305,7 @@ propertynotify(XEvent *e) return; /* ignore */ if((c = getclient(ev->window))) { - if(ev->atom == wm_atom[WMProtocols]) { + if(ev->atom == wmatom[WMProtocols]) { c->proto = getproto(c->win); return; } @@ -340,14 +313,14 @@ propertynotify(XEvent *e) default: break; case XA_WM_TRANSIENT_FOR: XGetTransientForHint(dpy, c->win, &trans); - if(!c->dofloat && (c->dofloat = (trans != 0))) + if(!c->isfloat && (c->isfloat = (trans != 0))) arrange(NULL); break; case XA_WM_NORMAL_HINTS: setsize(c); break; } - if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) { + if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { settitle(c); drawtitle(c); } @@ -363,3 +336,33 @@ unmapnotify(XEvent *e) if((c = getclient(ev->window))) unmanage(c); } + +/* extern functions */ + +void (*handler[LASTEvent]) (XEvent *) = { + [ButtonPress] = buttonpress, + [ConfigureRequest] = configurerequest, + [DestroyNotify] = destroynotify, + [EnterNotify] = enternotify, + [LeaveNotify] = leavenotify, + [Expose] = expose, + [KeyPress] = keypress, + [MapRequest] = maprequest, + [PropertyNotify] = propertynotify, + [UnmapNotify] = unmapnotify +}; + +void +grabkeys() +{ + static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 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); + XGrabKey(dpy, code, key[i].mod, root, True, + GrabModeAsync, GrabModeAsync); + } +}