stacker.c (2854B)
1 void 2 focusstack(const Arg *arg) 3 { 4 int i = stackpos(arg); 5 Client *c, *p; 6 7 if (i < 0) 8 return; 9 10 #if LOSEFULLSCREEN_PATCH 11 if (!selmon->sel) 12 return; 13 #elif FAKEFULLSCREEN_CLIENT_PATCH 14 if (!selmon->sel || (selmon->sel->isfullscreen && !selmon->sel->fakefullscreen)) 15 return; 16 #else 17 if (!selmon->sel || selmon->sel->isfullscreen) 18 return; 19 #endif // LOSEFULLSCREEN_PATCH 20 21 #if BAR_WINTITLEACTIONS_PATCH 22 for (p = NULL, c = selmon->clients; c && (i || !ISVISIBLE(c) || HIDDEN(c)); 23 i -= (ISVISIBLE(c) && !HIDDEN(c) ? 1 : 0), p = c, c = c->next); 24 #else 25 for (p = NULL, c = selmon->clients; c && (i || !ISVISIBLE(c)); 26 i -= (ISVISIBLE(c) ? 1 : 0), p = c, c = c->next); 27 #endif // BAR_WINTITLEACTIONS_PATCH 28 focus(c ? c : p); 29 restack(selmon); 30 } 31 32 void 33 pushstack(const Arg *arg) 34 { 35 int i = stackpos(arg); 36 Client *sel = selmon->sel, *c, *p; 37 38 if (i < 0) 39 return; 40 else if (i == 0) { 41 detach(sel); 42 attach(sel); 43 } 44 else { 45 for (p = NULL, c = selmon->clients; c; p = c, c = c->next) 46 #if BAR_WINTITLEACTIONS_PATCH 47 if (!(i -= (ISVISIBLE(c) && !HIDDEN(c) && c != sel))) 48 #else 49 if (!(i -= (ISVISIBLE(c) && c != sel))) 50 #endif // BAR_WINTITLEACTIONS_PATCH 51 break; 52 c = c ? c : p; 53 detach(sel); 54 sel->next = c->next; 55 c->next = sel; 56 } 57 arrange(selmon); 58 } 59 60 int 61 stackpos(const Arg *arg) 62 { 63 int n, i; 64 Client *c, *l; 65 66 if (!selmon->clients) 67 return -1; 68 69 #if BAR_WINTITLEACTIONS_PATCH 70 if (arg->i == PREVSEL) { 71 for (l = selmon->stack; l && (!ISVISIBLE(l) || HIDDEN(l) || l == selmon->sel); l = l->snext); 72 if (!l) 73 return -1; 74 for (i = 0, c = selmon->clients; c != l; i += (ISVISIBLE(c) && !HIDDEN(c) ? 1 : 0), c = c->next); 75 return i; 76 } 77 else if (ISINC(arg->i)) { 78 if (!selmon->sel) 79 return -1; 80 for (i = 0, c = selmon->clients; c != selmon->sel; i += (ISVISIBLE(c) && !HIDDEN(c) ? 1 : 0), c = c->next); 81 for (n = i; c; n += (ISVISIBLE(c) && !HIDDEN(c) ? 1 : 0), c = c->next); 82 return MOD(i + GETINC(arg->i), n); 83 } 84 else if (arg->i < 0) { 85 for (i = 0, c = selmon->clients; c; i += (ISVISIBLE(c) && !HIDDEN(c) ? 1 : 0), c = c->next); 86 return MAX(i + arg->i, 0); 87 } 88 else 89 return arg->i; 90 #else // !BAR_WINTITLEACTIONS_PATCH 91 if (arg->i == PREVSEL) { 92 for (l = selmon->stack; l && (!ISVISIBLE(l) || l == selmon->sel); l = l->snext); 93 if (!l) 94 return -1; 95 for (i = 0, c = selmon->clients; c != l; i += (ISVISIBLE(c) ? 1 : 0), c = c->next); 96 return i; 97 } 98 else if (ISINC(arg->i)) { 99 if (!selmon->sel) 100 return -1; 101 for (i = 0, c = selmon->clients; c != selmon->sel; i += (ISVISIBLE(c) ? 1 : 0), c = c->next); 102 for (n = i; c; n += (ISVISIBLE(c) ? 1 : 0), c = c->next); 103 return MOD(i + GETINC(arg->i), n); 104 } 105 else if (arg->i < 0) { 106 for (i = 0, c = selmon->clients; c; i += (ISVISIBLE(c) ? 1 : 0), c = c->next); 107 return MAX(i + arg->i, 0); 108 } 109 else 110 return arg->i; 111 #endif // BAR_WINTITLEACTIONS_PATCH 112 } 113