shiftview.c (1544B)
1 /** Function to shift the current view to the left/right 2 * 3 * @param: "arg->i" stores the number of tags to shift right (positive value) 4 * or left (negative value) 5 */ 6 void 7 shiftview(const Arg *arg) 8 { 9 Arg shifted; 10 Client *c; 11 unsigned int tagmask = 0; 12 13 for (c = selmon->clients; c; c = c->next) 14 if (!(c->tags & SPTAGMASK)) 15 tagmask = tagmask | c->tags; 16 17 shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK; 18 if (arg->i > 0) /* left circular shift */ 19 do { 20 shifted.ui = (shifted.ui << arg->i) 21 | (shifted.ui >> (LENGTH(tags) - arg->i)); 22 shifted.ui &= ~SPTAGMASK; 23 } while (tagmask && !(shifted.ui & tagmask)); 24 else /* right circular shift */ 25 do { 26 shifted.ui = (shifted.ui >> (- arg->i) 27 | shifted.ui << (LENGTH(tags) + arg->i)); 28 shifted.ui &= ~SPTAGMASK; 29 } while (tagmask && !(shifted.ui & tagmask)); 30 31 view(&shifted); 32 } 33 34 void 35 shifttag(const Arg *arg) 36 { 37 Arg a; 38 Client *c; 39 unsigned visible = 0; 40 int i = arg->i; 41 int count = 0; 42 int nextseltags, curseltags = selmon->tagset[selmon->seltags]; 43 44 do { 45 if(i > 0) // left circular shift 46 nextseltags = (curseltags << i) | (curseltags >> (LENGTH(tags) - i)); 47 48 else // right circular shift 49 nextseltags = (curseltags >> - i) | (curseltags << (LENGTH(tags) + i)); 50 51 // Check if tag is visible 52 for (c = selmon->clients; c && !visible; c = c->next) 53 if (nextseltags & c->tags) { 54 visible = 1; 55 break; 56 } 57 i += arg->i; 58 } while (!visible && ++count < 10); 59 60 if (count < 10) { 61 a.i = nextseltags; 62 tag(&a); 63 } 64 } 65