JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
removed DDC, all is Draw-dependent
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 10b0d0d..8b67cea 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -40,6 +40,8 @@
 #include <X11/extensions/Xinerama.h>
 #endif /* XINERAMA */
 
+#include "draw.h"
+
 /* macros */
 #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
 #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
@@ -60,7 +62,7 @@ enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
 enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
 enum { NetSupported, NetWMName, NetWMState,
        NetWMFullscreen, NetActiveWindow, NetWMWindowType,
-       NetWMWindowTypeDialog, NetLast };     /* EWMH atoms */
+       NetWMWindowTypeDialog, NetClientList, NetLast };     /* EWMH atoms */
 enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
        ClkClientWin, ClkRootWin, ClkLast };             /* clicks */
@@ -238,6 +240,7 @@ static void unmapnotify(XEvent *e);
 static Bool updategeom(void);
 static void updatebarpos(Monitor *m);
 static void updatebars(void);
+static void updateclientlist(void);
 static void updatenumlockmask(void);
 static void updatesizehints(Client *c);
 static void updatestatus(void);
@@ -499,6 +502,7 @@ cleanup(void) {
                cleanupmon(mons);
        XSync(dpy, False);
        XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
+       XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
 }
 
 void
@@ -573,8 +577,9 @@ configurenotify(XEvent *e) {
        XConfigureEvent *ev = &e->xconfigure;
        Bool dirty;
 
+       // TODO: updategeom handling sucks, needs to be simplified
        if(ev->window == root) {
-               dirty = (sw != ev->width);
+               dirty = (sw != ev->width || sh != ev->height);
                sw = ev->width;
                sh = ev->height;
                if(updategeom() || dirty) {
@@ -858,8 +863,10 @@ focus(Client *c) {
                XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
                setfocus(c);
        }
-       else
+       else {
                XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+               XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+       }
        selmon->sel = c;
        drawbars();
 }
@@ -880,7 +887,8 @@ focusmon(const Arg *arg) {
                return;
        if((m = dirtomon(arg->i)) == selmon)
                return;
-       unfocus(selmon->sel, True);
+       unfocus(selmon->sel, False); /* s/True/False/ fixes input focus issues
+                                       in gedit and anjuta */
        selmon = m;
        focus(NULL);
 }
@@ -1157,6 +1165,8 @@ manage(Window w, XWindowAttributes *wa) {
                XRaiseWindow(dpy, c->win);
        attach(c);
        attachstack(c);
+       XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
+                       (unsigned char *) &(c->win), 1);
        XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
        setclientstate(c, NormalState);
        if (c->mon == selmon)
@@ -1228,6 +1238,8 @@ movemouse(const Arg *arg) {
 
        if(!(c = selmon->sel))
                return;
+       if(c->isfullscreen) /* no support moving fullscreen windows by mouse */
+               return;
        restack(selmon);
        ocx = c->x;
        ocy = c->y;
@@ -1261,11 +1273,8 @@ movemouse(const Arg *arg) {
                                && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
                                        togglefloating(NULL);
                        }
-                       if(!selmon->lt[selmon->sellt]->arrange || c->isfloating) {
-                               if(c->isfullscreen)
-                                       setfullscreen(c, False);
+                       if(!selmon->lt[selmon->sellt]->arrange || c->isfloating)
                                resize(c, nx, ny, c->w, c->h, True);
-                       }
                        break;
                }
        } while(ev.type != ButtonRelease);
@@ -1375,6 +1384,8 @@ resizemouse(const Arg *arg) {
 
        if(!(c = selmon->sel))
                return;
+       if(c->isfullscreen) /* no support resizing fullscreen windows by mouse */
+               return;
        restack(selmon);
        ocx = c->x;
        ocy = c->y;
@@ -1400,11 +1411,8 @@ resizemouse(const Arg *arg) {
                                && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
                                        togglefloating(NULL);
                        }
-                       if(!selmon->lt[selmon->sellt]->arrange || c->isfloating) {
-                               if(c->isfullscreen)
-                                       setfullscreen(c, False);
+                       if(!selmon->lt[selmon->sellt]->arrange || c->isfloating)
                                resize(c, c->x, c->y, nw, nh, True);
-                       }
                        break;
                }
        } while(ev.type != ButtonRelease);
@@ -1527,8 +1535,12 @@ sendevent(Client *c, Atom proto) {
 
 void
 setfocus(Client *c) {
-       if(!c->neverfocus)
+       if(!c->neverfocus) {
                XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
+               XChangeProperty(dpy, root, netatom[NetActiveWindow],
+                               XA_WINDOW, 32, PropModeReplace,
+                               (unsigned char *) &(c->win), 1);
+       }
        sendevent(c, wmatom[WMTakeFocus]);
 }
 
@@ -1614,6 +1626,7 @@ setup(void) {
        netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
        netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
        netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
+       netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
        /* init cursors */
        cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
        cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
@@ -1636,6 +1649,7 @@ setup(void) {
        /* EWMH support per view */
        XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
                        PropModeReplace, (unsigned char *) netatom, NetLast);
+       XDeleteProperty(dpy, root, netatom[NetClientList]);
        /* select for events */
        wa.cursor = cursor[CurNormal];
        wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask|PointerMotionMask
@@ -1746,12 +1760,12 @@ void
 togglefloating(const Arg *arg) {
        if(!selmon->sel)
                return;
+       if(selmon->sel->isfullscreen) /* no support for fullscreen windows */
+               return;
        selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
        if(selmon->sel->isfloating)
                resize(selmon->sel, selmon->sel->x, selmon->sel->y,
                       selmon->sel->w, selmon->sel->h, False);
-       else if(selmon->sel->isfullscreen)
-               setfullscreen(selmon->sel, False);
        arrange(selmon);
 }
 
@@ -1786,8 +1800,10 @@ unfocus(Client *c, Bool setfocus) {
                return;
        grabbuttons(c, False);
        XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
-       if(setfocus)
+       if(setfocus) {
                XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+               XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+       }
 }
 
 void
@@ -1811,6 +1827,7 @@ unmanage(Client *c, Bool destroyed) {
        }
        free(c);
        focus(NULL);
+       updateclientlist();
        arrange(m);
 }
 
@@ -1859,6 +1876,19 @@ updatebarpos(Monitor *m) {
                m->by = -bh;
 }
 
+void
+updateclientlist() {
+       Client *c;
+       Monitor *m;
+
+       XDeleteProperty(dpy, root, netatom[NetClientList]);
+       for(m = mons; m; m = m->next)
+               for(c = m->clients; c; c = c->next)
+                       XChangeProperty(dpy, root, netatom[NetClientList],
+                                       XA_WINDOW, 32, PropModeAppend,
+                                       (unsigned char *) &(c->win), 1);
+}
+
 Bool
 updategeom(void) {
        Bool dirty = False;