summaryrefslogtreecommitdiffstats
path: root/dmenu.c
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2024-03-05 23:55:30 -0500
committerMalfurious <m@lfurio.us>2024-03-06 00:55:08 -0500
commit63095a31b993ce1b9a2d4fcff5c61cce9defacd2 (patch)
tree3efb1d97bee38122fe9cac6d4dc95a8b2ac6d208 /dmenu.c
parent6ed9dfbfd8d4786cecc359e7c37d05c7f785c2b2 (diff)
downloaddmenu-63095a31b993ce1b9a2d4fcff5c61cce9defacd2.tar.gz
dmenu-63095a31b993ce1b9a2d4fcff5c61cce9defacd2.zip
patch: alpha
This patch adds translucency to the dmenu window, while keeping the text in it opaque, just like the alpha patch for st.
Diffstat (limited to 'dmenu.c')
-rw-r--r--dmenu.c60
1 files changed, 55 insertions, 5 deletions
diff --git a/dmenu.c b/dmenu.c
index 40f93e0..617972c 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -10,10 +10,12 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
+#include <X11/Xproto.h>
#include <X11/Xutil.h>
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
+#include <X11/extensions/Xrender.h>
#include <X11/Xft/Xft.h>
#include "drw.h"
@@ -24,6 +26,8 @@
* MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
+#define OPAQUE 0xffu
+
/* enums */
enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
@@ -52,10 +56,16 @@ static XIC xic;
static Drw *drw;
static Clr *scheme[SchemeLast];
+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 unsigned int
textw_clamp(const char *str, unsigned int n)
@@ -627,7 +637,7 @@ setup(void)
#endif
/* init appearance */
for (j = 0; j < SchemeLast; j++)
- scheme[j] = drw_scm_create(drw, colors[j], 2);
+ scheme[j] = drw_scm_create(drw, colors[j], alphas[j], 2);
clip = XInternAtom(dpy, "CLIPBOARD", False);
utf8 = XInternAtom(dpy, "UTF8_STRING", False);
@@ -682,11 +692,13 @@ 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, root, x, y, mw, mh, 0,
- CopyFromParent, CopyFromParent, CopyFromParent,
- CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
+ depth, CopyFromParent, visual,
+ CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &swa);
XSetClassHint(dpy, win, &ch);
@@ -772,7 +784,8 @@ 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);
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
die("no fonts could be loaded.");
lrpad = drw->fonts->h;
@@ -794,3 +807,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);
+ }
+}