JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
monocle: don't resize windows when moving them offscreen
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 362e902..241c090 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -187,6 +187,7 @@ static void monocle(Monitor *m);
 static void motionnotify(XEvent *e);
 static void movemouse(const Arg *arg);
 static Client *nexttiled(Client *c);
+static Client *snexttiled(Client *c);
 static Client *nextvisible(Client *c);
 static void pop(Client *);
 static void propertynotify(XEvent *e);
@@ -317,7 +318,7 @@ update_window_opacities(Monitor *m) {
        }
        for (c = m->clients; c; c = c->next) {
                if (ISVISIBLE(c)) {
-                       if (c->isfloating || c == m->sel || (c == master && selection_floating)) {
+                       if (c->isfloating || c == m->sel || (selection_floating && (c == master || c == slave))) {
                                window_set_opaque(c);
                        } else if (c == master || c == slave) {
                                window_set_translucent(c);
@@ -374,7 +375,7 @@ applyrules(Client *c) {
 Bool
 applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact) {
        Bool baseismin;
-       Monitor *m = c->mon;
+       // Monitor *m = c->mon;
 
        /* set minimum possible */
        *w = MAX(1, *w);
@@ -389,16 +390,17 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact) {
                if(*y + *h + 2 * c->bw < 0)
                        *y = 0;
        }
-       else {
-               if(*x >= m->wx + m->ww)
-                       *x = m->wx + m->ww - WIDTH(c);
-               if(*y >= m->wy + m->wh)
-                       *y = m->wy + m->wh - HEIGHT(c);
-               if(*x + *w + 2 * c->bw <= m->wx)
-                       *x = m->wx;
-               if(*y + *h + 2 * c->bw <= m->wy)
-                       *y = m->wy;
-       }
+       // jason: let windows be offscreen
+       //else {
+       //      if(*x >= m->wx + m->ww)
+       //              *x = m->wx + m->ww - WIDTH(c);
+       //      if(*y >= m->wy + m->wh)
+       //              *y = m->wy + m->wh - HEIGHT(c);
+       //      if(*x + *w + 2 * c->bw <= m->wx)
+       //              *x = m->wx;
+       //      if(*y + *h + 2 * c->bw <= m->wy)
+       //              *y = m->wy;
+       //}
        if(*h < bh)
                *h = bh;
        if(*w < bh)
@@ -599,6 +601,7 @@ clientmessage(XEvent *e) {
                                      || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
        }
        else if(cme->message_type == netatom[NetActiveWindow]) {
+               // Jason added this so apps can't steal focus:
                return;
                if(!ISVISIBLE(c)) {
                        c->mon->seltags ^= 1;
@@ -842,6 +845,8 @@ enternotify(XEvent *e) {
        Monitor *m;
        XCrossingEvent *ev = &e->xcrossing;
 
+       return; // jason: added to stop mouse focus
+
        if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
                return;
        c = wintoclient(ev->window);
@@ -887,7 +892,7 @@ focus(Client *c) {
                XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
        }
        selmon->sel = c;
-       jason_layout(selmon);
+       arrange(selmon);
        update_window_opacities(selmon);
        drawbars();
        if(c && (!root || (c->win!=root)) )
@@ -1196,8 +1201,14 @@ monocle(Monitor *m) {
                        n++;
        if(n > 0) /* override layout symbol */
                snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
-       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, False, 0);
+       for(c = snexttiled(m->stack); c; c = snexttiled(c->snext)) {
+               if (c == m->sel) {
+                       resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, False, 0);
+               } else {
+                       // this window is should not be visible. move off top, but don't change h/w
+                       resize(c, m->wx, m->wy - 4000, c->w, c->h, False, 0);
+               }
+       }
 }
 
 void
@@ -1285,6 +1296,12 @@ nexttiled(Client *c) {
 }
 
 Client *
+snexttiled(Client *c) {
+       for(; c && (c->isfloating || !ISVISIBLE(c)); c = c->snext);
+       return c;
+}
+
+Client *
 nextvisible(Client *c) {
        for(; c && !ISVISIBLE(c); c = c->next);
        return c;
@@ -1367,7 +1384,7 @@ resizeclient(Client *c, int x, int y, int w, int h, Client *base) {
        c->oldy = c->y; c->y = wc.y = y;
        c->oldw = c->w; c->w = wc.width = w;
        c->oldh = c->h; c->h = wc.height = h;
-       base = 0;
+       // base = 0;
        if (base) {
                wc.stack_mode = Above;
                wc.sibling = base->win;
@@ -1778,12 +1795,12 @@ jason_layout(Monitor *m) {
 
        for(tiled_count = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), tiled_count++) {
                if (tiled_count == 0) { // master
-                       if (c == m->sel) {
-                               if (c->next) {
+                       if (c->next) {
+                               if (m->sel && (m->sel == c || m->sel->isfloating || !ISVISIBLE(m->sel))) {
                                        vis_slave = nexttiled(c->next);
+                               } else {
+                                       vis_slave = m->sel;
                                }
-                       } else {
-                               vis_slave = m->sel;
                        }
                } else {
                        if (c == vis_slave) {
@@ -1800,10 +1817,6 @@ jason_layout(Monitor *m) {
        if(tiled_count > 1 || (tiled_count == 1 && !nexttiled(m->clients)->screen_hog)) {
                mw = m->ww * m->mfact;
        } else {
-               // one of these:
-               // * zero tiled windows
-               // * one tiled window that's not a screen hog
-               // * miltiple tiled windows
                mw = m->ww;
        }
        right_width = m->ww - mw;