summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
authorAnselm R Garbe <anselm@garbe.us>2009-06-27 18:39:03 +0100
committerAnselm R Garbe <anselm@garbe.us>2009-06-27 18:39:03 +0100
commit176408afa895adf133a437038466ddc74e326a0c (patch)
tree02b5350da8e7e76033217534efefed6f1d04f81d /dwm.c
parentfixed focusmon brokeness (diff)
downloaddwm-176408afa895adf133a437038466ddc74e326a0c.tar.gz
dwm-176408afa895adf133a437038466ddc74e326a0c.zip
fixed several issues with focus handling via mouse, also added sending clients to the right monitor they belong to after mouse moves/resizals
Diffstat (limited to '')
-rw-r--r--dwm.c122
1 files changed, 79 insertions, 43 deletions
diff --git a/dwm.c b/dwm.c
index 096895c..9779654 100644
--- a/dwm.c
+++ b/dwm.c
@@ -166,7 +166,7 @@ static void detach(Client *c);
166static void detachstack(Client *c); 166static void detachstack(Client *c);
167static void die(const char *errstr, ...); 167static void die(const char *errstr, ...);
168static void drawbar(Monitor *m); 168static void drawbar(Monitor *m);
169static void drawbars(); 169static void drawbars(void);
170static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); 170static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
171static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); 171static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
172static void enternotify(XEvent *e); 172static void enternotify(XEvent *e);
@@ -176,6 +176,9 @@ static void focusin(XEvent *e);
176static void focusstack(const Arg *arg); 176static void focusstack(const Arg *arg);
177static Client *getclient(Window w); 177static Client *getclient(Window w);
178static unsigned long getcolor(const char *colstr); 178static unsigned long getcolor(const char *colstr);
179static Monitor *getmonitor(Window w);
180static Monitor *getmonitorxy(int x, int y);
181static Bool getrootpointer(int *x, int *y);
179static long getstate(Window w); 182static long getstate(Window w);
180static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); 183static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
181static void grabbuttons(Client *c, Bool focused); 184static void grabbuttons(Client *c, Bool focused);
@@ -197,6 +200,7 @@ static void resizemouse(const Arg *arg);
197static void restack(Monitor *m); 200static void restack(Monitor *m);
198static void run(void); 201static void run(void);
199static void scan(void); 202static void scan(void);
203static void sendmon(Client *c, Monitor *m);
200static void setclientstate(Client *c, long state); 204static void setclientstate(Client *c, long state);
201static void setlayout(const Arg *arg); 205static void setlayout(const Arg *arg);
202static void setmfact(const Arg *arg); 206static void setmfact(const Arg *arg);
@@ -397,15 +401,11 @@ buttonpress(XEvent *e) {
397 401
398 click = ClkRootWin; 402 click = ClkRootWin;
399 /* focus monitor if necessary */ 403 /* focus monitor if necessary */
400 for(m = mons; m; m = m->next) 404 if((m = getmonitor(ev->window)) && m != selmon) {
401 if(ev->window == m->barwin) { 405 unfocus(selmon->sel);
402 if(m != selmon) { 406 selmon = m;
403 unfocus(selmon->stack); 407 focus(NULL);
404 selmon = m; 408 }
405 focus(NULL);
406 }
407 break;
408 }
409 if(ev->window == selmon->barwin && ev->x >= selmon->btx) { 409 if(ev->window == selmon->barwin && ev->x >= selmon->btx) {
410 i = 0; 410 i = 0;
411 x = selmon->btx; 411 x = selmon->btx;
@@ -683,7 +683,7 @@ drawbar(Monitor *m) {
683} 683}
684 684
685void 685void
686drawbars() { 686drawbars(void) {
687 Monitor *m; 687 Monitor *m;
688 688
689 for(m = mons; m; m = m->next) 689 for(m = mons; m; m = m->next)
@@ -742,10 +742,15 @@ drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
742void 742void
743enternotify(XEvent *e) { 743enternotify(XEvent *e) {
744 Client *c; 744 Client *c;
745 Monitor *m;
745 XCrossingEvent *ev = &e->xcrossing; 746 XCrossingEvent *ev = &e->xcrossing;
746 747
747 if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) 748 if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
748 return; 749 return;
750 if((m = getmonitor(ev->window)) && m != selmon) {
751 unfocus(selmon->sel);
752 selmon = m;
753 }
749 if((c = getclient(ev->window))) 754 if((c = getclient(ev->window)))
750 focus(c); 755 focus(c);
751 else 756 else
@@ -757,12 +762,8 @@ expose(XEvent *e) {
757 Monitor *m; 762 Monitor *m;
758 XExposeEvent *ev = &e->xexpose; 763 XExposeEvent *ev = &e->xexpose;
759 764
760 if(ev->count == 0) 765 if(ev->count == 0 && (m = getmonitor(ev->window)))
761 for(m = mons; m; m = m->next) 766 drawbar(m);
762 if(ev->window == m->barwin) {
763 drawbar(m);
764 break;
765 }
766} 767}
767 768
768void 769void
@@ -809,7 +810,6 @@ focusmon(const Arg *arg) {
809 unfocus(selmon->sel); 810 unfocus(selmon->sel);
810 selmon = m; 811 selmon = m;
811 focus(NULL); 812 focus(NULL);
812 drawbars();
813 break; 813 break;
814 } 814 }
815} 815}
@@ -863,6 +863,40 @@ getcolor(const char *colstr) {
863 return color.pixel; 863 return color.pixel;
864} 864}
865 865
866Monitor *
867getmonitor(Window w) {
868 int x, y;
869 Client *c;
870 Monitor *m;
871
872 if(w == root && getrootpointer(&x, &y))
873 return getmonitorxy(x, y);
874 for(m = mons; m; m = m->next)
875 if(w == m->barwin)
876 return m;
877 if((c = getclient(w)))
878 return c->mon;
879 return NULL;
880}
881
882Monitor *
883getmonitorxy(int x, int y) {
884 Monitor *m;
885
886 for(m = mons; m; m = m->next)
887 if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh))
888 return m;
889 return NULL;
890}
891
892Bool
893getrootpointer(int *x, int *y) {
894 int di;
895 unsigned int dui;
896 Window dummy;
897 return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui);
898}
899
866long 900long
867getstate(Window w) { 901getstate(Window w) {
868 int format, status; 902 int format, status;
@@ -1124,10 +1158,9 @@ monocle(Monitor *m) {
1124 1158
1125void 1159void
1126movemouse(const Arg *arg) { 1160movemouse(const Arg *arg) {
1127 int x, y, ocx, ocy, di, nx, ny; 1161 int x, y, ocx, ocy, nx, ny;
1128 unsigned int dui;
1129 Client *c; 1162 Client *c;
1130 Window dummy; 1163 Monitor *m;
1131 XEvent ev; 1164 XEvent ev;
1132 1165
1133 if(!(c = selmon->sel)) 1166 if(!(c = selmon->sel))
@@ -1138,7 +1171,8 @@ movemouse(const Arg *arg) {
1138 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, 1171 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
1139 None, cursor[CurMove], CurrentTime) != GrabSuccess) 1172 None, cursor[CurMove], CurrentTime) != GrabSuccess)
1140 return; 1173 return;
1141 XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui); 1174 if(!getrootpointer(&x, &y))
1175 return;
1142 do { 1176 do {
1143 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); 1177 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
1144 switch (ev.type) { 1178 switch (ev.type) {
@@ -1171,6 +1205,8 @@ movemouse(const Arg *arg) {
1171 } 1205 }
1172 while(ev.type != ButtonRelease); 1206 while(ev.type != ButtonRelease);
1173 XUngrabPointer(dpy, CurrentTime); 1207 XUngrabPointer(dpy, CurrentTime);
1208 if((m = getmonitorxy(c->x + c->w / 2, c->y + c->h / 2)) != selmon)
1209 sendmon(c, m);
1174} 1210}
1175 1211
1176Client * 1212Client *
@@ -1239,6 +1275,7 @@ resizemouse(const Arg *arg) {
1239 int ocx, ocy; 1275 int ocx, ocy;
1240 int nw, nh; 1276 int nw, nh;
1241 Client *c; 1277 Client *c;
1278 Monitor *m;
1242 XEvent ev; 1279 XEvent ev;
1243 1280
1244 if(!(c = selmon->sel)) 1281 if(!(c = selmon->sel))
@@ -1277,6 +1314,8 @@ resizemouse(const Arg *arg) {
1277 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); 1314 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
1278 XUngrabPointer(dpy, CurrentTime); 1315 XUngrabPointer(dpy, CurrentTime);
1279 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); 1316 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
1317 if((m = getmonitorxy(c->x + c->w / 2, c->y + c->h / 2)) != selmon)
1318 sendmon(c, m);
1280} 1319}
1281 1320
1282void 1321void
@@ -1342,6 +1381,20 @@ scan(void) {
1342} 1381}
1343 1382
1344void 1383void
1384sendmon(Client *c, Monitor *m) {
1385 if(c->mon == m)
1386 return;
1387 detach(c);
1388 detachstack(c);
1389 c->mon = m;
1390 c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
1391 attach(c);
1392 attachstack(c);
1393 focus(NULL);
1394 arrange();
1395}
1396
1397void
1345setclientstate(Client *c, long state) { 1398setclientstate(Client *c, long state) {
1346 long data[] = {state, None}; 1399 long data[] = {state, None};
1347 1400
@@ -1497,14 +1550,7 @@ tagmon(const Arg *arg) {
1497 return; 1550 return;
1498 for(i = 0, m = mons; m; m = m->next, i++) 1551 for(i = 0, m = mons; m; m = m->next, i++)
1499 if(i == arg->ui) { 1552 if(i == arg->ui) {
1500 detach(c); 1553 sendmon(c, m);
1501 detachstack(c);
1502 c->mon = m;
1503 c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
1504 attach(c);
1505 attachstack(c);
1506 focus(NULL);
1507 arrange();
1508 break; 1554 break;
1509 } 1555 }
1510} 1556}
@@ -1676,11 +1722,9 @@ updatebarpos(Monitor *m) {
1676 1722
1677void 1723void
1678updategeom(void) { 1724updategeom(void) {
1679 int i, di, n = 1, x, y; 1725 int i, n = 1;
1680 unsigned int dui;
1681 Client *c; 1726 Client *c;
1682 Monitor *newmons = NULL, *m, *tm; 1727 Monitor *newmons = NULL, *m, *tm;
1683 Window dummy;
1684 1728
1685#ifdef XINULATOR 1729#ifdef XINULATOR
1686 n = 2; 1730 n = 2;
@@ -1763,17 +1807,9 @@ updategeom(void) {
1763 } 1807 }
1764 1808
1765 /* select focused monitor */ 1809 /* select focused monitor */
1766 selmon = newmons;
1767 if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui))
1768 for(m = newmons; m; m = m->next)
1769 if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh)) {
1770 selmon = m;
1771 break;
1772 }
1773
1774 /* final assignment of new monitors */
1775 cleanupmons(); 1810 cleanupmons();
1776 mons = newmons; 1811 mons = newmons;
1812 selmon = getmonitor(root);
1777} 1813}
1778 1814
1779void 1815void
@@ -1848,7 +1884,7 @@ updatetitle(Client *c) {
1848} 1884}
1849 1885
1850void 1886void
1851updatestatus() { 1887updatestatus(void) {
1852 if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) 1888 if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
1853 strcpy(stext, "dwm-"VERSION); 1889 strcpy(stext, "dwm-"VERSION);
1854 drawbar(selmon); 1890 drawbar(selmon);