roundedcorners: moving drawroundedcorners logic to resizeclient ref. #304

This commit is contained in:
bakkeby
2022-10-16 21:32:01 +02:00
parent b732821f7b
commit e6a74ad3ea
2 changed files with 44 additions and 61 deletions

View File

@@ -2,50 +2,52 @@
void drawroundedcorners(Client *c)
{
if (corner_radius <= 0 || !c || c->isfullscreen)
return;
XWindowAttributes win_attr;
Pixmap mask;
XGCValues xgcv;
GC shape_gc;
int dia, w, h;
Window win;
win = c->win;
if (!win)
return;
if (corner_radius <= 0 || !c)
return;
XWindowAttributes win_attr;
if (!XGetWindowAttributes(dpy, win, &win_attr))
return;
/* Clear window shape if fullscreen */
if (c->w == c->mon->mw && c->h == c->mon->mh) {
XRectangle rect = { .x = 0, .y = 0, .width = c->w, .height = c->h };
XShapeCombineRectangles(dpy, c->win, ShapeBounding, 0, 0, &rect, 1, ShapeSet, 1);
return;
}
int dia = 2 * corner_radius;
int w = c->w;
int h = c->h;
if (w < dia || h < dia)
return;
if (!XGetWindowAttributes(dpy, c->win, &win_attr))
return;
Pixmap mask;
mask = XCreatePixmap(dpy, win, w, h, 1);
if (!mask)
return;
dia = 2 * corner_radius;
w = c->w + 2 * c->bw;
h = c->h + 2 * c->bw;
if (w < dia || h < dia)
return;
XGCValues xgcv;
GC shape_gc;
shape_gc = XCreateGC(dpy, mask, 0, &xgcv);
mask = XCreatePixmap(dpy, c->win, w, h, 1);
if (!mask)
return;
if (!shape_gc) {
XFreePixmap(dpy, mask);
free(shape_gc);
return;
}
shape_gc = XCreateGC(dpy, mask, 0, &xgcv);
if (!shape_gc) {
XFreePixmap(dpy, mask);
free(shape_gc);
return;
}
XSetForeground(dpy, shape_gc, 0);
XFillRectangle(dpy, mask, shape_gc, 0, 0, w, h);
XSetForeground(dpy, shape_gc, 1);
XFillArc(dpy, mask, shape_gc, 0, 0, dia, dia, 0, 23040);
XFillArc(dpy, mask, shape_gc, w-dia-1, 0, dia, dia, 0, 23040);
XFillArc(dpy, mask, shape_gc, 0, h-dia-1, dia, dia, 0, 23040);
XFillArc(dpy, mask, shape_gc, w-dia-1, h-dia-1, dia, dia, 0, 23040);
XFillRectangle(dpy, mask, shape_gc, corner_radius, 0, w-dia, h);
XFillRectangle(dpy, mask, shape_gc, 0, corner_radius, w, h-dia);
XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, mask, ShapeSet);
XFreePixmap(dpy, mask);
XFreeGC(dpy, shape_gc);
XSetForeground(dpy, shape_gc, 0);
XFillRectangle(dpy, mask, shape_gc, 0, 0, w, h);
XSetForeground(dpy, shape_gc, 1);
XFillArc(dpy, mask, shape_gc, 0, 0, dia, dia, 0, 23040);
XFillArc(dpy, mask, shape_gc, w-dia-1, 0, dia, dia, 0, 23040);
XFillArc(dpy, mask, shape_gc, 0, h-dia-1, dia, dia, 0, 23040);
XFillArc(dpy, mask, shape_gc, w-dia-1, h-dia-1, dia, dia, 0, 23040);
XFillRectangle(dpy, mask, shape_gc, corner_radius, 0, w-dia, h);
XFillRectangle(dpy, mask, shape_gc, 0, corner_radius, w, h-dia);
XShapeCombineMask(dpy, c->win, ShapeBounding, -c->bw, -c->bw, mask, ShapeSet);
XFreePixmap(dpy, mask);
XFreeGC(dpy, shape_gc);
}