OK. Hopefully this is the last post regarding this particular patch.
The previous patch was not the most recent. I made a mistake while
differencing the sources. The only part missing was a check to ensure
floating was the previous layout before saving the geometry.
As stated in my previous post, please updated to this latest version
to avoid bugs.
- Abel
diff --git a/client.c b/client.c
index cd16e11..c0d55ca 100644
--- a/client.c
+++ b/client.c
@@ -185,11 +185,12 @@ manage(Window w, XWindowAttributes *wa) {
c = emallocz(sizeof(Client));
c->tags = emallocz(ntags * sizeof(Bool));
+ c->ftview = True;
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 +199,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..7d2540d 100644
--- a/dwm.h
+++ b/dwm.h
@@ -56,6 +56,7 @@ struct Client {
Client *prev;
Client *snext;
Window win;
+ Bool ftview; /* first time viewed on new layout */
};
typedef struct {
diff --git a/screen.c b/screen.c
index 255184a..d276d3d 100644
--- a/screen.c
+++ b/screen.c
@@ -43,12 +43,26 @@ idxoftag(const char *tag) {
}
static void
+savergeom(Client *c) {
+ c->rx = c->x;
+ c->ry = c->y;
+ c->rw = c->w;
+ c->rh = c->h;
+}
+
+static void
floating(void) { /* default floating layout */
Client *c;
for(c = clients; c; c = c->next)
- if(isvisible(c))
- resize(c, c->x, c->y, c->w, c->h, True);
+ if(isvisible(c)) {
+ if(c->ftview && !c->isfloating) {
+ resize(c, c->rx, c->ry, c->rw, c->rh, True);
+ c->ftview = False;
+ }
+ else
+ resize(c, c->x, c->y, c->w, c->h, True);
+ }
}
LAYOUTS
@@ -92,10 +106,16 @@ applyrules(Client *c) {
void
arrange(void) {
Client *c;
+ int i = (ltidx ? ltidx : nlayouts) - 1;
for(c = clients; c; c = c->next)
- if(isvisible(c))
+ if(isvisible(c)) {
unban(c);
+ if(!isfloating() && !c->isfloating && c->ftview &&
layouts[i].arrange == floating) {
+ savergeom(c);
+ c->ftview = False;
+ }
+ }
else
ban(c);
layouts[ltidx].arrange();
@@ -239,6 +259,7 @@ restack(void) {
void
setlayout(const char *arg) {
unsigned int i;
+ Client *c;
if(!arg) {
if(++ltidx == nlayouts)
@@ -252,6 +273,8 @@ setlayout(const char *arg) {
return;
ltidx = i;
}
+ for(c = clients; c; c = c->next)
+ c->ftview = True;
if(sel)
arrange();
else
@@ -288,7 +311,10 @@ 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
+ savergeom(sel);
+
arrange();
}
@@ -299,10 +325,7 @@ togglemax(const char *arg) {
if(!sel || (!isfloating() && !sel->isfloating) || sel->isfixed)
return;
if((sel->ismax = !sel->ismax)) {
- sel->rx = sel->x;
- sel->ry = sel->y;
- sel->rw = sel->w;
- sel->rh = sel->h;
+ savergeom(sel);
resize(sel, wax, way, waw - 2 * sel->border, wah - 2 *
sel->border, True);
}
else