aewl

view dev.c @ 49:466591c2f967

implemented tagging a client
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 17:09:35 +0200
parents ceff29af8c7b
children 148f25ed0ad7
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, spawn, { .argv = term } },
24 { Mod1Mask, XK_w, spawn, { .argv = browse } },
25 { Mod1Mask, XK_l, spawn, { .argv = xlock } },
26 { Mod1Mask, XK_k, prevc, { 0 } },
27 { Mod1Mask, XK_j, nextc, { 0 } },
28 { Mod1Mask, XK_t, tiling, { 0 } },
29 { Mod1Mask, XK_f, floating, { 0 } },
30 { Mod1Mask, XK_m, max, { 0 } },
31 { Mod1Mask, XK_0, tag, { .i = Tscratch } },
32 { Mod1Mask, XK_1, tag, { .i = Tdev } },
33 { Mod1Mask, XK_2, tag, { .i = Tirc } },
34 { Mod1Mask, XK_3, tag, { .i = Twww } },
35 { Mod1Mask, XK_4, tag, { .i = Twork } },
36 { Mod1Mask | ShiftMask, XK_c, ckill, { 0 } },
37 { Mod1Mask | ShiftMask, XK_q, quit, { 0 } },
38 };
40 /********** CUSTOMIZE **********/
42 void
43 update_keys(void)
44 {
45 unsigned int i, len;
46 KeyCode code;
48 len = sizeof(key) / sizeof(key[0]);
49 for(i = 0; i < len; i++) {
50 code = XKeysymToKeycode(dpy, key[i].keysym);
51 XUngrabKey(dpy, code, key[i].mod, root);
52 XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
53 }
54 }
56 void
57 keypress(XEvent *e)
58 {
59 XKeyEvent *ev = &e->xkey;
60 unsigned int i, len;
61 KeySym keysym;
63 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
64 len = sizeof(key) / sizeof(key[0]);
65 for(i = 0; i < len; i++)
66 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
67 if(key[i].func)
68 key[i].func(&key[i].arg);
69 return;
70 }
71 }
73 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
74 #define MouseMask (ButtonMask | PointerMotionMask)
76 void
77 mresize(Client *c)
78 {
79 XEvent ev;
80 int ocx, ocy;
82 ocx = c->x;
83 ocy = c->y;
84 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
85 None, cursor[CurResize], CurrentTime) != GrabSuccess)
86 return;
87 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
88 for(;;) {
89 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
90 switch(ev.type) {
91 default: break;
92 case Expose:
93 handler[Expose](&ev);
94 break;
95 case MotionNotify:
96 XFlush(dpy);
97 c->w = abs(ocx - ev.xmotion.x);
98 c->h = abs(ocy - ev.xmotion.y);
99 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
100 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
101 resize(c);
102 break;
103 case ButtonRelease:
104 XUngrabPointer(dpy, CurrentTime);
105 return;
106 }
107 }
108 }
110 void
111 mmove(Client *c)
112 {
113 XEvent ev;
114 int x1, y1, ocx, ocy, di;
115 unsigned int dui;
116 Window dummy;
118 ocx = c->x;
119 ocy = c->y;
120 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
121 None, cursor[CurMove], CurrentTime) != GrabSuccess)
122 return;
123 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
124 for(;;) {
125 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
126 switch (ev.type) {
127 default: break;
128 case Expose:
129 handler[Expose](&ev);
130 break;
131 case MotionNotify:
132 XFlush(dpy);
133 c->x = ocx + (ev.xmotion.x - x1);
134 c->y = ocy + (ev.xmotion.y - y1);
135 resize(c);
136 break;
137 case ButtonRelease:
138 XUngrabPointer(dpy, CurrentTime);
139 return;
140 }
141 }
142 }