From a42e4c88130cbe49778cef2b7501c345d7ca2320 Mon Sep 17 00:00:00 2001 From: Lukasz M Date: Tue, 18 May 2021 15:01:28 +0200 Subject: [PATCH] applied tapresize patch --- config.def.h | 16 ++++++++++++++++ dwm.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/config.def.h b/config.def.h index 01d39b7..45d848f 100644 --- a/config.def.h +++ b/config.def.h @@ -45,6 +45,9 @@ static const float mfact = 0.55; /* factor of master area size [0.05..0.95] static const int nmaster = 1; /* number of clients in master area */ static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ +/* mouse scroll resize */ +static const int scrollsensetivity = 30; /* 1 means resize window by 1 pixel for each scroll event */ + static const Layout layouts[] = { /* symbol arrange function */ { "[]=", tile }, /* first entry is default */ @@ -109,6 +112,15 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_q, quit, {0} }, }; +/* resizemousescroll direction argument list */ +static const int scrollargs[][2] = { + /* width change height change */ + { +scrollsensetivity, 0 }, + { -scrollsensetivity, 0 }, + { 0, +scrollsensetivity }, + { 0, -scrollsensetivity }, +}; + /* button definitions */ /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ static Button buttons[] = { @@ -120,6 +132,10 @@ static Button buttons[] = { { ClkClientWin, MODKEY, Button1, movemouse, {0} }, { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, + { 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]} }, { ClkTagBar, 0, Button1, view, {0} }, { ClkTagBar, 0, Button3, toggleview, {0} }, { ClkTagBar, MODKEY, Button1, tag, {0} }, diff --git a/dwm.c b/dwm.c index 161d162..978b6c6 100644 --- a/dwm.c +++ b/dwm.c @@ -62,6 +62,11 @@ #define GAP_TOGGLE 100 #define GAP_RESET 0 #define OPAQUE 0xffU +/* Undefined in X11/X.h buttons that are actualy exist and correspond to + * horizontal scroll + */ +#define Button6 6 +#define Button7 7 /* enums */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ @@ -203,6 +208,7 @@ 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 resizeclient(Client *c, int x, int y, int w, int h); static void resizemouse(const Arg *arg); +static void resizemousescroll(const Arg *arg); static void restack(Monitor *m); static void run(void); static void runautostart(void); @@ -1451,6 +1457,45 @@ resizemouse(const Arg *arg) } } +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); + } +} + void restack(Monitor *m) {