JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
shut up about deprecated Xlib functions
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 95571f6..7941bd1 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -40,6 +40,9 @@
 #include <X11/extensions/Xinerama.h>
 #endif /* XINERAMA */
 
+#include "drw.h"
+#include "util.h"
+
 /* macros */
 #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
 #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
@@ -47,8 +50,6 @@
                                * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
 #define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
 #define LENGTH(X)               (sizeof X / sizeof X[0])
-#define MAX(A, B)               ((A) > (B) ? (A) : (B))
-#define MIN(A, B)               ((A) < (B) ? (A) : (B))
 #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
 #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
 #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
@@ -60,7 +61,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 */
@@ -174,7 +175,6 @@ static Monitor *createmon(void);
 static void destroynotify(XEvent *e);
 static void detach(Client *c);
 static void detachstack(Client *c);
-static void die(const char *errstr, ...);
 static Monitor *dirtomon(int dir);
 static void drawbar(Monitor *m);
 static void drawbars(void);
@@ -238,6 +238,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);
@@ -574,8 +575,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) {
@@ -691,16 +693,6 @@ detachstack(Client *c) {
        }
 }
 
-void
-die(const char *errstr, ...) {
-       va_list ap;
-
-       va_start(ap, errstr);
-       vfprintf(stderr, errstr, ap);
-       va_end(ap);
-       exit(EXIT_FAILURE);
-}
-
 Monitor *
 dirtomon(int dir) {
        Monitor *m = NULL;
@@ -883,7 +875,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);
 }
@@ -1160,6 +1153,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)
@@ -1231,6 +1226,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;
@@ -1264,11 +1261,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);
@@ -1378,6 +1372,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;
@@ -1403,11 +1399,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);
@@ -1621,6 +1614,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);
@@ -1643,6 +1637,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
@@ -1753,12 +1748,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);
 }
 
@@ -1820,6 +1815,7 @@ unmanage(Client *c, Bool destroyed) {
        }
        free(c);
        focus(NULL);
+       updateclientlist();
        arrange(m);
 }
 
@@ -1868,6 +1864,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;