summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
authorAnselm R Garbe <anselm@garbe.us>2010-05-30 10:02:56 +0100
committerAnselm R Garbe <anselm@garbe.us>2010-05-30 10:02:56 +0100
commit62d3caa9990e4fd936850341095da4dd1bf4c846 (patch)
tree46afdc995d291b594e4c3441e8cd9792eae26b81 /dwm.c
parentAdded tag 5.8.1 for changeset 1ed1e75c9c2e (diff)
downloaddwm-62d3caa9990e4fd936850341095da4dd1bf4c846.tar.gz
dwm-62d3caa9990e4fd936850341095da4dd1bf4c846.zip
implemented better fullscreen handling, please test
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c105
1 files changed, 75 insertions, 30 deletions
diff --git a/dwm.c b/dwm.c
index 5df4919..670afbe 100644
--- a/dwm.c
+++ b/dwm.c
@@ -57,7 +57,8 @@
57/* enums */ 57/* enums */
58enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ 58enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
59enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ 59enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
60enum { NetSupported, NetWMName, NetWMState, NetLast }; /* EWMH atoms */ 60enum { NetSupported, NetWMName, NetWMState,
61 NetWMFullscreen, NetLast }; /* EWMH atoms */
61enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */ 62enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */
62enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, 63enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
63 ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ 64 ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
@@ -83,10 +84,11 @@ struct Client {
83 char name[256]; 84 char name[256];
84 float mina, maxa; 85 float mina, maxa;
85 int x, y, w, h; 86 int x, y, w, h;
87 int oldx, oldy, oldw, oldh;
86 int basew, baseh, incw, inch, maxw, maxh, minw, minh; 88 int basew, baseh, incw, inch, maxw, maxh, minw, minh;
87 int bw, oldbw; 89 int bw, oldbw;
88 unsigned int tags; 90 unsigned int tags;
89 Bool isfixed, isfloating, isurgent; 91 Bool isfixed, isfloating, isurgent, oldstate;
90 Client *next; 92 Client *next;
91 Client *snext; 93 Client *snext;
92 Monitor *mon; 94 Monitor *mon;
@@ -161,6 +163,7 @@ static void checkotherwm(void);
161static void cleanup(void); 163static void cleanup(void);
162static void cleanupmon(Monitor *mon); 164static void cleanupmon(Monitor *mon);
163static void clearurgent(Client *c); 165static void clearurgent(Client *c);
166static void clientmessage(XEvent *e);
164static void configure(Client *c); 167static void configure(Client *c);
165static void configurenotify(XEvent *e); 168static void configurenotify(XEvent *e);
166static void configurerequest(XEvent *e); 169static void configurerequest(XEvent *e);
@@ -200,6 +203,7 @@ static Monitor *ptrtomon(int x, int y);
200static void propertynotify(XEvent *e); 203static void propertynotify(XEvent *e);
201static void quit(const Arg *arg); 204static void quit(const Arg *arg);
202static void resize(Client *c, int x, int y, int w, int h, Bool interact); 205static void resize(Client *c, int x, int y, int w, int h, Bool interact);
206static void resizeclient(Client *c, int x, int y, int w, int h);
203static void resizemouse(const Arg *arg); 207static void resizemouse(const Arg *arg);
204static void restack(Monitor *m); 208static void restack(Monitor *m);
205static void run(void); 209static void run(void);
@@ -220,7 +224,7 @@ static void togglebar(const Arg *arg);
220static void togglefloating(const Arg *arg); 224static void togglefloating(const Arg *arg);
221static void toggletag(const Arg *arg); 225static void toggletag(const Arg *arg);
222static void toggleview(const Arg *arg); 226static void toggleview(const Arg *arg);
223static void unfocus(Client *c); 227static void unfocus(Client *c, Bool setfocus);
224static void unmanage(Client *c, Bool destroyed); 228static void unmanage(Client *c, Bool destroyed);
225static void unmapnotify(XEvent *e); 229static void unmapnotify(XEvent *e);
226static Bool updategeom(void); 230static Bool updategeom(void);
@@ -249,6 +253,7 @@ static int (*xerrorxlib)(Display *, XErrorEvent *);
249static unsigned int numlockmask = 0; 253static unsigned int numlockmask = 0;
250static void (*handler[LASTEvent]) (XEvent *) = { 254static void (*handler[LASTEvent]) (XEvent *) = {
251 [ButtonPress] = buttonpress, 255 [ButtonPress] = buttonpress,
256 [ClientMessage] = clientmessage,
252 [ConfigureRequest] = configurerequest, 257 [ConfigureRequest] = configurerequest,
253 [ConfigureNotify] = configurenotify, 258 [ConfigureNotify] = configurenotify,
254 [DestroyNotify] = destroynotify, 259 [DestroyNotify] = destroynotify,
@@ -423,7 +428,7 @@ buttonpress(XEvent *e) {
423 click = ClkRootWin; 428 click = ClkRootWin;
424 /* focus monitor if necessary */ 429 /* focus monitor if necessary */
425 if((m = wintomon(ev->window)) && m != selmon) { 430 if((m = wintomon(ev->window)) && m != selmon) {
426 unfocus(selmon->sel); 431 unfocus(selmon->sel, True);
427 selmon = m; 432 selmon = m;
428 focus(NULL); 433 focus(NULL);
429 } 434 }
@@ -792,7 +797,7 @@ enternotify(XEvent *e) {
792 if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) 797 if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
793 return; 798 return;
794 if((m = wintomon(ev->window)) && m != selmon) { 799 if((m = wintomon(ev->window)) && m != selmon) {
795 unfocus(selmon->sel); 800 unfocus(selmon->sel, True);
796 selmon = m; 801 selmon = m;
797 } 802 }
798 if((c = wintoclient(ev->window))) 803 if((c = wintoclient(ev->window)))
@@ -814,8 +819,9 @@ void
814focus(Client *c) { 819focus(Client *c) {
815 if(!c || !ISVISIBLE(c)) 820 if(!c || !ISVISIBLE(c))
816 for(c = selmon->stack; c && !ISVISIBLE(c); c = c->snext); 821 for(c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
817 if(selmon->sel) 822 /* was if(selmon->sel) */
818 unfocus(selmon->sel); 823 if(selmon->sel && selmon->sel != c)
824 unfocus(selmon->sel, False);
819 if(c) { 825 if(c) {
820 if(c->mon != selmon) 826 if(c->mon != selmon)
821 selmon = c->mon; 827 selmon = c->mon;
@@ -849,7 +855,7 @@ focusmon(const Arg *arg) {
849 return; 855 return;
850 if((m = dirtomon(arg->i)) == selmon) 856 if((m = dirtomon(arg->i)) == selmon)
851 return; 857 return;
852 unfocus(selmon->sel); 858 unfocus(selmon->sel, True);
853 selmon = m; 859 selmon = m;
854 focus(NULL); 860 focus(NULL);
855} 861}
@@ -901,15 +907,14 @@ getrootptr(int *x, int *y) {
901 907
902long 908long
903getstate(Window w) { 909getstate(Window w) {
904 int format, status; 910 int format;
905 long result = -1; 911 long result = -1;
906 unsigned char *p = NULL; 912 unsigned char *p = NULL;
907 unsigned long n, extra; 913 unsigned long n, extra;
908 Atom real; 914 Atom real;
909 915
910 status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState], 916 if(XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
911 &real, &format, &n, &extra, (unsigned char **)&p); 917 &real, &format, &n, &extra, (unsigned char **)&p) != Success)
912 if(status != Success)
913 return -1; 918 return -1;
914 if(n != 0) 919 if(n != 0)
915 result = *p; 920 result = *p;
@@ -1110,12 +1115,13 @@ manage(Window w, XWindowAttributes *wa) {
1110 applyrules(c); 1115 applyrules(c);
1111 } 1116 }
1112 /* geometry */ 1117 /* geometry */
1113 c->x = wa->x + c->mon->wx; 1118 c->x = c->oldx = wa->x + c->mon->wx;
1114 c->y = wa->y + c->mon->wy; 1119 c->y = c->oldy = wa->y + c->mon->wy;
1115 c->w = wa->width; 1120 c->w = c->oldw = wa->width;
1116 c->h = wa->height; 1121 c->h = c->oldh = wa->height;
1117 c->oldbw = wa->border_width; 1122 c->oldbw = wa->border_width;
1118 if(c->w == c->mon->mw && c->h == c->mon->mh) { 1123 if(c->w == c->mon->mw && c->h == c->mon->mh) {
1124 c->isfloating = 1;
1119 c->x = c->mon->mx; 1125 c->x = c->mon->mx;
1120 c->y = c->mon->my; 1126 c->y = c->mon->my;
1121 c->bw = 0; 1127 c->bw = 0;
@@ -1139,7 +1145,7 @@ manage(Window w, XWindowAttributes *wa) {
1139 XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); 1145 XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
1140 grabbuttons(c, False); 1146 grabbuttons(c, False);
1141 if(!c->isfloating) 1147 if(!c->isfloating)
1142 c->isfloating = trans != None || c->isfixed; 1148 c->isfloating = c->oldstate = trans != None || c->isfixed;
1143 if(c->isfloating) 1149 if(c->isfloating)
1144 XRaiseWindow(dpy, c->win); 1150 XRaiseWindow(dpy, c->win);
1145 attach(c); 1151 attach(c);
@@ -1292,24 +1298,61 @@ propertynotify(XEvent *e) {
1292} 1298}
1293 1299
1294void 1300void
1301clientmessage(XEvent *e) {
1302 XClientMessageEvent *cme = &e->xclient;
1303 Client *c;
1304
1305 if((c = wintoclient(cme->window))
1306 && (cme->message_type == netatom[NetWMState] && cme->data.l[1] == netatom[NetWMFullscreen]))
1307 {
1308 if(cme->data.l[0]) {
1309 XChangeProperty(dpy, cme->window, netatom[NetWMState], XA_ATOM, 32,
1310 PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1);
1311 c->oldstate = c->isfloating;
1312 c->oldbw = c->bw;
1313 c->bw = 0;
1314 c->isfloating = 1;
1315 resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
1316 XRaiseWindow(dpy, c->win);
1317 }
1318 else {
1319 XChangeProperty(dpy, cme->window, netatom[NetWMState], XA_ATOM, 32,
1320 PropModeReplace, (unsigned char*)0, 0);
1321 c->isfloating = c->oldstate;
1322 c->bw = c->oldbw;
1323 c->x = c->oldx;
1324 c->y = c->oldy;
1325 c->w = c->oldw;
1326 c->h = c->oldh;
1327 resizeclient(c, c->x, c->y, c->w, c->h);
1328 arrange(c->mon);
1329 }
1330 }
1331}
1332
1333void
1295quit(const Arg *arg) { 1334quit(const Arg *arg) {
1296 running = False; 1335 running = False;
1297} 1336}
1298 1337
1299void 1338void
1300resize(Client *c, int x, int y, int w, int h, Bool interact) { 1339resize(Client *c, int x, int y, int w, int h, Bool interact) {
1340 if(applysizehints(c, &x, &y, &w, &h, interact))
1341 resizeclient(c, x, y, w, h);
1342}
1343
1344void
1345resizeclient(Client *c, int x, int y, int w, int h) {
1301 XWindowChanges wc; 1346 XWindowChanges wc;
1302 1347
1303 if(applysizehints(c, &x, &y, &w, &h, interact)) { 1348 c->oldx = c->x; c->x = wc.x = x;
1304 c->x = wc.x = x; 1349 c->oldy = c->y; c->y = wc.y = y;
1305 c->y = wc.y = y; 1350 c->oldw = c->w; c->w = wc.width = w;
1306 c->w = wc.width = w; 1351 c->oldh = c->h; c->h = wc.height = h;
1307 c->h = wc.height = h; 1352 wc.border_width = c->bw;
1308 wc.border_width = c->bw; 1353 XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
1309 XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc); 1354 configure(c);
1310 configure(c); 1355 XSync(dpy, False);
1311 XSync(dpy, False);
1312 }
1313} 1356}
1314 1357
1315void 1358void
@@ -1427,7 +1470,7 @@ void
1427sendmon(Client *c, Monitor *m) { 1470sendmon(Client *c, Monitor *m) {
1428 if(c->mon == m) 1471 if(c->mon == m)
1429 return; 1472 return;
1430 unfocus(c); 1473 unfocus(c, True);
1431 detach(c); 1474 detach(c);
1432 detachstack(c); 1475 detachstack(c);
1433 c->mon = m; 1476 c->mon = m;
@@ -1495,6 +1538,7 @@ setup(void) {
1495 netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); 1538 netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
1496 netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); 1539 netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
1497 netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False); 1540 netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
1541 netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
1498 /* init cursors */ 1542 /* init cursors */
1499 cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); 1543 cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
1500 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); 1544 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
@@ -1663,12 +1707,13 @@ toggleview(const Arg *arg) {
1663} 1707}
1664 1708
1665void 1709void
1666unfocus(Client *c) { 1710unfocus(Client *c, Bool setfocus) {
1667 if(!c) 1711 if(!c)
1668 return; 1712 return;
1669 grabbuttons(c, False); 1713 grabbuttons(c, False);
1670 XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]); 1714 XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
1671 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); 1715 if(setfocus)
1716 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
1672} 1717}
1673 1718
1674void 1719void