Created
December 31, 2015 02:55
-
-
Save jgrar/7a0dace34dd3fb32e593 to your computer and use it in GitHub Desktop.
Add save float behaviour to all layout changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/dwm.c b/dwm.c | |
index 450e420..7978a1f 100644 | |
--- a/dwm.c | |
+++ b/dwm.c | |
@@ -89,6 +89,7 @@ struct Client { | |
char name[256]; | |
float mina, maxa; | |
int x, y, w, h; | |
+ int sfx, sfy, sfw, sfh; /* stored float geometry, used on mode revert */ | |
int oldx, oldy, oldw, oldh; | |
int basew, baseh, incw, inch, maxw, maxh, minw, minh; | |
int bw, oldbw; | |
@@ -1070,6 +1070,10 @@ manage(Window w, XWindowAttributes *wa) | |
updatewindowtype(c); | |
updatesizehints(c); | |
updatewmhints(c); | |
+ c->sfx = c->x; | |
+ c->sfy = c->y; | |
+ c->sfw = c->w; | |
+ c->sfh = c->h; | |
XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); | |
grabbuttons(c, 0); | |
if (!c->isfloating) | |
@@ -1517,10 +1522,29 @@ setfullscreen(Client *c, int fullscreen) | |
void | |
setlayout(const Arg *arg) | |
{ | |
+ Monitor *m; | |
+ Client *c; | |
+ unsigned int fromlt = selmon->sellt; | |
if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) | |
selmon->sellt ^= 1; | |
- if (arg && arg->v) | |
+ if (arg && arg->v) { | |
+ if (((Layout *)arg->v)->arrange == NULL | |
+ && selmon->lt[fromlt]->arrange != NULL) | |
+ /*restore last known float dimensions*/ | |
+ for (m = mons; m; m = m->next) | |
+ for (c = m->clients; c; c = c->next) | |
+ resize(c, c->sfx, c->sfy, c->sfw, c->sfh, 0); | |
+ else if (selmon->lt[fromlt]->arrange == NULL) | |
+ /*save last known float dimensions*/ | |
+ for (m = mons; m; m = m->next) | |
+ for (c = m->clients; c; c = c->next) { | |
+ c->sfx = c->x; | |
+ c->sfy = c->y; | |
+ c->sfw = c->w; | |
+ c->sfh = c->h; | |
+ } | |
selmon->lt[selmon->sellt] = (Layout *)arg->v; | |
+ } | |
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); | |
if (selmon->sel) | |
arrange(selmon); | |
@@ -1706,9 +1730,17 @@ togglefloating(const Arg *arg) | |
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, 0); | |
+ if (selmon->sel->isfloating) { | |
+ /*restore last known float dimensions*/ | |
+ resize(selmon->sel, selmon->sel->sfx, selmon->sel->sfy, | |
+ selmon->sel->sfw, selmon->sel->sfh, 0); | |
+ } else { | |
+ /*save last known float dimensions*/ | |
+ selmon->sel->sfx = selmon->sel->x; | |
+ selmon->sel->sfy = selmon->sel->y; | |
+ selmon->sel->sfw = selmon->sel->w; | |
+ selmon->sel->sfh = selmon->sel->h; | |
+ } | |
arrange(selmon); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Savefloats
Original
http://dwm.suckless.org/patches/save_floats
Applies to
http://git.suckless.org/dwm/commit/?id=3465bed290abc62cb2e69a8096084ba6b8eb4956
Changes
The original version of this patch only saves float geometry on togglefloating() (default MOD+shift+space). I've added float geometry saving to all layout changes (occurring through setlayout()) because I feel like that is the expected behaviour.
Bugs
Opening a window in floating layout and then switching to another workspace, changing layout, switching back to the original workspace (the one with the window you just made) and back again and then changing back to floating layout leaves an artefact of the new window in the new workspace.