sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-tapresize-20200819-f04cac6.diff (4885B)


      1 From d781863fb98f066d1ad98b573796d0880b48af8f Mon Sep 17 00:00:00 2001
      2 From: verschmelzen <ivan.komarov@protonmail.com>
      3 Date: Wed, 19 Aug 2020 00:05:34 +0300
      4 Subject: [PATCH] Resize windows with touchpad two-finger scroll
      5 
      6 This patch allows to resize windows using mouse scroll events. Since
      7 there is no right-click-tap-to-drag I found this patch to be the only
      8 way to be able to both move and resize windows with touchpad.
      9 ---
     10  config.def.h | 16 ++++++++++++++++
     11  dwm.c        | 46 ++++++++++++++++++++++++++++++++++++++++++++++
     12  2 files changed, 62 insertions(+)
     13 
     14 diff --git a/config.def.h b/config.def.h
     15 index 1c0b587..d7d208f 100644
     16 --- a/config.def.h
     17 +++ b/config.def.h
     18 @@ -36,6 +36,9 @@ static const float mfact     = 0.55; /* factor of master area size [0.05..0.95]
     19  static const int nmaster     = 1;    /* number of clients in master area */
     20  static const int resizehints = 1;    /* 1 means respect size hints in tiled resizals */
     21  
     22 +/* mouse scroll resize */
     23 +static const int scrollsensetivity = 30; /* 1 means resize window by 1 pixel for each scroll event */
     24 +
     25  static const Layout layouts[] = {
     26  	/* symbol     arrange function */
     27  	{ "[]=",      tile },    /* first entry is default */
     28 @@ -96,6 +99,15 @@ static Key keys[] = {
     29  	{ MODKEY|ShiftMask,             XK_q,      quit,           {0} },
     30  };
     31  
     32 +/* resizemousescroll direction argument list */
     33 +static const int scrollargs[][2] = {
     34 +	/* width change         height change */
     35 +	{ +scrollsensetivity,	0 },
     36 +	{ -scrollsensetivity,	0 },
     37 +	{ 0, 				  	+scrollsensetivity },
     38 +	{ 0, 					-scrollsensetivity },
     39 +};
     40 +
     41  /* button definitions */
     42  /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
     43  static Button buttons[] = {
     44 @@ -107,6 +119,10 @@ static Button buttons[] = {
     45  	{ ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
     46  	{ ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
     47  	{ ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
     48 +	{ ClkClientWin,         MODKEY,         Button4,        resizemousescroll, {.v = &scrollargs[0]} },
     49 +	{ ClkClientWin,         MODKEY,         Button5,        resizemousescroll, {.v = &scrollargs[1]} },
     50 +	{ ClkClientWin,         MODKEY,         Button6,        resizemousescroll, {.v = &scrollargs[2]} },
     51 +	{ ClkClientWin,         MODKEY,         Button7,        resizemousescroll, {.v = &scrollargs[3]} },
     52  	{ ClkTagBar,            0,              Button1,        view,           {0} },
     53  	{ ClkTagBar,            0,              Button3,        toggleview,     {0} },
     54  	{ ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
     55 diff --git a/dwm.c b/dwm.c
     56 index 9fd0286..30f14db 100644
     57 --- a/dwm.c
     58 +++ b/dwm.c
     59 @@ -57,6 +57,12 @@
     60  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
     61  #define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
     62  
     63 +/* Undefined in X11/X.h buttons that are actualy exist and correspond to
     64 + * horizontal scroll
     65 + */
     66 +#define Button6			6
     67 +#define Button7			7
     68 +
     69  /* enums */
     70  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
     71  enum { SchemeNorm, SchemeSel }; /* color schemes */
     72 @@ -192,6 +198,7 @@ static Monitor *recttomon(int x, int y, int w, int h);
     73  static void resize(Client *c, int x, int y, int w, int h, int interact);
     74  static void resizeclient(Client *c, int x, int y, int w, int h);
     75  static void resizemouse(const Arg *arg);
     76 +static void resizemousescroll(const Arg *arg);
     77  static void restack(Monitor *m);
     78  static void run(void);
     79  static void scan(void);
     80 @@ -1345,6 +1352,45 @@ resizemouse(const Arg *arg)
     81  	}
     82  }
     83  
     84 +void
     85 +resizemousescroll(const Arg *arg)
     86 +{
     87 +	int nw, nh;
     88 +	Client *c;
     89 +	Monitor *m;
     90 +	XEvent ev;
     91 +	int dw = *((int*)arg->v + 1);
     92 +	int dh = *(int*)arg->v;
     93 +
     94 +	if (!(c = selmon->sel))
     95 +		return;
     96 +	if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */
     97 +		return;
     98 +	restack(selmon);
     99 +	if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
    100 +		None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess)
    101 +		return;
    102 +	nw = MAX(c->w + dw, 1);
    103 +	nh = MAX(c->h + dh, 1);
    104 +	if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww
    105 +	&& c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh)
    106 +	{
    107 +		if (!c->isfloating && selmon->lt[selmon->sellt]->arrange
    108 +		&& (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
    109 +			togglefloating(NULL);
    110 +	}
    111 +	if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
    112 +		resize(c, c->x, c->y, nw, nh, 1);
    113 +	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
    114 +	XUngrabPointer(dpy, CurrentTime);
    115 +	while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
    116 +	if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
    117 +		sendmon(c, m);
    118 +		selmon = m;
    119 +		focus(NULL);
    120 +	}
    121 +}
    122 +
    123  void
    124  restack(Monitor *m)
    125  {
    126 -- 
    127 2.28.0
    128