dwm-meillo
view dev.c @ 55:fcbf7213d96f
continued with man page
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Fri, 14 Jul 2006 08:34:38 +0200 |
parents | d18f6dd0cf23 |
children | 5d4653de9a1c |
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 /* modifier key function arguments */
24 { Mod1Mask, XK_Return, zoom, { 0 } },
25 { Mod1Mask, XK_k, prevc, { 0 } },
26 { Mod1Mask, XK_j, nextc, { 0 } },
27 { Mod1Mask, XK_m, max, { 0 } },
28 { Mod1Mask, XK_0, view, { .i = Tscratch } },
29 { Mod1Mask, XK_1, view, { .i = Tdev } },
30 { Mod1Mask, XK_2, view, { .i = Tirc } },
31 { Mod1Mask, XK_3, view, { .i = Twww } },
32 { Mod1Mask, XK_4, view, { .i = Twork } },
33 { Mod1Mask, XK_space, tiling, { 0 } },
34 { Mod1Mask|ShiftMask, XK_space, floating, { 0 } },
35 { Mod1Mask|ShiftMask, XK_0, ttrunc, { .i = Tscratch } },
36 { Mod1Mask|ShiftMask, XK_1, ttrunc, { .i = Tdev } },
37 { Mod1Mask|ShiftMask, XK_2, ttrunc, { .i = Tirc } },
38 { Mod1Mask|ShiftMask, XK_3, ttrunc, { .i = Twww } },
39 { Mod1Mask|ShiftMask, XK_4, ttrunc, { .i = Twork } },
40 { Mod1Mask|ShiftMask, XK_c, ckill, { 0 } },
41 { Mod1Mask|ShiftMask, XK_q, quit, { 0 } },
42 { Mod1Mask|ShiftMask, XK_Return, spawn, { .argv = term } },
43 { Mod1Mask|ShiftMask, XK_w, spawn, { .argv = browse } },
44 { Mod1Mask|ShiftMask, XK_l, spawn, { .argv = xlock } },
45 { ControlMask, XK_0, tappend, { .i = Tscratch } },
46 { ControlMask, XK_1, tappend, { .i = Tdev } },
47 { ControlMask, XK_2, tappend, { .i = Tirc } },
48 { ControlMask, XK_3, tappend, { .i = Twww } },
49 { ControlMask, XK_4, tappend, { .i = Twork } },
50 };
52 /********** CUSTOMIZE **********/
54 void
55 update_keys(void)
56 {
57 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
58 unsigned int i;
59 KeyCode code;
61 for(i = 0; i < len; i++) {
62 code = XKeysymToKeycode(dpy, key[i].keysym);
63 XUngrabKey(dpy, code, key[i].mod, root);
64 XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
65 }
66 }
68 void
69 keypress(XEvent *e)
70 {
71 XKeyEvent *ev = &e->xkey;
72 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
73 unsigned int i;
74 KeySym keysym;
76 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
77 for(i = 0; i < len; i++)
78 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
79 if(key[i].func)
80 key[i].func(&key[i].arg);
81 return;
82 }
83 }
85 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
86 #define MouseMask (ButtonMask | PointerMotionMask)
88 void
89 mresize(Client *c)
90 {
91 XEvent ev;
92 int ocx, ocy;
94 ocx = c->x;
95 ocy = c->y;
96 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
97 None, cursor[CurResize], CurrentTime) != GrabSuccess)
98 return;
99 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
100 for(;;) {
101 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
102 switch(ev.type) {
103 default: break;
104 case Expose:
105 handler[Expose](&ev);
106 break;
107 case MotionNotify:
108 XFlush(dpy);
109 c->w = abs(ocx - ev.xmotion.x);
110 c->h = abs(ocy - ev.xmotion.y);
111 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
112 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
113 resize(c, True);
114 break;
115 case ButtonRelease:
116 XUngrabPointer(dpy, CurrentTime);
117 return;
118 }
119 }
120 }
122 void
123 mmove(Client *c)
124 {
125 XEvent ev;
126 int x1, y1, ocx, ocy, di;
127 unsigned int dui;
128 Window dummy;
130 ocx = c->x;
131 ocy = c->y;
132 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
133 None, cursor[CurMove], CurrentTime) != GrabSuccess)
134 return;
135 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
136 for(;;) {
137 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
138 switch (ev.type) {
139 default: break;
140 case Expose:
141 handler[Expose](&ev);
142 break;
143 case MotionNotify:
144 XFlush(dpy);
145 c->x = ocx + (ev.xmotion.x - x1);
146 c->y = ocy + (ev.xmotion.y - y1);
147 resize(c, False);
148 break;
149 case ButtonRelease:
150 XUngrabPointer(dpy, CurrentTime);
151 return;
152 }
153 }
154 }