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

   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 (selmon->sel)
       selmon->tagset[selmon->seltags] = selmon->sel->tags;
   arrange(selmon);
}