added key functions, changed keybinds

This commit is contained in:
WanderingPenwing 2024-07-31 12:07:04 +02:00
parent aff74e6ff9
commit 370089549f
6 changed files with 216 additions and 2567 deletions

View file

@ -29,8 +29,8 @@ static const Rule rules[] = {
* WM_NAME(STRING) = title * WM_NAME(STRING) = title
*/ */
/* class instance title tags mask isfloating monitor */ /* class instance title tags mask isfloating monitor */
{ "Chromium-browser", NULL, NULL, 0, 0, -1}, { "chromium-browser", NULL, NULL, 0, 0, -1},
{ "Jellyfin Media Player", NULL, NULL, 0, 0, -1}, { "jellyfinmediaplayer", NULL, NULL, 0, 0, -1},
{ "calcifer", NULL, NULL, 1<<2, 0, -1}, { "calcifer", NULL, NULL, 1<<2, 0, -1},
{ "jiji", NULL, NULL, 1<<3, 0, -1}, { "jiji", NULL, NULL, 1<<3, 0, -1},
{ "discord", NULL, NULL, 1<<3, 0, -1}, { "discord", NULL, NULL, 1<<3, 0, -1},
@ -70,26 +70,36 @@ static const char *screenlock[] = { "betterlockscreen", "-l", NULL };
static const Key keys[] = { static const Key keys[] = {
/* modifier key function argument */ /* modifier key function argument */
{ MODKEY, XK_d, spawn, {.v = dmenucmd } }, { MODKEY, XK_d, spawn, {.v = dmenucmd } },
{ MODKEY, XK_Return, spawn, {.v = termcmd } }, { MODKEY, XK_less, spawn, {.v = termcmd } },
{ MODKEY, XK_i, spawn, {.v = chromium } }, { MODKEY, XK_i, spawn, {.v = chromium } },
{ MODKEY, XK_twosuperior, spawn, {.v = screenlock } }, { MODKEY, XK_twosuperior, spawn, {.v = screenlock } },
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XK_m, setlayout, {.v = &layouts[1]} }, { MODKEY, XK_m, setlayout, {.v = &layouts[1]} },
{ MODKEY, XK_f, fullscreen, {0} }, { MODKEY, XK_f, togglefullscreen, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_Up, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } }, { MODKEY, XK_Down, focusstack, {.i = -1 } },
{ MODKEY, XK_z, incnmaster, {.i = +1 } }, { MODKEY, XK_F12, incnmaster, {.i = +1 } },
{ MODKEY, XK_s, incnmaster, {.i = -1 } }, { MODKEY, XK_F11, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} }, { MODKEY, XK_Left, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY, XK_Right, setmfact, {.f = +0.05} },
{ MODKEY|ShiftMask, XK_a, killclient, {0} }, { MODKEY|ShiftMask, XK_a, killclient, {0} },
{ MODKEY, XK_Tab, view, {.ui = ~0 } }, { MODKEY, XK_Tab, view, {.ui = ~0 } },
{ MODKEY|ShiftMask, XK_Tab, tag, {.ui = ~0 } }, { MODKEY|ShiftMask, XK_Tab, tag, {.ui = ~0 } },
{ MODKEY, XK_comma, focusmon, {.i = -1 } }, { MODKEY, XK_comma, focusmon, {.i = -1 } },
{ MODKEY, XK_semicolon, focusmon, {.i = +1 } }, { MODKEY, XK_semicolon, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_semicolon, tagmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_semicolon, tagmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_q, quit, {0} }, { MODKEY|ShiftMask, XK_q, quit, {0} },
{ MODKEY, XK_F1, spawn, SHCMD("pamixer -t && notify-send -u normal \"volume\" \"$(pamixer --get-volume-human)\"") },
{ MODKEY, XK_F2, spawn, SHCMD("pamixer -d 5 -u && notify-send -u normal \"volume\" \"$(pamixer --get-volume-human)\"") },
{ MODKEY, XK_F3, spawn, SHCMD("pamixer -i 5 -u && notify-send -u normal \"volume\" \"$(pamixer --get-volume-human)\"") },
{ MODKEY, XK_F4, spawn, SHCMD("brightnessctl -d \"amdgpu_bl1\" set 10%- && notify-send -u normal -a \"brightness\" \"$(brightnessctl -d 'amdgpu_bl1' get)\"") },
{ MODKEY, XK_F5, spawn, SHCMD("brightnessctl -d \"amdgpu_bl1\" set +10% && notify-send -u normal -a \"brightness\" \"$(brightnessctl -d 'amdgpu_bl1' get)\"") },
{ MODKEY, XK_F6, spawn, SHCMD("~/nixos/scripts/usb_guest.sh") },
{ MODKEY, XK_F7, spawn, SHCMD("~/nixos/scripts/susuwatari/client.sh") },
{ MODKEY, XK_F8, spawn, SHCMD("~/nixos/scripts/hdmi_paint.sh") },
{ MODKEY, XK_F9, spawn, SHCMD("~/nixos/scripts/screen_sleep.sh") },
{ ShiftMask, XK_Print, spawn, SHCMD("maim --select \"/home/penwing/Pictures/screenshots/$(date '+%Y_%m_%d %H:%M:%S').png\"") },
TAGKEYS( XK_ampersand, 0) TAGKEYS( XK_ampersand, 0)
TAGKEYS( XK_eacute, 1) TAGKEYS( XK_eacute, 1)
TAGKEYS( XK_quotedbl, 2) TAGKEYS( XK_quotedbl, 2)

