sites

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

tabbed-drag-20230128-41e2b8f.diff (1981B)


      1 From caf61ed5c47b32938bea4a0577f4f6953ddd1578 Mon Sep 17 00:00:00 2001
      2 From: Casey Fitzpatrick <kcghost@gmail.com>
      3 Date: Fri, 27 Jan 2023 19:46:05 -0500
      4 Subject: [PATCH] Support draggable tabs
      5 
      6 ---
      7  tabbed.c | 39 ++++++++++++++++++++++++++++++++++++++-
      8  1 file changed, 38 insertions(+), 1 deletion(-)
      9 
     10 diff --git a/tabbed.c b/tabbed.c
     11 index eafe28a..2e3b61a 100644
     12 --- a/tabbed.c
     13 +++ b/tabbed.c
     14 @@ -88,6 +88,7 @@ typedef struct {
     15  
     16  /* function declarations */
     17  static void buttonpress(const XEvent *e);
     18 +static void motionnotify(const XEvent *e);
     19  static void cleanup(void);
     20  static void clientmessage(const XEvent *e);
     21  static void configurenotify(const XEvent *e);
     22 @@ -151,6 +152,7 @@ static void (*handler[LASTEvent]) (const XEvent *) = {
     23  	[KeyPress] = keypress,
     24  	[MapRequest] = maprequest,
     25  	[PropertyNotify] = propertynotify,
     26 +	[MotionNotify] = motionnotify,
     27  };
     28  static int bh, obh, wx, wy, ww, wh;
     29  static unsigned int numlockmask;
     30 @@ -209,6 +211,41 @@ buttonpress(const XEvent *e)
     31  	}
     32  }
     33  
     34 +void
     35 +motionnotify(const XEvent *e)
     36 +{
     37 +	const XMotionEvent *ev = &e->xmotion;
     38 +	int i, fc;
     39 +	Arg arg;
     40 +
     41 +	if (ev->y < 0 || ev->y > bh)
     42 +		return;
     43 +
     44 +	if (! (ev->state & Button1Mask)) {
     45 +		return;
     46 +	}
     47 +
     48 +	if (((fc = getfirsttab()) > 0 && ev->x < TEXTW(before)) || ev->x < 0)
     49 +		return;
     50 +
     51 +	if (sel < 0)
     52 +		return;
     53 +
     54 +	for (i = fc; i < nclients; i++) {
     55 +		if (clients[i]->tabx > ev->x) {
     56 +			if (i == sel+1) {
     57 +				arg.i = 1;
     58 +				movetab(&arg);
     59 +			}
     60 +			if (i == sel-1) {
     61 +				arg.i = -1;
     62 +				movetab(&arg);
     63 +			}
     64 +			break;
     65 +		}
     66 +	}
     67 +}
     68 +
     69  void
     70  cleanup(void)
     71  {
     72 @@ -1046,7 +1083,7 @@ setup(void)
     73  	XSelectInput(dpy, win, SubstructureNotifyMask | FocusChangeMask |
     74  	             ButtonPressMask | ExposureMask | KeyPressMask |
     75  	             PropertyChangeMask | StructureNotifyMask |
     76 -	             SubstructureRedirectMask);
     77 +	             SubstructureRedirectMask | ButtonMotionMask);
     78  	xerrorxlib = XSetErrorHandler(xerror);
     79  
     80  	class_hint.res_name = wmname;
     81 -- 
     82 2.25.1
     83