about summary refs log tree commit diff
path: root/dmenu.c
diff options
context:
space:
mode:
Diffstat (limited to 'dmenu.c')
-rw-r--r--dmenu.c71
1 files changed, 56 insertions, 15 deletions
diff --git a/dmenu.c b/dmenu.c
index 0ff31b2..f383bb1 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -25,6 +25,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 */
 
@@ -33,7 +35,7 @@ struct item {
 	struct item *left, *right;
 	int out;
 };
-
+static void xinitvisual();
 static char text[BUFSIZ] = "";
 static char *embed;
 static int bh, mw, mh;
@@ -50,8 +52,10 @@ static Display *dpy;
 static Window root, parentwin, win;
 static XIC xic;
 
-#define OPAQUE 0xffffffff
-#define OPACITY "_NET_WM_WINDOW_OPACITY"
+static int useargb = 0;
+static Visual *visual;
+static int depth;
+static Colormap cmap;
 
 static Drw *drw;
 static Clr *scheme[SchemeLast];
@@ -645,6 +649,43 @@ paste(void)
 	drawmenu();
 }
 
+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);
+	}
+}
+
 static void
 readstdin(void)
 {
@@ -732,7 +773,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);
@@ -790,15 +831,16 @@ setup(void)
 
 	/* create menu window */
 	swa.override_redirect = True;
-	swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
+  swa.background_pixel = 0,
+  swa.colormap = cmap,
   swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask |
                    ButtonPressMask;	win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
-	                    CopyFromParent, CopyFromParent, CopyFromParent,
-	                    CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
-	XSetClassHint(dpy, win, &ch);
-  opacity = MIN(MAX(opacity, 0), 1);
-  unsigned int opacity_set = (unsigned int)(opacity * OPAQUE);
-  XChangeProperty(dpy, win, XInternAtom(dpy, OPACITY, False), XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &opacity_set, 1L);
+	                    depth, InputOutput, visual,
+	                    CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &swa);
+  XClassHint hint = { .res_name = name, .res_class = class };
+	XSetClassHint(dpy, win, &hint);
+  XChangeProperty(dpy, win, type, XA_ATOM, 32, PropModeReplace,
+                 (unsigned char *) &dock, 1);
 
 
 	/* input methods */
@@ -826,7 +868,7 @@ static void
 usage(void)
 {
 	fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
-				"             [-n name] [-c class] [ -o opacity] [-h height]\n"
+				"             [-n name] [-c class] [-h height]\n"
 	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
 	exit(1);
 }
@@ -868,8 +910,6 @@ main(int argc, char *argv[])
       name = argv[++i];
     else if (!strcmp(argv[i], "-c")) /* dmenu window class */
       class = argv[++i];
-    else if (!strcmp(argv[i], "-o"))  /* opacity */
-      opacity = atof(argv[++i]);
 		else if (!strcmp(argv[i], "-nb"))  /* normal background color */
 			colors[SchemeNorm][ColBg] = argv[++i];
 		else if (!strcmp(argv[i], "-nf"))  /* normal foreground color */
@@ -894,7 +934,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;