Xinqi Bao's Git

patch: alpha
[dmenu.git] / dmenu.c
diff --git a/dmenu.c b/dmenu.c
index 35ce141..15737ca 100644 (file)
--- a/dmenu.c
+++ b/dmenu.c
@@ -10,6 +10,7 @@
 
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
+#include <X11/Xproto.h>
 #include <X11/Xutil.h>
 #ifdef XINERAMA
 #include <X11/extensions/Xinerama.h>
 #include <X11/Xutil.h>
 #ifdef XINERAMA
 #include <X11/extensions/Xinerama.h>
@@ -25,6 +26,8 @@
 #define LENGTH(X)             (sizeof X / sizeof X[0])
 #define TEXTW(X)              (drw_fontset_getwidth(drw, (X)) + lrpad)
 
 #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 */
 
 /* enums */
 enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
 
@@ -53,10 +56,16 @@ static XIC xic;
 static Drw *drw;
 static Clr *scheme[SchemeLast];
 
 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;
 #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)
 
 static unsigned int
 textw_clamp(const char *str, unsigned int n)
@@ -633,7 +642,7 @@ setup(void)
 #endif
        /* init appearance */
        for (j = 0; j < SchemeLast; j++)
 #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);
 
        clip = XInternAtom(dpy, "CLIPBOARD",   False);
        utf8 = XInternAtom(dpy, "UTF8_STRING", False);
@@ -707,11 +716,13 @@ setup(void)
 
        /* create menu window */
        swa.override_redirect = True;
 
        /* 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, mw, mh, 0,
        swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
        win = XCreateWindow(dpy, parentwin, 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);
 
 
        XSetClassHint(dpy, win, &ch);
 
 
@@ -799,7 +810,8 @@ main(int argc, char *argv[])
        if (!XGetWindowAttributes(dpy, parentwin, &wa))
                die("could not get embedding window attributes: 0x%lx",
                    parentwin);
        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;
        if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
                die("no fonts could be loaded.");
        lrpad = drw->fonts->h;
@@ -821,3 +833,40 @@ main(int argc, char *argv[])
 
        return 1; /* unreachable */
 }
 
        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);
+       }
+}