aewl

view dev.c @ 46:58307ad56ec1

added xlock command (I need it regularly)
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 12:19:10 +0200
parents a36f95a4841a
children ceff29af8c7b
line source
1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
6 #include "dwm.h"
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <X11/keysym.h>
13 /********** CUSTOMIZE **********/
15 const char *term[] = {
16 "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
17 "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL
18 };
19 const char *browse[] = { "firefox", NULL };
20 const char *xlock[] = { "xlock", NULL };
22 static Key key[] = {
23 { Mod1Mask, XK_Return, (void (*)(void *))spawn, term },
24 { Mod1Mask, XK_w, (void (*)(void *))spawn, browse },
25 { Mod1Mask, XK_l, (void (*)(void *))spawn, xlock },
26 { Mod1Mask, XK_k, sel, "prev" },
27 { Mod1Mask, XK_j, sel, "next" },
28 { Mod1Mask, XK_t, tiling, NULL },
29 { Mod1Mask, XK_f, tiling, NULL },
30 { Mod1Mask, XK_m, max, NULL },
31 { Mod1Mask | ShiftMask, XK_c, ckill, NULL },
32 { Mod1Mask | ShiftMask, XK_q, quit, NULL },
33 };
35 /********** CUSTOMIZE **********/
37 void
38 update_keys(void)
39 {
40 unsigned int i, len;
41 KeyCode code;
43 len = sizeof(key) / sizeof(key[0]);
44 for(i = 0; i < len; i++) {
45 code = XKeysymToKeycode(dpy, key[i].keysym);
46 XUngrabKey(dpy, code, key[i].mod, root);
47 XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
48 }
49 }
51 void
52 keypress(XEvent *e)
53 {
54 XKeyEvent *ev = &e->xkey;
55 unsigned int i, len;
56 KeySym keysym;
58 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
59 len = sizeof(key) / sizeof(key[0]);
60 for(i = 0; i < len; i++)
61 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
62 if(key[i].func)
63 key[i].func(key[i].aux);
64 return;
65 }
66 }
68 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
69 #define MouseMask (ButtonMask | PointerMotionMask)
71 void
72 mresize(Client *c)
73 {
74 XEvent ev;
75 int ocx, ocy;
77 ocx = c->x;
78 ocy = c->y;
79 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
80 None, cursor[CurResize], CurrentTime) != GrabSuccess)
81 return;
82 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
83 for(;;) {
84 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
85 switch(ev.type) {
86 default: break;
87 case Expose:
88 handler[Expose](&ev);
89 break;
90 case MotionNotify:
91 XFlush(dpy);
92 c->w = abs(ocx - ev.xmotion.x);
93 c->h = abs(ocy - ev.xmotion.y);
94 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
95 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
96 resize(c);
97 break;
98 case ButtonRelease:
99 XUngrabPointer(dpy, CurrentTime);
100 return;
101 }
102 }
103 }
105 void
106 mmove(Client *c)
107 {
108 XEvent ev;
109 int x1, y1, ocx, ocy, di;
110 unsigned int dui;
111 Window dummy;
113 ocx = c->x;
114 ocy = c->y;
115 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
116 None, cursor[CurMove], CurrentTime) != GrabSuccess)
117 return;
118 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
119 for(;;) {
120 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
121 switch (ev.type) {
122 default: break;
123 case Expose:
124 handler[Expose](&ev);
125 break;
126 case MotionNotify:
127 XFlush(dpy);
128 c->x = ocx + (ev.xmotion.x - x1);
129 c->y = ocy + (ev.xmotion.y - y1);
130 resize(c);
131 break;
132 case ButtonRelease:
133 XUngrabPointer(dpy, CurrentTime);
134 return;
135 }
136 }
137 }