Skip to content

Commit 642416b

Browse files
author
Sokolov Innokenty
committed
patch movestack
1 parent 1718883 commit 642416b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

config.def.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* See LICENSE file for copyright and license details. */
22
#include "gaplessgrid.c"
33
#include "bstack.c"
4+
#include "movestack.c"
45

56
/* appearance */
67
static const unsigned int borderpx = 2; /* border pixel of windows */
@@ -137,6 +138,8 @@ static const Key keys[] = {
137138
{ MODKEY, XK_u, resetnmaster, {0} },
138139
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
139140
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
141+
{ MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } },
142+
{ MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } },
140143
{ MODKEY, XK_Return, zoom, {0} },
141144
{ MODKEY, XK_Tab, view, {0} },
142145
{ MODKEY|ShiftMask, XK_c, killclient, {0} },

movestack.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
void
2+
movestack(const Arg *arg) {
3+
Client *c = NULL, *p = NULL, *pc = NULL, *i;
4+
5+
if (arg->i > 0) {
6+
/* find the client after selmon->sel */
7+
for (c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
8+
if (!c)
9+
for (c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
10+
11+
}
12+
else {
13+
/* find the client before selmon->sel */
14+
for (i = selmon->clients; i != selmon->sel; i = i->next)
15+
if (ISVISIBLE(i) && !i->isfloating)
16+
c = i;
17+
if (!c)
18+
for (; i; i = i->next)
19+
if (ISVISIBLE(i) && !i->isfloating)
20+
c = i;
21+
}
22+
/* find the client before selmon->sel and c */
23+
for (i = selmon->clients; i && (!p || !pc); i = i->next) {
24+
if (i->next == selmon->sel)
25+
p = i;
26+
if (i->next == c)
27+
pc = i;
28+
}
29+
30+
/* swap c and selmon->sel selmon->clients in the selmon->clients list */
31+
if (c && c != selmon->sel) {
32+
Client *temp = selmon->sel->next == c ? selmon->sel : selmon->sel->next;
33+
selmon->sel->next = c->next == selmon->sel ? c : c->next;
34+
c->next = temp;
35+
36+
if (p && p != c)
37+
p->next = c;
38+
if (pc && pc != selmon->sel)
39+
pc->next = selmon->sel;
40+
41+
if (selmon->sel == selmon->clients)
42+
selmon->clients = c;
43+
else if (c == selmon->clients)
44+
selmon->clients = selmon->sel;
45+
46+
arrange(selmon);
47+
}
48+
}

0 commit comments

Comments
 (0)