[dwm] window dimensions patch

From: Abel Darc <abeldarc_AT_googlemail.com>
Date: Sat, 25 Aug 2007 12:40:40 +0100

The following patch should allow floating and tiled modes to maintain separate
window dimensions. You can now switch between modes and have floating windows
stay the same, even after tiled mode moves and resizes them.

I just put this together so it may look a little rough, and may not work in
all cases. Improvements welcome.

I looked through the mailing list and couldn't find a similar patch,
but if one exists I apologize.

- Abel

Patch against 4.4.

-------------------------------------------------------------------------------

diff --git a/client.c b/client.c
index a105514..f86d1a2 100644
--- a/client.c
+++ b/client.c
@@ -186,10 +186,10 @@ manage(Window w, XWindowAttributes *wa) {
         c = emallocz(sizeof(Client));
         c->tags = emallocz(ntags * sizeof(Bool));
         c->win = w;
- c->x = wa->x;
- c->y = wa->y;
- c->w = wa->width;
- c->h = wa->height;
+ c->x = c->rx = wa->x;
+ c->y = c->ry = wa->y;
+ c->w = c->rw = wa->width;
+ c->h = c->rh = wa->height;
         c->oldborder = wa->border_width;
         if(c->w == sw && c->h == sh) {
                 c->x = sx;
@@ -198,13 +198,13 @@ manage(Window w, XWindowAttributes *wa) {
         }
         else {
                 if(c->x + c->w + 2 * c->border > wax + waw)
- c->x = wax + waw - c->w - 2 * c->border;
+ c->x = c->rx = wax + waw - c->w - 2 * c->border;
                 if(c->y + c->h + 2 * c->border > way + wah)
- c->y = way + wah - c->h - 2 * c->border;
+ c->y = c->ry = way + wah - c->h - 2 * c->border;
                 if(c->x < wax)
- c->x = wax;
+ c->x = c->rx = wax;
                 if(c->y < way)
- c->y = way;
+ c->y = c->ry = way;
                 c->border = BORDERPX;
         }
         wc.border_width = c->border;
diff --git a/dwm.h b/dwm.h
index 1a12322..6cd3289 100644
--- a/dwm.h
+++ b/dwm.h
@@ -87,6 +87,7 @@ extern Cursor cursor[CurLast];
 extern DC dc; /* global draw context */
 extern Display *dpy;
 extern Window root, barwin;
+extern Bool ltchange;

 /* client.c */
 void attach(Client *c); /* attaches c to global client list */
diff --git a/screen.c b/screen.c
index 8d04911..f03395e 100644
--- a/screen.c
+++ b/screen.c
@@ -48,7 +48,7 @@ floating(void) { /* default floating layout */

         for(c = clients; c; c = c->next)
                 if(isvisible(c))
- resize(c, c->x, c->y, c->w, c->h, True);
+ resize(c, c->rx, c->ry, c->rw, c->rh, True);
 }

 LAYOUTS
@@ -56,6 +56,7 @@ LAYOUTS
 /* extern */

 unsigned int blw = 0;
+Bool ltchange = False;

 void
 applyrules(Client *c) {
@@ -243,6 +244,7 @@ setlayout(const char *arg) {
         if(!arg) {
                 if(++ltidx == nlayouts)
                         ltidx = 0;;
+ ltchange = True;
         }
         else {
                 for(i = 0; i < nlayouts; i++)
@@ -251,6 +253,7 @@ setlayout(const char *arg) {
                 if(i == nlayouts)
                         return;
                 ltidx = i;
+ ltchange = True;
         }
         if(sel)
                 arrange();
@@ -288,7 +291,14 @@ togglefloating(const char *arg) {
                 return;
         sel->isfloating = !sel->isfloating;
         if(sel->isfloating)
- resize(sel, sel->x, sel->y, sel->w, sel->h, True);
+ resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
+ else {
+ sel->rx = sel->x;
+ sel->ry = sel->y;
+ sel->rw = sel->w;
+ sel->rh = sel->h;
+ }
+
         arrange();
 }

diff --git a/tile.c b/tile.c
index 114e84c..47f5b89 100644
--- a/tile.c
+++ b/tile.c
@@ -63,11 +63,18 @@ tile(void) {
                         else
                                 nh = th - 2 * c->border;
                 }
+ if (ltchange) {
+ c->rx = c->x;
+ c->ry = c->y;
+ c->rw = c->w;
+ c->rh = c->h;
+ }
                 resize(c, nx, ny, nw, nh, False);
                 if(n > 1 && th != wah)
                         ny += nh + 2 * c->border;
                 i++;
         }
+ ltchange = False;
 }

 void
Received on Sat Aug 25 2007 - 13:40:42 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:51:13 UTC