[wiki] [sites] add awesomebar patch for dwm 6.2 || ornx

From: <git_AT_suckless.org>
Date: Thu, 27 Jun 2019 23:21:25 +0200

commit 0ff487452a65d8550817dafaa1d428664a9befa9
Author: ornx <ornx_AT_protonmail.com>
Date: Thu Jun 27 17:19:11 2019 -0400

    add awesomebar patch for dwm 6.2

diff --git a/dwm.suckless.org/patches/awesomebar/dwm-awesomebar-6.2.diff b/dwm.suckless.org/patches/awesomebar/dwm-awesomebar-6.2.diff
new file mode 100644
index 00000000..fd624001
--- /dev/null
+++ b/dwm.suckless.org/patches/awesomebar/dwm-awesomebar-6.2.diff
_AT_@ -0,0 +1,272 @@
+diff --git a/config.def.h b/config.def.h
+index 1c0b587..1e62218 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -16,6 +16,7 @@ static const char *colors[][3] = {
+ /* fg bg border */
+ [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
+ [SchemeSel] = { col_gray4, col_cyan, col_cyan },
++ [SchemeHid] = { col_cyan, col_gray1, col_cyan },
+ };
+
+ /* tagging */
+_AT_@ -102,6 +103,7 @@ static Button buttons[] = {
+ /* click event mask button function argument */
+ { ClkLtSymbol, 0, Button1, setlayout, {0} },
+ { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
++ { ClkWinTitle, 0, Button1, togglewin, {0} },
+ { 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 4465af1..be9582d 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -50,6 +50,7 @@
+ #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
+ * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
+ #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
++#define HIDDEN(C) ((getstate(C->win) == IconicState))
+ #define LENGTH(X) (sizeof X / sizeof X[0])
+ #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
+ #define WIDTH(X) ((X)->w + 2 * (X)->bw)
+_AT_@ -59,7 +60,7 @@
+
+ /* enums */
+ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
+-enum { SchemeNorm, SchemeSel }; /* color schemes */
++enum { SchemeNorm, SchemeSel, SchemeHid }; /* color schemes */
+ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
+ NetWMFullscreen, NetActiveWindow, NetWMWindowType,
+ NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
+_AT_@ -117,6 +118,8 @@ struct Monitor {
+ int nmaster;
+ int num;
+ int by; /* bar geometry */
++ int btw; /* width of tasks portion of bar */
++ int bt; /* number of tasks */
+ int mx, my, mw, mh; /* screen size */
+ int wx, wy, ww, wh; /* window area */
+ unsigned int seltags;
+_AT_@ -174,6 +177,7 @@ static long getstate(Window w);
+ static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
+ static void grabbuttons(Client *c, int focused);
+ static void grabkeys(void);
++static void hide(Client *c);
+ static void incnmaster(const Arg *arg);
+ static void keypress(XEvent *e);
+ static void killclient(const Arg *arg);
+_AT_@ -203,6 +207,7 @@ static void setlayout(const Arg *arg);
+ static void setmfact(const Arg *arg);
+ static void setup(void);
+ static void seturgent(Client *c, int urg);
++static void show(Client *c);
+ static void showhide(Client *c);
+ static void sigchld(int unused);
+ static void spawn(const Arg *arg);
+_AT_@ -213,6 +218,7 @@ static void togglebar(const Arg *arg);
+ static void togglefloating(const Arg *arg);
+ static void toggletag(const Arg *arg);
+ static void toggleview(const Arg *arg);
++static void togglewin(const Arg *arg);
+ static void unfocus(Client *c, int setfocus);
+ static void unmanage(Client *c, int destroyed);
+ static void unmapnotify(XEvent *e);
+_AT_@ -439,10 +445,25 @@ buttonpress(XEvent *e)
+ arg.ui = 1 << i;
+ } else if (ev->x < x + blw)
+ click = ClkLtSymbol;
+- else if (ev->x > selmon->ww - TEXTW(stext))
++ /* 2px right padding */
++ else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2)
+ click = ClkStatusText;
+- else
+- click = ClkWinTitle;
++ 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 if ((c = wintoclient(ev->window))) {
+ focus(c);
+ restack(selmon);
+_AT_@ -452,7 +473,7 @@ 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))
+- buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
++ buttons[i].func((click == ClkTagBar || click == ClkWinTitle) && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
+ }
+
+ void
+_AT_@ -695,7 +716,7 @@ dirtomon(int dir)
+ void
+ drawbar(Monitor *m)
+ {
+- int x, w, sw = 0;
++ int x, w, sw = 0, n = 0, scm;
+ int boxs = drw->fonts->h / 9;
+ int boxw = drw->fonts->h / 6 + 2;
+ unsigned int i, occ = 0, urg = 0;
+_AT_@ -709,6 +730,8 @@ drawbar(Monitor *m)
+ }
+
+ for (c = m->clients; c; c = c->next) {
++ if (ISVISIBLE(c))
++ n++;
+ occ |= c->tags;
+ if (c->isurgent)
+ urg |= c->tags;
+_AT_@ -729,16 +752,28 @@ drawbar(Monitor *m)
+ x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
+
+ if ((w = m->ww - sw - x) > bh) {
+- if (m->sel) {
+- drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
+- drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
+- if (m->sel->isfloating)
+- drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
++ 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);
+ }
+ }
++
++ m->bt = n;
++ m->btw = w;
+ drw_map(drw, m->barwin, 0, 0, m->ww, bh);
+ }
+
+_AT_@ -783,8 +818,8 @@ expose(XEvent *e)
+ void
+ focus(Client *c)
+ {
+- if (!c || !ISVISIBLE(c))
+- for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
++ if (!c || !ISVISIBLE(c) || HIDDEN(c))
++ for (c = selmon->stack; c && (!ISVISIBLE(c) || HIDDEN(c)); c = c->snext);
+ if (selmon->sel && selmon->sel != c)
+ unfocus(selmon->sel, 0);
+ if (c) {
+_AT_@ -963,6 +998,31 @@ grabkeys(void)
+ }
+ }
+
++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
+ incnmaster(const Arg *arg)
+ {
+_AT_@ -1067,12 +1127,14 @@ 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 */
+- setclientstate(c, NormalState);
++ if (!HIDDEN(c))
++ setclientstate(c, NormalState);
+ if (c->mon == selmon)
+ unfocus(selmon->sel, 0);
+ c->mon->sel = c;
+ arrange(c->mon);
+- XMapWindow(dpy, c->win);
++ if (!HIDDEN(c))
++ XMapWindow(dpy, c->win);
+ focus(NULL);
+ }
+
+_AT_@ -1195,7 +1257,7 @@ movemouse(const Arg *arg)
+ Client *
+ nexttiled(Client *c)
+ {
+- for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
++ for (; c && (c->isfloating || !ISVISIBLE(c) || HIDDEN(c)); c = c->next);
+ return c;
+ }
+
+_AT_@ -1610,6 +1672,17 @@ seturgent(Client *c, int urg)
+ XFree(wmh);
+ }
+
++void
++show(Client *c)
++{
++ if (!c || !HIDDEN(c))
++ return;
++
++ XMapWindow(dpy, c->win);
++ setclientstate(c, NormalState);
++ arrange(c->mon);
++}
++
+ void
+ showhide(Client *c)
+ {
+_AT_@ -1746,6 +1819,20 @@ toggleview(const Arg *arg)
+ }
+ }
+
++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);
++ }
++}
++
+ void
+ unfocus(Client *c, int setfocus)
+ {
diff --git a/dwm.suckless.org/patches/awesomebar/dwm-awesomebar-screenshot.png b/dwm.suckless.org/patches/awesomebar/dwm-awesomebar-screenshot.png
new file mode 100644
index 00000000..1a9cebb0
Binary files /dev/null and b/dwm.suckless.org/patches/awesomebar/dwm-awesomebar-screenshot.png differ
diff --git a/dwm.suckless.org/patches/awesomebar/index.md b/dwm.suckless.org/patches/awesomebar/index.md
new file mode 100644
index 00000000..7f6d7230
--- /dev/null
+++ b/dwm.suckless.org/patches/awesomebar/index.md
_AT_@ -0,0 +1,23 @@
+awesomebar
+=====================
+
+Description
+-----------
+This patch changes the taskbar to be more like awesome. To be specific, it:
+
+ * shows all tasks in the current tag in the taskbar at all times
+ * clicking on an unfocused window's title in the taskbar focuses that window
+ * clicking on a focused window's title in the taskbar hides that window
+ * clicking on a hidden window's title in the taskbar unhides and focuses that window
+
+Since this patch relies on knowing how big everything is in the taskbar, make sure to adjust the buttonpress()/drawbar() functions to account for any space in the taskbar used by other patches (such as systray).
+
+![screenshot](dwm-awesomebar-screenshot.png)
+
+Download
+--------
+* [dwm-awesomebar-6.2.diff](dwm-awesomebar-6.2.diff) (06/27/2019)
+
+Authors
+-------
+* ornx <ornx[at]protonmail.com>
\ No newline at end of file
Received on Thu Jun 27 2019 - 23:21:25 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 27 2019 - 23:24:31 CEST