From 07277cc460d73dd0c330257812180894f5c4c77e Mon Sep 17 00:00:00 2001 From: verschmelzen Date: Tue, 30 Mar 2021 22:31:45 +0300 Subject: [PATCH] Add tapresize patch --- config.def.h | 19 +++++++++++++++++++ patch/include.c | 3 +++ patch/include.h | 3 +++ patch/tapresize.c | 38 ++++++++++++++++++++++++++++++++++++++ patch/tapresize.h | 1 + patches.def.h | 7 +++++++ 6 files changed, 71 insertions(+) create mode 100644 patch/tapresize.c create mode 100644 patch/tapresize.h diff --git a/config.def.h b/config.def.h index ce368ee..85ad6e9 100644 --- a/config.def.h +++ b/config.def.h @@ -532,6 +532,19 @@ static const int decorhints = 1; /* 1 means respect decoration hints */ #define FORCE_VSPLIT 1 #endif +#if TAPRESIZE_PATCH +/* mouse scroll resize */ +static const int scrollsensetivity = 30; /* 1 means resize window by 1 pixel for each scroll event */ +/* resizemousescroll direction argument list */ +static const int scrollargs[][2] = { + /* width change height change */ + { +scrollsensetivity, 0 }, + { -scrollsensetivity, 0 }, + { 0, +scrollsensetivity }, + { 0, -scrollsensetivity }, +}; +#endif + #if FLEXTILE_DELUXE_LAYOUT static const Layout layouts[] = { /* symbol arrange function, { nmaster, nstack, layout, master axis, stack axis, secondary stack axis, symbol func } */ @@ -1207,6 +1220,12 @@ static Button buttons[] = { #endif // PLACEMOUSE_PATCH { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, + #if TAPRESIZE_PATCH + { ClkClientWin, MODKEY, Button4, resizemousescroll, {.v = &scrollargs[0]} }, + { ClkClientWin, MODKEY, Button5, resizemousescroll, {.v = &scrollargs[1]} }, + { ClkClientWin, MODKEY, Button6, resizemousescroll, {.v = &scrollargs[2]} }, + { ClkClientWin, MODKEY, Button7, resizemousescroll, {.v = &scrollargs[3]} }, + #endif // TAPRESIZE_PATCH #if DRAGCFACT_PATCH && CFACTS_PATCH { ClkClientWin, MODKEY|ShiftMask, Button3, dragcfact, {0} }, #endif // DRAGCFACT_PATCH diff --git a/patch/include.c b/patch/include.c index 73c3536..02ba47b 100644 --- a/patch/include.c +++ b/patch/include.c @@ -268,6 +268,9 @@ #if TAGSWAPMON_PATCH #include "tagswapmon.c" #endif +#if TAPRESIZE_PATCH +#include "tapresize.c" +#endif #if TOGGLEFULLSCREEN_PATCH #include "togglefullscreen.c" #endif diff --git a/patch/include.h b/patch/include.h index 27cf77b..7aab494 100644 --- a/patch/include.h +++ b/patch/include.h @@ -264,6 +264,9 @@ #if TAGSWAPMON_PATCH #include "tagswapmon.h" #endif +#if TAPRESIZE_PATCH +#include "tapresize.h" +#endif #if TOGGLEFULLSCREEN_PATCH #include "togglefullscreen.h" #endif diff --git a/patch/tapresize.c b/patch/tapresize.c new file mode 100644 index 0000000..546aa50 --- /dev/null +++ b/patch/tapresize.c @@ -0,0 +1,38 @@ +void +resizemousescroll(const Arg *arg) +{ + int nw, nh; + Client *c; + Monitor *m; + XEvent ev; + int dw = *((int*)arg->v + 1); + int dh = *(int*)arg->v; + + if (!(c = selmon->sel)) + return; + if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */ + return; + restack(selmon); + if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, + None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess) + return; + nw = MAX(c->w + dw, 1); + nh = MAX(c->h + dh, 1); + 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) + { + if (!c->isfloating && selmon->lt[selmon->sellt]->arrange + && (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) + togglefloating(NULL); + } + if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) + resize(c, c->x, c->y, nw, nh, 1); + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); + XUngrabPointer(dpy, CurrentTime); + while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); + if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { + sendmon(c, m); + selmon = m; + focus(NULL); + } +} diff --git a/patch/tapresize.h b/patch/tapresize.h new file mode 100644 index 0000000..867f9a0 --- /dev/null +++ b/patch/tapresize.h @@ -0,0 +1 @@ +static void resizemousescroll(const Arg *arg); diff --git a/patches.def.h b/patches.def.h index 69b2d7c..fe2d1e0 100644 --- a/patches.def.h +++ b/patches.def.h @@ -1017,6 +1017,13 @@ */ #define TAGSWAPMON_PATCH 0 +/* This patch can be useful to the touchpad users because it allows to + * resize windows using Mod + two-finger scroll. It is useful when + * two-finger scrolling is configured in libinput. + * https://dwm.suckless.org/patches/tapresize/ + */ +#define TAPRESIZE_PATCH 0 + /* This patch allows you to toggle fullscreen on and off using a single shortcut key. * https://github.com/bakkeby/patches/blob/master/dwm/dwm-togglefullscreen-6.2.diff */