sites

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

dwm-alpha-6.1.diff (8683B)


      1 diff --git a/config.def.h b/config.def.h
      2 index 7054c06..4448d46 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -11,6 +11,8 @@ static const char normfgcolor[]     = "#bbbbbb";
      6  static const char selbordercolor[]  = "#005577";
      7  static const char selbgcolor[]      = "#005577";
      8  static const char selfgcolor[]      = "#eeeeee";
      9 +static unsigned int baralpha        = 0xd0;
     10 +static unsigned int borderalpha     = OPAQUE;
     11  static const unsigned int borderpx  = 1;        /* border pixel of windows */
     12  static const unsigned int snap      = 32;       /* snap pixel */
     13  static const int showbar            = 1;        /* 0 means no bar */
     14 diff --git a/config.mk b/config.mk
     15 index 4eefb71..de25d2a 100644
     16 --- a/config.mk
     17 +++ b/config.mk
     18 @@ -22,7 +22,7 @@ FREETYPEINC = /usr/include/freetype2
     19  
     20  # includes and libs
     21  INCS = -I${X11INC} -I${FREETYPEINC}
     22 -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
     23 +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender
     24  
     25  # flags
     26  CPPFLAGS = -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
     27 diff --git a/drw.c b/drw.c
     28 index f49200b..12e3ebc 100644
     29 --- a/drw.c
     30 +++ b/drw.c
     31 @@ -61,7 +61,7 @@ utf8decode(const char *c, long *u, size_t clen)
     32  }
     33  
     34  Drw *
     35 -drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
     36 +drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap)
     37  {
     38  	Drw *drw;
     39  
     40 @@ -71,8 +71,11 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
     41  	drw->root = root;
     42  	drw->w = w;
     43  	drw->h = h;
     44 -	drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
     45 -	drw->gc = XCreateGC(dpy, root, 0, NULL);
     46 +	drw->visual = visual;
     47 +	drw->depth = depth;
     48 +	drw->cmap = cmap;
     49 +	drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
     50 +	drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL);
     51  	drw->fontcount = 0;
     52  	XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
     53  
     54 @@ -86,7 +89,7 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h)
     55  	drw->h = h;
     56  	if (drw->drawable)
     57  		XFreePixmap(drw->dpy, drw->drawable);
     58 -	drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
     59 +	drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth);
     60  }
     61  
     62  void
     63 @@ -180,16 +183,15 @@ drw_font_free(Fnt *font)
     64  }
     65  
     66  Clr *
     67 -drw_clr_create(Drw *drw, const char *clrname)
     68 +drw_clr_create(Drw *drw, const char *clrname, unsigned int alpha)
     69  {
     70  	Clr *clr;
     71  
     72  	clr = ecalloc(1, sizeof(Clr));
     73 -	if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
     74 -	                       DefaultColormap(drw->dpy, drw->screen),
     75 +	if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap,
     76  	                       clrname, &clr->rgb))
     77  		die("error, cannot allocate color '%s'\n", clrname);
     78 -	clr->pix = clr->rgb.pixel;
     79 +	clr->pix = (clr->rgb.pixel & 0x00ffffffU) | (alpha << 24);
     80  
     81  	return clr;
     82  }
     83 @@ -245,9 +247,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex
     84  		XSetForeground(drw->dpy, drw->gc, invert ?
     85  		               drw->scheme->fg->pix : drw->scheme->bg->pix);
     86  		XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
     87 -		d = XftDrawCreate(drw->dpy, drw->drawable,
     88 -		                  DefaultVisual(drw->dpy, drw->screen),
     89 -		                  DefaultColormap(drw->dpy, drw->screen));
     90 +		d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap);
     91  	}
     92  
     93  	curfont = drw->fonts[0];
     94 diff --git a/drw.h b/drw.h
     95 index e3b8515..1fed824 100644
     96 --- a/drw.h
     97 +++ b/drw.h
     98 @@ -30,6 +30,9 @@ typedef struct {
     99  	Display *dpy;
    100  	int screen;
    101  	Window root;
    102 +	Visual *visual;
    103 +	unsigned int depth;
    104 +	Colormap cmap;
    105  	Drawable drawable;
    106  	GC gc;
    107  	ClrScheme *scheme;
    108 @@ -43,7 +46,7 @@ typedef struct {
    109  } Extnts;
    110  
    111  /* Drawable abstraction */
    112 -Drw *drw_create(Display *, int, Window, unsigned int, unsigned int);
    113 +Drw *drw_create(Display *, int, Window, unsigned int, unsigned int, Visual*, unsigned int, Colormap);
    114  void drw_resize(Drw *, unsigned int, unsigned int);
    115  void drw_free(Drw *);
    116  
    117 @@ -55,7 +58,7 @@ void drw_font_getexts(Fnt *, const char *, unsigned int, Extnts *);
    118  unsigned int drw_font_getexts_width(Fnt *, const char *, unsigned int);
    119  
    120  /* Colour abstraction */
    121 -Clr *drw_clr_create(Drw *, const char *);
    122 +Clr *drw_clr_create(Drw *, const char *, unsigned int);
    123  void drw_clr_free(Clr *);
    124  
    125  /* Cursor abstraction */
    126 diff --git a/dwm.c b/dwm.c
    127 index 0362114..17fe373 100644
    128 --- a/dwm.c
    129 +++ b/dwm.c
    130 @@ -57,6 +57,8 @@
    131  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
    132  #define TEXTW(X)                (drw_text(drw, 0, 0, 0, 0, (X), 0) + drw->fonts[0]->h)
    133  
    134 +#define OPAQUE                  0xffU
    135 +
    136  /* enums */
    137  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
    138  enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */
    139 @@ -232,6 +234,7 @@ static Monitor *wintomon(Window w);
    140  static int xerror(Display *dpy, XErrorEvent *ee);
    141  static int xerrordummy(Display *dpy, XErrorEvent *ee);
    142  static int xerrorstart(Display *dpy, XErrorEvent *ee);
    143 +static void xinitvisual();
    144  static void zoom(const Arg *arg);
    145  
    146  /* variables */
    147 @@ -267,6 +270,11 @@ static Drw *drw;
    148  static Monitor *mons, *selmon;
    149  static Window root;
    150  
    151 +static int useargb = 0;
    152 +static Visual *visual;
    153 +static int depth;
    154 +static Colormap cmap;
    155 +
    156  /* configuration, allows nested code to access above variables */
    157  #include "config.h"
    158  
    159 @@ -1556,7 +1564,8 @@ setup(void)
    160  	sw = DisplayWidth(dpy, screen);
    161  	sh = DisplayHeight(dpy, screen);
    162  	root = RootWindow(dpy, screen);
    163 -	drw = drw_create(dpy, screen, root, sw, sh);
    164 +	xinitvisual();
    165 +	drw = drw_create(dpy, screen, root, sw, sh, visual, depth, cmap);
    166  	drw_load_fonts(drw, fonts, LENGTH(fonts));
    167  	if (!drw->fontcount)
    168  		die("no fonts could be loaded.\n");
    169 @@ -1580,12 +1589,12 @@ setup(void)
    170  	cursor[CurResize] = drw_cur_create(drw, XC_sizing);
    171  	cursor[CurMove] = drw_cur_create(drw, XC_fleur);
    172  	/* init appearance */
    173 -	scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor);
    174 -	scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor);
    175 -	scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor);
    176 -	scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor);
    177 -	scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor);
    178 -	scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor);
    179 +	scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor, borderalpha);
    180 +	scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor, baralpha);
    181 +	scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor, OPAQUE);
    182 +	scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor, borderalpha);
    183 +	scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor, baralpha);
    184 +	scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor, OPAQUE);
    185  	/* init bars */
    186  	updatebars();
    187  	updatestatus();
    188 @@ -1798,15 +1807,17 @@ updatebars(void)
    189  	Monitor *m;
    190  	XSetWindowAttributes wa = {
    191  		.override_redirect = True,
    192 -		.background_pixmap = ParentRelative,
    193 +		.background_pixel = 0,
    194 +		.border_pixel = 0,
    195 +		.colormap = cmap,
    196  		.event_mask = ButtonPressMask|ExposureMask
    197  	};
    198  	for (m = mons; m; m = m->next) {
    199  		if (m->barwin)
    200  			continue;
    201 -		m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
    202 -		                          CopyFromParent, DefaultVisual(dpy, screen),
    203 -		                          CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
    204 +		m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, depth,
    205 +		                          InputOutput, visual,
    206 +		                          CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa);
    207  		XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
    208  		XMapRaised(dpy, m->barwin);
    209  	}
    210 @@ -2107,6 +2118,43 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
    211  }
    212  
    213  void
    214 +xinitvisual()
    215 +{
    216 +	XVisualInfo *infos;
    217 +	XRenderPictFormat *fmt;
    218 +	int nitems;
    219 +	int i;
    220 +
    221 +	XVisualInfo tpl = {
    222 +		.screen = screen,
    223 +		.depth = 32,
    224 +		.class = TrueColor
    225 +	};
    226 +	long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
    227 +
    228 +	infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
    229 +	visual = NULL;
    230 +	for(i = 0; i < nitems; i ++) {
    231 +		fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
    232 +		if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
    233 +			visual = infos[i].visual;
    234 +			depth = infos[i].depth;
    235 +			cmap = XCreateColormap(dpy, root, visual, AllocNone);
    236 +			useargb = 1;
    237 +			break;
    238 +		}
    239 +	}
    240 +
    241 +	XFree(infos);
    242 +
    243 +	if (! visual) {
    244 +		visual = DefaultVisual(dpy, screen);
    245 +		depth = DefaultDepth(dpy, screen);
    246 +		cmap = DefaultColormap(dpy, screen);
    247 +	}
    248 +}
    249 +
    250 +void
    251  zoom(const Arg *arg)
    252  {
    253  	Client *c = selmon->sel;