summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
authorAnselm R Garbe <garbeam@gmail.com>2008-06-11 20:41:28 +0100
committerAnselm R Garbe <garbeam@gmail.com>2008-06-11 20:41:28 +0100
commit5cd65f8cd85928a0f26c80a209c82781cb342365 (patch)
tree42f47df72070dc5d3ecdc20f5fef94c87144042c /dwm.c
parentmade Xinerama screen index customizable (diff)
downloaddwm-5cd65f8cd85928a0f26c80a209c82781cb342365.tar.gz
dwm-5cd65f8cd85928a0f26c80a209c82781cb342365.zip
integrated yiyus mouse.diff (though the bar click handling is slightly broken, I'm to tired to debug it now, yiyus could you please?)
Diffstat (limited to '')
-rw-r--r--dwm.c101
1 files changed, 52 insertions, 49 deletions
diff --git a/dwm.c b/dwm.c
index dfc452a..4153f41 100644
--- a/dwm.c
+++ b/dwm.c
@@ -59,10 +59,28 @@ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
59enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ 59enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
60enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ 60enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */
61enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */ 61enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
62enum { ClkLtSymbol = -1, ClkStatusText = -2, ClkWinTitle = -3,
63 ClkClientWin = -4, ClkRootWin = -5, ClkLast = -6};/* clicks */
62 64
63/* typedefs */ 65/* typedefs */
64typedef unsigned int uint; 66typedef unsigned int uint;
65typedef unsigned long ulong; 67typedef unsigned long ulong;
68
69typedef union {
70 int i;
71 uint ui;
72 float f;
73 void *v;
74} Arg;
75
76typedef struct {
77 uint click;
78 uint mask;
79 uint button;
80 void (*func)(const Arg *arg);
81 const Arg arg;
82} Button;
83
66typedef struct Client Client; 84typedef struct Client Client;
67struct Client { 85struct Client {
68 char name[256]; 86 char name[256];
@@ -92,13 +110,6 @@ typedef struct {
92 } font; 110 } font;
93} DC; /* draw context */ 111} DC; /* draw context */
94 112
95typedef union {
96 int i;
97 uint ui;
98 float f;
99 void *v;
100} Arg;
101
102typedef struct { 113typedef struct {
103 uint mod; 114 uint mod;
104 KeySym keysym; 115 KeySym keysym;
@@ -157,12 +168,12 @@ static void killclient(const Arg *arg);
157static void manage(Window w, XWindowAttributes *wa); 168static void manage(Window w, XWindowAttributes *wa);
158static void mappingnotify(XEvent *e); 169static void mappingnotify(XEvent *e);
159static void maprequest(XEvent *e); 170static void maprequest(XEvent *e);
160static void movemouse(Client *c); 171static void movemouse(const Arg *arg);
161static Client *nexttiled(Client *c); 172static Client *nexttiled(Client *c);
162static void propertynotify(XEvent *e); 173static void propertynotify(XEvent *e);
163static void quit(const Arg *arg); 174static void quit(const Arg *arg);
164static void resize(Client *c, int x, int y, int w, int h, Bool sizehints); 175static void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
165static void resizemouse(Client *c); 176static void resizemouse(const Arg *arg);
166static void restack(void); 177static void restack(void);
167static void run(void); 178static void run(void);
168static void scan(void); 179static void scan(void);
@@ -297,50 +308,31 @@ attachstack(Client *c) {
297 308
298void 309void
299buttonpress(XEvent *e) { 310buttonpress(XEvent *e) {
300 uint i, mask; 311 uint i, x, click;
301 int x;
302 Client *c; 312 Client *c;
303 XButtonPressedEvent *ev = &e->xbutton; 313 XButtonPressedEvent *ev = &e->xbutton;
304 314
315 click = ClkRootWin;
305 if(ev->window == barwin) { 316 if(ev->window == barwin) {
306 x = 0; 317 x = 0;
307 for(i = 0; i < LENGTH(tags); i++) { 318 for(i = 0; i < LENGTH(tags) && ev->x >= x; i++) {
308 x += TEXTW(tags[i]); 319 x += TEXTW(tags[i]);
309 if(ev->x < x) { 320 if(i < LENGTH(tags) || ev->x <= x)
310 mask = 1 << i; 321 click = i - 1;
311 if(ev->button == Button1) { 322 else if(ev->x < x + blw)
312 if(ev->state & MODKEY) 323 click = ClkLtSymbol;
313 tag((Arg*)&mask); 324 else if(ev->x > wx + ww - TEXTW(stext))
314 else 325 click = ClkStatusText;
315 view((Arg*)&mask); 326 else
316 } 327 click = ClkWinTitle;
317 else if(ev->button == Button3) {
318 if(ev->state & MODKEY)
319 toggletag((Arg*)&mask);
320 else
321 toggleview((Arg*)&mask);
322 }
323 return;
324 }
325 }
326 if(ev->x < x + blw) {
327 if(ev->button == Button1)
328 togglelayout(NULL);
329 else if(ev->button == Button3)
330 togglemax(NULL);
331 } 328 }
332 } 329 }
333 else if((c = getclient(ev->window))) { 330 else if((c = getclient(ev->window)))
334 focus(c); 331 click = ClkClientWin;
335 if(CLEANMASK(ev->state) != MODKEY || (ismax && !c->isfixed)) 332
336 return; 333 for(i = 0; i < LENGTH(buttons); i++)
337 if(ev->button == Button1) 334 if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
338 movemouse(c); 335 buttons[i].func(&buttons[i].arg);
339 else if(ev->button == Button2)
340 togglefloating(NULL);
341 else if(ev->button == Button3 && !c->isfixed)
342 resizemouse(c);
343 }
344} 336}
345 337
346void 338void
@@ -971,12 +963,15 @@ maprequest(XEvent *e) {
971} 963}
972 964
973void 965void
974movemouse(Client *c) { 966movemouse(const Arg *arg) {
975 int x1, y1, ocx, ocy, di, nx, ny; 967 int x1, y1, ocx, ocy, di, nx, ny;
976 uint dui; 968 uint dui;
969 Client *c;
977 Window dummy; 970 Window dummy;
978 XEvent ev; 971 XEvent ev;
979 972
973 if(!(c = sel))
974 return;
980 restack(); 975 restack();
981 ocx = nx = c->x; 976 ocx = nx = c->x;
982 ocy = ny = c->y; 977 ocy = ny = c->y;
@@ -984,6 +979,11 @@ movemouse(Client *c) {
984 None, cursor[CurMove], CurrentTime) != GrabSuccess) 979 None, cursor[CurMove], CurrentTime) != GrabSuccess)
985 return; 980 return;
986 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); 981 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
982 if(x1 < c->x || x1 > c->x + c->w || y1 < c->y || y1 > c->y + c->h) {
983 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, 0, 0);
984 x1 = c->x + 1;
985 y1 = c->y + 1;
986 }
987 for(;;) { 987 for(;;) {
988 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); 988 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
989 switch (ev.type) { 989 switch (ev.type) {
@@ -1131,11 +1131,14 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
1131} 1131}
1132 1132
1133void 1133void
1134resizemouse(Client *c) { 1134resizemouse(const Arg *arg) {
1135 int ocx, ocy; 1135 int ocx, ocy;
1136 int nw, nh; 1136 int nw, nh;
1137 Client *c;
1137 XEvent ev; 1138 XEvent ev;
1138 1139
1140 if(!(c = sel))
1141 return;
1139 restack(); 1142 restack();
1140 ocx = c->x; 1143 ocx = c->x;
1141 ocy = c->y; 1144 ocy = c->y;
@@ -1377,7 +1380,7 @@ setup(void) {
1377 PropModeReplace, (unsigned char *) netatom, NetLast); 1380 PropModeReplace, (unsigned char *) netatom, NetLast);
1378 1381
1379 /* select for events */ 1382 /* select for events */
1380 wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask 1383 wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask
1381 |EnterWindowMask|LeaveWindowMask|StructureNotifyMask; 1384 |EnterWindowMask|LeaveWindowMask|StructureNotifyMask;
1382 XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); 1385 XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
1383 XSelectInput(dpy, root, wa.event_mask); 1386 XSelectInput(dpy, root, wa.event_mask);
@@ -1643,7 +1646,7 @@ updatewmhints(Client *c) {
1643void 1646void
1644view(const Arg *arg) { 1647view(const Arg *arg) {
1645 seltags ^= 1; /* toggle sel tagset */ 1648 seltags ^= 1; /* toggle sel tagset */
1646 if(arg && (arg->ui & TAGMASK)) 1649 if(arg && (arg->ui & TAGMASK) && (arg->ui & TAGMASK) != tagset[seltags ^ 1])
1647 tagset[seltags] = arg->i & TAGMASK; 1650 tagset[seltags] = arg->i & TAGMASK;
1648 arrange(); 1651 arrange();
1649} 1652}