sites

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

dwm-gestures-6.4.diff (3736B)


      1 diff -up a/config.def.h b/config.def.h
      2 --- a/config.def.h	2023-01-13 15:14:16.536118429 +0100
      3 +++ b/config.def.h	2023-01-13 15:21:25.946360539 +0100
      4 @@ -78,6 +78,7 @@ static const Key keys[] = {
      5  	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
      6  	{ MODKEY,                       XK_space,  setlayout,      {0} },
      7  	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
      8 +	{ MODKEY,                       XK_g,      gesture,        {0} },
      9  	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
     10  	{ MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
     11  	{ MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
     12 @@ -107,9 +108,21 @@ static const Button buttons[] = {
     13  	{ ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
     14  	{ ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
     15  	{ ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
     16 +    	{ ClkClientWin,         MODKEY|ShiftMask,Button3,       gesture,        {0} },
     17  	{ ClkTagBar,            0,              Button1,        view,           {0} },
     18  	{ ClkTagBar,            0,              Button3,        toggleview,     {0} },
     19  	{ ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
     20  	{ ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
     21  };
     22 
     23 +/* gestures
     24 + * u means up
     25 + * d means down
     26 + * l means left
     27 + * r means right
     28 + * ud means up and down
     29 + */
     30 +static Gesture gestures[] = {
     31 +	{ "u",  spawn, {.v = termcmd } },
     32 +	{ "d",  spawn, {.v = dmenucmd } },
     33 +};
     34 diff -up a/dwm.c b/dwm.c
     35 --- a/dwm.c	2023-01-13 15:14:16.536118429 +0100
     36 +++ b/dwm.c	2023-01-13 15:14:41.094075080 +0100
     37 @@ -75,6 +75,12 @@ typedef union {
     38  } Arg;
     39 
     40  typedef struct {
     41 +    char *gname;
     42 + 	void (*func)(const Arg *arg);
     43 + 	const Arg arg;
     44 +} Gesture;
     45 +
     46 +typedef struct {
     47  	unsigned int click;
     48  	unsigned int mask;
     49  	unsigned int button;
     50 @@ -183,6 +189,7 @@ static void mappingnotify(XEvent *e);
     51  static void maprequest(XEvent *e);
     52  static void monocle(Monitor *m);
     53  static void motionnotify(XEvent *e);
     54 +static void gesture(const Arg *arg);
     55  static void movemouse(const Arg *arg);
     56  static Client *nexttiled(Client *c);
     57  static void pop(Client *c);
     58 @@ -1134,6 +1141,68 @@ motionnotify(XEvent *e)
     59  }
     60 
     61  void
     62 +gesture(const Arg *arg) {
     63 +	int x, y, dx, dy, q;
     64 +	int valid=0, listpos=0, gestpos=0, count=0;
     65 +	char move, currGest[10];
     66 +	XEvent ev;
     67 +
     68 +	if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
     69 +		None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess)
     70 +		return;
     71 +	if(!getrootptr(&x, &y))
     72 +		return;
     73 +	do {
     74 +		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
     75 +		switch (ev.type) {
     76 +			case ConfigureRequest:
     77 +			case Expose:
     78 +			case MapRequest:
     79 +				handler[ev.type](&ev);
     80 +				break;
     81 +			case MotionNotify:
     82 +				if(count++ < 10)
     83 +					break;
     84 +				count = 0;
     85 +				dx = ev.xmotion.x - x;
     86 +				dy = ev.xmotion.y - y;
     87 +				x = ev.xmotion.x;
     88 +				y = ev.xmotion.y;
     89 +
     90 +				if( abs(dx)/(abs(dy)+1) == 0 )
     91 +					move = dy<0?'u':'d';
     92 +				else
     93 +					move = dx<0?'l':'r';
     94 +
     95 +				if(move!=currGest[gestpos-1])
     96 +				{
     97 +					if(gestpos>9)
     98 +					{	ev.type++;
     99 +						break;
    100 +					}
    101 +
    102 +					currGest[gestpos] = move;
    103 +					currGest[++gestpos] = '\0';
    104 +
    105 +					valid = 0;
    106 +					for(q = 0; q<LENGTH(gestures); q++)
    107 +					{	if(!strcmp(currGest, gestures[q].gname))
    108 +						{	valid++;
    109 +							listpos = q;
    110 +						}
    111 +					}
    112 +				}
    113 +
    114 +		}
    115 +	} while(ev.type != ButtonRelease);
    116 +
    117 +	if(valid)
    118 +		gestures[listpos].func(&(gestures[listpos].arg));
    119 +
    120 +	XUngrabPointer(dpy, CurrentTime);
    121 +}
    122 +
    123 +void
    124  movemouse(const Arg *arg)
    125  {
    126  	int x, y, ocx, ocy, nx, ny;