summaryrefslogtreecommitdiffhomepage
path: root/patch/reorganizetags.c
blob: 440d75c22fddeaa42465eb80f4ae1d0dd87a6bd7 (plain)
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
void
reorganizetags(const Arg *arg)
{
	Client *c;
	unsigned int occ, unocc, i;
	unsigned int tagdest[NUMTAGS];

	#if TAGSYNC_PATCH
	Monitor *origselmon = selmon;
	for (selmon = mons; selmon; selmon = selmon->next) {
	#endif // TAGSYNC_PATCH

	occ = 0;
	for (c = selmon->clients; c; c = c->next)
		occ |= (1 << (ffs(c->tags)-1));
	unocc = 0;
	for (i = 0; i < NUMTAGS; ++i) {
		while (unocc < i && (occ & (1 << unocc)))
			unocc++;
		if (occ & (1 << i)) {
			tagdest[i] = unocc;
			occ &= ~(1 << i);
			occ |= 1 << unocc;
		}
	}

	for (c = selmon->clients; c; c = c->next)
		c->tags = 1 << tagdest[ffs(c->tags)-1];
	#if TAGSYNC_PATCH
	}
	selmon = origselmon;
	#endif // TAGSYNC_PATCH

	if (selmon->sel)
		view(&((Arg) { .ui = selmon->sel->tags }));
	else
		#if TAGSYNC_PATCH
		arrange(NULL);
		#else
		arrange(selmon);
		#endif // TAGSYNC_PATCH
}