Skip to content

Commit

Permalink
pertag: simplifying implementation by removing prevtag
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkeby authored and UtkarshVerma committed Feb 19, 2023
1 parent c682388 commit 59cb087
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
9 changes: 3 additions & 6 deletions dwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@ createmon(void)
#if PERTAG_PATCH
if (!(m->pertag = (Pertag *)calloc(1, sizeof(Pertag))))
die("fatal: could not malloc() %u bytes\n", sizeof(Pertag));
m->pertag->curtag = m->pertag->prevtag = 1;
m->pertag->curtag = 1;
for (i = 0; i <= NUMTAGS; i++) {
#if FLEXTILE_DELUXE_LAYOUT
m->pertag->nstacks[i] = m->nstack;
Expand Down Expand Up @@ -4273,12 +4273,10 @@ toggleview(const Arg *arg)
if (newtagset == ~0)
#endif // SCRATCHPADS_PATCH
{
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = 0;
}
/* test if the user did not select the same tag */
if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
selmon->pertag->prevtag = selmon->pertag->curtag;
for (i = 0; !(newtagset & 1 << i); i++) ;
selmon->pertag->curtag = i + 1;
}
Expand Down Expand Up @@ -4920,11 +4918,10 @@ view(const Arg *arg)
tagpreviewswitchtag();
#endif // BAR_TAGPREVIEW_PATCH
selmon->seltags ^= 1; /* toggle sel tagset */
#if PERTAG_PATCH
pertagview(arg);
#else
if (arg->ui & TAGMASK)
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
#if PERTAG_PATCH
pertagview(arg);
#endif // PERTAG_PATCH
#if TAGSYNC_PATCH
}
Expand Down
31 changes: 12 additions & 19 deletions patch/pertag.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct Pertag {
unsigned int curtag, prevtag; /* current and previous tag */
unsigned int curtag; /* current tag index */
int nmasters[NUMTAGS + 1]; /* number of windows in master area */
#if FLEXTILE_DELUXE_LAYOUT
int nstacks[NUMTAGS + 1]; /* number of windows in primary stack area */
Expand Down Expand Up @@ -29,25 +29,18 @@ void
pertagview(const Arg *arg)
{
int i;
unsigned int tmptag;
if (arg->ui & TAGMASK) {
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
if (arg->ui == ~SPTAGMASK)
#else
if (arg->ui == ~0)
#endif // SCRATCHPADS_PATCH
selmon->pertag->curtag = 0;
else {
for (i = 0; !(arg->ui & 1 << i); i++) ;
selmon->pertag->curtag = i + 1;
}
} else {
tmptag = selmon->pertag->prevtag;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = tmptag;

#if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH
if (arg->ui == ~SPTAGMASK)
#else
if (arg->ui == ~0)
#endif // SCRATCHPADS_PATCH
selmon->pertag->curtag = 0;
else {
for (i = 0; !(selmon->tagset[selmon->seltags] & 1 << i); i++);
selmon->pertag->curtag = i + 1;
}

selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
#if FLEXTILE_DELUXE_LAYOUT
selmon->nstack = selmon->pertag->nstacks[selmon->pertag->curtag];
Expand Down

0 comments on commit 59cb087

Please sign in to comment.