dwm

Fork of suckless' dwm with my personal patches
git clone https://git.instinctive.eu/dwm.git
Log | Files | Refs | README | LICENSE

commit 905f4d544b75e919bd9eb4d42c91f36e78e9e3e7
parent 5fd6363b3da21d80bbcf1b55f19da7f40b3eea6d
Author: Natasha Kerensikova <natacha@instinctive.eu>
Date:   Sun, 21 May 2023 00:26:32 +0200

[nat] add click-to-focus to fancybar

Diffstat:
Mconfig.def.h | 1+
Mdwm.c | 25++++++++++++++++++++++---
2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -119,6 +119,7 @@ static const Button buttons[] = { /* click event mask button function argument */ { ClkLtSymbol, 0, Button1, setlayout, {0} }, { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, + { ClkWinTitle, 0, Button1, focustitle, {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 @@ -92,6 +92,7 @@ struct Client { int oldx, oldy, oldw, oldh; int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid; int bw, oldbw; + int barx, barw; unsigned int tags; int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; Client *next; @@ -174,6 +175,7 @@ static void focus(Client *c); static void focusin(XEvent *e); static void focusmon(const Arg *arg); static void focusstack(const Arg *arg); +static void focustitle(const Arg *arg); static Atom getatomprop(Client *c, Atom prop); static Client *getclientundermouse(void); static int getrootptr(int *x, int *y); @@ -488,8 +490,12 @@ buttonpress(XEvent *e) click = ClkLtSymbol; else if (ev->x > selmon->ww - (int)TEXTW(stext)) click = ClkStatusText; - else + else { click = ClkWinTitle; + for (c = m->clients; c; c = c->next) + if (c->barx >= 0 && ev->x >= c->barx && ev->x < c->barx + c->barw) + arg.v = c; + } } else if ((c = wintoclient(ev->window))) { focus(c); restack(selmon); @@ -499,7 +505,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 @@ -850,9 +856,14 @@ drawbar(Monitor *m) mw += ew / i; for (c = m->clients; c; c = c->next) { - if (!ISVISIBLE(c)) + if (!ISVISIBLE(c)) { + c->barx = c->barw = -1; continue; + } + tw = MIN(m->sel == c ? w : mw, TEXTW(c->name)); + c->barx = x; + c->barw = tw; drw_setscheme(drw, scheme[m == selmon && m->sel == c ? SchemeSel : SchemeNorm]); if (tw > lrpad / 2) @@ -986,6 +997,13 @@ focusstack(const Arg *arg) } } +void +focustitle(const Arg *arg) +{ + focus((Client *)arg->v); + restack(selmon); +} + Atom getatomprop(Client *c, Atom prop) { @@ -1182,6 +1200,7 @@ manage(Window w, XWindowAttributes *wa) c->w = c->oldw = wa->width; c->h = c->oldh = wa->height; c->oldbw = wa->border_width; + c->barx = c->barw = -1; updatetitle(c); if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {