dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

roundedcorners.c (1462B)


      1 #include <X11/extensions/shape.h>
      2 
      3 void drawroundedcorners(Client *c)
      4 {
      5 	XWindowAttributes win_attr;
      6 	Pixmap mask;
      7 	XGCValues xgcv;
      8 	GC shape_gc;
      9 	int dia, w, h;
     10 
     11 	if (corner_radius <= 0 || !c)
     12 		return;
     13 
     14 	/* Clear window shape if fullscreen */
     15 	if (c->w == c->mon->mw && c->h == c->mon->mh) {
     16 		XRectangle rect = { .x = 0, .y = 0, .width = c->w, .height = c->h };
     17 		XShapeCombineRectangles(dpy, c->win, ShapeBounding, 0, 0, &rect, 1, ShapeSet, 1);
     18 		return;
     19 	}
     20 
     21 	if (!XGetWindowAttributes(dpy, c->win, &win_attr))
     22 		return;
     23 
     24 	dia = 2 * corner_radius;
     25 	w = c->w + 2 * c->bw;
     26 	h = c->h + 2 * c->bw;
     27 	if (w < dia || h < dia)
     28 		return;
     29 
     30 	mask = XCreatePixmap(dpy, c->win, w, h, 1);
     31 	if (!mask)
     32 		return;
     33 
     34 	shape_gc = XCreateGC(dpy, mask, 0, &xgcv);
     35 	if (!shape_gc) {
     36 		XFreePixmap(dpy, mask);
     37 		free(shape_gc);
     38 		return;
     39 	}
     40 
     41 	XSetForeground(dpy, shape_gc, 0);
     42 	XFillRectangle(dpy, mask, shape_gc, 0, 0, w, h);
     43 	XSetForeground(dpy, shape_gc, 1);
     44 	XFillArc(dpy, mask, shape_gc, 0, 0, dia, dia, 0, 23040);
     45 	XFillArc(dpy, mask, shape_gc, w-dia-1, 0, dia, dia, 0, 23040);
     46 	XFillArc(dpy, mask, shape_gc, 0, h-dia-1, dia, dia, 0, 23040);
     47 	XFillArc(dpy, mask, shape_gc, w-dia-1, h-dia-1, dia, dia, 0, 23040);
     48 	XFillRectangle(dpy, mask, shape_gc, corner_radius, 0, w-dia, h);
     49 	XFillRectangle(dpy, mask, shape_gc, 0, corner_radius, w, h-dia);
     50 	XShapeCombineMask(dpy, c->win, ShapeBounding, -c->bw, -c->bw, mask, ShapeSet);
     51 	XFreePixmap(dpy, mask);
     52 	XFreeGC(dpy, shape_gc);
     53 }