JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
interactive resizals allow display dimensions again
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 61ac193..2e13241 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -148,7 +148,7 @@ typedef struct {
 
 /* function declarations */
 static void applyrules(Client *c);
-static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h);
+static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact);
 static void arrange(void);
 static void attach(Client *c);
 static void attachstack(Client *c);
@@ -172,6 +172,7 @@ static void enternotify(XEvent *e);
 static void expose(XEvent *e);
 static void focus(Client *c);
 static void focusin(XEvent *e);
+static void focusmon(const Arg *arg);
 static void focusstack(const Arg *arg);
 static unsigned long getcolor(const char *colstr);
 static Bool getrootpointer(int *x, int *y);
@@ -179,6 +180,7 @@ static long getstate(Window w);
 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
 static void grabbuttons(Client *c, Bool focused);
 static void grabkeys(void);
+static Monitor *idxtomon(unsigned int n);
 static void initfont(const char *fontstr);
 static Bool isprotodel(Client *c);
 static void keypress(XEvent *e);
@@ -192,7 +194,7 @@ static Client *nexttiled(Client *c);
 static Monitor *pointertomon(int x, int y);
 static void propertynotify(XEvent *e);
 static void quit(const Arg *arg);
-static void resize(Client *c, int x, int y, int w, int h);
+static void resize(Client *c, int x, int y, int w, int h, Bool interact);
 static void resizemouse(const Arg *arg);
 static void restack(Monitor *m);
 static void run(void);
@@ -206,6 +208,7 @@ static void showhide(Client *c);
 static void sigchld(int signal);
 static void spawn(const Arg *arg);
 static void tag(const Arg *arg);
+static void tagmon(const Arg *arg);
 static int textnw(const char *text, unsigned int len);
 static void tile(Monitor *);
 static void togglebar(const Arg *arg);
@@ -230,11 +233,6 @@ static int xerror(Display *dpy, XErrorEvent *ee);
 static int xerrordummy(Display *dpy, XErrorEvent *ee);
 static int xerrorstart(Display *dpy, XErrorEvent *ee);
 static void zoom(const Arg *arg);
-#ifdef XINERAMA
-static void focusmon(const Arg *arg);
-static Monitor *idxtomon(unsigned int n);
-static void tagmon(const Arg *arg);
-#endif /* XINERAMA */
 
 /* variables */
 static char stext[256];
@@ -300,7 +298,7 @@ applyrules(Client *c) {
 }
 
 Bool
-applysizehints(Client *c, int *x, int *y, int *w, int *h) {
+applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact) {
        Bool baseismin;
        Monitor *m = c->mon;
 
@@ -308,14 +306,26 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h) {
        *w = MAX(1, *w);
        *h = MAX(1, *h);
 
-       if(*x > m->mx + m->mw)
-               *x = m->mw - WIDTH(c);
-       if(*y > m->my + m->mh)
-               *y = m->mh - HEIGHT(c);
-       if(*x + *w + 2 * c->bw < m->mx)
-               *x = m->mx;
-       if(*y + *h + 2 * c->bw < m->my)
-               *y = m->my;
+       if(interact) {
+               if(*x > sw)
+                       *x = sw - WIDTH(c);
+               if(*y > sh)
+                       *y = sh - HEIGHT(c);
+               if(*x + *w + 2 * c->bw < 0)
+                       *x = 0;
+               if(*y + *h + 2 * c->bw < 0)
+                       *y = 0;
+       }
+       else {
+               if(*x > m->mx + m->mw)
+                       *x = m->mx + m->mw - WIDTH(c);
+               if(*y > m->my + m->mh)
+                       *y = m->my + m->mh - HEIGHT(c);
+               if(*x + *w + 2 * c->bw < m->mx)
+                       *x = m->mx;
+               if(*y + *h + 2 * c->bw < m->my)
+                       *y = m->my;
+       }
        if(*h < bh)
                *h = bh;
        if(*w < bh)
@@ -636,16 +646,11 @@ drawbar(Monitor *m) {
        }
 
        dc.x = 0;
-#ifdef XINERAMA
        if(mons->next) { /* more than a single monitor */
-               char buf[2];
-               buf[0] = m->screen_number + '0';
-               buf[1] = '\0';
-               dc.w = TEXTW(buf);
-               drawtext(buf, selmon == m ? dc.sel : dc.norm, True);
+               dc.w = TEXTW(monsyms[m->screen_number]);
+               drawtext(monsyms[m->screen_number], selmon == m ? dc.sel : dc.norm, False);
                dc.x += dc.w;
        }
-#endif /* XINERAMA */
        m->btx = dc.x;
        for(i = 0; i < LENGTH(tags); i++) {
                dc.w = TEXTW(tags[i]);
@@ -803,7 +808,6 @@ focusin(XEvent *e) { /* there are some broken focus acquiring clients */
                XSetInputFocus(dpy, selmon->sel->win, RevertToPointerRoot, CurrentTime);
 }
 
-#ifdef XINERAMA
 void
 focusmon(const Arg *arg) {
        Monitor *m;
@@ -814,7 +818,6 @@ focusmon(const Arg *arg) {
        selmon = m;
        focus(NULL);
 }
-#endif /* XINERAMA */
 
 void
 focusstack(const Arg *arg) {
@@ -943,7 +946,6 @@ grabkeys(void) {
        }
 }
 
-#ifdef XINERAMA
 Monitor *
 idxtomon(unsigned int n) {
        unsigned int i;
@@ -952,7 +954,6 @@ idxtomon(unsigned int n) {
        for(m = mons, i = 0; m && i != n; m = m->next, i++);
        return m;
 }
-#endif /* XINERAMA */
 
 void
 initfont(const char *fontstr) {
@@ -1131,7 +1132,7 @@ monocle(Monitor *m) {
        Client *c;
 
        for(c = nexttiled(m->clients); c; c = nexttiled(c->next))
-               resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw);
+               resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, False);
 }
 
 void
@@ -1177,7 +1178,7 @@ movemouse(const Arg *arg) {
                                        togglefloating(NULL);
                        }
                        if(!lt[selmon->sellt]->arrange || c->isfloating)
-                               resize(c, nx, ny, c->w, c->h);
+                               resize(c, nx, ny, c->w, c->h, True);
                        break;
                }
        }
@@ -1203,7 +1204,7 @@ pointertomon(int x, int y) {
        for(m = mons; m; m = m->next)
                if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh))
                        return m;
