aewl
view dev.c @ 43:989178822938
changed default colors
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Thu, 13 Jul 2006 11:43:05 +0200 |
parents | 040a7074d23c |
children | a36f95a4841a |
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 "aterm", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
17 "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL
18 };
19 const char *browse[] = { "firefox", NULL };
21 static Key key[] = {
22 { Mod1Mask, XK_Return, (void (*)(void *))spawn, term },
23 { Mod1Mask, XK_w, (void (*)(void *))spawn, browse },
24 { Mod1Mask, XK_k, sel, "prev" },
25 { Mod1Mask, XK_j, sel, "next" },
26 { Mod1Mask, XK_space, toggle, NULL },
27 { Mod1Mask, XK_m, max, NULL },
28 { Mod1Mask | ShiftMask, XK_c, ckill, NULL },
29 { Mod1Mask | ShiftMask, XK_q, quit, NULL },
30 };
32 /********** CUSTOMIZE **********/
34 void
35 update_keys(void)
36 {
37 unsigned int i, len;
38 KeyCode code;
40 len = sizeof(key) / sizeof(key[0]);
41 for(i = 0; i < len; i++) {
42 code = XKeysymToKeycode(dpy, key[i].keysym);
43 XUngrabKey(dpy, code, key[i].mod, root);
44 XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
45 }
46 }
48 void
49 keypress(XEvent *e)
50 {
51 XKeyEvent *ev = &e->xkey;
52 unsigned int i, len;
53 KeySym keysym;
55 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
56 len = sizeof(key) / sizeof(key[0]);
57 for(i = 0; i < len; i++)
58 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
59 if(key[i].func)
60 key[i].func(key[i].aux);
61 return;
62 }
63 }
65 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
66 #define MouseMask (ButtonMask | PointerMotionMask)
68 void
69 mresize(Client *c)
70 {
71 XEvent ev;
72 int ocx, ocy;
74 ocx = c->x;
75 ocy = c->y;
76 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
77 None, cursor[CurResize], CurrentTime) != GrabSuccess)
78 return;
79 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
80 for(;;) {
81 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
82 switch(ev.type) {
83 default: break;
84 case Expose:
85 handler[Expose](&ev);
86 break;
87 case MotionNotify:
88 XFlush(dpy);
89 c->w = abs(ocx - ev.xmotion.x);
90 c->h = abs(ocy - ev.xmotion.y);
91 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
92 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
93 resize(c);
94 break;
95 case ButtonRelease:
96 XUngrabPointer(dpy, CurrentTime);
97 return;
98 }
99 }
100 }
102 void
103 mmove(Client *c)
104 {
105 XEvent ev;
106 int x1, y1, ocx, ocy, di;
107 unsigned int dui;
108 Window dummy;
110 ocx = c->x;
111 ocy = c->y;
112 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
113 None, cursor[CurMove], CurrentTime) != GrabSuccess)
114 return;
115 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
116 for(;;) {
117 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
118 switch (ev.type) {
119 default: break;
120 case Expose:
121 handler[Expose](&ev);
122 break;
123 case MotionNotify:
124 XFlush(dpy);
125 c->x = ocx + (ev.xmotion.x - x1);
126 c->y = ocy + (ev.xmotion.y - y1);
127 resize(c);
128 break;
129 case ButtonRelease:
130 XUngrabPointer(dpy, CurrentTime);
131 return;
132 }
133 }
134 }