From 7d3bbd5e04685934acef976f1b4258e86a394fa5 Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Sun, 19 Dec 2021 19:56:13 -0500 Subject: Applied alpha patch https://tools.suckless.org/dmenu/patches/alpha/ --- dmenu.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 6 deletions(-) (limited to 'dmenu.c') diff --git a/dmenu.c b/dmenu.c index 9d57c21..0d05965 100644 --- a/dmenu.c +++ b/dmenu.c @@ -10,6 +10,7 @@ #include #include +#include #include #ifdef XINERAMA #include @@ -26,6 +27,8 @@ #define LENGTH(X) (sizeof X / sizeof X[0]) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) +#define OPAQUE 0xffU + /* enums */ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ @@ -58,10 +61,16 @@ static Clr *scheme[SchemeLast]; static char *colortemp[4]; static char *tempfonts; +static int useargb = 0; +static Visual *visual; +static int depth; +static Colormap cmap; + #include "config.h" static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; static char *(*fstrstr)(const char *, const char *) = strstr; +static void xinitvisual(); static void appenditem(struct item *item, struct item **list, struct item **last) @@ -638,7 +647,7 @@ setup(void) #endif /* init appearance */ for (j = 0; j < SchemeLast; j++) { - scheme[j] = drw_scm_create(drw, (const char**)colors[j], 2); + scheme[j] = drw_scm_create(drw, (const char**)colors[j], alphas[i], 2); } for (j = 0; j < SchemeOut; ++j) { for (i = 0; i < 2; ++i) @@ -712,11 +721,14 @@ setup(void) /* create menu window */ swa.override_redirect = True; - swa.background_pixel = scheme[SchemeNorm][ColBg].pixel; + swa.background_pixel = 0; + swa.border_pixel = 0; + swa.colormap = cmap; + swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; - win = XCreateWindow(dpy, parentwin, x, y - (topbar ? 0 : border_width * 2), mw - border_width * 2, mh, border_width, - CopyFromParent, CopyFromParent, CopyFromParent, - CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); + win = XCreateWindow(dpy, parentwin, x, y, mw, mh, border_width, + depth, CopyFromParent, visual, + CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &swa); if (border_width) XSetWindowBorder(dpy, win, scheme[SchemeSel][ColBg].pixel); XSetClassHint(dpy, win, &ch); @@ -845,7 +857,10 @@ main(int argc, char *argv[]) if (!XGetWindowAttributes(dpy, parentwin, &wa)) die("could not get embedding window attributes: 0x%lx", parentwin); - drw = drw_create(dpy, screen, root, wa.width, wa.height); + + xinitvisual(); + drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap); + readxresources(); /* Now we check whether to override xresources with commandline parameters */ if ( tempfonts ) @@ -882,3 +897,40 @@ main(int argc, char *argv[]) return 1; /* unreachable */ } + + 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); + } +} -- cgit v1.2.3