379
dwm.c
View file

@ -188,15 +188,15 @@ static void mappingnotify(XEvent *e);
static void maprequest(XEvent *e); static void maprequest(XEvent *e);
static void monocle(Monitor *m); static void monocle(Monitor *m);
static void motionnotify(XEvent *e); static void motionnotify(XEvent *e);
static void movemouse(const Arg *arg); //static void movemouse(const Arg *arg);
static Client *nexttiled(Client *c); static Client *nexttiled(Client *c);
static void pop(Client *c); //static void pop(Client *c);
static void propertynotify(XEvent *e); static void propertynotify(XEvent *e);
static void quit(const Arg *arg); static void quit(const Arg *arg);
static Monitor *recttomon(int x, int y, int w, int h); static Monitor *recttomon(int x, int y, int w, int h);
static void resize(Client *c, int x, int y, int w, int h, int interact); static void resize(Client *c, int x, int y, int w, int h, int interact);
static void resizeclient(Client *c, int x, int y, int w, int h); static void resizeclient(Client *c, int x, int y, int w, int h);
static void resizemouse(const Arg *arg); //static void resizemouse(const Arg *arg);
static void restack(Monitor *m); static void restack(Monitor *m);
static void run(void); static void run(void);
static void scan(void); static void scan(void);
@ -205,8 +205,9 @@ static void sendmon(Client *c, Monitor *m);
static void setclientstate(Client *c, long state); static void setclientstate(Client *c, long state);
static void setfocus(Client *c); static void setfocus(Client *c);
static void setfullscreen(Client *c, int fullscreen); static void setfullscreen(Client *c, int fullscreen);
static void fullscreen(const Arg *arg); //static void fullscreen(const Arg *arg);
static void setgaps(const Arg *arg); static void togglefullscreen(const Arg *arg);
//static void setgaps(const Arg *arg);
static void setlayout(const Arg *arg); static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg); static void setmfact(const Arg *arg);
static void setup(void); static void setup(void);
@ -216,8 +217,8 @@ static void spawn(const Arg *arg);
static void tag(const Arg *arg); static void tag(const Arg *arg);
static void tagmon(const Arg *arg); static void tagmon(const Arg *arg);
static void tile(Monitor *m); static void tile(Monitor *m);
static void togglebar(const Arg *arg); //static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg); //static void togglefloating(const Arg *arg);
static void toggletag(const Arg *arg); static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg); static void toggleview(const Arg *arg);
static void unfocus(Client *c, int setfocus); static void unfocus(Client *c, int setfocus);
@ -240,7 +241,7 @@ static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void xinitvisual(); static void xinitvisual();
static void zoom(const Arg *arg); //static void zoom(const Arg *arg);
/* variables */ /* variables */
static const char broken[] = "broken"; static const char broken[] = "broken";
@ -287,6 +288,14 @@ static Colormap cmap;
/* compile-time check if all tags fit into an unsigned int bit array. */ /* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
void togglefullscreen(const Arg *arg) {
Client *c = selmon->sel; // Get the currently focused client
if (!c) return; // Exit if there is no focused client
// Toggle fullscreen state
setfullscreen(c, !c->isfullscreen);
}
/* function implementations */ /* function implementations */
void void
applyrules(Client *c) applyrules(Client *c)
@ -717,8 +726,8 @@ void
drawbar(Monitor *m) drawbar(Monitor *m)
{ {
int x, w, tw = 0; int x, w, tw = 0;
int boxs = drw->fonts->h / 9; //int boxs = drw->fonts->h / 9;
int boxw = drw->fonts->h / 6 + 2; //int boxw = drw->fonts->h / 6 + 2;
unsigned int i, occ = 0, urg = 0; unsigned int i, occ = 0, urg = 0;
Client *c; Client *c;
@ -1152,65 +1161,65 @@ motionnotify(XEvent *e)
mon = m; mon = m;
} }
void // void
movemouse(const Arg *arg) // movemouse(const Arg *arg)
{ // {
int x, y, ocx, ocy, nx, ny; // int x, y, ocx, ocy, nx, ny;
Client *c; // Client *c;
Monitor *m; // Monitor *m;
XEvent ev; // XEvent ev;
Time lasttime = 0; // Time lasttime = 0;
//
if (!(c = selmon->sel)) // if (!(c = selmon->sel))
return; // return;
if (c->isfullscreen) /* no support moving fullscreen windows by mouse */ // if (c->isfullscreen) /* no support moving fullscreen windows by mouse */
return; // return;
restack(selmon); // restack(selmon);
ocx = c->x; // ocx = c->x;
ocy = c->y; // ocy = c->y;
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, // if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess) // None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess)
return; // return;
if (!getrootptr(&x, &y)) // if (!getrootptr(&x, &y))
return; // return;
do { // do {
XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); // XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
switch(ev.type) { // switch(ev.type) {
case ConfigureRequest: // case ConfigureRequest:
case Expose: // case Expose:
case MapRequest: // case MapRequest:
handler[ev.type](&ev); // handler[ev.type](&ev);
break; // break;
case MotionNotify: // case MotionNotify:
if ((ev.xmotion.time - lasttime) <= (1000 / 60)) // if ((ev.xmotion.time - lasttime) <= (1000 / 60))
continue; // continue;
lasttime = ev.xmotion.time; // lasttime = ev.xmotion.time;
//
nx = ocx + (ev.xmotion.x - x); // nx = ocx + (ev.xmotion.x - x);
ny = ocy + (ev.xmotion.y - y); // ny = ocy + (ev.xmotion.y - y);
if (abs(selmon->wx - nx) < snap) // if (abs(selmon->wx - nx) < snap)
nx = selmon->wx; // nx = selmon->wx;
else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap) // else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap)
nx = selmon->wx + selmon->ww - WIDTH(c); // nx = selmon->wx + selmon->ww - WIDTH(c);
if (abs(selmon->wy - ny) < snap) // if (abs(selmon->wy - ny) < snap)
ny = selmon->wy; // ny = selmon->wy;
else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap) // else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap)
ny = selmon->wy + selmon->wh - HEIGHT(c); // ny = selmon->wy + selmon->wh - HEIGHT(c);
if (!c->isfloating && selmon->lt[selmon->sellt]->arrange // if (!c->isfloating && selmon->lt[selmon->sellt]->arrange
&& (abs(nx - c->x) > snap || abs(ny - c->y) > snap)) // && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
togglefloating(NULL); // togglefloating(NULL);
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);
break; // break;
} // }
} while (ev.type != ButtonRelease); // } while (ev.type != ButtonRelease);
XUngrabPointer(dpy, CurrentTime); // XUngrabPointer(dpy, CurrentTime);
if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { // if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
sendmon(c, m); // sendmon(c, m);
selmon = m; // selmon = m;
focus(NULL); // focus(NULL);
} // }
} // }
Client * Client *
nexttiled(Client *c) nexttiled(Client *c)
@ -1219,14 +1228,14 @@ nexttiled(Client *c)
return c; return c;
} }
void // void
pop(Client *c) // pop(Client *c)
{ // {
detach(c); // detach(c);
attach(c); // attach(c);
focus(c); // focus(c);
arrange(c->mon); // arrange(c->mon);
} // }
void void
propertynotify(XEvent *e) propertynotify(XEvent *e)
@ -1304,62 +1313,62 @@ resizeclient(Client *c, int x, int y, int w, int h)
XSync(dpy, False); XSync(dpy, False);
} }
void // void
resizemouse(const Arg *arg) // resizemouse(const Arg *arg)
{ // {
int ocx, ocy, nw, nh; // int ocx, ocy, nw, nh;
Client *c; // Client *c;
Monitor *m; // Monitor *m;
XEvent ev; // XEvent ev;
Time lasttime = 0; // Time lasttime = 0;
//
if (!(c = selmon->sel)) // if (!(c = selmon->sel))
return; // return;
if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */ // if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */
return; // return;
restack(selmon); // restack(selmon);
ocx = c->x; // ocx = c->x;
ocy = c->y; // ocy = c->y;
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, // if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess) // None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess)
return; // return;
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); // XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
do { // do {
XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); // XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
switch(ev.type) { // switch(ev.type) {
case ConfigureRequest: // case ConfigureRequest:
case Expose: // case Expose:
case MapRequest: // case MapRequest:
handler[ev.type](&ev); // handler[ev.type](&ev);
break; // break;
case MotionNotify: // case MotionNotify:
if ((ev.xmotion.time - lasttime) <= (1000 / 60)) // if ((ev.xmotion.time - lasttime) <= (1000 / 60))
continue; // continue;
lasttime = ev.xmotion.time; // lasttime = ev.xmotion.time;
//
nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); // nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); // nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww // if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww
&& c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh) // && c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh)
{ // {
if (!c->isfloating && selmon->lt[selmon->sellt]->arrange // if (!c->isfloating && selmon->lt[selmon->sellt]->arrange
&& (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) // && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
togglefloating(NULL); // togglefloating(NULL);
} // }
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) // if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
resize(c, c->x, c->y, nw, nh, 1); // resize(c, c->x, c->y, nw, nh, 1);
break; // break;
} // }
} while (ev.type != ButtonRelease); // } while (ev.type != ButtonRelease);
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); // XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
XUngrabPointer(dpy, CurrentTime); // XUngrabPointer(dpy, CurrentTime);
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); // while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { // if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
sendmon(c, m); // sendmon(c, m);
selmon = m; // selmon = m;
focus(NULL); // focus(NULL);
} // }
} // }
void void
restack(Monitor *m) restack(Monitor *m)
@ -1514,28 +1523,28 @@ setfullscreen(Client *c, int fullscreen)
} }
} }
void // void
setgaps(const Arg *arg) // setgaps(const Arg *arg)
{ // {
if ((arg->i == 0) || (selmon->gappx + arg->i < 0)) // if ((arg->i == 0) || (selmon->gappx + arg->i < 0))
selmon->gappx = 0; // selmon->gappx = 0;
else // else
selmon->gappx += arg->i; // selmon->gappx += arg->i;
arrange(selmon); // arrange(selmon);
} // }
Layout *last_layout; Layout *last_layout;
void // void
fullscreen(const Arg *arg) // fullscreen(const Arg *arg)
{ // {
if (selmon->showbar) { // if (selmon->showbar) {
for(last_layout = (Layout *)layouts; last_layout != selmon->lt[selmon->sellt]; last_layout++); // for(last_layout = (Layout *)layouts; last_layout != selmon->lt[selmon->sellt]; last_layout++);
setlayout(&((Arg) { .v = &layouts[2] })); // setlayout(&((Arg) { .v = &layouts[2] }));
} else { // } else {
setlayout(&((Arg) { .v = last_layout })); // setlayout(&((Arg) { .v = last_layout }));
} // }
togglebar(arg); // togglebar(arg);
} // }
void void
setlayout(const Arg *arg) setlayout(const Arg *arg)
@ -1744,28 +1753,28 @@ tile(Monitor *m)
} }
} }
void // void
togglebar(const Arg *arg) // togglebar(const Arg *arg)
{ // {
selmon->showbar = !selmon->showbar; // selmon->showbar = !selmon->showbar;
updatebarpos(selmon); // updatebarpos(selmon);
XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); // XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
arrange(selmon); // arrange(selmon);
} // }
void // void
togglefloating(const Arg *arg) // togglefloating(const Arg *arg)
{ // {
if (!selmon->sel) // if (!selmon->sel)
return; // return;
if (selmon->sel->isfullscreen) /* no support for fullscreen windows */ // if (selmon->sel->isfullscreen) /* no support for fullscreen windows */
return; // return;
selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed; // selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
if (selmon->sel->isfloating) // if (selmon->sel->isfloating)
resize(selmon->sel, selmon->sel->x, selmon->sel->y, // resize(selmon->sel, selmon->sel->x, selmon->sel->y,
selmon->sel->w, selmon->sel->h, 0); // selmon->sel->w, selmon->sel->h, 0);
arrange(selmon); // arrange(selmon);
} // }
void void
toggletag(const Arg *arg) toggletag(const Arg *arg)
@ -2199,17 +2208,17 @@ xinitvisual()
} }
} }
void // void
zoom(const Arg *arg) // zoom(const Arg *arg)
{ // {
Client *c = selmon->sel; // Client *c = selmon->sel;
//
if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating) // if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating)
return; // return;
if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next))) // if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next)))
return; // return;
pop(c); // pop(c);
} // }
int int
main(int argc, char *argv[]) main(int argc, char *argv[])

