summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
authorMatt Hunter <m@lfurio.us>2026-01-17 23:02:28 -0500
committerMatt Hunter <m@lfurio.us>2026-01-17 23:14:26 -0500
commit4da63c93feab351ecc33d47a86c4ad06680d1ee3 (patch)
treed95dc9f4161ebf4f51b6adb01a62f94a79e71a7e /dwm.c
parent1f4592f644d618656e7b405361fe8d1e09b0c451 (diff)
downloaddwm-4da63c93feab351ecc33d47a86c4ad06680d1ee3.tar.gz
dwm-4da63c93feab351ecc33d47a86c4ad06680d1ee3.zip
patch: alpha
Allow dwm to have translucent bars, while keeping all the text on it opaque, just like the alpha patch for st. By default dwm might make windows' borders transparent when using composit window manager (e.g. xcompmgr, picom). Alpha patch allows to make borders opaque. If all you want is to make borders opaque, you don't care about statusbar opacity and/or have problems applying alpha patch, then you might use fixborders patch instead.
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c60
1 files changed, 54 insertions, 6 deletions
diff --git a/dwm.c b/dwm.c
index 53b393e..fb6153c 100644
--- a/dwm.c
+++ b/dwm.c
@@ -56,6 +56,8 @@
#define TAGMASK ((1 << LENGTH(tags)) - 1)
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
+#define OPAQUE 0xffU
+
/* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { SchemeNorm, SchemeSel }; /* color schemes */
@@ -231,6 +233,7 @@ static Monitor *wintomon(Window w);
static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
+static void xinitvisual(void);
static void zoom(const Arg *arg);
/* variables */
@@ -266,6 +269,10 @@ static Display *dpy;
static Drw *drw;
static Monitor *mons, *selmon;
static Window root, wmcheckwin;
+static int useargb = 0;
+static Visual *visual;
+static int depth;
+static Colormap cmap;
/* configuration, allows nested code to access above variables */
#include "config.h"
@@ -1558,7 +1565,8 @@ setup(void)
sw = DisplayWidth(dpy, screen);
sh = DisplayHeight(dpy, screen);
root = RootWindow(dpy, screen);
- drw = drw_create(dpy, screen, root, sw, sh);
+ xinitvisual();
+ drw = drw_create(dpy, screen, root, sw, sh, visual, depth, cmap);
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
die("no fonts could be loaded.");
lrpad = drw->fonts->h;
@@ -1585,8 +1593,9 @@ setup(void)
cursor[CurMove] = drw_cur_create(drw, XC_fleur);
/* init appearance */
scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
+ unsigned int alphas[] = {borderalpha, baralpha, OPAQUE};
for (i = 0; i < LENGTH(colors); i++)
- scheme[i] = drw_scm_create(drw, colors[i], 3);
+ scheme[i] = drw_scm_create(drw, colors[i], alphas, 3);
/* init bars */
updatebars();
updatestatus();
@@ -1821,16 +1830,18 @@ updatebars(void)
Monitor *m;
XSetWindowAttributes wa = {
.override_redirect = True,
- .background_pixmap = ParentRelative,
+ .background_pixel = 0,
+ .border_pixel = 0,
+ .colormap = cmap,
.event_mask = ButtonPressMask|ExposureMask
};
XClassHint ch = {"dwm", "dwm"};
for (m = mons; m; m = m->next) {
if (m->barwin)
continue;
- m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
- CopyFromParent, DefaultVisual(dpy, screen),
- CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
+ m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, depth,
+ InputOutput, visual,
+ CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa);
XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
XMapRaised(dpy, m->barwin);
XSetClassHint(dpy, m->barwin, &ch);
@@ -2129,6 +2140,43 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
}
void
+xinitvisual(void)
+{
+ XVisualInfo *infos;
+ XRenderPictFormat *fmt;
+ int nitems;
+ int i;
+
+ XVisualInfo tpl = {
+ .screen = screen,
+ .depth = 32,
+ .class = TrueColor
+ };
+ long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
+
+ infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
+ visual = NULL;
+ for(i = 0; i < nitems; i++) {
+ fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
+ if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
+ visual = infos[i].visual;
+ depth = infos[i].depth;
+ cmap = XCreateColormap(dpy, root, visual, AllocNone);
+ useargb = 1;
+ break;
+ }
+ }
+
+ XFree(infos);
+
+ if (!visual) {
+ visual = DefaultVisual(dpy, screen);
+ depth = DefaultDepth(dpy, screen);
+ cmap = DefaultColormap(dpy, screen);
+ }
+}
+
+void
zoom(const Arg *arg)
{
Client *c = selmon->sel;