Improve code of view func

This commit is contained in:
Alex Kotov 2021-11-14 06:31:19 +05:00
parent cef2566f82
commit c57a2b172e
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 13 additions and 8 deletions

21
dwm.c
View File

@ -2674,25 +2674,28 @@ updatewmhints(Client *c)
void
view(const Arg *arg)
{
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) return;
const unsigned int old_tagset = selmon->tagset[selmon->seltags] & TAGMASK;
const unsigned int new_tagset = arg->ui & TAGMASK;
if (new_tagset == old_tagset) return;
selmon->seltags ^= 1; /* toggle sel tagset */
if (arg->ui & TAGMASK) {
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
if (new_tagset == 0) {
unsigned int tmptag = selmon->pertag->prevtag;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = tmptag;
} else {
selmon->tagset[selmon->seltags] = new_tagset;
selmon->pertag->prevtag = selmon->pertag->curtag;
if (arg->ui == ~0) {
selmon->pertag->curtag = 0;
} else {
int i = 0;
while (!(arg->ui & 1 << i)) ++i;
while (!(new_tagset & 1 << i)) ++i;
selmon->pertag->curtag = i + 1;
}
} else {
unsigned int tmptag = selmon->pertag->prevtag;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = tmptag;
}
selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
@ -2721,6 +2724,8 @@ viewrel(const Arg *arg)
if (new_tagset == old_tagset) return;
selmon->seltags ^= 1; /* toggle sel tagset */
if (new_tagset == 0) {
unsigned int tmptag = selmon->pertag->prevtag;
selmon->pertag->prevtag = selmon->pertag->curtag;