2
0
mirror of https://github.com/bakkeby/patches synced 2024-11-07 15:20:22 +00:00
patches/dwm/dwm-barmodules-taggrid-6.2.diff
2020-07-20 15:58:35 +02:00

261 lines
8.4 KiB
Diff

From 309128900da962d6f46030fa2975c50b76cd2895 Mon Sep 17 00:00:00 2001
From: bakkeby <bakkeby@gmail.com>
Date: Mon, 20 Jul 2020 15:57:24 +0200
Subject: [PATCH 2/2] Adding taggrid module
---
config.def.h | 25 ++++++++
patch/bar_taggrid.c | 148 ++++++++++++++++++++++++++++++++++++++++++++
patch/bar_taggrid.h | 4 ++
patch/include.c | 3 +-
patch/include.h | 3 +-
5 files changed, 181 insertions(+), 2 deletions(-)
create mode 100644 patch/bar_taggrid.c
create mode 100644 patch/bar_taggrid.h
diff --git a/config.def.h b/config.def.h
index 2534eac..afee168 100644
--- a/config.def.h
+++ b/config.def.h
@@ -21,6 +21,22 @@ static const char *colors[][3] = {
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+/* 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;
+
static const Rule rules[] = {
/* xprop(1):
* WM_CLASS(STRING) = instance, class
@@ -46,6 +62,7 @@ static const Rule rules[] = {
static const BarRule barrules[] = {
/* monitor bar alignment widthfunc drawfunc clickfunc name */
{ -1, 0, BAR_ALIGN_LEFT, width_tags, draw_tags, click_tags, "tags" },
+ { -1, 0, BAR_ALIGN_LEFT, width_taggrid, draw_taggrid, click_taggrid, "taggrid" },
{ -1, 0, BAR_ALIGN_LEFT, width_ltsymbol, draw_ltsymbol, click_ltsymbol, "layout" },
{ 'A', 0, BAR_ALIGN_RIGHT, width_status, draw_status, click_status, "status" },
{ -1, 0, BAR_ALIGN_NONE, width_wintitle, draw_wintitle, click_wintitle, "wintitle" },
@@ -100,6 +117,14 @@ static Key keys[] = {
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY, XK_0, view, {.ui = ~0 } },
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
+ { 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 } },
{ MODKEY, XK_comma, focusmon, {.i = -1 } },
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
diff --git a/patch/bar_taggrid.c b/patch/bar_taggrid.c
new file mode 100644
index 0000000..53046fa
--- /dev/null
+++ b/patch/bar_taggrid.c
@@ -0,0 +1,148 @@
+int
+width_taggrid(Bar *bar, BarWidthArg *a)
+{
+ return (bh / 2) * (LENGTH(tags) / tagrows + ((LENGTH(tags) % tagrows > 0) ? 1 : 0)) + lrpad;
+}
+
+int
+draw_taggrid(Bar *bar, BarDrawArg *a)
+{
+ unsigned int x, y, h, max_x = 0, columns, occ = 0;
+ int invert, i,j, k;
+ Client *c;
+
+ for (c = bar->mon->clients; c; c = c->next)
+ occ |= c->tags;
+
+ max_x = x = a->x + lrpad / 2;
+ h = bh / tagrows;
+ 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][ColBg].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 = a->x + lrpad / 2;
+ for (k = 0; k < columns; k++, i++) {
+ if (i < LENGTH(tags)) {
+ invert = bar->mon->tagset[bar->mon->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);
+ }
+ } else {
+ XSetForeground(drw->dpy, drw->gc, scheme[SchemeNorm][ColBg].pixel);
+ XFillRectangle(dpy, drw->drawable, drw->gc, x+1, y+1, h-1, h);
+ }
+ x += h;
+ if (x > max_x) {
+ max_x = x;
+ }
+ }
+ y += h;
+ }
+ return max_x;
+}
+
+int
+click_taggrid(Bar *bar, Arg *arg, BarClickArg *a)
+{
+ unsigned int i, columns;
+
+ columns = LENGTH(tags) / tagrows + ((LENGTH(tags) % tagrows > 0) ? 1 : 0);
+ i = (a->rel_x - lrpad / 2) / (bh / tagrows) + columns * (a->rel_y / (bh / tagrows));
+ if (i >= LENGTH(tags)) {
+ i = LENGTH(tags) - 1;
+ }
+ arg->ui = 1 << i;
+ return ClkTagBar;
+}
+
+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/bar_taggrid.h b/patch/bar_taggrid.h
new file mode 100644
index 0000000..c35b337
--- /dev/null
+++ b/patch/bar_taggrid.h
@@ -0,0 +1,4 @@
+static int width_taggrid(Bar *bar, BarWidthArg *a);
+static int draw_taggrid(Bar *bar, BarDrawArg *a);
+static int click_taggrid(Bar *bar, Arg *arg, BarClickArg *a);
+static void switchtag(const Arg *arg);
\ No newline at end of file
diff --git a/patch/include.c b/patch/include.c
index d422f56..f6455d8 100644
--- a/patch/include.c
+++ b/patch/include.c
@@ -2,4 +2,5 @@
#include "bar_ltsymbol.c"
#include "bar_status.c"
#include "bar_tags.c"
-#include "bar_wintitle.c"
\ No newline at end of file
+#include "bar_wintitle.c"
+#include "bar_taggrid.c"
\ No newline at end of file
diff --git a/patch/include.h b/patch/include.h
index 5f9a3fe..98ac046 100644
--- a/patch/include.h
+++ b/patch/include.h
@@ -2,4 +2,5 @@
#include "bar_ltsymbol.h"
#include "bar_status.h"
#include "bar_tags.h"
-#include "bar_wintitle.h"
\ No newline at end of file
+#include "bar_wintitle.h"
+#include "bar_taggrid.h"
\ No newline at end of file
--
2.19.1