aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h (renamed from config.def.h)8
-rw-r--r--dmenu.c62
-rw-r--r--drw.c26
-rw-r--r--drw.h9
4 files changed, 84 insertions, 21 deletions
diff --git a/config.def.h b/config.h
index 1edb647..697d511 100644
--- a/config.def.h
+++ b/config.h
@@ -2,6 +2,7 @@
2/* Default settings; can be overriden by command line. */ 2/* Default settings; can be overriden by command line. */
3 3
4static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ 4static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
5static const unsigned int alpha = 0xf0;
5/* -fn option overrides fonts[0]; default X11 font or font set */ 6/* -fn option overrides fonts[0]; default X11 font or font set */
6static const char *fonts[] = { 7static const char *fonts[] = {
7 "monospace:size=10" 8 "monospace:size=10"
@@ -13,6 +14,13 @@ static const char *colors[SchemeLast][2] = {
13 [SchemeSel] = { "#eeeeee", "#005577" }, 14 [SchemeSel] = { "#eeeeee", "#005577" },
14 [SchemeOut] = { "#000000", "#00ffff" }, 15 [SchemeOut] = { "#000000", "#00ffff" },
15}; 16};
17
18static const unsigned int alphas[SchemeLast][2] = {
19 [SchemeNorm] = { OPAQUE, alpha },
20 [SchemeSel] = { OPAQUE, alpha },
21 [SchemeOut] = { OPAQUE, alpha },
22};
23
16/* -l option; if nonzero, dmenu uses vertical list with given number of lines */ 24/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
17static unsigned int lines = 0; 25static unsigned int lines = 0;
18 26
diff --git a/dmenu.c b/dmenu.c
index 7cf253b..ab2d29a 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -10,6 +10,7 @@
10 10
11#include <X11/Xlib.h> 11#include <X11/Xlib.h>
12#include <X11/Xatom.h> 12#include <X11/Xatom.h>
13#include <X11/Xproto.h>
13#include <X11/Xutil.h> 14#include <X11/Xutil.h>
14#ifdef XINERAMA 15#ifdef XINERAMA
15#include <X11/extensions/Xinerama.h> 16#include <X11/extensions/Xinerama.h>
@@ -25,6 +26,8 @@
25#define LENGTH(X) (sizeof X / sizeof X[0]) 26#define LENGTH(X) (sizeof X / sizeof X[0])
26#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) 27#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
27 28
29#define OPAQUE 0xffU
30
28/* enums */ 31/* enums */
29enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ 32enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
30 33
@@ -53,10 +56,16 @@ static XIC xic;
53static Drw *drw; 56static Drw *drw;
54static Clr *scheme[SchemeLast]; 57static Clr *scheme[SchemeLast];
55 58
59static int useargb = 0;
60static Visual *visual;
61static int depth;
62static Colormap cmap;
63
56#include "config.h" 64#include "config.h"
57 65
58static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; 66static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
59static char *(*fstrstr)(const char *, const char *) = strstr; 67static char *(*fstrstr)(const char *, const char *) = strstr;
68static void xinitvisual();
60 69
61static unsigned int 70static unsigned int
62textw_clamp(const char *str, unsigned int n) 71textw_clamp(const char *str, unsigned int n)
@@ -623,7 +632,7 @@ setup(void)
623#endif 632#endif
624 /* init appearance */ 633 /* init appearance */
625 for (j = 0; j < SchemeLast; j++) 634 for (j = 0; j < SchemeLast; j++)
626 scheme[j] = drw_scm_create(drw, colors[j], 2); 635 scheme[j] = drw_scm_create(drw, colors[j], alphas[i], 2);
627 636
628 clip = XInternAtom(dpy, "CLIPBOARD", False); 637 clip = XInternAtom(dpy, "CLIPBOARD", False);
629 utf8 = XInternAtom(dpy, "UTF8_STRING", False); 638 utf8 = XInternAtom(dpy, "UTF8_STRING", False);
@@ -661,6 +670,7 @@ setup(void)
661 x = info[i].x_org; 670 x = info[i].x_org;
662 y = info[i].y_org + (topbar ? 0 : info[i].height - mh); 671 y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
663 mw = info[i].width; 672 mw = info[i].width;
673
664 XFree(info); 674 XFree(info);
665 } else 675 } else
666#endif 676#endif
@@ -678,11 +688,13 @@ setup(void)
678 688
679 /* create menu window */ 689 /* create menu window */
680 swa.override_redirect = True; 690 swa.override_redirect = True;
681 swa.background_pixel = scheme[SchemeNorm][ColBg].pixel; 691 swa.background_pixel = 0;
692 swa.border_pixel = 0;
693 swa.colormap = cmap;
682 swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; 694 swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
683 win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0, 695 win = XCreateWindow(dpy, parentwin, x, y, mw, mh, border_width,
684 CopyFromParent, CopyFromParent, CopyFromParent, 696 depth, CopyFromParent, visual,
685 CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); 697 CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &swa);
686 XSetClassHint(dpy, win, &ch); 698 XSetClassHint(dpy, win, &ch);
687 699
688 700
@@ -767,7 +779,8 @@ main(int argc, char *argv[])
767 if (!XGetWindowAttributes(dpy, parentwin, &wa)) 779 if (!XGetWindowAttributes(dpy, parentwin, &wa))
768 die("could not get embedding window attributes: 0x%lx", 780 die("could not get embedding window attributes: 0x%lx",
769 parentwin); 781 parentwin);
770 drw = drw_create(dpy, screen, root, wa.width, wa.height); 782 xinitvisual();
783 drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap);
771 if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) 784 if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
772 die("no fonts could be loaded."); 785 die("no fonts could be loaded.");
773 lrpad = drw->fonts->h; 786 lrpad = drw->fonts->h;
@@ -789,3 +802,40 @@ main(int argc, char *argv[])
789 802
790 return 1; /* unreachable */ 803 return 1; /* unreachable */
791} 804}
805
806 void
807xinitvisual()
808{
809 XVisualInfo *infos;
810 XRenderPictFormat *fmt;
811 int nitems;
812 int i;
813
814 XVisualInfo tpl = {
815 .screen = screen,
816 .depth = 32,
817 .class = TrueColor
818 };
819 long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
820
821 infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
822 visual = NULL;
823 for(i = 0; i < nitems; i ++) {
824 fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
825 if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
826 visual = infos[i].visual;
827 depth = infos[i].depth;
828 cmap = XCreateColormap(dpy, root, visual, AllocNone);
829 useargb = 1;
830 break;
831 }
832 }
833
834 XFree(infos);
835
836 if (! visual) {
837 visual = DefaultVisual(dpy, screen);
838 depth = DefaultDepth(dpy, screen);
839 cmap = DefaultColormap(dpy, screen);
840 }
841}
diff --git a/drw.c b/drw.c
index a58a2b4..42700e5 100644
--- a/drw.c
+++ b/drw.c
@@ -61,7 +61,7 @@ utf8decode(const char *c, long *u, size_t clen)
61} 61}
62 62
63Drw * 63Drw *
64drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) 64drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap)
65{ 65{
66 Drw *drw = ecalloc(1, sizeof(Drw)); 66 Drw *drw = ecalloc(1, sizeof(Drw));
67 67
@@ -70,8 +70,11 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
70 drw->root = root; 70 drw->root = root;
71 drw->w = w; 71 drw->w = w;
72 drw->h = h; 72 drw->h = h;
73 drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen)); 73 drw->visual = visual;
74 drw->gc = XCreateGC(dpy, root, 0, NULL); 74 drw->depth = depth;
75 drw->cmap = cmap;
76 drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
77 drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL);
75 XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); 78 XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
76 79
77 return drw; 80 return drw;
@@ -87,7 +90,7 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h)
87 drw->h = h; 90 drw->h = h;
88 if (drw->drawable) 91 if (drw->drawable)
89 XFreePixmap(drw->dpy, drw->drawable); 92 XFreePixmap(drw->dpy, drw->drawable);
90 drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen)); 93 drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth);
91} 94}
92 95
93void 96void
@@ -181,21 +184,22 @@ drw_fontset_free(Fnt *font)
181} 184}
182 185
183void 186void
184drw_clr_create(Drw *drw, Clr *dest, const char *clrname) 187drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha)
185{ 188{
186 if (!drw || !dest || !clrname) 189 if (!drw || !dest || !clrname)
187 return; 190 return;
188 191
189 if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), 192 if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap,
190 DefaultColormap(drw->dpy, drw->screen),
191 clrname, dest)) 193 clrname, dest))
192 die("error, cannot allocate color '%s'", clrname); 194 die("error, cannot allocate color '%s'", clrname);
195
196 dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24);
193} 197}
194 198
195/* Wrapper to create color schemes. The caller has to call free(3) on the 199/* Wrapper to create color schemes. The caller has to call free(3) on the
196 * returned color scheme when done using it. */ 200 * returned color scheme when done using it. */
197Clr * 201Clr *
198drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) 202drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount)
199{ 203{
200 size_t i; 204 size_t i;
201 Clr *ret; 205 Clr *ret;
@@ -205,7 +209,7 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
205 return NULL; 209 return NULL;
206 210
207 for (i = 0; i < clrcount; i++) 211 for (i = 0; i < clrcount; i++)
208 drw_clr_create(drw, &ret[i], clrnames[i]); 212 drw_clr_create(drw, &ret[i], clrnames[i], alphas[i]);
209 return ret; 213 return ret;
210} 214}
211 215
@@ -263,9 +267,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
263 } else { 267 } else {
264 XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); 268 XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
265 XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); 269 XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
266 d = XftDrawCreate(drw->dpy, drw->drawable, 270 d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap);
267 DefaultVisual(drw->dpy, drw->screen),
268 DefaultColormap(drw->dpy, drw->screen));
269 x += lpad; 271 x += lpad;
270 w -= lpad; 272 w -= lpad;
271 } 273 }
diff --git a/drw.h b/drw.h
index fd7631b..48f2f93 100644
--- a/drw.h
+++ b/drw.h
@@ -20,6 +20,9 @@ typedef struct {
20 Display *dpy; 20 Display *dpy;
21 int screen; 21 int screen;
22 Window root; 22 Window root;
23 Visual *visual;
24 unsigned int depth;
25 Colormap cmap;
23 Drawable drawable; 26 Drawable drawable;
24 GC gc; 27 GC gc;
25 Clr *scheme; 28 Clr *scheme;
@@ -27,7 +30,7 @@ typedef struct {
27} Drw; 30} Drw;
28 31
29/* Drawable abstraction */ 32/* Drawable abstraction */
30Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h); 33Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual*, unsigned int, Colormap);
31void drw_resize(Drw *drw, unsigned int w, unsigned int h); 34void drw_resize(Drw *drw, unsigned int w, unsigned int h);
32void drw_free(Drw *drw); 35void drw_free(Drw *drw);
33 36
@@ -39,8 +42,8 @@ unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int
39void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); 42void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
40 43
41/* Colorscheme abstraction */ 44/* Colorscheme abstraction */
42void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); 45void drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha);
43Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); 46Clr *drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount);
44 47
45/* Cursor abstraction */ 48/* Cursor abstraction */
46Cur *drw_cur_create(Drw *drw, int shape); 49Cur *drw_cur_create(Drw *drw, int shape);