-
-
Notifications
You must be signed in to change notification settings - Fork 545
/
shiftview.c
65 lines (56 loc) · 1.51 KB
/
shiftview.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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);
}
}