-       return mons;
+       return selmon;
 }
 
 void
@@ -1246,10 +1247,10 @@ quit(const Arg *arg) {
 }
 
 void
-resize(Client *c, int x, int y, int w, int h) {
+resize(Client *c, int x, int y, int w, int h, Bool interact) {
        XWindowChanges wc;
 
-       if(applysizehints(c, &x, &y, &w, &h)) {
+       if(applysizehints(c, &x, &y, &w, &h, interact)) {
                c->x = wc.x = x;
                c->y = wc.y = y;
                c->w = wc.width = w;
@@ -1297,7 +1298,7 @@ resizemouse(const Arg *arg) {
                                        togglefloating(NULL);
                        }
                        if(!lt[selmon->sellt]->arrange || c->isfloating)
-                               resize(c, c->x, c->y, nw, nh);
+                               resize(c, c->x, c->y, nw, nh, True);
                        break;
                }
        }
@@ -1378,6 +1379,7 @@ void
 sendmon(Client *c, Monitor *m) {
        if(c->mon == m)
                return;
+       unfocus(c);
        detach(c);
        detachstack(c);
        c->mon = m;
@@ -1494,7 +1496,7 @@ showhide(Client *c) {
        if(ISVISIBLE(c)) { /* show clients top down */
                XMoveWindow(dpy, c->win, c->x, c->y);
                if(!lt[c->mon->sellt]->arrange || c->isfloating)
-                       resize(c, c->x, c->y, c->w, c->h);
+                       resize(c, c->x, c->y, c->w, c->h, False);
                showhide(c->snext);
        }
        else { /* hide clients bottom up */
@@ -1531,7 +1533,6 @@ tag(const Arg *arg) {
        }
 }
 
-#ifdef XINERAMA
 void
 tagmon(const Arg *arg) {
        Monitor *m;
@@ -1540,7 +1541,6 @@ tagmon(const Arg *arg) {
                return;
        sendmon(selmon->sel, m);
 }
-#endif /* XINERAMA */
 
 int
 textnw(const char *text, unsigned int len) {
@@ -1566,7 +1566,7 @@ tile(Monitor *m) {
        /* master */
        c = nexttiled(m->clients);
        mw = m->mfact * m->ww;
-       resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw);
+       resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw, False);
 
        if(--n == 0)
                return;
@@ -1581,7 +1581,7 @@ tile(Monitor *m) {
 
        for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
                resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
-                      ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw));
+                      ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw), False);
                if(h != m->wh)
                        y = c->y + HEIGHT(c);
        }
@@ -1601,7 +1601,8 @@ togglefloating(const Arg *arg) {
                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);
+               resize(selmon->sel, selmon->sel->x, selmon->sel->y,
+                      selmon->sel->w, selmon->sel->h, False);
        arrange();
 }
 
@@ -1736,9 +1737,9 @@ updategeom(void) {
        /* default monitor setup */
        {
                m->screen_number = 0;
-               m->wx = 0;
+               m->mx = m->wx = 0;
                m->my = m->wy = 0;
-               m->ww = sw;
+               m->mw = m->ww = sw;
                m->mh = m->wh = sh;
        }
 
@@ -1767,7 +1768,7 @@ updategeom(void) {
 
        /* select focused monitor */
        cleanupmons();
-       mons = newmons;
+       selmon = mons = newmons;
        selmon = wintomon(root);
 }
 
@@ -1900,7 +1901,7 @@ wintomon(Window w) {
                        return m;
        if((c = wintoclient(w)))
                return c->mon;
-       return mons;
+       return selmon;
 }
 
 /* There's no way to check accesses to destroyed windows, thus those cases are