summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorbakkeby <[email protected]>2019-09-10 00:18:46 +0200
committerbakkeby <[email protected]>2019-09-10 00:30:17 +0200
commitd6517bf4f83298cd8655481c474519987b41c71c (patch)
tree96fea81a537246c79a74f648d233c00b63b8072d
parent4a17b880ad2cc4ae9098809ca3ccf4d439127450 (diff)
downloaddwm-flexipatch-d6517bf4f83298cd8655481c474519987b41c71c.tar.gz
dwm-flexipatch-d6517bf4f83298cd8655481c474519987b41c71c.zip
Adding awesomebar patch
-rw-r--r--README.md2
-rw-r--r--config.def.h6
-rw-r--r--dwm.c99
-rw-r--r--patch/awesomebar.c49
-rw-r--r--patch/awesomebar.h3
-rw-r--r--patch/include.c4
-rw-r--r--patch/include.h4
-rw-r--r--patches.h6
8 files changed, 165 insertions, 8 deletions
diff --git a/README.md b/README.md
index 98f65d1..7457382 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
This side project has a different take on dwm patching. It uses preprocessor directives to decide whether or not to include a patch during build time. Essentially this means that this build, for better or worse, contains both the patched _and_ the original code. The aim being that you can select which patches to include and the build will contain that code and nothing more.
-For example to include the alpha patch then you would only need to flip this setting from 0 to 1 in [patches.h](https://github.com/bakkeby/dwm-flexipatch/blob/master/patches.h):
+For example to include the `alpha` patch then you would only need to flip this setting from 0 to 1 in [patches.h](https://github.com/bakkeby/dwm-flexipatch/blob/master/patches.h):
```c
#define ALPHA_PATCH 1
```
diff --git a/config.def.h b/config.def.h
index 4b24161..30152ec 100644
--- a/config.def.h
+++ b/config.def.h
@@ -42,6 +42,9 @@ static const char *colors[][3] = {
/* fg bg border */
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
+ #if AWESOMEBAR_PATCH
+ [SchemeHid] = { col_cyan, col_gray1, col_cyan },
+ #endif // AWESOMEBAR_PATCH
};
/* tagging */
@@ -276,6 +279,9 @@ static Button buttons[] = {
/* click event mask button function argument */
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
+ #if AWESOMEBAR_PATCH
+ { ClkWinTitle, 0, Button1, togglewin, {0} },
+ #endif // AWESOMEBAR_PATCH
{ ClkWinTitle, 0, Button2, zoom, {0} },
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
diff --git a/dwm.c b/dwm.c
index 3e40820..cf95dbd 100644
--- a/dwm.c
+++ b/dwm.c
@@ -56,6 +56,9 @@
#else
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
#endif // ATTACHASIDE_PATCH
+#if AWESOMEBAR_PATCH
+#define HIDDEN(C) ((getstate(C->win) == IconicState))
+#endif // AWESOMEBAR_PATCH
#define LENGTH(X) (sizeof X / sizeof X[0])
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
@@ -65,7 +68,11 @@
/* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
+#if AWESOMEBAR_PATCH
+enum { SchemeNorm, SchemeSel, SchemeHid }; /* color schemes */
+#else
enum { SchemeNorm, SchemeSel }; /* color schemes */
+#endif // #if AWESOMEBAR_PATCH
#if SYSTRAY_PATCH
enum { NetSupported, NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayVisual,
NetWMName, NetWMState, NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetWMWindowTypeDock,
@@ -148,6 +155,10 @@ struct Monitor {
int nmaster;
int num;
int by; /* bar geometry */
+ #if AWESOMEBAR_PATCH
+ int btw; /* width of tasks portion of bar */
+ int bt; /* number of tasks */
+ #endif // AWESOMEBAR_PATCH
int mx, my, mw, mh; /* screen size */
int wx, wy, ww, wh; /* window area */
#if VANITYGAPS_PATCH
@@ -533,14 +544,38 @@ buttonpress(XEvent *e)
arg.ui = 1 << i;
} else if (ev->x < x + blw)
click = ClkLtSymbol;
- #if SYSTRAY_PATCH
+ #if AWESOMEBAR_PATCH && SYSTRAY_PATCH
+ else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2 - getsystraywidth())
+ #elif AWESOMEBAR_PATCH
+ else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2)
+ #elif SYSTRAY_PATCH
else if (ev->x > selmon->ww - TEXTW(stext) - getsystraywidth())
#else
else if (ev->x > selmon->ww - TEXTW(stext))
#endif // SYSTRAY_PATCH
click = ClkStatusText;
+
+ #if AWESOMEBAR_PATCH
+ else {
+ x += blw;
+ c = m->clients;
+
+ do {
+ if (!ISVISIBLE(c))
+ continue;
+ else
+ x += (1.0 / (double)m->bt) * m->btw;
+ } while (ev->x > x && (c = c->next));
+
+ if (c) {
+ click = ClkWinTitle;
+ arg.v = c;
+ }
+ }
+ #else
else
click = ClkWinTitle;
+ #endif // AWESOMEBAR_PATCH
} else if ((c = wintoclient(ev->window))) {
focus(c);
restack(selmon);
@@ -550,7 +585,11 @@ buttonpress(XEvent *e)
for (i = 0; i < LENGTH(buttons); i++)
if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
+ #if AWESOMEBAR_PATCH
+ buttons[i].func((click == ClkTagBar || click == ClkWinTitle) && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
+ #else
buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
+ #endif
}
void
@@ -920,10 +959,12 @@ drawbar(Monitor *m)
#if ALTERNATIVE_TAGS_PATCH
int wdelta;
#endif // ALTERNATIVE_TAGS_PATCH
- #if FANCYBAR_PATCH
+ #if AWESOMEBAR_PATCH
+ int n = 0, scm;
+ #elif FANCYBAR_PATCH
int tw, mw, ew = 0;
- unsigned int n = 0;
- #endif // FANCYBAR_PATCH
+ int n = 0;
+ #endif // FANCYBAR_PATCH, AWESOMEBAR_PATCH
#if SYSTRAY_PATCH
int stw = 0;
#endif // SYSTRAY_PATCH
@@ -958,7 +999,7 @@ drawbar(Monitor *m)
}
for (c = m->clients; c; c = c->next) {
- #if FANCYBAR_PATCH
+ #if AWESOMEBAR_PATCH || FANCYBAR_PATCH
if (ISVISIBLE(c))
n++;
#endif // FANCYBAR_PATCH
@@ -994,7 +1035,26 @@ drawbar(Monitor *m)
if ((w = m->ww - sw - x) > bh)
#endif // SYSTRAY_PATCH
{
- #if FANCYBAR_PATCH
+ #if AWESOMEBAR_PATCH
+ if (n > 0) {
+ for (c = m->clients; c; c = c->next) {
+ if (!ISVISIBLE(c))
+ continue;
+ if (m->sel == c)
+ scm = SchemeSel;
+ else if (HIDDEN(c))
+ scm = SchemeHid;
+ else
+ scm = SchemeNorm;
+ drw_setscheme(drw, scheme[scm]);
+ drw_text(drw, x, 0, (1.0 / (double)n) * w, bh, lrpad / 2, c->name, 0);
+ x += (1.0 / (double)n) * w;
+ }
+ } else {
+ drw_setscheme(drw, scheme[SchemeNorm]);
+ drw_rect(drw, x, 0, w, bh, 1, 1);
+ }
+ #elif FANCYBAR_PATCH
if (n > 0) {
tw = TEXTW(m->sel->name) + lrpad;
mw = (tw >= w || n == 1) ? 0 : (w - tw) / (n - 1);
@@ -1038,8 +1098,13 @@ drawbar(Monitor *m)
drw_setscheme(drw, scheme[SchemeNorm]);
drw_rect(drw, x, 0, w, bh, 1, 1);
}
- #endif // FANCYBAR_PATCH
+ #endif // FANCYBAR_PATCH, AWESOMEBAR_PATCH
}
+
+ #if AWESOMEBAR_PATCH
+ m->bt = n;
+ m->btw = w;
+ #endif // AWESOMEBAR_PATCH
#if SYSTRAY_PATCH
drw_map(drw, m->barwin, 0, 0, m->ww - stw, bh);
#else
@@ -1093,8 +1158,13 @@ expose(XEvent *e)
void
focus(Client *c)
{
+ #if AWESOMEBAR_PATCH
+ if (!c || !ISVISIBLE(c) || HIDDEN(c))
+ for (c = selmon->stack; c && (!ISVISIBLE(c) || HIDDEN(c)); c = c->snext);
+ #else
if (!c || !ISVISIBLE(c))
for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
+ #endif // AWESOMEBAR_PATCH
if (selmon->sel && selmon->sel != c)
unfocus(selmon->sel, 0);
if (c) {
@@ -1440,12 +1510,23 @@ manage(Window w, XWindowAttributes *wa)
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
(unsigned char *) &(c->win), 1);
XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
+
+ #if AWESOMEBAR_PATCH
+ if (!HIDDEN(c))
+ setclientstate(c, NormalState);
+ #else
setclientstate(c, NormalState);
+ #endif // AWESOMEBAR_PATCH
if (c->mon == selmon)
unfocus(selmon->sel, 0);
c->mon->sel = c;
arrange(c->mon);
+ #if AWESOMEBAR_PATCH
+ if (!HIDDEN(c))
+ XMapWindow(dpy, c->win);
+ #else
XMapWindow(dpy, c->win);
+ #endif // AWESOMEBAR_PATCH
focus(NULL);
}
@@ -1569,7 +1650,11 @@ movemouse(const Arg *arg)
Client *
nexttiled(Client *c)
{
+ #if AWESOMEBAR_PATCH
+ for (; c && (c->isfloating || !ISVISIBLE(c) || HIDDEN(c)); c = c->next);
+ #else
for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
+ #endif // AWESOMEBAR_PATCH
return c;
}
diff --git a/patch/awesomebar.c b/patch/awesomebar.c
new file mode 100644
index 0000000..20a54c7
--- /dev/null
+++ b/patch/awesomebar.c
@@ -0,0 +1,49 @@
+void
+hide(Client *c) {
+ if (!c || HIDDEN(c))
+ return;
+
+ Window w = c->win;
+ static XWindowAttributes ra, ca;
+
+ // more or less taken directly from blackbox's hide() function
+ XGrabServer(dpy);
+ XGetWindowAttributes(dpy, root, &ra);
+ XGetWindowAttributes(dpy, w, &ca);
+ // prevent UnmapNotify events
+ XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
+ XSelectInput(dpy, w, ca.your_event_mask & ~StructureNotifyMask);
+ XUnmapWindow(dpy, w);
+ setclientstate(c, IconicState);
+ XSelectInput(dpy, root, ra.your_event_mask);
+ XSelectInput(dpy, w, ca.your_event_mask);
+ XUngrabServer(dpy);
+
+ focus(c->snext);
+ arrange(c->mon);
+}
+
+void
+show(Client *c)
+{
+ if (!c || !HIDDEN(c))
+ return;
+
+ XMapWindow(dpy, c->win);
+ setclientstate(c, NormalState);
+ arrange(c->mon);
+}
+
+void
+togglewin(const Arg *arg)
+{
+ Client *c = (Client*)arg->v;
+ if (c == selmon->sel)
+ hide(c);
+ else {
+ if (HIDDEN(c))
+ show(c);
+ focus(c);
+ restack(selmon);
+ }
+} \ No newline at end of file
diff --git a/patch/awesomebar.h b/patch/awesomebar.h
new file mode 100644
index 0000000..2ca3dd1
--- /dev/null
+++ b/patch/awesomebar.h
@@ -0,0 +1,3 @@
+static void hide(Client *c);
+static void show(Client *c);
+static void togglewin(const Arg *arg); \ No newline at end of file
diff --git a/patch/include.c b/patch/include.c
index 04d66f4..43a636b 100644
--- a/patch/include.c
+++ b/patch/include.c
@@ -16,6 +16,10 @@
#include "autostart.c"
#endif
+#if AWESOMEBAR_PATCH
+#include "awesomebar.c"
+#endif
+
#if CFACTS_PATCH
#include "cfacts.c"
#endif
diff --git a/patch/include.h b/patch/include.h
index f76f6f1..49d3a1c 100644
--- a/patch/include.h
+++ b/patch/include.h
@@ -16,6 +16,10 @@
#include "autostart.h"
#endif
+#if AWESOMEBAR_PATCH
+#include "awesomebar.h"
+#endif
+
#if CFACTS_PATCH
#include "cfacts.h"
#endif
diff --git a/patches.h b/patches.h
index 6673f77..a042aaf 100644
--- a/patches.h
+++ b/patches.h
@@ -55,6 +55,12 @@
*/
#define AUTOSTART_PATCH 0
+/* Enhanced taskbar that shows the titles of all visible windows in the status bar
+ * and allows focus / hiding / unhiding of windows by clicking on the status bar.
+ * https://dwm.suckless.org/patches/awesomebar/
+ */
+#define AWESOMEBAR_PATCH 1
+
/* This patch adds an iscentered rule to automatically center clients on the current monitor.
* https://dwm.suckless.org/patches/center/
*/