Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switchcol but for swapping selected window in stack with master #406

Open
luravoid opened this issue Jan 11, 2024 · 3 comments
Open

Switchcol but for swapping selected window in stack with master #406

luravoid opened this issue Jan 11, 2024 · 3 comments

Comments

@luravoid
Copy link

I have switchcol on super+space hotkey and I would like to have something like switchcol-swap on super+shift+space.
Do you have any patch for it? It would be great

@bakkeby
Copy link
Owner

bakkeby commented Jan 11, 2024

Yes probably, it sounds a bit like zoomswap.

@luravoid
Copy link
Author

Zoomswap would be good if after swapping with the master window, the switchcol hotkey returned to the same place in the stack. Instead switchcol shifts focus to the window in the stack that was focused prior to the one swapped with the master

@bakkeby
Copy link
Owner

bakkeby commented Jan 12, 2024

void
switchcol(const Arg *arg)
{
Client *c, *t;
int col = 0;
int i;
if (!selmon->sel)
return;
for (i = 0, c = nexttiled(selmon->clients); c ;
c = nexttiled(c->next), i++) {
if (c == selmon->sel)
col = (i + 1) > selmon->nmaster;
}
if (i <= selmon->nmaster)
return;
for (c = selmon->stack; c; c = c->snext) {
if (!ISVISIBLE(c))
continue;
for (i = 0, t = nexttiled(selmon->clients); t && t != c;
t = nexttiled(t->next), i++);
if (t && (i + 1 > selmon->nmaster) != col) {
focus(c);
restack(selmon);
break;
}
}
}

Instead switchcol shifts focus to the window in the stack that was focused prior to the one swapped with the master

That is not entirely accurate. The function loops through the stacking order, i.e. the order in which windows received focused going from most recent to oldest.

Let's say that you have a master window and three windows 1, 2, 3 in the stack area.

You use MOD+v (switchcol) to move from the master area to the stack area and you land on the first window 1.

Four example scenarios:

  1. You use the MOD+j to move focus to window 2.

Window 2 is the window that most recently have focus, window 1 is the one after that.

You do MOD+Return to trigger zoomswap replacing the master window with window 2. Window 2 retains focus.

You now do MOD+v to trigger switchcol. The first window in the stack is window 2 - which is the selected client. We are in the master area and the selected client is in the master area so we go to the stack area. The next client in the stack is tried and this is Window 1. That window is in the stack area and thus it ends up receiving focus.

  1. You use MOD+j two times to move focus to window 3, then use MOD+k to move back to Window 2.

Now you do MOD+Return to trigger zoomswap replacing the master window with window 2.

You now do MOD+v to trigger switchcol. The outcome is that Window 3 gets focus as that is the window in the stack area that most recently had focus.

  1. You use MOD+j to move focus to window 2.

You do MOD+Return to trigger zoomswap replacing the master window with window 2.

You now do MOD+Return to trigger zoomswap replacing window 2 with the original master window. The master window receives focus.

You do MOD+Return once more to trigger zoomswap replacing the master window with window 2.

Then you do MOD+v to trigger switchcol. The outcome is that the master window in the stack area gets focus because that is the window in the stack area that most recently had focus.

  1. Same as 3) just that you do MOD+v to trigger switchcol back and forth before triggering zoom.

All in all it seems to work as intended.

But I can see how this might be annoying for this particular workflow so one might work around this by moving the master window to the top of the stack before swapping.

diff --git a/dwm.c b/dwm.c
index fa51816..1081043 100644
--- a/dwm.c
+++ b/dwm.c
@@ -5171,6 +5171,8 @@ zoom(const Arg *arg)

        c->mon->tagmarked[i] = cold;
        #endif // FOCUSMASTER_RETURN_PATCH
+       detachstack(cold);
+       attachstack(cold);
        detach(c);
        attach(c);
        /* swap windows instead of pushing the previous one down */

I don't have it included in dwm-flexipatch but the masterstacker patch might also be an alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants