From 89e03501c62b7533d7c4399e2b65feaaf8ccf1b0 Mon Sep 17 00:00:00 2001 From: elbachir-one Date: Fri, 3 Oct 2025 10:39:34 +0100 Subject: [PATCH] Fixed patch — no more errors when applying it --- config.def.h | 2 ++ dwm.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 3836510..d1bf68c 100644 --- a/config.def.h +++ b/config.def.h @@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int snap = 32; /* snap pixel */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ +static const int extrabar = 1; /* 0 means no extra bar */ static const char *fonts[] = { "monospace:size=10" }; static const char dmenufont[] = "monospace:size=10"; static const char col_gray1[] = "#222222"; @@ -66,6 +67,7 @@ static const Key keys[] = { { MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, { MODKEY, XK_b, togglebar, {0} }, + { MODKEY, XK_b, toggleextrabar, {0} }, { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, { MODKEY, XK_i, incnmaster, {.i = +1 } }, diff --git a/dwm.c b/dwm.c index 4f345ee..52149ad 100644 --- a/dwm.c +++ b/dwm.c @@ -140,6 +140,13 @@ typedef struct { int monitor; } Rule; +typedef struct { + int y; + int show; + Window win; + char text[256]; +} Bar; + /* function declarations */ static void applyrules(Client *c); static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact); @@ -209,6 +216,7 @@ static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void tile(Monitor *m); static void togglebar(const Arg *arg); +static void toggleextrabar(const Arg *arg); static void togglefloating(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); @@ -266,6 +274,7 @@ static Display *dpy; static Drw *drw; static Monitor *mons, *selmon; static Window root, wmcheckwin; +static Bar eb; /* configuration, allows nested code to access above variables */ #include "config.h" @@ -481,6 +490,8 @@ cleanup(void) while (m->stack) unmanage(m->stack, 0); XUngrabKey(dpy, AnyKey, AnyModifier, root); + XUnmapWindow(dpy, eb.win); + XDestroyWindow(dpy, eb.win); while (mons) cleanupmon(mons); for (i = 0; i < CurLast; i++) @@ -570,6 +581,7 @@ configurenotify(XEvent *e) if (c->isfullscreen) resizeclient(c, m->mx, m->my, m->mw, m->mh); XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh); + XMoveResizeWindow(dpy, eb.win, mons->wx, eb.y, mons->ww, bh); } focus(NULL); arrange(NULL); @@ -745,6 +757,9 @@ drawbar(Monitor *m) } } drw_map(drw, m->barwin, 0, 0, m->ww, bh); + drw_setscheme(drw, scheme[SchemeNorm]); + drw_text(drw, 0, 0, mons->ww, bh, 0, eb.text, 0); + drw_map(drw, eb.win, 0, 0, mons->ww, bh); } void @@ -1558,6 +1573,7 @@ setup(void) sh = DisplayHeight(dpy, screen); root = RootWindow(dpy, screen); drw = drw_create(dpy, screen, root, sw, sh); + eb.show = extrabar; if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) die("no fonts could be loaded."); lrpad = drw->fonts->h; @@ -1720,6 +1736,17 @@ togglebar(const Arg *arg) arrange(selmon); } +void +toggleextrabar(const Arg *arg) +{ + if(selmon == mons) { + eb.show = !eb.show; + updatebarpos(selmon); + XMoveResizeWindow(dpy, eb.win, selmon->wx, eb.y, selmon->ww, bh); + arrange(selmon); + } +} + void togglefloating(const Arg *arg) { @@ -1834,6 +1861,13 @@ updatebars(void) XMapRaised(dpy, m->barwin); XSetClassHint(dpy, m->barwin, &ch); } + if (!eb.win) { + eb.win = XCreateWindow(dpy, root, mons->wx, eb.y, mons->ww, bh, 0, DefaultDepth(dpy, screen), + CopyFromParent, DefaultVisual(dpy, screen), + CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); + XDefineCursor(dpy, eb.win, cursor[CurNormal]->cursor); + XMapRaised(dpy, eb.win); + } } void @@ -1847,6 +1881,13 @@ updatebarpos(Monitor *m) m->wy = m->topbar ? m->wy + bh : m->wy; } else m->by = -bh; + + if (m == mons && eb.show) { + m->wh -= bh; + eb.y = topbar ? m->wy + m->wh : m->wy; + m->wy = m->topbar ? m->wy : m->wy + bh; + } else + eb.y = -bh; } void @@ -2004,8 +2045,19 @@ updatesizehints(Client *c) void updatestatus(void) { - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) + char text[512]; + if (!gettextprop(root, XA_WM_NAME, text, sizeof(text))) { strcpy(stext, "dwm-"VERSION); + eb.text[0] = '\0'; + } else { + char *e = strchr(text, ';'); + if (e) { + *e = '\0'; e++; + strncpy(eb.text, e, sizeof(eb.text)-1); + } else + eb.text[0] = '\0'; + strncpy(stext, text, sizeof(stext)-1); + } drawbar(selmon); } -- 2.50.1