Skip to content

Commit

Permalink
feat: add move stack
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn authored and prabirshrestha committed May 22, 2020
1 parent 5faecd8 commit 7f23f92
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions dwm-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void drawborder(Client *c, COLORREF color);
void eprint(const wchar_t *errstr, ...);
static void focus(Client *c);
static void focusstack(const Arg *arg);
static void movestack(const Arg *arg);
static Client *getclient(HWND hwnd);
LPWSTR getclientclassname(HWND hwnd);
LPWSTR getclienttitle(HWND hwnd);
Expand Down Expand Up @@ -1473,6 +1474,56 @@ zoom(const Arg *arg) {
arrange();
}

void
movestack(const Arg *arg) {
Client *c = NULL, *p = NULL, *pc = NULL, *i;

if(arg->i > 0) {
/* find the client after selmon->sel */
for(c = sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
if(!c)
for(c = clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);

}
else {
/* find the client before sel */
for(i = clients; i != sel; i = i->next)
if(ISVISIBLE(i) && !i->isfloating)
c = i;
if(!c)
for(; i; i = i->next)
if(ISVISIBLE(i) && !i->isfloating)
c = i;
}
/* find the client before sel and c */
for(i = clients; i && (!p || !pc); i = i->next) {
if(i->next == sel)
p = i;
if(i->next == c)
pc = i;
}

/* swap c and sel clients in the clients list */
if(c && c != sel) {
Client *temp = sel->next==c?sel:sel->next;
sel->next = c->next==sel?c:c->next;
c->next = temp;

if(p && p != c)
p->next = c;
if(pc && pc != sel)
pc->next = sel;

if(sel == clients)
clients = c;
else if(c == clients)
clients = sel;

arrange();
}
}


int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) {
MSG msg;

Expand Down

0 comments on commit 7f23f92

Please sign in to comment.