Rounded corners on dwm

Nestero
Bismillahirrahmanirrahim

Rounded corners pada dwm

Untuk memebuat dwm memiliki rounded corners ada beberapa cara antara lain :

  • Menggunakan compositor picom versi dari ibhagwan .
  • Menggunakan patch .

Yang akan dibahas kali ini adalah yang kedua yaitu menggunakan patch.

Persiapan

Tambhakan -lXext dalam variabel LIBS pada file config.mk

LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender -lXext

Tambhakan CORNER_RADIUS pada file config.def.h dan set borderpx menjadi 0

static const int CORNER_RADIUS = 10;

Patching

Masuk kedalam direktori dimana source dwm disimpan, dan simpan patch berikut rounded_corners.diff :

--- dwm/dwm.c	Mon Feb 24 21:41:55 2020
+++ dwm/dwm.c	Mon Feb 24 21:48:42 2020
@@ -39,6 +39,7 @@
 #ifdef XINERAMA
 #include <X11/extensions/Xinerama.h>
 #endif /* XINERAMA */
+#include <X11/extensions/shape.h>
 #include <X11/Xft/Xft.h>
 
 #include "drw.h"
@@ -241,6 +242,7 @@ /* function declarations */
 static int xerrordummy(Display *dpy, XErrorEvent *ee);
 static int xerrorstart(Display *dpy, XErrorEvent *ee);
 static void xinitvisual();
+static void drawroundedcorners(Client *c);
 
 /* variables */
 static const char broken[] = "broken";
@@ -1133,6 +1135,9 @@ manage(Window w, XWindowAttributes *wa)
 		unfocus(selmon->sel, 0);
 	c->mon->sel = c;
 	arrange(c->mon);
+
+    drawroundedcorners(c);
+
 	XMapWindow(dpy, c->win);
 	focus(NULL);
 }
@@ -1337,6 +1342,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)
 {
@@ -1393,6 +1447,9 @@ movemouse(const Arg *arg)
 
 			if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
 				resize(c, nx, ny, nw, nh, 1);
+
+            drawroundedcorners(c);
+
 			break;
 		}
 	} while (ev.type != ButtonRelease);
@@ -1406,6 +1463,7 @@ resizemouse(const Arg *arg)
 		selmon = m;
 		focus(NULL);
 	}
+    drawroundedcorners(c);
 }
 
 void

Melakukan patching :

$ patch < rounded_corners.diff
$ sudo make clean install
  • Jika ada konflik dengan patch lain silahkan di perbaiki sendiri 😄.
  • Terakhir jangan lupa dwmnya di restart kembali.

Tags:

Referensi:

Imam Az-Zuhri rahimahullah mengatakan :

Sesungguhnya yang menyebabkan ilmu hilang adalah lupa dan tidak mengulanginya.

"Sesungguhnya yang menyebabkan ilmu hilang adalah lupa dan tidak mengulanginya."

Catatan Terkait :

#semuabisaonline dengan Jetdino

Jetdino

comments powered by Disqus
Catatan Nestero

Nestero

🔥 GNU/Linux Enthusiast 🔥
🌟 Void Linux User 🌟

Catatan Terbaru :

Steam on Void

Nestero
Catatan Nestero

Pyblog

Nestero
Catatan Nestero

Enable Virtual Cam On OBS

Nestero
Catatan Nestero