Added pertag patch

This commit is contained in:
bakkeby 2019-09-05 22:58:16 +02:00
parent cba0991170
commit 591caea975
5 changed files with 150 additions and 9 deletions

View File

@ -11,13 +11,15 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
### Changelog:
2019-09-05 - Systray patch added
2019-09-05 - Alpha patch added
2019-09-05 - Alpha, systray and pertag patches added
### Patches included:
- [alpha](https://dwm.suckless.org/patches/alpha/)
- adds transparency for the status bar
- [pertag](https://dwm.suckless.org/patches/pertag/)
- adds nmaster, mfact, layouts and more per tag rather than per monitor
- [systray](https://dwm.suckless.org/patches/systray/)
- adds system tray in the status bar

117
dwm.c
View File

@ -118,6 +118,9 @@ typedef struct {
void (*arrange)(Monitor *);
} Layout;
#if PERTAG_PATCH
typedef struct Pertag Pertag;
#endif // PERTAG_PATCH
struct Monitor {
char ltsymbol[16];
float mfact;
@ -137,6 +140,9 @@ struct Monitor {
Monitor *next;
Window barwin;
const Layout *lt[2];
#if PERTAG_PATCH
Pertag *pertag;
#endif // PERTAG_PATCH
};
typedef struct {
@ -713,6 +719,9 @@ Monitor *
createmon(void)
{
Monitor *m;
#if PERTAG_PATCH
int i;
#endif // PERTAG_PATCH
m = ecalloc(1, sizeof(Monitor));
m->tagset[0] = m->tagset[1] = 1;
@ -723,6 +732,31 @@ createmon(void)
m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)];
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
#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;
for (i=0; i <= LENGTH(tags); i++) {
/* init nmaster */
m->pertag->nmasters[i] = m->nmaster;
/* init mfacts */
m->pertag->mfacts[i] = m->mfact;
/* init layouts */
m->pertag->ltidxs[i][0] = m->lt[0];
m->pertag->ltidxs[i][1] = m->lt[1];
m->pertag->sellts[i] = m->sellt;
#if PERTAGBAR_PATCH
/* init showbar */
m->pertag->showbars[i] = m->showbar;
/* swap focus and zoomswap*/
m->pertag->prevzooms[i] = NULL;
#endif // PERTAGBAR_PATCH
}
#endif // PERTAG_PATCH
return m;
}
@ -1108,7 +1142,11 @@ grabkeys(void)
void
incnmaster(const Arg *arg)
{
#if PERTAG_PATCH
selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
#else
selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
#endif // PERTAG_PATCH
arrange(selmon);
}
@ -1705,10 +1743,21 @@ setfullscreen(Client *c, int fullscreen)
void
setlayout(const Arg *arg)
{
if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) {
#if PERTAG_PATCH
selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
#else
selmon->sellt ^= 1;
#endif // PERTAG_PATCH
}
if (arg && arg->v)
#if PERTAG_PATCH
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
#else
selmon->lt[selmon->sellt] = (Layout *)arg->v;
#endif // PERTAG_PATCH
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
if (selmon->sel)
arrange(selmon);
@ -1727,7 +1776,11 @@ setmfact(const Arg *arg)
f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
if (f < 0.1 || f > 0.9)
return;
#if PERTAG_PATCH
selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
#else
selmon->mfact = f;
#endif // PERTAG_PATCH
arrange(selmon);
}
@ -1929,7 +1982,11 @@ tile(Monitor *m)
void
togglebar(const Arg *arg)
{
#if PERTAG_PATCH && PERTAGBAR_PATCH
selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar;
#else
selmon->showbar = !selmon->showbar;
#endif // PERTAG_PATCH
updatebarpos(selmon);
XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
#if SYSTRAY_PATCH
@ -1981,9 +2038,36 @@ void
toggleview(const Arg *arg)
{
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
#if PERTAG_PATCH
int i;
#endif // PERTAG_PATCH
if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset;
#if PERTAG_PATCH
if (newtagset == ~0) {
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;
}
/* apply settings for this view */
selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
#if PERTAGBAR_PATCH
if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
togglebar(NULL);
#endif // PERTAGBAR_PATCH
#endif // PERTAG_PATCH
focus(NULL);
arrange(selmon);
}
@ -2312,11 +2396,42 @@ updatewmhints(Client *c)
void
view(const Arg *arg)
{
#if PERTAG_PATCH
int i;
unsigned int tmptag;
#endif // PERTAG_PATCH
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
return;
selmon->seltags ^= 1; /* toggle sel tagset */
#if PERTAG_PATCH
if (arg->ui & TAGMASK) {
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
if (arg->ui == ~0)
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;
}
selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
#if PERTAGBAR_PATCH
if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
togglebar(NULL);
#endif // PERTAGBAR_PATCH
#else
if (arg->ui & TAGMASK)
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
#endif // PERTAG_PATCH
focus(NULL);
arrange(selmon);
}

View File

@ -2,6 +2,10 @@
#include "alpha.c"
#endif
#if PERTAG_PATCH
#include "pertag.c"
#endif
#if SYSTRAY_PATCH
#include "systray.c"
#endif

11
patch/pertag.c Normal file
View File

@ -0,0 +1,11 @@
struct Pertag {
unsigned int curtag, prevtag; /* current and previous tag */
int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */
#if PERTAGBAR_PATCH
Bool showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
#endif // PERTAGBAR_PATCH
Client *prevzooms[LENGTH(tags) + 1]; /* store zoom information */
};

View File

@ -7,14 +7,23 @@
* relevant descriptions.
*/
/*
* The alpha patch adds transparency for the status bar.
/* The alpha patch adds transparency for the status bar.
* https://dwm.suckless.org/patches/alpha/
*/
#define ALPHA_PATCH 0
/*
* The systray patch adds systray for the status bar.
/* The systray patch adds systray for the status bar.
* https://dwm.suckless.org/patches/systray/
*/
#define SYSTRAY_PATCH 0
/* The pertag patch adds nmaster, mfacts and layouts per tag rather
* than per monitor (default).
* https://dwm.suckless.org/patches/pertag/
*/
#define PERTAG_PATCH 0
/* This controls whether or not to also store bar position on a per
* tag basis, or leave it as one bar per monitor.
*/
#define PERTAGBAR_PATCH 0