shift-tools.c (3873B)
1 /* Sends a window to the next/prev tag */ 2 void 3 shifttag(const Arg *arg) 4 { 5 Arg shifted; 6 shifted.ui = selmon->tagset[selmon->seltags]; 7 8 9 if (arg->i > 0) /* left circular shift */ 10 shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i))); 11 else /* right circular shift */ 12 shifted.ui = (shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i)); 13 tag(&shifted); 14 } 15 /* Sends a window to the next/prev tag that has a client, else it moves it to the next/prev one. */ 16 void 17 shifttagclients(const Arg *arg) 18 { 19 20 Arg shifted; 21 Client *c; 22 unsigned int tagmask = 0; 23 shifted.ui = selmon->tagset[selmon->seltags]; 24 25 for (c = selmon->clients; c; c = c->next) 26 if (!(c->tags)) 27 tagmask = tagmask | c->tags; 28 29 30 if (arg->i > 0) /* left circular shift */ 31 do { 32 shifted.ui = (shifted.ui << arg->i) 33 | (shifted.ui >> (LENGTH(tags) - arg->i)); 34 } while (tagmask && !(shifted.ui & tagmask)); 35 else /* right circular shift */ 36 do { 37 shifted.ui = (shifted.ui >> (- arg->i) 38 | shifted.ui << (LENGTH(tags) + arg->i)); 39 } while (tagmask && !(shifted.ui & tagmask)); 40 tag(&shifted); 41 } 42 /* Navigate to the next/prev tag */ 43 void 44 shiftview(const Arg *arg) 45 { 46 Arg shifted; 47 shifted.ui = selmon->tagset[selmon->seltags]; 48 49 if (arg->i > 0) {/* left circular shift */ 50 shifted.ui = (shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i)); 51 } else { /* right circular shift */ 52 shifted.ui = (shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i)); 53 } 54 view(&shifted); 55 } 56 /* Navigate to the next/prev tag that has a client, else moves it to the next/prev tag */ 57 void 58 shiftviewclients(const Arg *arg) 59 { 60 Arg shifted; 61 Client *c; 62 unsigned int tagmask = 0; 63 shifted.ui = selmon->tagset[selmon->seltags]; 64 65 for (c = selmon->clients; c; c = c->next) 66 if (!(c->tags)) 67 tagmask = tagmask | c->tags; 68 69 70 if (arg->i > 0) /* left circular shift */ 71 do { 72 shifted.ui = (shifted.ui << arg->i) 73 | (shifted.ui >> (LENGTH(tags) - arg->i)); 74 } while (tagmask && !(shifted.ui & tagmask)); 75 else /* right circular shift */ 76 do { 77 shifted.ui = (shifted.ui >> (- arg->i) 78 | shifted.ui << (LENGTH(tags) + arg->i)); 79 } while (tagmask && !(shifted.ui & tagmask)); 80 view(&shifted); 81 } 82 /* move the current active window to the next/prev tag and view it. More like following the window */ 83 void 84 shiftboth(const Arg *arg) 85 { 86 Arg shifted; 87 shifted.ui = selmon->tagset[selmon->seltags]; 88 89 if (arg->i > 0) /* left circular shift */ 90 shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i))); 91 else /* right circular shift */ 92 shifted.ui = ((shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i))); 93 tag(&shifted); 94 view(&shifted); 95 } 96 //helper function for shiftswaptags found on: 97 //https://github.com/moizifty/DWM-Build/blob/65379c62640788881486401a0d8c79333751b02f/config.h#L48 98 void 99 swaptags(const Arg *arg) 100 { 101 Client *c; 102 unsigned int newtag = arg->ui & TAGMASK; 103 unsigned int curtag = selmon->tagset[selmon->seltags]; 104 105 if (newtag == curtag || !curtag || (curtag & (curtag-1))) 106 return; 107 108 for (c = selmon->clients; c != NULL; c = c->next) { 109 if ((c->tags & newtag) || (c->tags & curtag)) 110 c->tags ^= curtag ^ newtag; 111 112 if (!c->tags) 113 c->tags = newtag; 114 } 115 116 //move to the swaped tag 117 //selmon->tagset[selmon->seltags] = newtag; 118 119 focus(NULL); 120 arrange(selmon); 121 } 122 /* swaps "tags" (all the clients) with the next/prev tag. */ 123 void 124 shiftswaptags(const Arg *arg) 125 { 126 Arg shifted; 127 shifted.ui = selmon->tagset[selmon->seltags]; 128 129 if (arg->i > 0) /* left circular shift */ 130 shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i))); 131 else /* right circular shift */ 132 shifted.ui = ((shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i))); 133 swaptags(&shifted); 134 // uncomment if you also want to "go" (view) the tag where the the clients are going 135 //view(&shifted); 136 }