From 813717224baa0fe02c85ab0e27ea235b71e4e636 Mon Sep 17 00:00:00 2001 From: Alexis Jhon Gaspar Date: Wed, 1 Nov 2023 23:07:38 +0800 Subject: [PATCH] Add tabbed patches not included in upstream --- tabbed-flexipatch/config.def.h | 3 +++ tabbed-flexipatch/patch/drag.c | 34 +++++++++++++++++++++++++++++++ tabbed-flexipatch/patch/drag.h | 1 + tabbed-flexipatch/patch/include.c | 5 ++++- tabbed-flexipatch/patch/include.h | 5 ++++- tabbed-flexipatch/patches.def.h | 17 ++++++++++++++++ tabbed-flexipatch/tabbed.c | 31 +++++++++++++++++++++++++--- 7 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 tabbed-flexipatch/patch/drag.c create mode 100644 tabbed-flexipatch/patch/drag.h diff --git a/tabbed-flexipatch/config.def.h b/tabbed-flexipatch/config.def.h index aa7953f..92de326 100644 --- a/tabbed-flexipatch/config.def.h +++ b/tabbed-flexipatch/config.def.h @@ -18,6 +18,9 @@ static const int tabwidth = 200; #endif // AWESOMEBAR_PATCH static const Bool foreground = True; static Bool urgentswitch = False; +#if SEPERATOR_PATCH +static const int separator = 1; +#endif // SEPERATOR_PATCH #if BAR_HEIGHT_PATCH static const int barheight = 0; /* 0 means derive by font (default), otherwise absolute height */ diff --git a/tabbed-flexipatch/patch/drag.c b/tabbed-flexipatch/patch/drag.c new file mode 100644 index 0000000..e8ed39b --- /dev/null +++ b/tabbed-flexipatch/patch/drag.c @@ -0,0 +1,34 @@ +void +motionnotify(const XEvent *e) +{ + const XMotionEvent *ev = &e->xmotion; + int i, fc; + Arg arg; + + if (ev->y < 0 || ev->y > bh) + return; + + if (! (ev->state & Button1Mask)) { + return; + } + + if (((fc = getfirsttab()) > 0 && ev->x < TEXTW(before)) || ev->x < 0) + return; + + if (sel < 0) + return; + + for (i = fc; i < nclients; i++) { + if (clients[i]->tabx > ev->x) { + if (i == sel+1) { + arg.i = 1; + movetab(&arg); + } + if (i == sel-1) { + arg.i = -1; + movetab(&arg); + } + break; + } + } +} diff --git a/tabbed-flexipatch/patch/drag.h b/tabbed-flexipatch/patch/drag.h new file mode 100644 index 0000000..47068bc --- /dev/null +++ b/tabbed-flexipatch/patch/drag.h @@ -0,0 +1 @@ +static void motionnotify(const XEvent *e); diff --git a/tabbed-flexipatch/patch/include.c b/tabbed-flexipatch/patch/include.c index 59a24eb..c87d004 100644 --- a/tabbed-flexipatch/patch/include.c +++ b/tabbed-flexipatch/patch/include.c @@ -1,4 +1,7 @@ /* Patches */ +#if DRAG_PATCH +#include "drag.c" +#endif #if HIDETABS_PATCH #include "hidebar.c" #endif @@ -10,4 +13,4 @@ #endif #if XRESOURCES_PATCH #include "xresources.c" -#endif \ No newline at end of file +#endif diff --git a/tabbed-flexipatch/patch/include.h b/tabbed-flexipatch/patch/include.h index 1ef3327..6411530 100644 --- a/tabbed-flexipatch/patch/include.h +++ b/tabbed-flexipatch/patch/include.h @@ -1,4 +1,7 @@ /* Patches */ +#if DRAG_PATCH +#include "drag.h" +#endif #if HIDETABS_PATCH #include "hidebar.h" #endif @@ -10,4 +13,4 @@ #endif #if XRESOURCES_PATCH #include "xresources.h" -#endif \ No newline at end of file +#endif diff --git a/tabbed-flexipatch/patches.def.h b/tabbed-flexipatch/patches.def.h index 912180c..63bc950 100644 --- a/tabbed-flexipatch/patches.def.h +++ b/tabbed-flexipatch/patches.def.h @@ -42,11 +42,22 @@ */ #define CENTER_PATCH 1 +/* With this patch, tabbed interprets large position numbers as the largest known position. + * This allows Ctrl-9, for example, to always select the rightmost tab, even if there are only 4 tabs. + * https://tools.suckless.org/tabbed/patches/move-clamped/ + */ +#define CLAMPEDMOVE_PATCH 1 + /* This patch prints the position number of the client before the window title. * https://tools.suckless.org/tabbed/patches/clientnumber/ */ #define CLIENTNUMBER_PATCH 1 +/* Support dragging tabs left and right with the mouse. + * https://tools.suckless.org/tabbed/patches/drag/ + */ +#define DRAG_PATCH 1 + /* This patch hides all the tabs and only shows them when Mod+Shift is pressed. All functions * with switching, rotating, and creating tabs involve Mod+Shift. When not doing one of these * functions, visibility of the tabs is not needed. @@ -85,6 +96,12 @@ */ #define REPARENT_PATCH 1 +/* Add a decorative separator bar to the beginning of each tab. + * Configure the width via the separator property in config.h. + * https://tools.suckless.org/tabbed/patches/separator/ + */ +#define SEPERATOR_PATCH 0 + /* This patch allows tabbed colors to be defined via Xresources. * https://tools.suckless.org/tabbed/patches/xresources/ */ diff --git a/tabbed-flexipatch/tabbed.c b/tabbed-flexipatch/tabbed.c index 8f15629..ccfe59e 100644 --- a/tabbed-flexipatch/tabbed.c +++ b/tabbed-flexipatch/tabbed.c @@ -172,6 +172,9 @@ static void (*handler[LASTEvent]) (const XEvent *) = { #endif // KEYRELEASE_PATCH [MapRequest] = maprequest, [PropertyNotify] = propertynotify, + #if DRAG_PATCH + [MotionNotify] = motionnotify, + #endif // DRAG_PATCH }; static int bh, obh, wx, wy, ww, wh; #if AUTOHIDE_PATCH || HIDETABS_PATCH @@ -476,10 +479,20 @@ drawtext(const char *text, XftColor col[ColLast]) int i, j, x, y, h, len, olen; char buf[256]; XftDraw *d; + #if SEPERATOR_PATCH + XRectangle tab = { dc.x+separator, dc.y, dc.w-separator, dc.h }; + XRectangle sep = { dc.x, dc.y, separator, dc.h }; + #else XRectangle r = { dc.x, dc.y, dc.w, dc.h }; + #endif // SEPERATOR_PATCH XSetForeground(dpy, dc.gc, col[ColBG].pixel); + #if SEPERATOR_PATCH + XFillRectangles(dpy, dc.drawable, dc.gc, &tab, 1); + #else XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); + #endif // SEPERATOR_PATCH + if (!text) return; @@ -928,8 +941,15 @@ maprequest(const XEvent *e) void move(const Arg *arg) { - if (arg->i >= 0 && arg->i < nclients) - focus(arg->i); + #if CLAMPEDMOVE_PATCH + int i; + i = arg->i < nclients ? arg->i : nclients - 1; + if (i >= 0) + focus(i); + #else + if (arg->i >= 0 && arg->i < nclients) + focus(arg->i); + #endif // CLAMPEDMOVE_PATCH } void @@ -1264,7 +1284,12 @@ setup(void) KeyReleaseMask | #endif // KEYRELEASE_PATCH PropertyChangeMask | StructureNotifyMask | - SubstructureRedirectMask); + #if DRAG_PATCH + SubstructureRedirectMask | ButtonMotionMask + #else + SubstructureRedirectMask + #endif // DRAG_PATCH + ); xerrorxlib = XSetErrorHandler(xerror); class_hint.res_name = wmname;