164 static void destroynotify(XEvent *e); |
164 static void destroynotify(XEvent *e); |
165 static void detach(Client *c); |
165 static void detach(Client *c); |
166 static void detachstack(Client *c); |
166 static void detachstack(Client *c); |
167 static void die(const char *errstr, ...); |
167 static void die(const char *errstr, ...); |
168 static void drawbar(Monitor *m); |
168 static void drawbar(Monitor *m); |
169 static void drawbars(); |
169 static void drawbars(void); |
170 static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); |
170 static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); |
171 static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); |
171 static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); |
172 static void enternotify(XEvent *e); |
172 static void enternotify(XEvent *e); |
173 static void expose(XEvent *e); |
173 static void expose(XEvent *e); |
174 static void focus(Client *c); |
174 static void focus(Client *c); |
175 static void focusin(XEvent *e); |
175 static void focusin(XEvent *e); |
176 static void focusstack(const Arg *arg); |
176 static void focusstack(const Arg *arg); |
177 static Client *getclient(Window w); |
177 static Client *getclient(Window w); |
178 static unsigned long getcolor(const char *colstr); |
178 static unsigned long getcolor(const char *colstr); |
|
179 static Monitor *getmonitor(Window w); |
|
180 static Monitor *getmonitorxy(int x, int y); |
|
181 static Bool getrootpointer(int *x, int *y); |
179 static long getstate(Window w); |
182 static long getstate(Window w); |
180 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); |
183 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); |
181 static void grabbuttons(Client *c, Bool focused); |
184 static void grabbuttons(Client *c, Bool focused); |
182 static void grabkeys(void); |
185 static void grabkeys(void); |
183 static void initfont(const char *fontstr); |
186 static void initfont(const char *fontstr); |
195 static void resize(Client *c, int x, int y, int w, int h); |
198 static void resize(Client *c, int x, int y, int w, int h); |
196 static void resizemouse(const Arg *arg); |
199 static void resizemouse(const Arg *arg); |
197 static void restack(Monitor *m); |
200 static void restack(Monitor *m); |
198 static void run(void); |
201 static void run(void); |
199 static void scan(void); |
202 static void scan(void); |
|
203 static void sendmon(Client *c, Monitor *m); |
200 static void setclientstate(Client *c, long state); |
204 static void setclientstate(Client *c, long state); |
201 static void setlayout(const Arg *arg); |
205 static void setlayout(const Arg *arg); |
202 static void setmfact(const Arg *arg); |
206 static void setmfact(const Arg *arg); |
203 static void setup(void); |
207 static void setup(void); |
204 static void showhide(Client *c); |
208 static void showhide(Client *c); |
859 XColor color; |
859 XColor color; |
860 |
860 |
861 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) |
861 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) |
862 die("error, cannot allocate color '%s'\n", colstr); |
862 die("error, cannot allocate color '%s'\n", colstr); |
863 return color.pixel; |
863 return color.pixel; |
|
864 } |
|
865 |
|
866 Monitor * |
|
867 getmonitor(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 |
|
882 Monitor * |
|
883 getmonitorxy(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 |
|
892 Bool |
|
893 getrootpointer(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); |
864 } |
898 } |
865 |
899 |
866 long |
900 long |
867 getstate(Window w) { |
901 getstate(Window w) { |
868 int format, status; |
902 int format, status; |
1122 resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw); |
1156 resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw); |
1123 } |
1157 } |
1124 |
1158 |
1125 void |
1159 void |
1126 movemouse(const Arg *arg) { |
1160 movemouse(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)) |
1134 return; |
1167 return; |
1135 restack(selmon); |
1168 restack(selmon); |
1136 ocx = c->x; |
1169 ocx = c->x; |
1137 ocy = c->y; |
1170 ocy = c->y; |
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) { |
1145 case ConfigureRequest: |
1179 case ConfigureRequest: |
1146 case Expose: |
1180 case Expose: |
1275 } |
1312 } |
1276 while(ev.type != ButtonRelease); |
1313 while(ev.type != ButtonRelease); |
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 |
1282 void |
1321 void |
1283 restack(Monitor *m) { |
1322 restack(Monitor *m) { |
1284 Client *c; |
1323 Client *c; |
1761 attach(c); |
1805 attach(c); |
1762 attachstack(c); |
1806 attachstack(c); |
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 |
1779 void |
1815 void |
1780 updatenumlockmask(void) { |
1816 updatenumlockmask(void) { |
1781 unsigned int i, j; |
1817 unsigned int i, j; |
1846 if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) |
1882 if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) |
1847 gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name); |
1883 gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name); |
1848 } |
1884 } |
1849 |
1885 |
1850 void |
1886 void |
1851 updatestatus() { |
1887 updatestatus(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); |
1855 } |
1891 } |
1856 |
1892 |