about summary refs log tree commit diff
path: root/pkgs/dwm/dwm-rounded.diff
diff options
context:
space:
mode:
authorPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2020-09-25 22:45:48 +0200
committerPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2020-09-25 22:45:48 +0200
commite80b0b5447c823715f90791b8613cb3d21ea76e0 (patch)
treebca5c610aa8d6a829cd0386ac11ba690aa8885b3 /pkgs/dwm/dwm-rounded.diff
parentcef8f9740ee898c09c5d2971dc859d9d23ab0744 (diff)
downloadpnpkgs-e80b0b5447c823715f90791b8613cb3d21ea76e0.tar.gz
pnpkgs-e80b0b5447c823715f90791b8613cb3d21ea76e0.zip
Add rounded dwm
Diffstat (limited to 'pkgs/dwm/dwm-rounded.diff')
-rw-r--r--pkgs/dwm/dwm-rounded.diff102
1 files changed, 102 insertions, 0 deletions
diff --git a/pkgs/dwm/dwm-rounded.diff b/pkgs/dwm/dwm-rounded.diff
new file mode 100644
index 0000000..320846c
--- /dev/null
+++ b/pkgs/dwm/dwm-rounded.diff
@@ -0,0 +1,102 @@
+diff --git a/dwm.c b/dwm.c
+index 290dc2d..f3e70c9 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -40,6 +40,7 @@
+ #ifdef XINERAMA
+ #include <X11/extensions/Xinerama.h>
+ #endif /* XINERAMA */
++#include <X11/extensions/shape.h>
+ #include <X11/Xft/Xft.h>
+ #include <X11/Xlib-xcb.h>
+ #include <xcb/res.h>
+@@ -315,6 +316,7 @@ static Client *wintosystrayicon(Window w);
+ static int xerror(Display *dpy, XErrorEvent *ee);
+ static int xerrordummy(Display *dpy, XErrorEvent *ee);
+ static int xerrorstart(Display *dpy, XErrorEvent *ee);
++static void drawroundedcorners(Client *c);
+ static void xrdb(const Arg *arg);
+ static void zoom(const Arg *arg);
+ 
+@@ -1391,6 +1393,9 @@ manage(Window w, XWindowAttributes *wa)
+ 		unfocus(selmon->sel, 0);
+ 	c->mon->sel = c;
+ 	arrange(c->mon);
++
++    drawroundedcorners(c);
++
+ 	XMapWindow(dpy, c->win);
+ 	if (term)
+ 		swallow(term, c);
+@@ -1508,6 +1513,7 @@ movemouse(const Arg *arg)
+ 				togglefloating(NULL);
+ 			if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
+ 				resize(c, nx, ny, c->w, c->h, 1);
++        drawroundedcorners(c);
+ 			break;
+ 		}
+ 	} while (ev.type != ButtonRelease);
+@@ -1671,6 +1677,55 @@ resizeclient(Client *c, int x, int y, int w, int h)
+ 	XSync(dpy, False);
+ }
+ 
++void drawroundedcorners(Client *c) {
++    // if set to zero in config.h, do not attempt to round
++    if(CORNER_RADIUS < 0) return;
++
++    // NOTE: this is extremely hacky and surely could be optimized.
++    //       Any X wizards out there reading this, please pull request.
++    if (CORNER_RADIUS > 0 && c && !c->isfullscreen) {
++        Window win;
++        win = c->win;
++        if(!win) return;
++
++        XWindowAttributes win_attr;
++        if(!XGetWindowAttributes(dpy, win, &win_attr)) return;
++
++        // set in config.h:
++        int dia = 2 * CORNER_RADIUS;
++        int w = c->w;
++        int h = c->h;
++        if(w < dia || h < dia) return;
++
++        Pixmap mask;
++        mask = XCreatePixmap(dpy, win, w, h, 1);
++        if(!mask) return;
++
++        XGCValues xgcv;
++        GC shape_gc;
++        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);
++    }
++}
++
+ void
+ resizemouse(const Arg *arg)
+ {
+@@ -1726,6 +1781,7 @@ resizemouse(const Arg *arg)
+ 		selmon = m;
+ 		focus(NULL);
+ 	}
++    drawroundedcorners(c);
+ }
+ 
+ void