Improve code of func "movestack"
This commit is contained in:
parent
2ccbcbabcd
commit
fdd4d2cc84
62
src/dwm.c
62
src/dwm.c
|
@ -1011,48 +1011,68 @@ void movemouse(__attribute__((unused)) const Arg *arg)
|
||||||
|
|
||||||
void movestack(const Arg *arg)
|
void movestack(const Arg *arg)
|
||||||
{
|
{
|
||||||
Client *c = NULL, *p = NULL, *pc = NULL, *i;
|
Client *c = NULL, *p = NULL, *pc = NULL, *i = NULL;
|
||||||
|
|
||||||
if(arg->i > 0) {
|
if (arg->i > 0) {
|
||||||
/* find the client after selmon->sel */
|
/* find the client after selmon->sel */
|
||||||
for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
|
for (
|
||||||
if(!c)
|
c = selmon->sel->next;
|
||||||
for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
|
c && (!ISVISIBLE(c) || c->isfloating);
|
||||||
|
c = c->next
|
||||||
|
);
|
||||||
|
|
||||||
}
|
if(!c) {
|
||||||
else {
|
for(
|
||||||
|
c = selmon->clients;
|
||||||
|
c && (!ISVISIBLE(c) || c->isfloating);
|
||||||
|
c = c->next
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
/* find the client before selmon->sel */
|
/* find the client before selmon->sel */
|
||||||
for(i = selmon->clients; i != selmon->sel; i = i->next)
|
for (i = selmon->clients; i != selmon->sel; i = i->next) {
|
||||||
if(ISVISIBLE(i) && !i->isfloating)
|
if (ISVISIBLE(i) && !i->isfloating) {
|
||||||
c = i;
|
c = i;
|
||||||
if(!c)
|
}
|
||||||
for(; i; i = i->next)
|
}
|
||||||
if(ISVISIBLE(i) && !i->isfloating)
|
|
||||||
|
if (!c) {
|
||||||
|
for (; i; i = i->next) {
|
||||||
|
if (ISVISIBLE(i) && !i->isfloating) {
|
||||||
c = i;
|
c = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find the client before selmon->sel and c */
|
/* find the client before selmon->sel and c */
|
||||||
for(i = selmon->clients; i && (!p || !pc); i = i->next) {
|
for (i = selmon->clients; i && (!p || !pc); i = i->next) {
|
||||||
if(i->next == selmon->sel)
|
if (i->next == selmon->sel) {
|
||||||
p = i;
|
p = i;
|
||||||
if(i->next == c)
|
}
|
||||||
|
if (i->next == c) {
|
||||||
pc = i;
|
pc = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* swap c and selmon->sel selmon->clients in the selmon->clients list */
|
/* swap c and selmon->sel selmon->clients in the selmon->clients list */
|
||||||
if(c && c != selmon->sel) {
|
if (c && c != selmon->sel) {
|
||||||
Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next;
|
Client *temp = selmon->sel->next == c ? selmon->sel : selmon->sel->next;
|
||||||
selmon->sel->next = c->next==selmon->sel?c:c->next;
|
selmon->sel->next = c->next==selmon->sel?c:c->next;
|
||||||
c->next = temp;
|
c->next = temp;
|
||||||
|
|
||||||
if(p && p != c)
|
if (p && p != c) {
|
||||||
p->next = c;
|
p->next = c;
|
||||||
if(pc && pc != selmon->sel)
|
}
|
||||||
|
if (pc && pc != selmon->sel) {
|
||||||
pc->next = selmon->sel;
|
pc->next = selmon->sel;
|
||||||
|
}
|
||||||
|
|
||||||
if(selmon->sel == selmon->clients)
|
if (selmon->sel == selmon->clients) {
|
||||||
selmon->clients = c;
|
selmon->clients = c;
|
||||||
else if(c == selmon->clients)
|
} else if (c == selmon->clients) {
|
||||||
selmon->clients = selmon->sel;
|
selmon->clients = selmon->sel;
|
||||||
|
}
|
||||||
|
|
||||||
arrange(selmon);
|
arrange(selmon);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue