sites

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

dwm-alpha-6.4.diff (9494B)


      1 From 4ee637701f1144e07338d5990fecb3dc44982223 Mon Sep 17 00:00:00 2001
      2 From: NekoCWD <nekodevelopper@gmail.com>
      3 Date: Fri, 27 Jan 2023 21:59:15 +0300
      4 Subject: [PATCH] [dwm] update 'alpha' path for dwm6.4
      5 
      6 ---
      7  config.def.h |  2 ++
      8  config.mk    |  2 +-
      9  drw.c        | 27 +++++++++++-----------
     10  drw.h        |  9 +++++---
     11  dwm.c        | 63 +++++++++++++++++++++++++++++++++++++++++++++++-----
     12  5 files changed, 80 insertions(+), 23 deletions(-)
     13 
     14 diff --git a/config.def.h b/config.def.h
     15 index 061ad66..3a4236d 100644
     16 --- a/config.def.h
     17 +++ b/config.def.h
     18 @@ -7,6 +7,8 @@ static const int showbar            = 1;        /* 0 means no bar */
     19  static const int topbar             = 1;        /* 0 means bottom bar */
     20  static const char *fonts[]          = { "monospace:size=10" };
     21  static const char dmenufont[]       = "monospace:size=10";
     22 +static unsigned int baralpha        = 0xd0;
     23 +static unsigned int borderalpha     = OPAQUE;
     24  static const char col_gray1[]       = "#222222";
     25  static const char col_gray2[]       = "#444444";
     26  static const char col_gray3[]       = "#bbbbbb";
     27 diff --git a/config.mk b/config.mk
     28 index ef8acf7..6d41560 100644
     29 --- a/config.mk
     30 +++ b/config.mk
     31 @@ -23,7 +23,7 @@ FREETYPEINC = /usr/include/freetype2
     32  
     33  # includes and libs
     34  INCS = -I${X11INC} -I${FREETYPEINC}
     35 -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
     36 +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender
     37  
     38  # flags
     39  CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
     40 diff --git a/drw.c b/drw.c
     41 index a58a2b4..10e39f9 100644
     42 --- a/drw.c
     43 +++ b/drw.c
     44 @@ -61,7 +61,7 @@ utf8decode(const char *c, long *u, size_t clen)
     45  }
     46  
     47  Drw *
     48 -drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
     49 +drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap)
     50  {
     51  	Drw *drw = ecalloc(1, sizeof(Drw));
     52  
     53 @@ -70,8 +70,11 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
     54  	drw->root = root;
     55  	drw->w = w;
     56  	drw->h = h;
     57 -	drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
     58 -	drw->gc = XCreateGC(dpy, root, 0, NULL);
     59 +	drw->visual = visual;
     60 +	drw->depth = depth;
     61 +	drw->cmap = cmap;
     62 +	drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
     63 +	drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL);
     64  	XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
     65  
     66  	return drw;
     67 @@ -87,7 +90,7 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h)
     68  	drw->h = h;
     69  	if (drw->drawable)
     70  		XFreePixmap(drw->dpy, drw->drawable);
     71 -	drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
     72 +	drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth);
     73  }
     74  
     75  void
     76 @@ -181,21 +184,20 @@ drw_fontset_free(Fnt *font)
     77  }
     78  
     79  void
     80 -drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
     81 +drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha)
     82  {
     83  	if (!drw || !dest || !clrname)
     84  		return;
     85 -
     86 -	if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
     87 -	                       DefaultColormap(drw->dpy, drw->screen),
     88 +  if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap,
     89  	                       clrname, dest))
     90  		die("error, cannot allocate color '%s'", clrname);
     91 +  dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24);
     92  }
     93  
     94  /* Wrapper to create color schemes. The caller has to call free(3) on the
     95   * returned color scheme when done using it. */
     96  Clr *
     97 -drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
     98 +drw_scm_create(Drw *drw, const char *clrnames[], unsigned int clralphas[], size_t clrcount)
     99  {
    100  	size_t i;
    101  	Clr *ret;
    102 @@ -205,7 +207,7 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
    103  		return NULL;
    104  
    105  	for (i = 0; i < clrcount; i++)
    106 -		drw_clr_create(drw, &ret[i], clrnames[i]);
    107 +		drw_clr_create(drw, &ret[i], clrnames[i], clralphas[i]);
    108  	return ret;
    109  }
    110  
    111 @@ -263,9 +265,8 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
    112  	} else {
    113  		XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
    114  		XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
    115 -		d = XftDrawCreate(drw->dpy, drw->drawable,
    116 -		                  DefaultVisual(drw->dpy, drw->screen),
    117 -		                  DefaultColormap(drw->dpy, drw->screen));
    118 +    d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap);
    119 +
    120  		x += lpad;
    121  		w -= lpad;
    122  	}
    123 diff --git a/drw.h b/drw.h
    124 index 6471431..51dc017 100644
    125 --- a/drw.h
    126 +++ b/drw.h
    127 @@ -20,6 +20,9 @@ typedef struct {
    128  	Display *dpy;
    129  	int screen;
    130  	Window root;
    131 +	Visual *visual;
    132 +	unsigned int depth;
    133 +	Colormap cmap;
    134  	Drawable drawable;
    135  	GC gc;
    136  	Clr *scheme;
    137 @@ -27,7 +30,7 @@ typedef struct {
    138  } Drw;
    139  
    140  /* Drawable abstraction */
    141 -Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
    142 +Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual*, unsigned int, Colormap);
    143  void drw_resize(Drw *drw, unsigned int w, unsigned int h);
    144  void drw_free(Drw *drw);
    145  
    146 @@ -39,8 +42,8 @@ unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int
    147  void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
    148  
    149  /* Colorscheme abstraction */
    150 -void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
    151 -Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
    152 +void drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha);
    153 +Clr *drw_scm_create(Drw *drw, const char *clrnames[], unsigned int clralphas[], size_t clrcount);
    154  
    155  /* Cursor abstraction */
    156  Cur *drw_cur_create(Drw *drw, int shape);
    157 diff --git a/dwm.c b/dwm.c
    158 index e5efb6a..708ca43 100644
    159 --- a/dwm.c
    160 +++ b/dwm.c
    161 @@ -57,6 +57,10 @@
    162  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
    163  #define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
    164  
    165 +#define OPAQUE                  0xffU
    166 +
    167 +#define OPAQUE                  0xffU
    168 +
    169  /* enums */
    170  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
    171  enum { SchemeNorm, SchemeSel }; /* color schemes */
    172 @@ -233,6 +237,7 @@ static Monitor *wintomon(Window w);
    173  static int xerror(Display *dpy, XErrorEvent *ee);
    174  static int xerrordummy(Display *dpy, XErrorEvent *ee);
    175  static int xerrorstart(Display *dpy, XErrorEvent *ee);
    176 +static void xinitvisual();
    177  static void zoom(const Arg *arg);
    178  
    179  /* variables */
    180 @@ -269,6 +274,11 @@ static Drw *drw;
    181  static Monitor *mons, *selmon;
    182  static Window root, wmcheckwin;
    183  
    184 +static int useargb = 0;
    185 +static Visual *visual;
    186 +static int depth;
    187 +static Colormap cmap;
    188 +
    189  /* configuration, allows nested code to access above variables */
    190  #include "config.h"
    191  
    192 @@ -1542,7 +1552,8 @@ setup(void)
    193  	sw = DisplayWidth(dpy, screen);
    194  	sh = DisplayHeight(dpy, screen);
    195  	root = RootWindow(dpy, screen);
    196 -	drw = drw_create(dpy, screen, root, sw, sh);
    197 +  xinitvisual();
    198 +	drw = drw_create(dpy, screen, root, sw, sh, visual, depth, cmap);
    199  	if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
    200  		die("no fonts could be loaded.");
    201  	lrpad = drw->fonts->h;
    202 @@ -1569,8 +1580,9 @@ setup(void)
    203  	cursor[CurMove] = drw_cur_create(drw, XC_fleur);
    204  	/* init appearance */
    205  	scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
    206 +  unsigned int alphas[] = {borderalpha, baralpha, OPAQUE};
    207  	for (i = 0; i < LENGTH(colors); i++)
    208 -		scheme[i] = drw_scm_create(drw, colors[i], 3);
    209 +		scheme[i] = drw_scm_create(drw, colors[i], alphas, 3);
    210  	/* init bars */
    211  	updatebars();
    212  	updatestatus();
    213 @@ -1803,16 +1815,18 @@ updatebars(void)
    214  	Monitor *m;
    215  	XSetWindowAttributes wa = {
    216  		.override_redirect = True,
    217 -		.background_pixmap = ParentRelative,
    218 +		.background_pixel = 0,
    219 +		.border_pixel = 0,
    220 +		.colormap = cmap,
    221  		.event_mask = ButtonPressMask|ExposureMask
    222  	};
    223  	XClassHint ch = {"dwm", "dwm"};
    224  	for (m = mons; m; m = m->next) {
    225  		if (m->barwin)
    226  			continue;
    227 -		m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
    228 -				CopyFromParent, DefaultVisual(dpy, screen),
    229 -				CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
    230 +		m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, depth,
    231 +		                          InputOutput, visual,
    232 +		                          CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa);
    233  		XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
    234  		XMapRaised(dpy, m->barwin);
    235  		XSetClassHint(dpy, m->barwin, &ch);
    236 @@ -2110,6 +2124,43 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
    237  	return -1;
    238  }
    239  
    240 +void
    241 +xinitvisual()
    242 +{
    243 +	XVisualInfo *infos;
    244 +	XRenderPictFormat *fmt;
    245 +	int nitems;
    246 +	int i;
    247 +
    248 +	XVisualInfo tpl = {
    249 +		.screen = screen,
    250 +		.depth = 32,
    251 +		.class = TrueColor
    252 +	};
    253 +	long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
    254 +
    255 +	infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
    256 +	visual = NULL;
    257 +	for(i = 0; i < nitems; i ++) {
    258 +		fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
    259 +		if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
    260 +			visual = infos[i].visual;
    261 +			depth = infos[i].depth;
    262 +			cmap = XCreateColormap(dpy, root, visual, AllocNone);
    263 +			useargb = 1;
    264 +			break;
    265 +		}
    266 +	}
    267 +
    268 +	XFree(infos);
    269 +
    270 +	if (! visual) {
    271 +		visual = DefaultVisual(dpy, screen);
    272 +		depth = DefaultDepth(dpy, screen);
    273 +		cmap = DefaultColormap(dpy, screen);
    274 +	}
    275 +}
    276 +
    277  void
    278  zoom(const Arg *arg)
    279  {
    280 -- 
    281 2.39.1
    282