diff options
-rw-r--r-- | config.h | 8 | ||||
-rw-r--r-- | config.mk | 2 | ||||
-rw-r--r-- | drw.c | 26 | ||||
-rw-r--r-- | drw.h | 9 | ||||
-rw-r--r-- | dwm.c | 60 |
5 files changed, 82 insertions, 23 deletions
@@ -22,12 +22,18 @@ static const char col_gray2[] = "#3c3836"; | |||
22 | static const char col_gray3[] = "#ebdbb2"; | 22 | static const char col_gray3[] = "#ebdbb2"; |
23 | static const char col_gray4[] = "#fdf1c7"; | 23 | static const char col_gray4[] = "#fdf1c7"; |
24 | static const char col_cyan[] = "#d79921"; | 24 | static const char col_cyan[] = "#d79921"; |
25 | 25 | static const unsigned int baralpha = 0xd0; | |
26 | static const unsigned int borderalpha = OPAQUE; | ||
26 | static const char *colors[][3] = { | 27 | static const char *colors[][3] = { |
27 | /* fg bg border */ | 28 | /* fg bg border */ |
28 | [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, | 29 | [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, |
29 | [SchemeSel] = { col_gray4, col_cyan, col_cyan }, | 30 | [SchemeSel] = { col_gray4, col_cyan, col_cyan }, |
30 | }; | 31 | }; |
32 | static const unsigned int alphas[][3] = { | ||
33 | /* fg bg border */ | ||
34 | [SchemeNorm] = { OPAQUE, baralpha, borderalpha }, | ||
35 | [SchemeSel] = { OPAQUE, baralpha, borderalpha }, | ||
36 | }; | ||
31 | 37 | ||
32 | /* tagging */ | 38 | /* tagging */ |
33 | static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; | 39 | static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; |
@@ -22,7 +22,7 @@ FREETYPEINC = /usr/include/freetype2 | |||
22 | 22 | ||
23 | # includes and libs | 23 | # includes and libs |
24 | INCS = -I${X11INC} -I${FREETYPEINC} | 24 | INCS = -I${X11INC} -I${FREETYPEINC} |
25 | LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-res | 25 | LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-res -lXrender |
26 | 26 | ||
27 | # flags | 27 | # flags |
28 | CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} | 28 | CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} |
@@ -61,7 +61,7 @@ utf8decode(const char *c, long *u, size_t clen) | |||
61 | } | 61 | } |
62 | 62 | ||
63 | Drw * | 63 | Drw * |
64 | drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) | 64 | drw_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 | ||
93 | void | 96 | void |
@@ -193,21 +196,22 @@ drw_fontset_free(Fnt *font) | |||
193 | } | 196 | } |
194 | 197 | ||
195 | void | 198 | void |
196 | drw_clr_create(Drw *drw, Clr *dest, const char *clrname) | 199 | drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha) |
197 | { | 200 | { |
198 | if (!drw || !dest || !clrname) | 201 | if (!drw || !dest || !clrname) |
199 | return; | 202 | return; |
200 | 203 | ||
201 | if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), | 204 | if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap, |
202 | DefaultColormap(drw->dpy, drw->screen), | ||
203 | clrname, dest)) | 205 | clrname, dest)) |
204 | die("error, cannot allocate color '%s'", clrname); | 206 | die("error, cannot allocate color '%s'", clrname); |
207 | |||
208 | dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24); | ||
205 | } | 209 | } |
206 | 210 | ||
207 | /* Wrapper to create color schemes. The caller has to call free(3) on the | 211 | /* Wrapper to create color schemes. The caller has to call free(3) on the |
208 | * returned color scheme when done using it. */ | 212 | * returned color scheme when done using it. */ |
209 | Clr * | 213 | Clr * |
210 | drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) | 214 | drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount) |
211 | { | 215 | { |
212 | size_t i; | 216 | size_t i; |
213 | Clr *ret; | 217 | Clr *ret; |
@@ -217,7 +221,7 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) | |||
217 | return NULL; | 221 | return NULL; |
218 | 222 | ||
219 | for (i = 0; i < clrcount; i++) | 223 | for (i = 0; i < clrcount; i++) |
220 | drw_clr_create(drw, &ret[i], clrnames[i]); | 224 | drw_clr_create(drw, &ret[i], clrnames[i], alphas[i]); |
221 | return ret; | 225 | return ret; |
222 | } | 226 | } |
223 | 227 | ||
@@ -273,9 +277,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp | |||
273 | } else { | 277 | } else { |
274 | XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); | 278 | XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); |
275 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); | 279 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); |
276 | d = XftDrawCreate(drw->dpy, drw->drawable, | 280 | d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap); |
277 | DefaultVisual(drw->dpy, drw->screen), | ||
278 | DefaultColormap(drw->dpy, drw->screen)); | ||
279 | x += lpad; | 281 | x += lpad; |
280 | w -= lpad; | 282 | w -= lpad; |
281 | } | 283 | } |
@@ -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 */ |
30 | Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h); | 33 | Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap); |
31 | void drw_resize(Drw *drw, unsigned int w, unsigned int h); | 34 | void drw_resize(Drw *drw, unsigned int w, unsigned int h); |
32 | void drw_free(Drw *drw); | 35 | void drw_free(Drw *drw); |
33 | 36 | ||
@@ -38,8 +41,8 @@ unsigned int drw_fontset_getwidth(Drw *drw, const char *text); | |||
38 | void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); | 41 | void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); |
39 | 42 | ||
40 | /* Colorscheme abstraction */ | 43 | /* Colorscheme abstraction */ |
41 | void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); | 44 | void drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha); |
42 | Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); | 45 | Clr *drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount); |
43 | 46 | ||
44 | /* Cursor abstraction */ | 47 | /* Cursor abstraction */ |
45 | Cur *drw_cur_create(Drw *drw, int shape); | 48 | Cur *drw_cur_create(Drw *drw, int shape); |
@@ -59,6 +59,8 @@ | |||
59 | #define TAGMASK ((1 << LENGTH(tags)) - 1) | 59 | #define TAGMASK ((1 << LENGTH(tags)) - 1) |
60 | #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) | 60 | #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) |
61 | 61 | ||
62 | #define OPAQUE 0xffU | ||
63 | |||
62 | /* enums */ | 64 | /* enums */ |
63 | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ | 65 | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
64 | enum { SchemeNorm, SchemeSel }; /* color schemes */ | 66 | enum { SchemeNorm, SchemeSel }; /* color schemes */ |
@@ -245,6 +247,7 @@ static Monitor *wintomon(Window w); | |||
245 | static int xerror(Display *dpy, XErrorEvent *ee); | 247 | static int xerror(Display *dpy, XErrorEvent *ee); |
246 | static int xerrordummy(Display *dpy, XErrorEvent *ee); | 248 | static int xerrordummy(Display *dpy, XErrorEvent *ee); |
247 | static int xerrorstart(Display *dpy, XErrorEvent *ee); | 249 | static int xerrorstart(Display *dpy, XErrorEvent *ee); |
250 | static void xinitvisual(); | ||
248 | static void zoom(const Arg *arg); | 251 | static void zoom(const Arg *arg); |
249 | 252 | ||
250 | static pid_t getparentprocess(pid_t p); | 253 | static pid_t getparentprocess(pid_t p); |
@@ -294,6 +297,11 @@ static Window root, wmcheckwin; | |||
294 | 297 | ||
295 | static xcb_connection_t *xcon; | 298 | static xcb_connection_t *xcon; |
296 | 299 | ||
300 | static int useargb = 0; | ||
301 | static Visual *visual; | ||
302 | static int depth; | ||
303 | static Colormap cmap; | ||
304 | |||
297 | /* configuration, allows nested code to access above variables */ | 305 | /* configuration, allows nested code to access above variables */ |
298 | #include "config.h" | 306 | #include "config.h" |
299 | 307 | ||
@@ -1721,7 +1729,8 @@ setup(void) | |||
1721 | sw = DisplayWidth(dpy, screen); | 1729 | sw = DisplayWidth(dpy, screen); |
1722 | sh = DisplayHeight(dpy, screen); | 1730 | sh = DisplayHeight(dpy, screen); |
1723 | root = RootWindow(dpy, screen); | 1731 | root = RootWindow(dpy, screen); |
1724 | drw = drw_create(dpy, screen, root, sw, sh); | 1732 | xinitvisual(); |
1733 | drw = drw_create(dpy, screen, root, sw, sh, visual, depth, cmap); | ||
1725 | if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) | 1734 | if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) |
1726 | die("no fonts could be loaded."); | 1735 | die("no fonts could be loaded."); |
1727 | lrpad = drw->fonts->h; | 1736 | lrpad = drw->fonts->h; |
@@ -1753,7 +1762,7 @@ setup(void) | |||
1753 | /* init appearance */ | 1762 | /* init appearance */ |
1754 | scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); | 1763 | scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); |
1755 | for (i = 0; i < LENGTH(colors); i++) | 1764 | for (i = 0; i < LENGTH(colors); i++) |
1756 | scheme[i] = drw_scm_create(drw, colors[i], 3); | 1765 | scheme[i] = drw_scm_create(drw, colors[i], alphas[i], 3); |
1757 | /* init bars */ | 1766 | /* init bars */ |
1758 | updatebars(); | 1767 | updatebars(); |
1759 | updatestatus(); | 1768 | updatestatus(); |
@@ -2004,16 +2013,18 @@ updatebars(void) | |||
2004 | Monitor *m; | 2013 | Monitor *m; |
2005 | XSetWindowAttributes wa = { | 2014 | XSetWindowAttributes wa = { |
2006 | .override_redirect = True, | 2015 | .override_redirect = True, |
2007 | .background_pixmap = ParentRelative, | 2016 | .background_pixel = 0, |
2017 | .border_pixel = 0, | ||
2018 | .colormap = cmap, | ||
2008 | .event_mask = ButtonPressMask|ExposureMask | 2019 | .event_mask = ButtonPressMask|ExposureMask |
2009 | }; | 2020 | }; |
2010 | XClassHint ch = {"dwm", "dwm"}; | 2021 | XClassHint ch = {"dwm", "dwm"}; |
2011 | for (m = mons; m; m = m->next) { | 2022 | for (m = mons; m; m = m->next) { |
2012 | if (m->barwin) | 2023 | if (m->barwin) |
2013 | continue; | 2024 | continue; |
2014 | m->barwin = XCreateWindow(dpy, root, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh, 0, DefaultDepth(dpy, screen), | 2025 | m->barwin = XCreateWindow(dpy, root, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh, 0, depth, |
2015 | CopyFromParent, DefaultVisual(dpy, screen), | 2026 | InputOutput, visual, |
2016 | CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); | 2027 | CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa); |
2017 | XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); | 2028 | XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); |
2018 | XMapRaised(dpy, m->barwin); | 2029 | XMapRaised(dpy, m->barwin); |
2019 | XSetClassHint(dpy, m->barwin, &ch); | 2030 | XSetClassHint(dpy, m->barwin, &ch); |
@@ -2458,6 +2469,43 @@ xerrorstart(Display *dpy, XErrorEvent *ee) | |||
2458 | } | 2469 | } |
2459 | 2470 | ||
2460 | void | 2471 | void |
2472 | xinitvisual() | ||
2473 | { | ||
2474 | XVisualInfo *infos; | ||
2475 | XRenderPictFormat *fmt; | ||
2476 | int nitems; | ||
2477 | int i; | ||
2478 | |||
2479 | XVisualInfo tpl = { | ||
2480 | .screen = screen, | ||
2481 | .depth = 32, | ||
2482 | .class = TrueColor | ||
2483 | }; | ||
2484 | long masks = VisualScreenMask | VisualDepthMask | VisualClassMask; | ||
2485 | |||
2486 | infos = XGetVisualInfo(dpy, masks, &tpl, &nitems); | ||
2487 | visual = NULL; | ||
2488 | for(i = 0; i < nitems; i ++) { | ||
2489 | fmt = XRenderFindVisualFormat(dpy, infos[i].visual); | ||
2490 | if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) { | ||
2491 | visual = infos[i].visual; | ||
2492 | depth = infos[i].depth; | ||
2493 | cmap = XCreateColormap(dpy, root, visual, AllocNone); | ||
2494 | useargb = 1; | ||
2495 | break; | ||
2496 | } | ||
2497 | } | ||
2498 | |||
2499 | XFree(infos); | ||
2500 | |||
2501 | if (! visual) { | ||
2502 | visual = DefaultVisual(dpy, screen); | ||
2503 | depth = DefaultDepth(dpy, screen); | ||
2504 | cmap = DefaultColormap(dpy, screen); | ||
2505 | } | ||
2506 | } | ||
2507 | |||
2508 | void | ||
2461 | zoom(const Arg *arg) | 2509 | zoom(const Arg *arg) |
2462 | { | 2510 | { |
2463 | Client *c = selmon->sel; | 2511 | Client *c = selmon->sel; |