diff options
author | Malfurious <m@lfurio.us> | 2020-06-22 00:55:33 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2024-03-05 20:21:09 -0500 |
commit | 1533625373f1404709b8562d008008adc5d007c8 (patch) | |
tree | 07f1d51f3e9d8190a512c2bca9bea5748bb1681d /dwm.c | |
parent | 48b85889b34d4b7198e305e36a0f6abac2444e61 (diff) | |
download | dwm-1533625373f1404709b8562d008008adc5d007c8.tar.gz dwm-1533625373f1404709b8562d008008adc5d007c8.zip |
patch: alpha
Allow dwm to have translucent bars, while keeping all the text on it
opaque, just like the alpha-patch for st.
Fix transparent borders
-----------------------
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.c | 60 |
1 files changed, 54 insertions, 6 deletions
@@ -57,6 +57,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 */ @@ -232,6 +234,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(); static void zoom(const Arg *arg); /* variables */ @@ -268,6 +271,11 @@ 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 +1566,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; @@ -1586,7 +1595,7 @@ setup(void) /* init appearance */ scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); 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[i], 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() +{ + 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; |