Xinqi Bao's Git

patch: alpha
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index f266a37..5b0c792 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -63,6 +63,8 @@
 #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
 #define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
 
 #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 */
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
 enum { SchemeNorm, SchemeSel }; /* color schemes */
@@ -243,6 +245,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 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);
 
 static pid_t getparentprocess(pid_t p);
 static void zoom(const Arg *arg);
 
 static pid_t getparentprocess(pid_t p);
@@ -287,6 +290,11 @@ static Window root, wmcheckwin;
 
 static xcb_connection_t *xcon;
 
 
 static xcb_connection_t *xcon;
 
+static int useargb = 0;
+static Visual *visual;
+static int depth;
+static Colormap cmap;
+
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 
@@ -1620,7 +1628,8 @@ setup(void)
        sw = DisplayWidth(dpy, screen);
        sh = DisplayHeight(dpy, screen);
        root = RootWindow(dpy, screen);
        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;
        if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
                die("no fonts could be loaded.");
        lrpad = drw->fonts->h;
@@ -1648,7 +1657,7 @@ setup(void)
        /* init appearance */
        scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
        for (i = 0; i < LENGTH(colors); i++)
        /* 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();
        /* init bars */
        updatebars();
        updatestatus();
@@ -1902,16 +1911,18 @@ updatebars(void)
        Monitor *m;
        XSetWindowAttributes wa = {
                .override_redirect = True,
        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;
                .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);
                XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
                XMapRaised(dpy, m->barwin);
                XSetClassHint(dpy, m->barwin, &ch);
@@ -2338,6 +2349,43 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
        return -1;
 }
 
        return -1;
 }
 
+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)
 {
 void
 zoom(const Arg *arg)
 {