From f5eca5af208cc362b5f4c2dd0231ad52759179bd Mon Sep 17 00:00:00 2001 From: davidpkj Date: Thu, 16 Mar 2023 17:30:20 +0100 Subject: Custom changes (including center title & cycle layout patches) --- dwm.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 14 deletions(-) (limited to 'dwm.c') diff --git a/dwm.c b/dwm.c index ae71522..18d0341 100644 --- a/dwm.c +++ b/dwm.c @@ -173,6 +173,7 @@ struct Monitor { int ntabs; int tab_widths[MAXTABS]; const Layout *lt[2]; + int ltcur; Pertag *pertag; }; @@ -203,10 +204,12 @@ static void configure(Client *c); static void configurenotify(XEvent *e); static void configurerequest(XEvent *e); static Monitor *createmon(void); +static void cyclelayout(const Arg *arg); static void destroynotify(XEvent *e); static void detach(Client *c); static void detachstack(Client *c); static Monitor *dirtomon(int dir); +static void drawcentered(Monitor *m, int x, int y, int w, int h, int lrpad, char* text); static void drawbar(Monitor *m); static void drawbars(void); static int drawstatusbar(Monitor *m, int bh, char* text); @@ -401,6 +404,9 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) int baseismin; Monitor *m = c->mon; + if (&monocle == c->mon->lt[c->mon->sellt]->arrange) + return 1; + /* set minimum possible */ *w = MAX(1, *w); *h = MAX(1, *h); @@ -793,6 +799,7 @@ createmon(void) m = ecalloc(1, sizeof(Monitor)); m->tagset[0] = m->tagset[1] = 1; + m->ltcur = 0; m->mfact = mfact; m->nmaster = nmaster; m->showbar = showbar; @@ -829,6 +836,27 @@ createmon(void) return m; } +void +cyclelayout(const Arg *arg) +{ + if (!arg || !arg->i) + return; + int switchto = selmon->ltcur + arg->i; + int l = LENGTH(layouts); + + if (switchto == l) + switchto = 0; + else if(switchto < 0) + switchto = l - 1; + + if (switchto != 1) + togglebar(0); + + selmon->ltcur = switchto; + Arg arg2 = {.v= &layouts[switchto] }; + setlayout(&arg2); +} + void destroynotify(XEvent *e) { @@ -992,7 +1020,6 @@ void drawbar(Monitor *m) { int x, w, tw = 0; - int tlpad; int boxs = drw->fonts->h / 9; int boxw = drw->fonts->h / 6 + 2; unsigned int i, occ = 0, urg = 0; @@ -1026,24 +1053,32 @@ drawbar(Monitor *m) drw_setscheme(drw, scheme[SchemeNorm]); x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); - if ((w = m->ww + m->gap->gappx * 2 - tw - x) > bh) { + if ((w = m->ww - tw -x) > bh) { if (m->sel) { - drw_setscheme(drw, SchemeNorm); - tlpad = MAX((m->ww - ((int)TEXTW(m->sel->name) - lrpad)) / 2 - x, lrpad / 2); - drw_text(drw, x, 0, w - 2 * sp, bh, tlpad, m->sel->name, 0); + drw_setscheme(drw, scheme[SchemeNorm]); + drawcentered(m, x, 0, w, bh, lrpad, m->sel->name); if (m->sel->isfloating) { - drw_rect(drw, x + boxs + tlpad - lrpad / 2, boxs, boxw, boxw, m->sel->isfixed, 0); + drw_rect(drw, x + boxs - lrpad / 2, boxs, boxw, boxw, m->sel->isfixed, 0); if (m->sel->isalwaysontop) - drw_rect(drw, x + boxs + tlpad - lrpad / 2, bh - boxw, boxw, boxw, 0, 0); + drw_rect(drw, x + boxs - lrpad / 2, bh - boxw, boxw, boxw, 0, 0); } } else { drw_setscheme(drw, scheme[SchemeNorm]); - drw_rect(drw, x, 0, w - 2 * sp, bh, 1, 1); + drawcentered(m, x, 0, w, bh, lrpad, "Enjoying the desktop"); } } drw_map(drw, m->barwin, 0, 0, m->ww, bh); } +void +drawcentered(Monitor *m, int x, int y, int w, int h, int lrpad, char* text) +{ + if (TEXTW(text) > w) + drw_text(drw, x, y, w, h, lrpad / 2, text, 0); + else + drw_text(drw, x, y, w, h, (w - TEXTW(text)) / 2, text, 0); +} + void drawbars(void) { @@ -1560,14 +1595,8 @@ maprequest(XEvent *e) void monocle(Monitor *m) { - unsigned int n = 0; Client *c; - for (c = m->clients; c; c = c->next) - if (ISVISIBLE(c)) - n++; - if (n > 0) /* override layout symbol */ - snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n); for (c = nexttiled(m->clients); c; c = nexttiled(c->next)) resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0); } @@ -1811,6 +1840,13 @@ resizeclient(Client *c, int x, int y, int w, int h) c->oldw = c->w; c->w = wc.width = w; c->oldh = c->h; c->h = wc.height = h; wc.border_width = c->bw; + + if ((&monocle == c->mon->lt[c->mon->sellt]->arrange) && (!c->isfloating)) { + wc.border_width = 0; + c->w = wc.width += c->bw * 2; + c->h = wc.height += c->bw * 2; + } + XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc); configure(c); XSync(dpy, False); -- cgit v1.2.3