From adaa28a6e600f636f5e86244ccef69e98419ba1a Mon Sep 17 00:00:00 2001 From: "Anselm R. Garbe" Date: Sat, 15 Jul 2006 17:00:56 +0200 Subject: proceeded with cleaning up, sorting functions, etc --- event.c | 266 +++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 128 insertions(+), 138 deletions(-) (limited to 'event.c') diff --git a/event.c b/event.c index 59c9bb9..2d8a728 100644 --- a/event.c +++ b/event.c @@ -2,17 +2,12 @@ * (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) @@ -54,130 +49,10 @@ 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 void -resizemouse(Client *c) -{ - XEvent ev; - int ocx, ocy; - - ocx = c->x; - ocy = c->y; - if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, - None, cursor[CurResize], CurrentTime) != GrabSuccess) - return; - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); - for(;;) { - XMaskEvent(dpy, MouseMask | ExposureMask, &ev); - 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); - break; - case ButtonRelease: - XUngrabPointer(dpy, CurrentTime); - return; - } - } -} - -static void -movemouse(Client *c) -{ - XEvent ev; - int x1, y1, ocx, ocy, di; - unsigned int dui; - Window dummy; +/* static functions */ - ocx = c->x; - ocy = c->y; - if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, - None, cursor[CurMove], CurrentTime) != GrabSuccess) - return; - XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); - for(;;) { - XMaskEvent(dpy, MouseMask | ExposureMask, &ev); - 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); - break; - case ButtonRelease: - XUngrabPointer(dpy, CurrentTime); - return; - } - } -} +static void movemouse(Client *c); +static void resizemouse(Client *c); static void buttonpress(XEvent *e) @@ -279,15 +154,6 @@ enternotify(XEvent *e) issel = True; } -static void -leavenotify(XEvent *e) -{ - XCrossingEvent *ev = &e->xcrossing; - - if((ev->window == root) && !ev->same_screen) - issel = True; -} - static void expose(XEvent *e) { @@ -302,6 +168,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) { @@ -321,6 +213,40 @@ maprequest(XEvent *e) manage(ev->window, &wa); } +static void +movemouse(Client *c) +{ + XEvent ev; + 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[CurMove], CurrentTime) != GrabSuccess) + return; + XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); + for(;;) { + XMaskEvent(dpy, MouseMask | ExposureMask, &ev); + 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); + break; + case ButtonRelease: + XUngrabPointer(dpy, CurrentTime); + return; + } + } +} + static void propertynotify(XEvent *e) { @@ -354,6 +280,40 @@ propertynotify(XEvent *e) } } +static void +resizemouse(Client *c) +{ + XEvent ev; + int ocx, ocy; + + ocx = c->x; + ocy = c->y; + if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, + None, cursor[CurResize], CurrentTime) != GrabSuccess) + return; + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); + for(;;) { + XMaskEvent(dpy, MouseMask | ExposureMask, &ev); + 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); + break; + case ButtonRelease: + XUngrabPointer(dpy, CurrentTime); + return; + } + } +} + static void unmapnotify(XEvent *e) { @@ -363,3 +323,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); + } +} -- cgit v1.2.3-13-gbd6f