2236
dwm.c.orig

File diff suppressed because it is too large Load diff

View file

@ -1,20 +0,0 @@
--- dwm.c Mon Feb 24 21:41:55 2020
+++ dwm.c Mon Feb 24 21:48:42 2020
@@ -242,6 +243,7 @@
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";
@@ -1446,6 +1500,9 @@
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
resize(c, nx, ny, nw, nh, 1);
+
+ drawroundedcorners(c);
+
break;
}
} while (ev.type != ButtonRelease);

BIN
dwm.o

Binary file not shown.

View file

@ -1,114 +0,0 @@
/* -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* */
/* Back by popular demand, the dwm rounded corners patch. */
/* http://github.com/mitchweaver/suckless */
/* -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* */
/* Things to know about this patch: */
/* 1. You need to add '-lXext' to the libraries linked in config.mk */
/* LIBS = -L${X11LIB} -lX11 -lXext */
/* 2. You need to set a CORNER_RADIUS integer in your config.h: */
/* static const int CORNER_RADIUS = 10; */
/* 3. You must have "borderpx = 0;" in your config.h */
/* 4. This patch assumes ALL other "OFFICIAL" and "mitch" patches have been applied. */
/* -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* */
--- 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 @@
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 @@
unfocus(selmon->sel, 0);
c->mon->sel = c;
arrange(c->mon);
+
+ drawroundedcorners(c);
+
XMapWindow(dpy, c->win);
focus(NULL);
}
@@ -1337,6 +1342,55 @@
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 @@
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 @@
selmon = m;
focus(NULL);
}
+ drawroundedcorners(c);
}
void