aewl

view dev.c @ 51:035617ee18d1

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