-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotatemons.c
105 lines (93 loc) · 2.16 KB
/
rotatemons.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
struct ClientListItem;
typedef struct ClientListItem ClientListItem;
struct ClientListItem {
Client* c;
ClientListItem* next;
};
void
changemon(Client *c, Monitor *m) {
int xo = 0, yo = 0;
if(c->mon == m)
return;
if(c->isfloating) {
xo = m->mx - c->mon->mx;
yo = m->my - c->mon->my;
}
detach(c);
detachstack(c);
c->x += xo;
c->y += yo;
c->mon = m;
attach(c);
attachstack(c);
}
void
movetomon (const unsigned int views, Monitor *msrc, Monitor *mdst) {
Client* c;
ClientListItem* nextitem = NULL;
ClientListItem* baseitem = NULL;
ClientListItem* item = NULL;
for(c = msrc->stack; c; c = c->snext)
if (c->tags & views) {
item = (ClientListItem*)calloc(1, sizeof(ClientListItem));
item->c = c;
item->next = nextitem;
nextitem = item;
}
baseitem = item;
for(item = baseitem; item && item->c; item = item->next) {
changemon(item->c, mdst);
}
mdst->sel = msrc->sel;
item = baseitem;
while (item) {
nextitem = item->next;
free(item);
item = nextitem;
}
mdst->topbar = msrc->topbar;
mdst->clock = msrc->clock;
if (views == ~0)
mdst->vs = msrc->vs;
}
void
swapmonitors(const unsigned int views, Monitor *mon1, Monitor *mon2, Monitor *sparem) {
movetomon(views, mon1, sparem);
movetomon(views, mon2, mon1);
movetomon(views, sparem, mon2);
}
void
rotatemonitor(const Arg* arg) {
Monitor *m, *nextm, *lastm, *sparem = createmon();
Bool allviews = (arg->i != 0);
const ViewStack *vs;
const unsigned int views = allviews ? ~0 : selmon->vs->tagset;
int i;
rotatingMons = True;
/* rotate clients */
for(m = mons, nextm = mons->next; nextm; m = m->next, nextm = nextm->next) {
if (!nextm)
nextm = mons;
swapmonitors(views, m, nextm, sparem);
}
free(sparem);
/* tidy monitors (num, tagset, lt) */
for(lastm = mons; lastm && lastm->next; lastm = lastm->next) ;
for (i = 0, m = mons; m; m = m->next, ++i) {
m->num = i;
if(!allviews) {
if (hasclientson(m, views)) {
monview(m, views);
vs = getviewstackof(lastm, views);
copyviewstack(m->vs, vs);
}
else if (!hasclientson(m, m->vs->tagset))
monview(m, 0);
}
restorebar(m);
arrange(m);
lastm = m;
}
updatecurrentdesktop();
rotatingMons = False;
}