diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-07-08 15:51:18 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-07-08 15:51:18 +0200 |
commit | cf8aefdf23c53cb3f83428269aa74b6eb47657fd (patch) | |
tree | afdf0bab9b6aa5943c389e1b2efbd310cfde456e /shiftview.c | |
parent | 17f1d5e7a654c6a70cc08e8c5e1e8c11ee415bac (diff) |
Latest update
Diffstat (limited to 'shiftview.c')
-rw-r--r-- | shiftview.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/shiftview.c b/shiftview.c new file mode 100644 index 0000000..3d2706b --- /dev/null +++ b/shiftview.c @@ -0,0 +1,64 @@ +/** Function to shift the current view to the left/right + * + * @param: "arg->i" stores the number of tags to shift right (positive value) + * or left (negative value) + */ +void +shiftview(const Arg *arg) +{ + Arg shifted; + Client *c; + unsigned int tagmask = 0; + + for (c = selmon->clients; c; c = c->next) + if (!(c->tags & SPTAGMASK)) + tagmask = tagmask | c->tags; + + shifted.ui = selmon->tagset[selmon->seltags] & ~SPTAGMASK; + if (arg->i > 0) /* left circular shift */ + do { + shifted.ui = (shifted.ui << arg->i) + | (shifted.ui >> (LENGTH(tags) - arg->i)); + shifted.ui &= ~SPTAGMASK; + } while (tagmask && !(shifted.ui & tagmask)); + else /* right circular shift */ + do { + shifted.ui = (shifted.ui >> (- arg->i) + | shifted.ui << (LENGTH(tags) + arg->i)); + shifted.ui &= ~SPTAGMASK; + } while (tagmask && !(shifted.ui & tagmask)); + + view(&shifted); +} + +void +shifttag(const Arg *arg) +{ + Arg a; + Client *c; + unsigned visible = 0; + int i = arg->i; + int count = 0; + int nextseltags, curseltags = selmon->tagset[selmon->seltags]; + + do { + if(i > 0) // left circular shift + nextseltags = (curseltags << i) | (curseltags >> (LENGTH(tags) - i)); + + else // right circular shift + nextseltags = curseltags >> (- i) | (curseltags << (LENGTH(tags) + i)); + + // Check if tag is visible + for (c = selmon->clients; c && !visible; c = c->next) + if (nextseltags & c->tags) { + visible = 1; + break; + } + i += arg->i; + } while (!visible && ++count < 10); + + if (count < 10) { + a.i = nextseltags; + tag(&a); + } +} |