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

25
dwm.c
View File

@ -1102,11 +1102,6 @@ arrangemon(Monitor *m)
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol); strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
if (m->lt[m->sellt]->arrange) if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m); m->lt[m->sellt]->arrange(m);
#if ROUNDED_CORNERS_PATCH
Client *c;
for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
drawroundedcorners(c);
#endif // ROUNDED_CORNERS_PATCH
} }
void void
@ -2746,9 +2741,6 @@ movemouse(const Arg *arg)
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) { if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) {
resize(c, nx, ny, c->w, c->h, 1); resize(c, nx, ny, c->w, c->h, 1);
} }
#if ROUNDED_CORNERS_PATCH
drawroundedcorners(c);
#endif // ROUNDED_CORNERS_PATCH
break; break;
} }
} while (ev.type != ButtonRelease); } while (ev.type != ButtonRelease);
@ -2772,9 +2764,6 @@ movemouse(const Arg *arg)
c->sfy = ny; c->sfy = ny;
} }
#endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH #endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH
#if ROUNDED_CORNERS_PATCH
drawroundedcorners(c);
#endif // ROUNDED_CORNERS_PATCH
ignoreconfigurerequests = 0; ignoreconfigurerequests = 0;
} }
@ -2932,6 +2921,9 @@ resizeclient(Client *c, int x, int y, int w, int h)
c->expandmask = 0; c->expandmask = 0;
#endif // EXRESIZE_PATCH #endif // EXRESIZE_PATCH
wc.border_width = c->bw; wc.border_width = c->bw;
#if ROUNDED_CORNERS_PATCH
drawroundedcorners(c);
#endif // ROUNDED_CORNERS_PATCH
#if NOBORDER_PATCH #if NOBORDER_PATCH
if (((nexttiled(c->mon->clients) == c && !nexttiled(c->next)) if (((nexttiled(c->mon->clients) == c && !nexttiled(c->next))
#if MONOCLE_LAYOUT #if MONOCLE_LAYOUT
@ -3064,9 +3056,6 @@ resizemouse(const Arg *arg)
} }
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) { if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) {
resize(c, nx, ny, nw, nh, 1); resize(c, nx, ny, nw, nh, 1);
#if ROUNDED_CORNERS_PATCH
drawroundedcorners(c);
#endif // ROUNDED_CORNERS_PATCH
} }
break; break;
} }
@ -3482,10 +3471,6 @@ setfullscreen(Client *c, int fullscreen)
c->bw = 0; c->bw = 0;
c->isfloating = 1; c->isfloating = 1;
resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
#if ROUNDED_CORNERS_PATCH
XRectangle rect = { .x = 0, .y = 0, .width = c->w, .height = c->h };
XShapeCombineRectangles(dpy, c->win, ShapeBounding, 0, 0, &rect, 1, ShapeSet, 1);
#endif // ROUNDED_CORNERS_PATCH
XRaiseWindow(dpy, c->win); XRaiseWindow(dpy, c->win);
} else if (restorestate && (c->oldstate & (1 << 1))) { } else if (restorestate && (c->oldstate & (1 << 1))) {
c->bw = c->oldbw; c->bw = c->oldbw;
@ -3520,10 +3505,6 @@ setfullscreen(Client *c, int fullscreen)
c->bw = 0; c->bw = 0;
c->isfloating = 1; c->isfloating = 1;
resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
#if ROUNDED_CORNERS_PATCH
XRectangle rect = { .x = 0, .y = 0, .width = c->w, .height = c->h };
XShapeCombineRectangles(dpy, c->win, ShapeBounding, 0, 0, &rect, 1, ShapeSet, 1);
#endif // ROUNDED_CORNERS_PATCH
XRaiseWindow(dpy, c->win); XRaiseWindow(dpy, c->win);
#endif // !FAKEFULLSCREEN_PATCH #endif // !FAKEFULLSCREEN_PATCH
} else if (!fullscreen && c->isfullscreen){ } else if (!fullscreen && c->isfullscreen){

View File

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