dwm-meillo
diff event.c @ 76:4bd49f404f10
proceeded with cleaning up, sorting functions, etc
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Sat, 15 Jul 2006 17:00:56 +0200 |
parents | f08271b7cb20 |
children | 38c8f7f7d401 |
line diff
1.1 --- a/event.c Sat Jul 15 16:30:50 2006 +0200 1.2 +++ b/event.c Sat Jul 15 17:00:56 2006 +0200 1.3 @@ -2,17 +2,12 @@ 1.4 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> 1.5 * See LICENSE file for license details. 1.6 */ 1.7 +#include "dwm.h" 1.8 1.9 -#include <fcntl.h> 1.10 -#include <stdio.h> 1.11 #include <stdlib.h> 1.12 -#include <string.h> 1.13 -#include <unistd.h> 1.14 #include <X11/keysym.h> 1.15 #include <X11/Xatom.h> 1.16 1.17 -#include "dwm.h" 1.18 - 1.19 #define ButtonMask (ButtonPressMask | ButtonReleaseMask) 1.20 #define MouseMask (ButtonMask | PointerMotionMask) 1.21 1.22 @@ -54,130 +49,10 @@ 1.23 1.24 /********** CUSTOMIZE **********/ 1.25 1.26 -/* local functions */ 1.27 -static void buttonpress(XEvent *e); 1.28 -static void configurerequest(XEvent *e); 1.29 -static void destroynotify(XEvent *e); 1.30 -static void enternotify(XEvent *e); 1.31 -static void leavenotify(XEvent *e); 1.32 -static void expose(XEvent *e); 1.33 -static void keypress(XEvent *e); 1.34 -static void maprequest(XEvent *e); 1.35 -static void propertynotify(XEvent *e); 1.36 -static void unmapnotify(XEvent *e); 1.37 +/* static functions */ 1.38 1.39 -void (*handler[LASTEvent]) (XEvent *) = { 1.40 - [ButtonPress] = buttonpress, 1.41 - [ConfigureRequest] = configurerequest, 1.42 - [DestroyNotify] = destroynotify, 1.43 - [EnterNotify] = enternotify, 1.44 - [LeaveNotify] = leavenotify, 1.45 - [Expose] = expose, 1.46 - [KeyPress] = keypress, 1.47 - [MapRequest] = maprequest, 1.48 - [PropertyNotify] = propertynotify, 1.49 - [UnmapNotify] = unmapnotify 1.50 -}; 1.51 - 1.52 -void 1.53 -grabkeys() 1.54 -{ 1.55 - static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; 1.56 - unsigned int i; 1.57 - KeyCode code; 1.58 - 1.59 - for(i = 0; i < len; i++) { 1.60 - code = XKeysymToKeycode(dpy, key[i].keysym); 1.61 - XUngrabKey(dpy, code, key[i].mod, root); 1.62 - XGrabKey(dpy, code, key[i].mod, root, True, 1.63 - GrabModeAsync, GrabModeAsync); 1.64 - } 1.65 -} 1.66 - 1.67 -static void 1.68 -keypress(XEvent *e) 1.69 -{ 1.70 - XKeyEvent *ev = &e->xkey; 1.71 - static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; 1.72 - unsigned int i; 1.73 - KeySym keysym; 1.74 - 1.75 - keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); 1.76 - for(i = 0; i < len; i++) 1.77 - if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { 1.78 - if(key[i].func) 1.79 - key[i].func(&key[i].arg); 1.80 - return; 1.81 - } 1.82 -} 1.83 - 1.84 -static void 1.85 -resizemouse(Client *c) 1.86 -{ 1.87 - XEvent ev; 1.88 - int ocx, ocy; 1.89 - 1.90 - ocx = c->x; 1.91 - ocy = c->y; 1.92 - if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 1.93 - None, cursor[CurResize], CurrentTime) != GrabSuccess) 1.94 - return; 1.95 - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); 1.96 - for(;;) { 1.97 - XMaskEvent(dpy, MouseMask | ExposureMask, &ev); 1.98 - switch(ev.type) { 1.99 - default: break; 1.100 - case Expose: 1.101 - handler[Expose](&ev); 1.102 - break; 1.103 - case MotionNotify: 1.104 - XFlush(dpy); 1.105 - c->w = abs(ocx - ev.xmotion.x); 1.106 - c->h = abs(ocy - ev.xmotion.y); 1.107 - c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w; 1.108 - c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h; 1.109 - resize(c, True); 1.110 - break; 1.111 - case ButtonRelease: 1.112 - XUngrabPointer(dpy, CurrentTime); 1.113 - return; 1.114 - } 1.115 - } 1.116 -} 1.117 - 1.118 -static void 1.119 -movemouse(Client *c) 1.120 -{ 1.121 - XEvent ev; 1.122 - int x1, y1, ocx, ocy, di; 1.123 - unsigned int dui; 1.124 - Window dummy; 1.125 - 1.126 - ocx = c->x; 1.127 - ocy = c->y; 1.128 - if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 1.129 - None, cursor[CurMove], CurrentTime) != GrabSuccess) 1.130 - return; 1.131 - XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); 1.132 - for(;;) { 1.133 - XMaskEvent(dpy, MouseMask | ExposureMask, &ev); 1.134 - switch (ev.type) { 1.135 - default: break; 1.136 - case Expose: 1.137 - handler[Expose](&ev); 1.138 - break; 1.139 - case MotionNotify: 1.140 - XFlush(dpy); 1.141 - c->x = ocx + (ev.xmotion.x - x1); 1.142 - c->y = ocy + (ev.xmotion.y - y1); 1.143 - resize(c, False); 1.144 - break; 1.145 - case ButtonRelease: 1.146 - XUngrabPointer(dpy, CurrentTime); 1.147 - return; 1.148 - } 1.149 - } 1.150 -} 1.151 +static void movemouse(Client *c); 1.152 +static void resizemouse(Client *c); 1.153 1.154 static void 1.155 buttonpress(XEvent *e) 1.156 @@ -280,15 +155,6 @@ 1.157 } 1.158 1.159 static void 1.160 -leavenotify(XEvent *e) 1.161 -{ 1.162 - XCrossingEvent *ev = &e->xcrossing; 1.163 - 1.164 - if((ev->window == root) && !ev->same_screen) 1.165 - issel = True; 1.166 -} 1.167 - 1.168 -static void 1.169 expose(XEvent *e) 1.170 { 1.171 XExposeEvent *ev = &e->xexpose; 1.172 @@ -303,6 +169,32 @@ 1.173 } 1.174 1.175 static void 1.176 +keypress(XEvent *e) 1.177 +{ 1.178 + XKeyEvent *ev = &e->xkey; 1.179 + static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; 1.180 + unsigned int i; 1.181 + KeySym keysym; 1.182 + 1.183 + keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); 1.184 + for(i = 0; i < len; i++) 1.185 + if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { 1.186 + if(key[i].func) 1.187 + key[i].func(&key[i].arg); 1.188 + return; 1.189 + } 1.190 +} 1.191 + 1.192 +static void 1.193 +leavenotify(XEvent *e) 1.194 +{ 1.195 + XCrossingEvent *ev = &e->xcrossing; 1.196 + 1.197 + if((ev->window == root) && !ev->same_screen) 1.198 + issel = True; 1.199 +} 1.200 + 1.201 +static void 1.202 maprequest(XEvent *e) 1.203 { 1.204 XMapRequestEvent *ev = &e->xmaprequest; 1.205 @@ -322,6 +214,40 @@ 1.206 } 1.207 1.208 static void 1.209 +movemouse(Client *c) 1.210 +{ 1.211 + XEvent ev; 1.212 + int x1, y1, ocx, ocy, di; 1.213 + unsigned int dui; 1.214 + Window dummy; 1.215 + 1.216 + ocx = c->x; 1.217 + ocy = c->y; 1.218 + if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 1.219 + None, cursor[CurMove], CurrentTime) != GrabSuccess) 1.220 + return; 1.221 + XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); 1.222 + for(;;) { 1.223 + XMaskEvent(dpy, MouseMask | ExposureMask, &ev); 1.224 + switch (ev.type) { 1.225 + default: break; 1.226 + case Expose: 1.227 + handler[Expose](&ev); 1.228 + break; 1.229 + case MotionNotify: 1.230 + XFlush(dpy); 1.231 + c->x = ocx + (ev.xmotion.x - x1); 1.232 + c->y = ocy + (ev.xmotion.y - y1); 1.233 + resize(c, False); 1.234 + break; 1.235 + case ButtonRelease: 1.236 + XUngrabPointer(dpy, CurrentTime); 1.237 + return; 1.238 + } 1.239 + } 1.240 +} 1.241 + 1.242 +static void 1.243 propertynotify(XEvent *e) 1.244 { 1.245 XPropertyEvent *ev = &e->xproperty; 1.246 @@ -355,6 +281,40 @@ 1.247 } 1.248 1.249 static void 1.250 +resizemouse(Client *c) 1.251 +{ 1.252 + XEvent ev; 1.253 + int ocx, ocy; 1.254 + 1.255 + ocx = c->x; 1.256 + ocy = c->y; 1.257 + if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 1.258 + None, cursor[CurResize], CurrentTime) != GrabSuccess) 1.259 + return; 1.260 + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); 1.261 + for(;;) { 1.262 + XMaskEvent(dpy, MouseMask | ExposureMask, &ev); 1.263 + switch(ev.type) { 1.264 + default: break; 1.265 + case Expose: 1.266 + handler[Expose](&ev); 1.267 + break; 1.268 + case MotionNotify: 1.269 + XFlush(dpy); 1.270 + c->w = abs(ocx - ev.xmotion.x); 1.271 + c->h = abs(ocy - ev.xmotion.y); 1.272 + c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w; 1.273 + c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h; 1.274 + resize(c, True); 1.275 + break; 1.276 + case ButtonRelease: 1.277 + XUngrabPointer(dpy, CurrentTime); 1.278 + return; 1.279 + } 1.280 + } 1.281 +} 1.282 + 1.283 +static void 1.284 unmapnotify(XEvent *e) 1.285 { 1.286 Client *c; 1.287 @@ -363,3 +323,33 @@ 1.288 if((c = getclient(ev->window))) 1.289 unmanage(c); 1.290 } 1.291 + 1.292 +/* extern functions */ 1.293 + 1.294 +void (*handler[LASTEvent]) (XEvent *) = { 1.295 + [ButtonPress] = buttonpress, 1.296 + [ConfigureRequest] = configurerequest, 1.297 + [DestroyNotify] = destroynotify, 1.298 + [EnterNotify] = enternotify, 1.299 + [LeaveNotify] = leavenotify, 1.300 + [Expose] = expose, 1.301 + [KeyPress] = keypress, 1.302 + [MapRequest] = maprequest, 1.303 + [PropertyNotify] = propertynotify, 1.304 + [UnmapNotify] = unmapnotify 1.305 +}; 1.306 + 1.307 +void 1.308 +grabkeys() 1.309 +{ 1.310 + static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; 1.311 + unsigned int i; 1.312 + KeyCode code; 1.313 + 1.314 + for(i = 0; i < len; i++) { 1.315 + code = XKeysymToKeycode(dpy, key[i].keysym); 1.316 + XUngrabKey(dpy, code, key[i].mod, root); 1.317 + XGrabKey(dpy, code, key[i].mod, root, True, 1.318 + GrabModeAsync, GrabModeAsync); 1.319 + } 1.320 +}