From 15a4c58924fd786b5e335f60aa8cc55f543cc772 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sat, 5 Oct 2019 23:28:50 +0200 Subject: [PATCH] Adding taggrid patch --- README.md | 5 +- config.def.h | 28 ++++++++++++ dwm.c | 37 ++++++++++++++- patch/include.c | 4 ++ patch/include.h | 4 ++ patch/taggrid.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ patch/taggrid.h | 2 + patches.h | 5 ++ 8 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 patch/taggrid.c create mode 100644 patch/taggrid.h diff --git a/README.md b/README.md index bf12fa0..a5f6af7 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: -2019-10-05 - Added killunsel patch +2019-10-05 - Added killunsel and taggrid patches 2019-10-04 - Added maximize, movestack, monoclesymbol, noborder, tagall and tagintostack patches @@ -209,6 +209,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t - makes new clients attach into the stack area when you toggle a new tag into view - this means your master area will remain unchanged when toggling views + - [taggrid](https://dwm.suckless.org/patches/taggrid/) + - adds an option to place tags in rows like in many other window managers + - [tagmonfixfs](https://github.com/bakkeby/dwm-vanitygaps/blob/master/patches/dwm-tagmonfixfs-6.2.diff) - allows moving a fullscreen window to another monitor while remaining in fullscreen diff --git a/config.def.h b/config.def.h index ec350fc..40db765 100644 --- a/config.def.h +++ b/config.def.h @@ -144,6 +144,24 @@ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; static const char *tagsalt[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; #endif // ALTERNATIVE_TAGS_PATCH +#if TAGGRID_PATCH +/* grid of tags */ +#define DRAWCLASSICTAGS 1 << 0 +#define DRAWTAGGRID 1 << 1 + +#define SWITCHTAG_UP 1 << 0 +#define SWITCHTAG_DOWN 1 << 1 +#define SWITCHTAG_LEFT 1 << 2 +#define SWITCHTAG_RIGHT 1 << 3 +#define SWITCHTAG_TOGGLETAG 1 << 4 +#define SWITCHTAG_TAG 1 << 5 +#define SWITCHTAG_VIEW 1 << 6 +#define SWITCHTAG_TOGGLEVIEW 1 << 7 + +static const unsigned int drawtagmask = DRAWTAGGRID; /* | DRAWCLASSICTAGS to show classic row of tags */ +static const int tagrows = 2; +#endif // TAGGRID_PATCH + static const Rule rules[] = { /* xprop(1): * WM_CLASS(STRING) = instance, class @@ -460,6 +478,16 @@ static Key keys[] = { #if ALTERNATIVE_TAGS_PATCH { MODKEY, XK_n, togglealttag, {0} }, #endif // ALTERNATIVE_TAGS_PATCH + #if TAGGRID_PATCH + { MODKEY|ControlMask, XK_Up, switchtag, { .ui = SWITCHTAG_UP | SWITCHTAG_VIEW } }, + { MODKEY|ControlMask, XK_Down, switchtag, { .ui = SWITCHTAG_DOWN | SWITCHTAG_VIEW } }, + { MODKEY|ControlMask, XK_Right, switchtag, { .ui = SWITCHTAG_RIGHT | SWITCHTAG_VIEW } }, + { MODKEY|ControlMask, XK_Left, switchtag, { .ui = SWITCHTAG_LEFT | SWITCHTAG_VIEW } }, + { MODKEY|Mod4Mask, XK_Up, switchtag, { .ui = SWITCHTAG_UP | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, + { MODKEY|Mod4Mask, XK_Down, switchtag, { .ui = SWITCHTAG_DOWN | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, + { MODKEY|Mod4Mask, XK_Right, switchtag, { .ui = SWITCHTAG_RIGHT | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, + { MODKEY|Mod4Mask, XK_Left, switchtag, { .ui = SWITCHTAG_LEFT | SWITCHTAG_TAG | SWITCHTAG_VIEW } }, + #endif // TAGGRID_PATCH #if SETBORDERPX_PATCH { MODKEY|ShiftMask, XK_minus, setborderpx, {.i = -1 } }, { MODKEY|ShiftMask, XK_plus, setborderpx, {.i = +1 } }, diff --git a/dwm.c b/dwm.c index 11d3c8f..09b7427 100644 --- a/dwm.c +++ b/dwm.c @@ -601,11 +601,17 @@ void buttonpress(XEvent *e) { unsigned int i, x, click; + #if TAGGRID_PATCH + unsigned int columns; + #endif // TAGGRID_PATCH Arg arg = {0}; Client *c; Monitor *m; XButtonPressedEvent *ev = &e->xbutton; + #if TAGGRID_PATCH + columns = LENGTH(tags) / tagrows + ((LENGTH(tags) % tagrows > 0) ? 1 : 0); + #endif // TAGGRID_PATCH click = ClkRootWin; /* focus monitor if necessary */ if ((m = wintomon(ev->window)) && m != selmon @@ -664,14 +670,35 @@ buttonpress(XEvent *e) #endif // AWESOMEBAR_PATCH } #else // LEFTLAYOUT_PATCH + #if TAGGRID_PATCH + if (drawtagmask & DRAWCLASSICTAGS) + #endif // TAGGRID_PATCH do x += TEXTW(tags[i]); while (ev->x >= x && ++i < LENGTH(tags)); - if (i < LENGTH(tags)) { + if (i < LENGTH(tags) + #if TAGGRID_PATCH + && (drawtagmask & DRAWCLASSICTAGS) + #endif + ) { click = ClkTagBar; arg.ui = 1 << i; + #if TAGGRID_PATCH + } else if (ev->x < x + columns * bh / tagrows && (drawtagmask & DRAWTAGGRID)) { + click = ClkTagBar; + i = (ev->x - x) / (bh / tagrows); + i = i + columns * (ev->y / (bh / tagrows)); + if (i >= LENGTH(tags)) { + i = LENGTH(tags) - 1; + } + arg.ui = 1 << i; + } + else if (ev->x < x + blw + columns * bh / tagrows) + click = ClkLtSymbol; + #else } else if (ev->x < x + blw) click = ClkLtSymbol; + #endif // TAGGRID_PATCH #if AWESOMEBAR_PATCH && SYSTRAY_PATCH else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2 - getsystraywidth()) #elif AWESOMEBAR_PATCH @@ -1209,6 +1236,9 @@ drawbar(Monitor *m) drw_setscheme(drw, scheme[SchemeNorm]); x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); #endif // LEFTLAYOUT_PATCH + #if TAGGRID_PATCH + if (drawtagmask & DRAWCLASSICTAGS) + #endif // TAGGRID_PATCH for (i = 0; i < LENGTH(tags); i++) { w = TEXTW(tags[i]); #if ALTERNATIVE_TAGS_PATCH @@ -1232,6 +1262,11 @@ drawbar(Monitor *m) #endif // ACTIVETAGINDICATORBAR_PATCH x += w; } + #if TAGGRID_PATCH + if (drawtagmask & DRAWTAGGRID) { + drawtaggrid(m,&x,occ); + } + #endif // TAGGRID_PATCH #if !LEFTLAYOUT_PATCH w = blw = TEXTW(m->ltsymbol); drw_setscheme(drw, scheme[SchemeNorm]); diff --git a/patch/include.c b/patch/include.c index 204f2d8..084f64e 100644 --- a/patch/include.c +++ b/patch/include.c @@ -110,6 +110,10 @@ #include "tagallmon.c" #endif +#if TAGGRID_PATCH +#include "taggrid.c" +#endif + #if TAGSWAPMON_PATCH #include "tagswapmon.c" #endif diff --git a/patch/include.h b/patch/include.h index 38f5485..426853d 100644 --- a/patch/include.h +++ b/patch/include.h @@ -110,6 +110,10 @@ #include "tagallmon.h" #endif +#if TAGGRID_PATCH +#include "taggrid.h" +#endif + #if TAGSWAPMON_PATCH #include "tagswapmon.h" #endif diff --git a/patch/taggrid.c b/patch/taggrid.c new file mode 100644 index 0000000..ab7f460 --- /dev/null +++ b/patch/taggrid.c @@ -0,0 +1,118 @@ +void drawtaggrid(Monitor *m, int *x_pos, unsigned int occ) +{ + unsigned int x, y, h, max_x, columns; + int invert, i,j, k; + + h = bh / tagrows; + x = max_x = *x_pos; + y = 0; + columns = LENGTH(tags) / tagrows + ((LENGTH(tags) % tagrows > 0) ? 1 : 0); + + /* Firstly we will fill the borders of squares */ + + XSetForeground(drw->dpy, drw->gc, scheme[SchemeNorm][ColBorder].pixel); + XFillRectangle(dpy, drw->drawable, drw->gc, x, y, h*columns + 1, bh); + + /* We will draw LENGTH(tags) squares in tagraws raws. */ + for (j = 0, i= 0; j < tagrows; j++) { + x = *x_pos; + for (k = 0; k < columns && i < LENGTH(tags); k++, i++) { + invert = m->tagset[m->seltags] & 1 << i ? 0 : 1; + + /* Select active color for current square */ + XSetForeground(drw->dpy, drw->gc, !invert ? scheme[SchemeSel][ColBg].pixel : + scheme[SchemeNorm][ColFg].pixel); + XFillRectangle(dpy, drw->drawable, drw->gc, x+1, y+1, h-1, h-1); + + /* Mark square if tag has client */ + if (occ & 1 << i) { + XSetForeground(drw->dpy, drw->gc, !invert ? scheme[SchemeSel][ColFg].pixel : + scheme[SchemeNorm][ColBg].pixel); + XFillRectangle(dpy, drw->drawable, drw->gc, x + 1, y + 1, + h / 2, h / 2); + } + x += h; + if (x > max_x) { + max_x = x; + } + } + y += h; + } + *x_pos = max_x + 1; +} + +void switchtag(const Arg *arg) +{ + unsigned int columns; + unsigned int new_tagset = 0; + unsigned int pos, i; + int col, row; + Arg new_arg; + + columns = LENGTH(tags) / tagrows + ((LENGTH(tags) % tagrows > 0) ? 1 : 0); + + for (i = 0; i < LENGTH(tags); ++i) { + if (!(selmon->tagset[selmon->seltags] & 1 << i)) { + continue; + } + pos = i; + row = pos / columns; + col = pos % columns; + if (arg->ui & SWITCHTAG_UP) { /* UP */ + row --; + if (row < 0) { + row = tagrows - 1; + } + do { + pos = row * columns + col; + row --; + } while (pos >= LENGTH(tags)); + } + if (arg->ui & SWITCHTAG_DOWN) { /* DOWN */ + row ++; + if (row >= tagrows) { + row = 0; + } + pos = row * columns + col; + if (pos >= LENGTH(tags)) { + row = 0; + } + pos = row * columns + col; + } + if (arg->ui & SWITCHTAG_LEFT) { /* LEFT */ + col --; + if (col < 0) { + col = columns - 1; + } + do { + pos = row * columns + col; + col --; + } while (pos >= LENGTH(tags)); + } + if (arg->ui & SWITCHTAG_RIGHT) { /* RIGHT */ + col ++; + if (col >= columns) { + col = 0; + } + pos = row * columns + col; + if (pos >= LENGTH(tags)) { + col = 0; + pos = row * columns + col; + } + } + new_tagset |= 1 << pos; + } + new_arg.ui = new_tagset; + if (arg->ui & SWITCHTAG_TOGGLETAG) { + toggletag(&new_arg); + } + if (arg->ui & SWITCHTAG_TAG) { + tag(&new_arg); + } + if (arg->ui & SWITCHTAG_VIEW) { + view (&new_arg); + } + if (arg->ui & SWITCHTAG_TOGGLEVIEW) { + toggleview (&new_arg); + } +} \ No newline at end of file diff --git a/patch/taggrid.h b/patch/taggrid.h new file mode 100644 index 0000000..27343a6 --- /dev/null +++ b/patch/taggrid.h @@ -0,0 +1,2 @@ +static void drawtaggrid(Monitor *m, int *x_pos, unsigned int occ); +static void switchtag(const Arg *arg); \ No newline at end of file diff --git a/patches.h b/patches.h index 9bd770a..8c35a63 100644 --- a/patches.h +++ b/patches.h @@ -331,6 +331,11 @@ */ #define TAGALLMON_PATCH 0 +/* This patch adds an option to place tags in rows like in many other window managers. + * https://dwm.suckless.org/patches/taggrid/ + */ +#define TAGGRID_PATCH 0 + /* This patch makes new clients attach into the stack area when you toggle a new tag into * view. This means your master area will remain unchanged when toggling views. * The allmaster patch will cause all clients in the master area to be left alone. This patch