comparison event.c @ 73:c2ddb9dbbd10

rearranged
author Anselm R. Garbe <garbeam@wmii.de>
date Fri, 14 Jul 2006 22:33:38 +0200
parents e5fff8249705
children 5370ef170cc9
comparison
equal deleted inserted replaced
72:d0eb0bb63c40 73:c2ddb9dbbd10
5 5
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 #include <unistd.h>
10 #include <X11/keysym.h> 11 #include <X11/keysym.h>
11 #include <X11/Xatom.h> 12 #include <X11/Xatom.h>
12 13
13 #include "dwm.h" 14 #include "dwm.h"
15
16 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
17 #define MouseMask (ButtonMask | PointerMotionMask)
14 18
15 /* local functions */ 19 /* local functions */
16 static void buttonpress(XEvent *e); 20 static void buttonpress(XEvent *e);
17 static void configurerequest(XEvent *e); 21 static void configurerequest(XEvent *e);
18 static void destroynotify(XEvent *e); 22 static void destroynotify(XEvent *e);
19 static void enternotify(XEvent *e); 23 static void enternotify(XEvent *e);
20 static void leavenotify(XEvent *e); 24 static void leavenotify(XEvent *e);
21 static void expose(XEvent *e); 25 static void expose(XEvent *e);
22 static void keymapnotify(XEvent *e);
23 static void maprequest(XEvent *e); 26 static void maprequest(XEvent *e);
24 static void propertynotify(XEvent *e); 27 static void propertynotify(XEvent *e);
25 static void unmapnotify(XEvent *e); 28 static void unmapnotify(XEvent *e);
26 29
27 void (*handler[LASTEvent]) (XEvent *) = { 30 void (*handler[LASTEvent]) (XEvent *) = {
30 [DestroyNotify] = destroynotify, 33 [DestroyNotify] = destroynotify,
31 [EnterNotify] = enternotify, 34 [EnterNotify] = enternotify,
32 [LeaveNotify] = leavenotify, 35 [LeaveNotify] = leavenotify,
33 [Expose] = expose, 36 [Expose] = expose,
34 [KeyPress] = keypress, 37 [KeyPress] = keypress,
35 [KeymapNotify] = keymapnotify,
36 [MapRequest] = maprequest, 38 [MapRequest] = maprequest,
37 [PropertyNotify] = propertynotify, 39 [PropertyNotify] = propertynotify,
38 [UnmapNotify] = unmapnotify 40 [UnmapNotify] = unmapnotify
39 }; 41 };
40 42
41 static void 43 static void
44 mresize(Client *c)
45 {
46 XEvent ev;
47 int ocx, ocy;
48
49 ocx = c->x;
50 ocy = c->y;
51 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
52 None, cursor[CurResize], CurrentTime) != GrabSuccess)
53 return;
54 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
55 for(;;) {
56 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
57 switch(ev.type) {
58 default: break;
59 case Expose:
60 handler[Expose](&ev);
61 break;
62 case MotionNotify:
63 XFlush(dpy);
64 c->w = abs(ocx - ev.xmotion.x);
65 c->h = abs(ocy - ev.xmotion.y);
66 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
67 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
68 resize(c, True);
69 break;
70 case ButtonRelease:
71 XUngrabPointer(dpy, CurrentTime);
72 return;
73 }
74 }
75 }
76
77 static void
78 mmove(Client *c)
79 {
80 XEvent ev;
81 int x1, y1, ocx, ocy, di;
82 unsigned int dui;
83 Window dummy;
84
85 ocx = c->x;
86 ocy = c->y;
87 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
88 None, cursor[CurMove], CurrentTime) != GrabSuccess)
89 return;
90 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
91 for(;;) {
92 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
93 switch (ev.type) {
94 default: break;
95 case Expose:
96 handler[Expose](&ev);
97 break;
98 case MotionNotify:
99 XFlush(dpy);
100 c->x = ocx + (ev.xmotion.x - x1);
101 c->y = ocy + (ev.xmotion.y - y1);
102 resize(c, False);
103 break;
104 case ButtonRelease:
105 XUngrabPointer(dpy, CurrentTime);
106 return;
107 }
108 }
109 }
110
111 static void
42 buttonpress(XEvent *e) 112 buttonpress(XEvent *e)
43 { 113 {
114 int x;
115 Arg a;
44 XButtonPressedEvent *ev = &e->xbutton; 116 XButtonPressedEvent *ev = &e->xbutton;
45 Client *c; 117 Client *c;
46 118
47 if(barwin == ev->window) 119 if(barwin == ev->window) {
48 barclick(ev); 120 x = (arrange == floating) ? textw("~") : 0;
121 for(a.i = 0; a.i < TLast; a.i++) {
122 x += textw(tags[a.i]);
123 if(ev->x < x) {
124 view(&a);
125 break;
126 }
127 }
128 }
49 else if((c = getclient(ev->window))) { 129 else if((c = getclient(ev->window))) {
130 if(arrange == tiling && !c->floating)
131 return;
50 craise(c); 132 craise(c);
51 switch(ev->button) { 133 switch(ev->button) {
52 default: 134 default:
53 break; 135 break;
54 case Button1: 136 case Button1:
148 draw_client(c); 230 draw_client(c);
149 } 231 }
150 } 232 }
151 233
152 static void 234 static void
153 keymapnotify(XEvent *e)
154 {
155 update_keys();
156 }
157
158 static void
159 maprequest(XEvent *e) 235 maprequest(XEvent *e)
160 { 236 {
161 XMapRequestEvent *ev = &e->xmaprequest; 237 XMapRequestEvent *ev = &e->xmaprequest;
162 static XWindowAttributes wa; 238 static XWindowAttributes wa;
163 239