From b3d336322e56637c7e157a44695dab6def2fcb05 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Thu, 27 Aug 2020 07:34:21 +0200 Subject: [PATCH] Adding aspectresize patch --- README.md | 5 +++++ config.def.h | 4 ++++ dwm.c | 4 ++++ patch/aspectresize.c | 24 ++++++++++++++++++++++++ patch/aspectresize.h | 1 + patch/include.c | 3 +++ patch/include.h | 3 +++ patches.def.h | 5 +++++ 8 files changed, 49 insertions(+) create mode 100644 patch/aspectresize.c create mode 100644 patch/aspectresize.h diff --git a/README.md b/README.md index cb2435a..a7e3f36 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: +2020-08-27 - Added aspectresize patch + 2020-08-25 - Unified tag icon handling while adding support for different icons per monitor. Added alttagsdecoration patch. 2020-08-22 - Added logic to auto-hide bars if nothing is drawn on them (e.g. for standalone bars that only show certain clients). Added clientindicators patch and unified indicator code. Simplified Pango integration by settling on common function signatures. @@ -170,6 +172,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t - [alwaysfullscreen](https://dwm.suckless.org/patches/alwaysfullscreen/) - prevents the focus to drift from the active fullscreen client when using focusstack\(\) + - [aspectresize](https://dwm.suckless.org/patches/aspectresize/) + - allows windows to be resized with its aspect ratio remaining constant + - [attachabove](https://dwm.suckless.org/patches/attachabove/) - new windows are placed above selected client diff --git a/config.def.h b/config.def.h index 9f682c7..9ed5922 100644 --- a/config.def.h +++ b/config.def.h @@ -945,6 +945,10 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_l, setcfact, {.f = -0.25} }, { MODKEY|ShiftMask, XK_o, setcfact, {0} }, #endif // CFACTS_PATCH + #if ASPECTRESIZE_PATCH + { MODKEY|ControlMask|ShiftMask, XK_e, aspectresize, {.i = +24} }, + { MODKEY|ControlMask|ShiftMask, XK_r, aspectresize, {.i = -24} }, + #endif // ASPECTRESIZE_PATCH #if MOVERESIZE_PATCH { MODKEY|Mod4Mask, XK_Down, moveresize, {.v = "0x 25y 0w 0h" } }, { MODKEY|Mod4Mask, XK_Up, moveresize, {.v = "0x -25y 0w 0h" } }, diff --git a/dwm.c b/dwm.c index ad63384..4de4f34 100644 --- a/dwm.c +++ b/dwm.c @@ -63,6 +63,10 @@ #endif // SPAWNCMD_PATCH /* macros */ +#define Button6 6 +#define Button7 7 +#define Button8 8 +#define Button9 9 #define NUMTAGS 9 #define BARRULES 20 #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) diff --git a/patch/aspectresize.c b/patch/aspectresize.c new file mode 100644 index 0000000..73a0342 --- /dev/null +++ b/patch/aspectresize.c @@ -0,0 +1,24 @@ +void +aspectresize(const Arg *arg) +{ + /* only floating windows can be moved */ + Client *c; + c = selmon->sel; + float ratio; + int w, h,nw, nh; + + if (!c || !arg) + return; + if (selmon->lt[selmon->sellt]->arrange && !c->isfloating) + return; + + ratio = (float)c->w / (float)c->h; + h = arg->i; + w = (int)(ratio * h); + + nw = c->w + w; + nh = c->h + h; + + XRaiseWindow(dpy, c->win); + resize(c, c->x, c->y, nw, nh, True); +} \ No newline at end of file diff --git a/patch/aspectresize.h b/patch/aspectresize.h new file mode 100644 index 0000000..ad0d054 --- /dev/null +++ b/patch/aspectresize.h @@ -0,0 +1 @@ +static void aspectresize(const Arg *arg); \ No newline at end of file diff --git a/patch/include.c b/patch/include.c index 606377e..e13348e 100644 --- a/patch/include.c +++ b/patch/include.c @@ -82,6 +82,9 @@ #endif /* Other patches */ +#if ASPECTRESIZE_PATCH +#include "aspectresize.c" +#endif #if ATTACHABOVE_PATCH || ATTACHASIDE_PATCH || ATTACHBELOW_PATCH || ATTACHBOTTOM_PATCH #include "attachx.c" #endif diff --git a/patch/include.h b/patch/include.h index 3961d41..9130311 100644 --- a/patch/include.h +++ b/patch/include.h @@ -79,6 +79,9 @@ #endif /* Other patches */ +#if ASPECTRESIZE_PATCH +#include "aspectresize.h" +#endif #if ATTACHABOVE_PATCH || ATTACHASIDE_PATCH || ATTACHBELOW_PATCH || ATTACHBOTTOM_PATCH #include "attachx.h" #endif diff --git a/patches.def.h b/patches.def.h index e4c1232..e558d92 100644 --- a/patches.def.h +++ b/patches.def.h @@ -299,6 +299,11 @@ * Other patches */ +/* This patch allows windows to be resized with its aspect ratio remaining constant. + * https://dwm.suckless.org/patches/aspectresize/ + */ +#define ASPECTRESIZE_PATCH 0 + /* This patch prevents the focus to drift from the active fullscreen client when * using focusstack(). * https://dwm.suckless.org/patches/alwaysfullscreen/