diff --git a/dwm.c b/dwm.c index 1bbb4b3..c4e2f0c 100644 --- a/dwm.c +++ b/dwm.c @@ -1663,6 +1663,27 @@ toggletag(const Arg *arg) { void toggleview(const Arg *arg) { unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); + Client *const selected = selmon->sel; + + // clients in the master area should be the same after we add a new tag + Client **const masters = calloc(selmon->nmaster, sizeof(Client *)); + if (!masters) { + die("fatal: could not calloc() %u bytes \n", selmon->nmaster * sizeof(Client *)); + } + // collect (from last to first) references to all clients in the master area + Client *c; + size_t i; + for (c = nexttiled(selmon->clients), i = 0; c && i < selmon->nmaster; c = nexttiled(c->next), ++i) + masters[selmon->nmaster - (i + 1)] = c; + // put the master clients at the front of the list + // > go from the 'last' master to the 'first' + for (size_t i = 0; i < selmon->nmaster; ++i) + if (masters[i]) + pop(masters[i]); + free(masters); + + // we also want to be sure not to mutate the focus + focus(selected); if(newtagset) { selmon->tagset[selmon->seltags] = newtagset;