sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dmenu-alpha-20210605-1a13d04.diff (8685B)


      1 diff --git a/config.def.h b/config.def.h
      2 index 1edb647..697d511 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -2,6 +2,7 @@
      6  /* Default settings; can be overriden by command line. */
      7  
      8  static int topbar = 1;                      /* -b  option; if 0, dmenu appears at bottom     */
      9 +static const unsigned int alpha = 0xf0;
     10  /* -fn option overrides fonts[0]; default X11 font or font set */
     11  static const char *fonts[] = {
     12  	"monospace:size=10"
     13 @@ -13,6 +14,13 @@ static const char *colors[SchemeLast][2] = {
     14  	[SchemeSel] = { "#eeeeee", "#005577" },
     15  	[SchemeOut] = { "#000000", "#00ffff" },
     16  };
     17 +
     18 +static const unsigned int alphas[SchemeLast][2] = {
     19 +	[SchemeNorm] = { OPAQUE, alpha },
     20 +	[SchemeSel] = { OPAQUE, alpha },
     21 +	[SchemeOut] = { OPAQUE, alpha },
     22 +};
     23 +
     24  /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
     25  static unsigned int lines      = 0;
     26  
     27 diff --git a/dmenu.c b/dmenu.c
     28 index 65f25ce..3e56e1a 100644
     29 --- a/dmenu.c
     30 +++ b/dmenu.c
     31 @@ -10,6 +10,7 @@
     32  
     33  #include <X11/Xlib.h>
     34  #include <X11/Xatom.h>
     35 +#include <X11/Xproto.h>
     36  #include <X11/Xutil.h>
     37  #ifdef XINERAMA
     38  #include <X11/extensions/Xinerama.h>
     39 @@ -25,6 +26,8 @@
     40  #define LENGTH(X)             (sizeof X / sizeof X[0])
     41  #define TEXTW(X)              (drw_fontset_getwidth(drw, (X)) + lrpad)
     42  
     43 +#define OPAQUE                0xffU
     44 +
     45  /* enums */
     46  enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
     47  
     48 @@ -53,10 +56,16 @@ static XIC xic;
     49  static Drw *drw;
     50  static Clr *scheme[SchemeLast];
     51  
     52 +static int useargb = 0;
     53 +static Visual *visual;
     54 +static int depth;
     55 +static Colormap cmap;
     56 +
     57  #include "config.h"
     58  
     59  static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
     60  static char *(*fstrstr)(const char *, const char *) = strstr;
     61 +static void xinitvisual();
     62  
     63  static void
     64  appenditem(struct item *item, struct item **list, struct item **last)
     65 @@ -602,7 +611,7 @@ setup(void)
     66  #endif
     67  	/* init appearance */
     68  	for (j = 0; j < SchemeLast; j++)
     69 -		scheme[j] = drw_scm_create(drw, colors[j], 2);
     70 +		scheme[j] = drw_scm_create(drw, colors[j], alphas[i], 2);
     71  
     72  	clip = XInternAtom(dpy, "CLIPBOARD",   False);
     73  	utf8 = XInternAtom(dpy, "UTF8_STRING", False);
     74 @@ -640,6 +649,7 @@ setup(void)
     75  		x = info[i].x_org;
     76  		y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
     77  		mw = info[i].width;
     78 +
     79  		XFree(info);
     80  	} else
     81  #endif
     82 @@ -657,11 +667,13 @@ setup(void)
     83  
     84  	/* create menu window */
     85  	swa.override_redirect = True;
     86 -	swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
     87 +	swa.background_pixel = 0;
     88 +	swa.border_pixel = 0;
     89 +	swa.colormap = cmap;
     90  	swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
     91 -	win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
     92 -	                    CopyFromParent, CopyFromParent, CopyFromParent,
     93 -	                    CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
     94 +	win = XCreateWindow(dpy, parentwin, x, y, mw, mh, border_width,
     95 +	                    depth, CopyFromParent, visual,
     96 +	                    CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &swa);
     97  	XSetClassHint(dpy, win, &ch);
     98  
     99  
    100 @@ -747,7 +759,8 @@ main(int argc, char *argv[])
    101  	if (!XGetWindowAttributes(dpy, parentwin, &wa))
    102  		die("could not get embedding window attributes: 0x%lx",
    103  		    parentwin);
    104 -	drw = drw_create(dpy, screen, root, wa.width, wa.height);
    105 +	xinitvisual();
    106 +	drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap);
    107  	if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
    108  		die("no fonts could be loaded.");
    109  	lrpad = drw->fonts->h;
    110 @@ -769,3 +782,40 @@ main(int argc, char *argv[])
    111  
    112  	return 1; /* unreachable */
    113  }
    114 +
    115 + void
    116 +xinitvisual()
    117 +{
    118 +	XVisualInfo *infos;
    119 +	XRenderPictFormat *fmt;
    120 +	int nitems;
    121 +	int i;
    122 +
    123 +	XVisualInfo tpl = {
    124 +		.screen = screen,
    125 +		.depth = 32,
    126 +		.class = TrueColor
    127 +	};
    128 +	long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
    129 +
    130 +	infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
    131 +	visual = NULL;
    132 +	for(i = 0; i < nitems; i ++) {
    133 +		fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
    134 +		if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
    135 +			visual = infos[i].visual;
    136 +			depth = infos[i].depth;
    137 +			cmap = XCreateColormap(dpy, root, visual, AllocNone);
    138 +			useargb = 1;
    139 +			break;
    140 +		}
    141 +	}
    142 +
    143 +	XFree(infos);
    144 +
    145 +	if (! visual) {
    146 +		visual = DefaultVisual(dpy, screen);
    147 +		depth = DefaultDepth(dpy, screen);
    148 +		cmap = DefaultColormap(dpy, screen);
    149 +	}
    150 +}
    151 diff --git a/drw.c b/drw.c
    152 index 4cdbcbe..fe3aadd 100644
    153 --- a/drw.c
    154 +++ b/drw.c
    155 @@ -61,7 +61,7 @@ utf8decode(const char *c, long *u, size_t clen)
    156  }
    157  
    158  Drw *
    159 -drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
    160 +drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap)
    161  {
    162  	Drw *drw = ecalloc(1, sizeof(Drw));
    163  
    164 @@ -70,8 +70,11 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
    165  	drw->root = root;
    166  	drw->w = w;
    167  	drw->h = h;
    168 -	drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
    169 -	drw->gc = XCreateGC(dpy, root, 0, NULL);
    170 +	drw->visual = visual;
    171 +	drw->depth = depth;
    172 +	drw->cmap = cmap;
    173 +	drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
    174 +	drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL);
    175  	XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
    176  
    177  	return drw;
    178 @@ -87,7 +90,7 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h)
    179  	drw->h = h;
    180  	if (drw->drawable)
    181  		XFreePixmap(drw->dpy, drw->drawable);
    182 -	drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
    183 +	drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth);
    184  }
    185  
    186  void
    187 @@ -194,21 +197,22 @@ drw_fontset_free(Fnt *font)
    188  }
    189  
    190  void
    191 -drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
    192 +drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha)
    193  {
    194  	if (!drw || !dest || !clrname)
    195  		return;
    196  
    197 -	if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
    198 -	                       DefaultColormap(drw->dpy, drw->screen),
    199 +	if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap,
    200  	                       clrname, dest))
    201  		die("error, cannot allocate color '%s'", clrname);
    202 +
    203 +	dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24);
    204  }
    205  
    206  /* Wrapper to create color schemes. The caller has to call free(3) on the
    207   * returned color scheme when done using it. */
    208  Clr *
    209 -drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
    210 +drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount)
    211  {
    212  	size_t i;
    213  	Clr *ret;
    214 @@ -218,7 +222,7 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
    215  		return NULL;
    216  
    217  	for (i = 0; i < clrcount; i++)
    218 -		drw_clr_create(drw, &ret[i], clrnames[i]);
    219 +		drw_clr_create(drw, &ret[i], clrnames[i], alphas[i]);
    220  	return ret;
    221  }
    222  
    223 @@ -274,9 +278,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
    224  	} else {
    225  		XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
    226  		XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
    227 -		d = XftDrawCreate(drw->dpy, drw->drawable,
    228 -		                  DefaultVisual(drw->dpy, drw->screen),
    229 -		                  DefaultColormap(drw->dpy, drw->screen));
    230 +		d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap);
    231  		x += lpad;
    232  		w -= lpad;
    233  	}
    234 diff --git a/drw.h b/drw.h
    235 index 4c67419..f6fa5cd 100644
    236 --- a/drw.h
    237 +++ b/drw.h
    238 @@ -20,6 +20,9 @@ typedef struct {
    239  	Display *dpy;
    240  	int screen;
    241  	Window root;
    242 +	Visual *visual;
    243 +	unsigned int depth;
    244 +	Colormap cmap;
    245  	Drawable drawable;
    246  	GC gc;
    247  	Clr *scheme;
    248 @@ -27,7 +30,7 @@ typedef struct {
    249  } Drw;
    250  
    251  /* Drawable abstraction */
    252 -Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
    253 +Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual*, unsigned int, Colormap);
    254  void drw_resize(Drw *drw, unsigned int w, unsigned int h);
    255  void drw_free(Drw *drw);
    256  
    257 @@ -38,8 +41,8 @@ unsigned int drw_fontset_getwidth(Drw *drw, const char *text);
    258  void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
    259  
    260  /* Colorscheme abstraction */
    261 -void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
    262 -Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
    263 +void drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha);
    264 +Clr *drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount);
    265  
    266  /* Cursor abstraction */
    267  Cur *drw_cur_create(Drw *drw, int shape);