sites

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

commit d42f88065db1a508c202091071cc1ad021cfa6ce
parent 8e600b83bb3d7b4e8a3cf59c6eaa903cb366c244
Author: Sourav Nayak <nonameblank007@gmail.com>
Date:   Sat, 21 Nov 2026 22:01:01 +0530

[new][dwm][scrollview] a scrolling layout with overview and gapps support

Diffstat:
Adwm.suckless.org/patches/scrollview/dwm-scrollview-1563572.diff | 2729+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adwm.suckless.org/patches/scrollview/index.md | 45+++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 2774 insertions(+), 0 deletions(-)

diff --git a/dwm.suckless.org/patches/scrollview/dwm-scrollview-1563572.diff b/dwm.suckless.org/patches/scrollview/dwm-scrollview-1563572.diff @@ -0,0 +1,2729 @@ +From e0589ff26d5882282ee17d83cd28ccb2d3574a10 Mon Sep 17 00:00:00 2001 +From: Sourav Nayak <nonameblank007@gmail.com> +Date: Sat, 21 Nov 2026 18:24:50 +0530 +Subject: [PATCH] dwm: scrollview 6.8+ + +--- + config.def.h | 214 ++++++++---- + dwm.c | 236 ++++++++++++-- + overview.c | 880 +++++++++++++++++++++++++++++++++++++++++++++++++ + overview.h | 34 ++ + scrollview.c | 907 +++++++++++++++++++++++++++++++++++++++++++++++++++ + scrollview.h | 52 +++ + 6 files changed, 2237 insertions(+), 86 deletions(-) + create mode 100644 overview.c + create mode 100644 overview.h + create mode 100644 scrollview.c + create mode 100644 scrollview.h + +diff --git a/config.def.h b/config.def.h +index a1d9b6f..b67f040 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -46,9 +46,37 @@ static const int refreshrate = 120; /* refresh rate (per second) for client mov + #define FORCE_VSPLIT 1 /* nrowgrid layout: force two clients to always split vertically */ + #include "vanitygaps.c" + ++/* scroller layout settings */ ++static int centermode = CenterOnFlow; /* CenterOnFlow, CenterAlways, CenterNever */ ++static const float winsizes[] = { 0.33333f, 0.50f, 0.66667f, 1.0f }; /* window width presets [0.1..1.0] */ ++static const float defwinw = 0.50f; /* default width factor for multi-window ribbons [0.1..1.0] */ ++static const float swinw = 0.50f; /* default width factor for single window or stack [0.1..1.0] */ ++static const int centerswin = 0; /* 1 means always center single window */ ++static const int scrollstep = 45; /* trackpad and mouse wheel scroll step in pixels */ ++static const int strutleft = 55; /* pixels reserved on left edge for focus jump (0 to disable) */ ++static const int strutright = 55; /* pixels reserved on right edge for focus jump (0 to disable) */ ++static int loopnav = 1; /* 1 means loop navigation */ ++ ++/* overview layout settings */ ++static const int ovgappov = 16; /* vert outer padding between overview area and screen edge */ ++static const int ovgappoh = 24; /* horiz outer padding between overview ribbons and screen edge */ ++static const int ovlayergap = 14; /* vert gap between workspace layers */ ++static const int ovinpady = 6; /* vert inner padding inside workspace layer */ ++static const int ovgappih = 8; /* horiz gap between miniature windows */ ++static const int ovgappiv = 4; /* vert gap between stacked window panes */ ++static const float ovsingleh = 0.45f; /* single layer window height factor */ ++static const int ovuniformlayer = 1; /* 0 means scale to fit ovmaxfit */ ++static const int ovmaxfit = 4; /* max visible workspace layers before vertical scrolling */ ++static const int ovedgezone = 80; /* edge distance in pixels triggering auto-scroll during drag */ ++static const int ovedgestep = 25; /* auto-scroll step in pixels per motion event during drag */ ++static int ovloopnav = 1; /* 1 means loop navigation */ ++ ++#include "scrollview.c" ++ + static const Layout layouts[] = { + /* symbol arrange function */ + { "[]=", tile }, /* first entry is default */ ++ { "[|||]", scroller }, + { "[M]", monocle }, + { "[@]", spiral }, + { "[\\]", dwindle }, +@@ -61,6 +89,7 @@ static const Layout layouts[] = { + { ":::", gaplessgrid }, + { "|M|", centeredmaster }, + { ">M>", centeredfloatingmaster }, ++ { "[⊞]", overview }, + { "><>", NULL }, /* no layout function means floating behavior */ + { NULL, NULL }, + }; +@@ -68,10 +97,12 @@ static const Layout layouts[] = { + /* key definitions */ + #define MODKEY Mod1Mask + #define TAGKEYS(KEY,TAG) \ +- { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ +- { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ +- { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ +- { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, ++ { Normal, MODKEY, KEY, view, {.ui = 1 << TAG} }, \ ++ { Normal, MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ ++ { Normal, MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ ++ { Normal, MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, \ ++ { Overview, 0, KEY, ovjumptag, {.ui = TAG} }, \ ++ { Overview, MODKEY, KEY, ovjumptag, {.ui = TAG} }, + + /* helper for spawning shell commands in the pre dwm-5.0 fashion */ + #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } +@@ -81,50 +112,92 @@ static char dmenumon[8]; /* component of dmenucmd, manipulated in spawn() */ + static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; + static const char *termcmd[] = { "st", NULL }; + ++#include "overview.c" ++ + static const Key keys[] = { +- /* modifier key function argument */ +- { MODKEY, XK_p, spawn, {.v = dmenucmd } }, +- { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, +- { MODKEY, XK_b, togglebar, {0} }, +- { MODKEY, XK_j, focusstack, {.i = +1 } }, +- { MODKEY, XK_k, focusstack, {.i = -1 } }, +- { MODKEY, XK_i, incnmaster, {.i = +1 } }, +- { MODKEY, XK_d, incnmaster, {.i = -1 } }, +- { MODKEY, XK_h, setmfact, {.f = -0.05} }, +- { MODKEY, XK_l, setmfact, {.f = +0.05} }, +- { MODKEY|ShiftMask, XK_h, setcfact, {.f = +0.25} }, +- { MODKEY|ShiftMask, XK_l, setcfact, {.f = -0.25} }, +- { MODKEY|ShiftMask, XK_o, setcfact, {.f = 0.00} }, +- { MODKEY, XK_Return, zoom, {0} }, +- { MODKEY|Mod4Mask, XK_u, incrgaps, {.i = +1 } }, +- { MODKEY|Mod4Mask|ShiftMask, XK_u, incrgaps, {.i = -1 } }, +- { MODKEY|Mod4Mask, XK_i, incrigaps, {.i = +1 } }, +- { MODKEY|Mod4Mask|ShiftMask, XK_i, incrigaps, {.i = -1 } }, +- { MODKEY|Mod4Mask, XK_o, incrogaps, {.i = +1 } }, +- { MODKEY|Mod4Mask|ShiftMask, XK_o, incrogaps, {.i = -1 } }, +- { MODKEY|Mod4Mask, XK_6, incrihgaps, {.i = +1 } }, +- { MODKEY|Mod4Mask|ShiftMask, XK_6, incrihgaps, {.i = -1 } }, +- { MODKEY|Mod4Mask, XK_7, incrivgaps, {.i = +1 } }, +- { MODKEY|Mod4Mask|ShiftMask, XK_7, incrivgaps, {.i = -1 } }, +- { MODKEY|Mod4Mask, XK_8, incrohgaps, {.i = +1 } }, +- { MODKEY|Mod4Mask|ShiftMask, XK_8, incrohgaps, {.i = -1 } }, +- { MODKEY|Mod4Mask, XK_9, incrovgaps, {.i = +1 } }, +- { MODKEY|Mod4Mask|ShiftMask, XK_9, incrovgaps, {.i = -1 } }, +- { MODKEY|Mod4Mask, XK_0, togglegaps, {0} }, +- { MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} }, +- { MODKEY, XK_Tab, view, {0} }, +- { MODKEY|ShiftMask, XK_c, killclient, {0} }, +- { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, +- { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, +- { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, +- { MODKEY, XK_space, setlayout, {0} }, +- { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, +- { MODKEY, XK_0, view, {.ui = ~0 } }, +- { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, +- { MODKEY, XK_comma, focusmon, {.i = -1 } }, +- { MODKEY, XK_period, focusmon, {.i = +1 } }, +- { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, +- { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, ++ /* mode modifier key function argument */ ++ { Normal, MODKEY, XK_p, spawn, {.v = dmenucmd } }, ++ { Normal, MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, ++ { Normal, MODKEY, XK_b, togglebar, {0} }, ++ { Normal, MODKEY, XK_j, focusstack, {.i = +1 } }, ++ { Normal, MODKEY, XK_k, focusstack, {.i = -1 } }, ++ { Normal, MODKEY, XK_i, incnmaster, {.i = +1 } }, ++ { Normal, MODKEY, XK_d, incnmaster, {.i = -1 } }, ++ { Normal, MODKEY, XK_h, setmfact, {.f = -0.05} }, ++ { Normal, MODKEY, XK_l, setmfact, {.f = +0.05} }, ++ { Normal, MODKEY|ShiftMask, XK_h, setcfact, {.f = +0.25} }, ++ { Normal, MODKEY|ShiftMask, XK_l, setcfact, {.f = -0.25} }, ++ { Normal, MODKEY|ShiftMask, XK_o, setcfact, {.f = 0.00} }, ++ { Normal, MODKEY, XK_Return, zoom, {0} }, ++ { Normal, MODKEY|Mod4Mask, XK_u, incrgaps, {.i = +1 } }, ++ { Normal, MODKEY|Mod4Mask|ShiftMask, XK_u, incrgaps, {.i = -1 } }, ++ { Normal, MODKEY|Mod4Mask, XK_i, incrigaps, {.i = +1 } }, ++ { Normal, MODKEY|Mod4Mask|ShiftMask, XK_i, incrigaps, {.i = -1 } }, ++ { Normal, MODKEY|Mod4Mask, XK_o, incrogaps, {.i = +1 } }, ++ { Normal, MODKEY|Mod4Mask|ShiftMask, XK_o, incrogaps, {.i = -1 } }, ++ { Normal, MODKEY|Mod4Mask, XK_6, incrihgaps, {.i = +1 } }, ++ { Normal, MODKEY|Mod4Mask|ShiftMask, XK_6, incrihgaps, {.i = -1 } }, ++ { Normal, MODKEY|Mod4Mask, XK_7, incrivgaps, {.i = +1 } }, ++ { Normal, MODKEY|Mod4Mask|ShiftMask, XK_7, incrivgaps, {.i = -1 } }, ++ { Normal, MODKEY|Mod4Mask, XK_8, incrohgaps, {.i = +1 } }, ++ { Normal, MODKEY|Mod4Mask|ShiftMask, XK_8, incrohgaps, {.i = -1 } }, ++ { Normal, MODKEY|Mod4Mask, XK_9, incrovgaps, {.i = +1 } }, ++ { Normal, MODKEY|Mod4Mask|ShiftMask, XK_9, incrovgaps, {.i = -1 } }, ++ { Normal, MODKEY|Mod4Mask, XK_0, togglegaps, {0} }, ++ { Normal, MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} }, ++ { Normal, MODKEY, XK_Tab, view, {0} }, ++ { Normal, MODKEY|ShiftMask, XK_c, killclient, {0} }, ++ { Normal, MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, ++ { Normal, MODKEY, XK_s, setlayout, {.v = &layouts[1]} }, ++ { Normal, MODKEY, XK_f, setlayout, {.v = &layouts[2]} }, ++ { Normal, MODKEY, XK_m, setlayout, {.v = &layouts[3]} }, ++ { Normal, MODKEY, XK_space, setlayout, {0} }, ++ { Normal, MODKEY|ShiftMask, XK_space, togglefloating, {0} }, ++ { Normal, MODKEY, XK_0, view, {.ui = ~0 } }, ++ { Normal, MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, ++ { Normal, MODKEY, XK_comma, focusmon, {.i = -1 } }, ++ { Normal, MODKEY, XK_period, focusmon, {.i = +1 } }, ++ { Normal, MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, ++ { Normal, MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, ++ ++ /* scroll */ ++ { Scroll, MODKEY, XK_Left, scrollwin, {.i = -1} }, ++ { Scroll, MODKEY, XK_Right, scrollwin, {.i = +1} }, ++ { Scroll, MODKEY, XK_Up, focuswinstack, {.i = -1} }, ++ { Scroll, MODKEY, XK_Down, focuswinstack, {.i = +1} }, ++ { Scroll, MODKEY, XK_Tab, toggleov, {0} }, ++ { Scroll, MODKEY, XK_o, toggleov, {0} }, ++ { Scroll, MODKEY, XK_w, togglestack, {0} }, ++ { Scroll, MODKEY, XK_r, cyclewinwidth, {0} }, ++ { Scroll, MODKEY, XK_c, centerfocused, {0} }, ++ { Scroll, MODKEY|ShiftMask, XK_c, togglecentering, {0} }, ++ { Scroll, MODKEY|ShiftMask, XK_Left, movewin, {.i = -1} }, ++ { Scroll, MODKEY|ShiftMask, XK_Right, movewin, {.i = +1} }, ++ { Scroll, MODKEY|ShiftMask, XK_Up, movewinstack, {.i = -1} }, ++ { Scroll, MODKEY|ShiftMask, XK_Down, movewinstack, {.i = +1} }, ++ { Scroll, MODKEY|ControlMask, XK_n, toggleloopnav, {0} }, ++ ++ /* overview */ ++ { Overview, 0, XK_Escape, toggleov, {0} }, ++ { Overview, 0, XK_Return, zoomov, {0} }, ++ { Overview, MODKEY, XK_Return, zoomov, {0} }, ++ { Overview, 0, XK_Up, focusovlayer, {.i = -1} }, ++ { Overview, 0, XK_Down, focusovlayer, {.i = +1} }, ++ { Overview, 0, XK_k, focusovlayer, {.i = -1} }, ++ { Overview, 0, XK_j, focusovlayer, {.i = +1} }, ++ { Overview, 0, XK_Left, focusovwin, {.i = -1} }, ++ { Overview, 0, XK_Right, focusovwin, {.i = +1} }, ++ { Overview, 0, XK_h, focusovwin, {.i = -1} }, ++ { Overview, 0, XK_l, focusovwin, {.i = +1} }, ++ { Overview, MODKEY|ShiftMask, XK_Left, ovmovewin, {.i = -1} }, ++ { Overview, MODKEY|ShiftMask, XK_Right, ovmovewin, {.i = +1} }, ++ { Overview, MODKEY|ShiftMask, XK_h, ovmovewin, {.i = -1} }, ++ { Overview, MODKEY|ShiftMask, XK_l, ovmovewin, {.i = +1} }, ++ { Overview, MODKEY|ShiftMask, XK_Up, ovmovewinlayer, {.i = -1} }, ++ { Overview, MODKEY|ShiftMask, XK_Down, ovmovewinlayer, {.i = +1} }, ++ { Overview, MODKEY|ShiftMask, XK_k, ovmovewinlayer, {.i = -1} }, ++ { Overview, MODKEY|ShiftMask, XK_j, ovmovewinlayer, {.i = +1} }, ++ { Overview, MODKEY, XK_n, toggleovloopnav,{0} }, + TAGKEYS( XK_1, 0) + TAGKEYS( XK_2, 1) + TAGKEYS( XK_3, 2) +@@ -134,23 +207,44 @@ static const Key keys[] = { + TAGKEYS( XK_7, 6) + TAGKEYS( XK_8, 7) + TAGKEYS( XK_9, 8) +- { MODKEY|ShiftMask, XK_q, quit, {0} }, ++ { Normal, MODKEY|ShiftMask, XK_q, quit, {0} }, ++ + }; + + /* button definitions */ + /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ + static const Button buttons[] = { +- /* click event mask button function argument */ +- { ClkLtSymbol, 0, Button1, setlayout, {0} }, +- { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, +- { ClkWinTitle, 0, Button2, zoom, {0} }, +- { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, +- { ClkClientWin, MODKEY, Button1, movemouse, {0} }, +- { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, +- { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, +- { ClkTagBar, 0, Button1, view, {0} }, +- { ClkTagBar, 0, Button3, toggleview, {0} }, +- { ClkTagBar, MODKEY, Button1, tag, {0} }, +- { ClkTagBar, MODKEY, Button3, toggletag, {0} }, ++ /* mode click event mask button function argument */ ++ { Normal, ClkLtSymbol, 0, Button1, setlayout, {0} }, ++ { Normal, ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, ++ { Normal, ClkWinTitle, 0, Button2, zoom, {0} }, ++ { Normal, ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, ++ { All, ClkClientWin, MODKEY, Button1, dragdrop, {0} }, ++ { Normal, ClkClientWin, MODKEY, Button2, togglefloating, {0} }, ++ { All, ClkClientWin, MODKEY, Button3, resizemouse, {0} }, ++ { Normal, ClkTagBar, 0, Button1, view, {0} }, ++ { Normal, ClkTagBar, 0, Button3, toggleview, {0} }, ++ { Normal, ClkTagBar, MODKEY, Button1, tag, {0} }, ++ { Normal, ClkTagBar, MODKEY, Button3, toggletag, {0} }, ++ { Scroll, ClkClientWin, MODKEY, Button4, scrollwin, {.i = -1} }, ++ { Scroll, ClkClientWin, MODKEY, Button5, scrollwin, {.i = +1} }, ++ { Scroll, ClkRootWin, MODKEY, Button4, scrollwin, {.i = -1} }, ++ { Scroll, ClkRootWin, MODKEY, Button5, scrollwin, {.i = +1} }, ++ { Scroll, ClkClientWin, MODKEY, 6, trackscroll, {.i = -1} }, ++ { Scroll, ClkClientWin, MODKEY, 7, trackscroll, {.i = +1} }, ++ { Scroll, ClkRootWin, MODKEY, 6, trackscroll, {.i = -1} }, ++ { Scroll, ClkRootWin, MODKEY, 7, trackscroll, {.i = +1} }, ++ { Overview, ClkClientWin, 0, Button4, ovscrollvert, {.i = -1} }, ++ { Overview, ClkClientWin, 0, Button5, ovscrollvert, {.i = +1} }, ++ { Overview, ClkRootWin, 0, Button4, ovscrollvert, {.i = -1} }, ++ { Overview, ClkRootWin, 0, Button5, ovscrollvert, {.i = +1} }, ++ { Overview, ClkClientWin, ShiftMask, Button4, ovscrollribbon, {.i = -1} }, ++ { Overview, ClkClientWin, ShiftMask, Button5, ovscrollribbon, {.i = +1} }, ++ { Overview, ClkRootWin, ShiftMask, Button4, ovscrollribbon, {.i = -1} }, ++ { Overview, ClkRootWin, ShiftMask, Button5, ovscrollribbon, {.i = +1} }, ++ { Overview, ClkClientWin, 0, 6, ovscrollribbon, {.i = -1} }, ++ { Overview, ClkClientWin, 0, 7, ovscrollribbon, {.i = +1} }, ++ { Overview, ClkRootWin, 0, 6, ovscrollribbon, {.i = -1} }, ++ { Overview, ClkRootWin, 0, 7, ovscrollribbon, {.i = +1} }, + }; + +diff --git a/dwm.c b/dwm.c +index da30118..12de80e 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -49,7 +49,7 @@ + #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) + #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \ + * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy))) +-#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags])) ++#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]) || (isov && C->mon == selmon && !C->isfloating)) + #define MOUSEMASK (BUTTONMASK|PointerMotionMask) + #define WIDTH(X) ((X)->w + 2 * (X)->bw) + #define HEIGHT(X) ((X)->h + 2 * (X)->bw) +@@ -65,6 +65,12 @@ enum { NetSupported, NetWMName, NetWMState, NetWMCheck, + enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ + enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, + ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ ++enum { ++ Normal = 1 << 0, /* active in all layouts except overview */ ++ Overview = 1 << 1, /* only active in overview layout */ ++ Scroll = 1 << 2, /* only active in scroller layout */ ++ All = Normal | Overview | Scroll /* active in all layouts */ ++}; + + typedef union { + int i; +@@ -74,6 +80,7 @@ typedef union { + } Arg; + + typedef struct { ++ unsigned int mode; + unsigned int click; + unsigned int mask; + unsigned int button; +@@ -87,12 +94,15 @@ struct Client { + char name[256]; + float mina, maxa; + float cfact; ++ float unstacked_cfact; ++ int is_custom_cfact; + int x, y, w, h; + int oldx, oldy, oldw, oldh; + int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid; + int bw, oldbw; + unsigned int tags; + int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; ++ int is_stacked; + Client *next; + Client *snext; + Monitor *mon; +@@ -100,6 +110,7 @@ struct Client { + }; + + typedef struct { ++ unsigned int mode; + unsigned int mod; + KeySym keysym; + void (*func)(const Arg *); +@@ -133,6 +144,9 @@ struct Monitor { + Client *stack; + Monitor *next; + Window barwin; ++ int scroll_x; ++ int prev_ncol; ++ int prev_sel_col; + const Layout *lt[2]; + }; + +@@ -189,6 +203,8 @@ static void monocle(Monitor *m); + static void motionnotify(XEvent *e); + static void movemouse(const Arg *arg); + static Client *nexttiled(Client *c); ++static void ovacquireseat(void); ++static void ovreleaseseat(void); + static void pop(Client *c); + static void propertynotify(XEvent *e); + static void quit(const Arg *arg); +@@ -270,7 +286,12 @@ static Clr **scheme; + static Display *dpy; + static Drw *drw; + static Monitor *mons, *selmon; +-static Window root, wmcheckwin; ++static Window root, wmcheckwin, ov_seat_win; ++static int isov = 0; ++static Time last_button_time = 0; ++ ++#include "scrollview.h" ++#include "overview.h" + + /* configuration, allows nested code to access above variables */ + #include "config.h" +@@ -334,20 +355,25 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) + if (*y + *h + 2 * c->bw < 0) + *y = 0; + } else { +- if (*x >= m->wx + m->ww) ++ if (!isov && m->lt[m->sellt]->arrange != scroller && *x >= m->wx + m->ww) + *x = m->wx + m->ww - WIDTH(c); +- if (*y >= m->wy + m->wh) ++ if (!isov && *y >= m->wy + m->wh) + *y = m->wy + m->wh - HEIGHT(c); +- if (*x + *w + 2 * c->bw <= m->wx) ++ if (!isov && m->lt[m->sellt]->arrange != scroller && *x + *w + 2 * c->bw <= m->wx) + *x = m->wx; +- if (*y + *h + 2 * c->bw <= m->wy) ++ if (!isov && *y + *h + 2 * c->bw <= m->wy) + *y = m->wy; + } +- if (*h < bh) +- *h = bh; +- if (*w < bh) +- *w = bh; +- if (resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) { ++ if (!isov) { ++ if (*h < bh) ++ *h = bh; ++ if (*w < bh) ++ *w = bh; ++ } ++ if (!isov && (resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange)) { ++ int orig_w = *w; ++ int orig_h = *h; ++ + if (!c->hintsvalid) + updatesizehints(c); + /* see last two sentences in ICCCM 4.1.2.3 */ +@@ -379,6 +405,12 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) + *w = MIN(*w, c->maxw); + if (c->maxh) + *h = MIN(*h, c->maxh); ++ ++ /* In tiled/stacked layouts, size hints must never exceed allocated slot bounds */ ++ if (!c->isfloating && c->mon->lt[c->mon->sellt]->arrange) { ++ *w = MAX(1, MIN(*w, orig_w)); ++ *h = MAX(1, MIN(*h, orig_h)); ++ } + } + return *x != c->x || *y != c->y || *w != c->w || *h != c->h; + } +@@ -400,6 +432,11 @@ arrange(Monitor *m) + void + arrangemon(Monitor *m) + { ++ if (isov && m == selmon) { ++ snprintf(m->ltsymbol, sizeof(m->ltsymbol), "[⊞]"); ++ overview(m); ++ return; ++ } + snprintf(m->ltsymbol, sizeof(m->ltsymbol), "%s", m->lt[m->sellt]->symbol); + if (m->lt[m->sellt]->arrange) + m->lt[m->sellt]->arrange(m); +@@ -424,10 +461,11 @@ buttonpress(XEvent *e) + { + unsigned int i, x, click; + Arg arg = {0}; +- Client *c; ++ Client *c = NULL; + Monitor *m; + XButtonPressedEvent *ev = &e->xbutton; + ++ last_button_time = ev->time; + click = ClkRootWin; + /* focus monitor if necessary */ + if ((m = wintomon(ev->window)) && m != selmon) { +@@ -435,7 +473,19 @@ buttonpress(XEvent *e) + selmon = m; + focus(NULL); + } +- if (ev->window == selmon->barwin) { ++ if (isov) { ++ XAllowEvents(dpy, AsyncPointer, CurrentTime); ++ c = wintoclient(ev->window); ++ if (!c) ++ c = getovwin(ev->x_root, ev->y_root); ++ if (c) { ++ focus(c); ++ restack(selmon); ++ click = ClkClientWin; ++ } else { ++ click = ClkRootWin; ++ } ++ } else if (ev->window == selmon->barwin) { + i = x = 0; + do + x += TEXTW(tags[i]); +@@ -455,10 +505,20 @@ buttonpress(XEvent *e) + XAllowEvents(dpy, ReplayPointer, CurrentTime); + click = ClkClientWin; + } ++ unsigned int cur_mode = CURRENT_MODE(); + for (i = 0; i < LENGTH(buttons); i++) + if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button +- && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) ++ && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state) ++ && (buttons[i].mode & cur_mode)) { + buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); ++ return; ++ } ++ if (isov) { ++ if (CLEANMASK(ev->state) == 0) ++ ovclick(c, ev->x_root, ev->y_root, ev->button); ++ } else { ++ XAllowEvents(dpy, AsyncPointer, CurrentTime); ++ } + } + + void +@@ -494,6 +554,8 @@ cleanup(void) + drw_scm_free(drw, scheme[i], 3); + free(scheme); + XDestroyWindow(dpy, wmcheckwin); ++ if (ov_seat_win) ++ XDestroyWindow(dpy, ov_seat_win); + drw_free(drw); + XSync(dpy, False); + XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); +@@ -654,6 +716,7 @@ createmon(void) + m->gappov = gappov; + m->lt[0] = &layouts[0]; + m->lt[1] = &layouts[1 % LENGTH(layouts)]; ++ m->prev_sel_col = -1; + snprintf(m->ltsymbol, sizeof(m->ltsymbol), "%s", layouts[0].symbol); + return m; + } +@@ -671,7 +734,11 @@ destroynotify(XEvent *e) + void + detach(Client *c) + { +- Client **tc; ++ Client **tc, *nxt; ++ ++ nxt = nexttiled(c->next); ++ if (!c->is_stacked && nxt && nxt->is_stacked) ++ nxt->is_stacked = 0; + + for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next); + *tc = c->next; +@@ -775,6 +842,8 @@ enternotify(XEvent *e) + Monitor *m; + XCrossingEvent *ev = &e->xcrossing; + ++ if (isov) ++ return; + if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) + return; + c = wintoclient(ev->window); +@@ -800,11 +869,15 @@ expose(XEvent *e) + void + focus(Client *c) + { ++ XEvent ev; ++ int changed; ++ + if (!c || !ISVISIBLE(c)) + for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext); + if (selmon->sel && selmon->sel != c) + unfocus(selmon->sel, 0); + if (c) { ++ changed = (c != selmon->sel); + if (c->mon != selmon) + selmon = c->mon; + if (c->isurgent) +@@ -817,9 +890,14 @@ focus(Client *c) + } else { + XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + XDeleteProperty(dpy, root, netatom[NetActiveWindow]); ++ changed = 0; + } + selmon->sel = c; + drawbars(); ++ if (changed && selmon->lt[selmon->sellt]->arrange == scroller) { ++ arrangemon(selmon); ++ while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); ++ } + } + + /* there are some broken focus acquiring clients needing extra handling */ +@@ -828,6 +906,11 @@ focusin(XEvent *e) + { + XFocusChangeEvent *ev = &e->xfocus; + ++ if (isov) { ++ if (ev->window != ov_seat_win) ++ ovacquireseat(); ++ return; ++ } + if (selmon->sel && ev->window != selmon->sel->win) + setfocus(selmon->sel); + } +@@ -948,16 +1031,26 @@ grabbuttons(Client *c, int focused) + unsigned int i, j; + unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; + XUngrabButton(dpy, AnyButton, AnyModifier, c->win); +- if (!focused) ++ if (isov) { + XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, ++ BUTTONMASK, GrabModeAsync, GrabModeAsync, None, None); ++ return; ++ } ++ if (!focused) { ++ XGrabButton(dpy, Button1, AnyModifier, c->win, False, ++ BUTTONMASK, GrabModeSync, GrabModeSync, None, None); ++ XGrabButton(dpy, Button2, AnyModifier, c->win, False, + BUTTONMASK, GrabModeSync, GrabModeSync, None, None); ++ XGrabButton(dpy, Button3, AnyModifier, c->win, False, ++ BUTTONMASK, GrabModeSync, GrabModeSync, None, None); ++ } + for (i = 0; i < LENGTH(buttons); i++) +- if (buttons[i].click == ClkClientWin) ++ if (buttons[i].click == ClkClientWin && (buttons[i].mode & (Normal | Scroll))) + for (j = 0; j < LENGTH(modifiers); j++) + XGrabButton(dpy, buttons[i].button, + buttons[i].mask | modifiers[j], + c->win, False, BUTTONMASK, +- GrabModeAsync, GrabModeSync, None, None); ++ GrabModeAsync, GrabModeAsync, None, None); + } + } + +@@ -978,8 +1071,7 @@ grabkeys(void) + return; + for (k = start; k <= end; k++) + for (i = 0; i < LENGTH(keys); i++) +- /* skip modifier codes, we do that ourselves */ +- if (keys[i].keysym == syms[(k - start) * skip]) ++ if ((keys[i].mode & (Normal | Scroll)) && keys[i].keysym == syms[(k - start) * skip]) + for (j = 0; j < LENGTH(modifiers); j++) + XGrabKey(dpy, k, + keys[i].mod | modifiers[j], +@@ -1014,14 +1106,29 @@ keypress(XEvent *e) + unsigned int i; + KeySym keysym; + XKeyEvent *ev; ++ unsigned int current_mode = CURRENT_MODE(); + + ev = &e->xkey; + keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); +- for (i = 0; i < LENGTH(keys); i++) +- if (keysym == keys[i].keysym ++ for (i = 0; i < LENGTH(keys); i++) { ++ if (keys[i].mode == current_mode ++ && keysym == keys[i].keysym + && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) +- && keys[i].func) ++ && keys[i].func) { + keys[i].func(&(keys[i].arg)); ++ return; ++ } ++ } ++ ++ for (i = 0; i < LENGTH(keys); i++) { ++ if ((keys[i].mode & current_mode) ++ && keysym == keys[i].keysym ++ && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) ++ && keys[i].func) { ++ keys[i].func(&(keys[i].arg)); ++ return; ++ } ++ } + } + + void +@@ -1055,7 +1162,6 @@ manage(Window w, XWindowAttributes *wa) + c->w = c->oldw = wa->width; + c->h = c->oldh = wa->height; + c->oldbw = wa->border_width; +- c->cfact = 1.0; + + updatetitle(c); + if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) { +@@ -1066,6 +1172,10 @@ manage(Window w, XWindowAttributes *wa) + applyrules(c); + } + ++ c->cfact = defwinw; ++ c->unstacked_cfact = defwinw; ++ c->is_custom_cfact = 0; ++ + if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww) + c->x = c->mon->wx + c->mon->ww - WIDTH(c); + if (c->y + HEIGHT(c) > c->mon->wy + c->mon->wh) +@@ -1098,6 +1208,8 @@ manage(Window w, XWindowAttributes *wa) + c->mon->sel = c; + arrange(c->mon); + XMapWindow(dpy, c->win); ++ if (isov) ++ setov(0); + focus(NULL); + } + +@@ -1164,10 +1276,18 @@ movemouse(const Arg *arg) + XEvent ev; + Time lasttime = 0; + ++ if (isov) { ++ dragdrop(arg); ++ return; ++ } + if (!(c = selmon->sel)) + return; + if (c->isfullscreen) /* no support moving fullscreen windows by mouse */ + return; ++ if (selmon->lt[selmon->sellt]->arrange == scroller && !c->isfloating) { ++ dragdrop(arg); ++ return; ++ } + restack(selmon); + ocx = c->x; + ocy = c->y; +@@ -1319,6 +1439,10 @@ resizemouse(const Arg *arg) + XEvent ev; + Time lasttime = 0; + ++ if (isov) { ++ ovresizemouse(arg); ++ return; ++ } + if (!(c = selmon->sel)) + return; + if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */ +@@ -1345,10 +1469,23 @@ resizemouse(const Arg *arg) + + nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); + nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); ++ if (selmon->lt[selmon->sellt]->arrange == scroller && !c->isfloating) { ++ int usable_w = selmon->ww - 2 * selmon->gappoh; ++ if (usable_w < 100) usable_w = selmon->ww; ++ float new_cfact = (float)nw / (float)usable_w; ++ if (new_cfact < 0.10f) new_cfact = 0.10f; ++ if (new_cfact > 1.0f) new_cfact = 1.0f; ++ c->cfact = new_cfact; ++ c->unstacked_cfact = new_cfact; ++ c->is_custom_cfact = 1; ++ syncwincfact(c, new_cfact); ++ arrangemon(selmon); ++ continue; ++ } + 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 ++ if (!c->isfloating && selmon->lt[selmon->sellt]->arrange && selmon->lt[selmon->sellt]->arrange != scroller + && (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) + togglefloating(NULL); + } +@@ -1360,6 +1497,12 @@ resizemouse(const Arg *arg) + 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 (selmon->lt[selmon->sellt]->arrange == scroller && !c->isfloating) { ++ arrangemon(selmon); ++ focus(c); ++ XSync(dpy, False); ++ return; ++ } + if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { + sendmon(c, m); + selmon = m; +@@ -1457,6 +1600,21 @@ setclientstate(Client *c, long state) + PropModeReplace, (unsigned char *)data, 2); + } + ++void ++ovacquireseat(void) ++{ ++ if (!isov) ++ return; ++ XSetInputFocus(dpy, ov_seat_win, RevertToParent, CurrentTime); ++ XGrabKeyboard(dpy, ov_seat_win, False, GrabModeAsync, GrabModeAsync, CurrentTime); ++} ++ ++void ++ovreleaseseat(void) ++{ ++ XUngrabKeyboard(dpy, CurrentTime); ++} ++ + int + sendevent(Client *c, Atom proto) + { +@@ -1485,6 +1643,10 @@ sendevent(Client *c, Atom proto) + void + setfocus(Client *c) + { ++ if (isov) { ++ XSetInputFocus(dpy, ov_seat_win, RevertToParent, CurrentTime); ++ return; ++ } + if (!c->neverfocus) + XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); + XChangeProperty(dpy, root, netatom[NetActiveWindow], XA_WINDOW, 32, +@@ -1527,6 +1689,12 @@ setlayout(const Arg *arg) + selmon->sellt ^= 1; + if (arg && arg->v) + selmon->lt[selmon->sellt] = (Layout *)arg->v; ++ if (selmon->lt[selmon->sellt]->arrange == overview) { ++ if (!isov) ++ setov(1); ++ } else if (isov) { ++ setov(0); ++ } + snprintf(selmon->ltsymbol, sizeof(selmon->ltsymbol), "%s", selmon->lt[selmon->sellt]->symbol); + if (selmon->sel) + arrange(selmon); +@@ -1549,6 +1717,10 @@ setcfact(const Arg *arg) { + else if(f < 0.25 || f > 4.0) + return; + c->cfact = f; ++ c->unstacked_cfact = f; ++ c->is_custom_cfact = 1; ++ if (selmon->lt[selmon->sellt]->arrange == scroller) ++ syncwincfact(c, f); + arrange(selmon); + } + +@@ -1629,6 +1801,12 @@ setup(void) + PropModeReplace, (unsigned char *) "dwm", 3); + XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32, + PropModeReplace, (unsigned char *) &wmcheckwin, 1); ++ wa.override_redirect = True; ++ wa.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | FocusChangeMask; ++ ov_seat_win = XCreateWindow(dpy, root, -1, -1, 1, 1, 0, ++ CopyFromParent, InputOnly, CopyFromParent, ++ CWOverrideRedirect | CWEventMask, &wa); ++ XMapWindow(dpy, ov_seat_win); + /* EWMH support per view */ + XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, + PropModeReplace, (unsigned char *) netatom, NetLast); +@@ -1684,6 +1862,10 @@ spawn(const Arg *arg) + if (arg->v == dmenucmd) + snprintf(dmenumon, sizeof(dmenumon), "%d", selmon->num); + ++ if (isov) { ++ ovreleaseseat(); ++ XSync(dpy, False); ++ } + if ((pid = fork()) == -1) { + fprintf(stderr, "dwm: fork failed: %s\n", strerror(errno)); + return; +@@ -2063,7 +2245,9 @@ updatewmhints(Client *c) + void + view(const Arg *arg) + { +- if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) ++ if (isov) ++ setov(0); ++ else if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) + return; + selmon->seltags ^= 1; /* toggle sel tagset */ + if (arg->ui & TAGMASK) +diff --git a/overview.c b/overview.c +new file mode 100644 +index 0000000..ed8951e +--- /dev/null ++++ b/overview.c +@@ -0,0 +1,880 @@ ++#ifndef OVERVIEW_C ++#define OVERVIEW_C ++ ++#include "overview.h" ++#include "scrollview.h" ++ ++static OvLayer g_layers[16]; ++static int g_nlayers = 0; ++static int g_sel_layer = 0; ++static int g_ovscroll_y = 0; ++static int g_ovmaxscroll_y = 0; ++static int g_need_center_sel = 1; ++static unsigned int saved_ovtags = 0; ++static const Layout *saved_ovlayout = NULL; ++ ++static inline void ++restore_ovlayout(void) ++{ ++ const Layout *lt = (saved_ovlayout && saved_ovlayout->arrange != overview) ++ ? saved_ovlayout : &layouts[0]; ++ saved_ovlayout = NULL; ++ if (selmon->lt[selmon->sellt]->arrange == overview) ++ setlayout(&(Arg){.v = (void *)lt}); ++} ++ ++static inline int ++layer_by_tag(unsigned int tagmask) ++{ ++ for (int i = 0; i < g_nlayers; i++) ++ if (tagmask & (1 << g_layers[i].tag)) ++ return i; ++ return -1; ++} ++ ++static inline int ++sync_sel_layer(void) ++{ ++ int l = selmon->sel ? layer_by_tag(selmon->sel->tags) : -1; ++ if (l < 0) ++ l = (g_sel_layer >= 0 && g_sel_layer < g_nlayers) ? g_sel_layer : 0; ++ return g_sel_layer = l; ++} ++ ++static inline void ++ovfocuswin(Client *c) ++{ ++ if (!c) return; ++ focus(c); ++ restack(selmon); ++ g_need_center_sel = 1; ++ arrangemon(selmon); ++} ++ ++static void ++setov(int enable) ++{ ++ if (isov == enable) ++ return; ++ isov = enable; ++ if (enable) { ++ g_ovscroll_y = 0; ++ g_ovmaxscroll_y = 0; ++ g_need_center_sel = 1; ++ ovacquireseat(); ++ for (Monitor *m = mons; m; m = m->next) ++ for (Client *c = m->clients; c; c = c->next) ++ grabbuttons(c, 0); ++ } else { ++ ovreleaseseat(); ++ grabkeys(); ++ restore_ovlayout(); ++ for (Monitor *m = mons; m; m = m->next) ++ for (Client *c = m->clients; c; c = c->next) ++ grabbuttons(c, c == m->sel); ++ if (selmon->sel) ++ focus(selmon->sel); ++ } ++} ++ ++static void ++toggleov(const Arg *arg) ++{ ++ if (isov) { ++ setov(0); ++ if (saved_ovtags) ++ selmon->tagset[selmon->seltags] = saved_ovtags; ++ focus(NULL); ++ arrange(selmon); ++ } else { ++ saved_ovtags = selmon->tagset[selmon->seltags]; ++ saved_ovlayout = selmon->lt[selmon->sellt]; ++ g_sel_layer = MAX(0, layer_by_tag(saved_ovtags)); ++ for (int i = 0; i < LENGTH(layouts); i++) { ++ if (layouts[i].arrange == overview) { ++ selmon->lt[selmon->sellt] = (Layout *)&layouts[i]; ++ break; ++ } ++ } ++ g_ovscroll_y = 0; ++ g_ovmaxscroll_y = 0; ++ g_need_center_sel = 1; ++ setov(1); ++ arrange(selmon); ++ } ++} ++ ++static int ++getlayercols(Monitor *m, unsigned int tagmask, Client *skip, Column cols[MAX_COLS]) ++{ ++ int ncol = 0; ++ if (!m) ++ return 0; ++ ++ for (Client *c = m->clients; c; c = c->next) { ++ if (c == skip || c->isfloating || !(c->tags & tagmask)) ++ continue; ++ if (ncol == 0 || !c->is_stacked) { ++ if (ncol < MAX_COLS) { ++ cols[ncol].clients[0] = c; ++ cols[ncol].count = 1; ++ ncol++; ++ } ++ } else { ++ if (cols[ncol - 1].count < MAX_COL_CLIENTS) ++ cols[ncol - 1].clients[cols[ncol - 1].count++] = c; ++ } ++ } ++ return ncol; ++} ++ ++static void ++focusovwindir(int dir) ++{ ++ if (g_nlayers == 0) ++ return; ++ ++ int cur_layer = sync_sel_layer(); ++ Column cols[MAX_COLS]; ++ int ncol = getlayercols(selmon, 1 << g_layers[cur_layer].tag, NULL, cols); ++ if (ncol == 0) ++ return; ++ ++ int cur_row = 0; ++ int cur_col = find_col_row(cols, ncol, selmon->sel, &cur_row); ++ ++ int target_col; ++ if (cur_col == -1) { ++ target_col = (dir > 0) ? 0 : ncol - 1; ++ } else { ++ target_col = NAV_WRAP(cur_col, dir, ncol, ovloopnav); ++ if (target_col == cur_col) ++ return; ++ } ++ int target_row = (cur_col == -1) ? 0 : MIN(cur_row, cols[target_col].count - 1); ++ ++ ovfocuswin(cols[target_col].clients[target_row]); ++} ++ ++static void ++focusovlayerdir(int dir) ++{ ++ if (g_nlayers == 0) ++ return; ++ ++ int cur_layer = sync_sel_layer(); ++ Column cols[MAX_COLS]; ++ int ncol = getlayercols(selmon, 1 << g_layers[cur_layer].tag, NULL, cols); ++ ++ int cur_row = 0; ++ int cur_col = find_col_row(cols, ncol, selmon->sel, &cur_row); ++ ++ if (cur_col != -1 && cols[cur_col].count > 1) { ++ if ((dir < 0 && cur_row > 0) || (dir > 0 && cur_row < cols[cur_col].count - 1)) { ++ ovfocuswin(cols[cur_col].clients[cur_row + dir]); ++ return; ++ } ++ } ++ ++ if (g_nlayers > 1) { ++ int target_layer = NAV_WRAP(cur_layer, dir, g_nlayers, ovloopnav); ++ if (target_layer == cur_layer) ++ return; ++ Column target_cols[MAX_COLS]; ++ int target_ncol = getlayercols(selmon, 1 << g_layers[target_layer].tag, NULL, target_cols); ++ ++ if (target_ncol > 0) { ++ int tcol = CLAMP(cur_col < 0 ? 0 : cur_col, 0, target_ncol - 1); ++ int trow = (dir > 0) ? 0 : (target_cols[tcol].count - 1); ++ Client *target_win = target_cols[tcol].clients[MIN(trow, target_cols[tcol].count - 1)]; ++ if (target_win) { ++ focus(target_win); ++ restack(selmon); ++ } ++ } ++ g_sel_layer = target_layer; ++ g_need_center_sel = 1; ++ arrangemon(selmon); ++ return; ++ } ++ ++ if (cur_col != -1 && cols[cur_col].count > 1) { ++ if (!ovloopnav) ++ return; ++ int trow = (dir < 0) ? (cols[cur_col].count - 1) : 0; ++ ovfocuswin(cols[cur_col].clients[trow]); ++ } else { ++ focusovwindir(dir); ++ } ++} ++ ++static void ++ovjumptagidx(int tag_idx) ++{ ++ int l = layer_by_tag(1 << tag_idx); ++ if (l >= 0) { ++ g_sel_layer = l; ++ if (g_layers[l].first_win) ++ focus(g_layers[l].first_win); ++ g_need_center_sel = 1; ++ arrangemon(selmon); ++ return; ++ } ++ view(&(Arg){.ui = 1 << tag_idx}); ++} ++ ++static void ++zoomovsel(void) ++{ ++ if (g_nlayers == 0) { ++ toggleov(NULL); ++ return; ++ } ++ ++ int tag = g_layers[g_sel_layer].tag; ++ Client *c = selmon->sel; ++ view(&(Arg){.ui = 1 << tag}); ++ restore_ovlayout(); ++ focus((c && (c->tags & (1 << tag))) ? c : g_layers[g_sel_layer].first_win); ++ restack(selmon); ++} ++ ++static void ++zoomovwin(Client *c) ++{ ++ if (!c) ++ return; ++ view(&(Arg){.ui = c->tags}); ++ restore_ovlayout(); ++ focus(c); ++ restack(selmon); ++} ++ ++static int ++getovexactlayertag(int px, int py) ++{ ++ for (int i = 0; i < g_nlayers; i++) { ++ if (py >= g_layers[i].y && py < g_layers[i].y + g_layers[i].h) ++ return g_layers[i].tag; ++ } ++ return -1; ++} ++ ++static Client * ++getovwin(int px, int py) ++{ ++ int tag = getovexactlayertag(px, py); ++ if (tag < 0) ++ return NULL; ++ unsigned int tagmask = 1 << tag; ++ for (Client *c = selmon->clients; c; c = c->next) { ++ if (!c->isfloating && (c->tags & tagmask) && ++ px >= c->x && px < c->x + c->w + 2 * c->bw && ++ py >= c->y && py < c->y + c->h + 2 * c->bw) ++ return c; ++ } ++ return NULL; ++} ++ ++static int ++getovlayertag(int px, int py) ++{ ++ int best_tag = -1; ++ long min_dy = -1; ++ ++ for (int i = 0; i < g_nlayers; i++) { ++ if (py >= g_layers[i].y && py < g_layers[i].y + g_layers[i].h) ++ return g_layers[i].tag; ++ ++ int cy = g_layers[i].y + g_layers[i].h / 2; ++ long dy = abs(py - cy); ++ if (min_dy < 0 || dy < min_dy) { ++ min_dy = dy; ++ best_tag = g_layers[i].tag; ++ } ++ } ++ return best_tag; ++} ++ ++static void ++ovdrop(Client *c, int drop_x, int drop_y) ++{ ++ if (!c) ++ return; ++ ++ if (drop_y <= selmon->by + bh) { ++ int i = 0, tx = 0; ++ do { ++ tx += TEXTW(tags[i]); ++ } while (drop_x >= tx && ++i < LENGTH(tags)); ++ if (i < LENGTH(tags)) { ++ c->tags = 1 << i; ++ c->is_stacked = 0; ++ c->cfact = (c->unstacked_cfact > 0.05f) ? c->unstacked_cfact : defwinw; ++ detach(c); ++ attach(c); ++ } ++ } else { ++ int target_tag = getovlayertag(drop_x, drop_y); ++ if (target_tag >= 0) { ++ unsigned int new_tags = 1 << target_tag; ++ Column tag_cols[MAX_COLS]; ++ int tag_ncol = getlayercols(selmon, new_tags, c, tag_cols); ++ ++ c->tags = new_tags; ++ ++ if (tag_ncol == 0) { ++ c->is_stacked = 0; ++ c->cfact = (c->unstacked_cfact > 0.05f) ? c->unstacked_cfact : defwinw; ++ detach(c); ++ attach(c); ++ } else { ++ Client *first_win = tag_cols[0].clients[0]; ++ Client *last_win = tag_cols[tag_ncol - 1].clients[tag_cols[tag_ncol - 1].count - 1]; ++ int left_bound = first_win->x; ++ int right_bound = last_win->x + last_win->w + 2 * last_win->bw; ++ ++ if (drop_x <= left_bound + 10) { ++ c->is_stacked = 0; ++ unstackreorder(c, first_win, InsBefore); ++ } else if (drop_x >= right_bound - 10) { ++ c->is_stacked = 0; ++ unstackreorder(c, last_win, InsAfter); ++ } else { ++ int placed = 0; ++ for (int k = 0; k < tag_ncol; k++) { ++ Client *win_lead = tag_cols[k].clients[0]; ++ int col_x = win_lead->x; ++ int col_w = win_lead->w + 2 * win_lead->bw; ++ int next_col_x = (k + 1 < tag_ncol) ? tag_cols[k + 1].clients[0]->x : right_bound; ++ ++ if (drop_x >= col_x && drop_x < col_x + col_w) { ++ int edge_zone = MAX(20, (int)(col_w * 0.22)); ++ ++ if (drop_x < col_x + edge_zone) { ++ c->is_stacked = 0; ++ unstackreorder(c, win_lead, InsBefore); ++ placed = 1; ++ break; ++ } else if (drop_x > col_x + col_w - edge_zone) { ++ c->is_stacked = 0; ++ unstackreorder(c, tag_cols[k].clients[tag_cols[k].count - 1], InsAfter); ++ placed = 1; ++ break; ++ } else { ++ Client *target_win = win_lead; ++ for (int j = 0; j < tag_cols[k].count; j++) { ++ Client *win = tag_cols[k].clients[j]; ++ if (drop_y >= win->y && drop_y <= win->y + win->h + 2 * win->bw) { ++ target_win = win; ++ break; ++ } ++ } ++ ++ if (drop_y < target_win->y + target_win->h / 3) { ++ c->is_stacked = 1; ++ reorderclient(c, target_win, StkBefore); ++ c->cfact = target_win->cfact; ++ } else if (drop_y > target_win->y + (target_win->h * 2) / 3) { ++ c->is_stacked = 1; ++ reorderclient(c, target_win, StkAfter); ++ c->cfact = target_win->cfact; ++ } else if (drop_x < col_x + col_w / 2) { ++ c->is_stacked = 0; ++ unstackreorder(c, win_lead, InsBefore); ++ } else { ++ c->is_stacked = 0; ++ unstackreorder(c, tag_cols[k].clients[tag_cols[k].count - 1], InsAfter); ++ } ++ placed = 1; ++ break; ++ } ++ } else if (drop_x >= col_x + col_w && drop_x < next_col_x) { ++ c->is_stacked = 0; ++ unstackreorder(c, tag_cols[k].clients[tag_cols[k].count - 1], InsAfter); ++ placed = 1; ++ break; ++ } ++ } ++ ++ if (!placed) { ++ c->is_stacked = 0; ++ unstackreorder(c, last_win, InsAfter); ++ } ++ } ++ } ++ int l = layer_by_tag(new_tags); ++ if (l >= 0) g_sel_layer = l; ++ } ++ } ++ c->x = -9999; ++ c->y = -9999; ++ selmon->sel = c; ++ g_need_center_sel = 1; ++ arrangemon(selmon); ++ focus(c); ++ XSync(dpy, False); ++} ++ ++static void ++focusovlayer(const Arg *arg) ++{ ++ focusovlayerdir(arg->i); ++} ++ ++static void ++focusovwin(const Arg *arg) ++{ ++ focusovwindir(arg->i); ++} ++ ++static void ++ovmovewindir(int dir) ++{ ++ if (!selmon || !selmon->sel || selmon->sel->isfloating || g_nlayers == 0) ++ return; ++ ++ Client *c = selmon->sel; ++ int cur_layer = sync_sel_layer(); ++ if (cur_layer < 0 || cur_layer >= g_nlayers) ++ return; ++ ++ Column cols[MAX_COLS]; ++ int ncol = getlayercols(selmon, 1 << g_layers[cur_layer].tag, NULL, cols); ++ if (ncol == 0) ++ return; ++ ++ int cur_col = find_col_row(cols, ncol, c, NULL); ++ if (cur_col == -1 || (ncol <= 1 && cols[cur_col].count <= 1)) ++ return; ++ ++ if (!reorder_col_dir(c, cols, ncol, cur_col, dir, ovloopnav)) ++ return; ++ ++ c->x = -9999; ++ c->y = -9999; ++ selmon->sel = c; ++ g_need_center_sel = 1; ++ arrangemon(selmon); ++ focus(c); ++ keep_cursor_inside(c); ++} ++ ++static void ++ovmovewinlayerdir(int dir) ++{ ++ if (!selmon || !selmon->sel || selmon->sel->isfloating || g_nlayers <= 1) ++ return; ++ ++ Client *c = selmon->sel; ++ int cur_layer = sync_sel_layer(); ++ if (cur_layer < 0 || cur_layer >= g_nlayers) ++ return; ++ ++ int target_layer = NAV_WRAP(cur_layer, dir, g_nlayers, ovloopnav); ++ if (target_layer == cur_layer) ++ return; ++ ++ unsigned int target_tag = g_layers[target_layer].tag; ++ unsigned int new_tags = 1 << target_tag; ++ ++ Column cur_cols[MAX_COLS]; ++ int cur_ncol = getlayercols(selmon, 1 << g_layers[cur_layer].tag, NULL, cur_cols); ++ int cur_col = find_col_row(cur_cols, cur_ncol, c, NULL); ++ ++ Column target_cols[MAX_COLS]; ++ int target_ncol = getlayercols(selmon, new_tags, c, target_cols); ++ ++ detach_unstack(c); ++ ++ c->is_stacked = 0; ++ ENSURE_CFACT(c); ++ c->is_custom_cfact = IS_CUSTOM_CFACT(c->cfact); ++ c->tags = new_tags; ++ ++ if (target_ncol == 0) { ++ c->next = selmon->clients; ++ selmon->clients = c; ++ } else { ++ int col_pos = (cur_col < 0) ? target_ncol - 1 : cur_col; ++ Client **tc; ++ if (col_pos == 0) { ++ Client *first_win = target_cols[0].clients[0]; ++ for (tc = &selmon->clients; *tc && *tc != first_win; tc = &(*tc)->next); ++ c->next = first_win; ++ *tc = c; ++ } else { ++ int t_col = MIN(col_pos, target_ncol) - 1; ++ Client *prev_win = target_cols[t_col].clients[target_cols[t_col].count - 1]; ++ c->next = prev_win->next; ++ prev_win->next = c; ++ } ++ } ++ ++ c->x = -9999; ++ c->y = -9999; ++ selmon->sel = c; ++ g_sel_layer = target_layer; ++ g_need_center_sel = 1; ++ arrangemon(selmon); ++ focus(c); ++ keep_cursor_inside(c); ++} ++ ++static void ++ovmovewin(const Arg *arg) ++{ ++ ovmovewindir(arg->i); ++} ++ ++static void ++ovmovewinlayer(const Arg *arg) ++{ ++ ovmovewinlayerdir(arg->i); ++} ++ ++static void ++toggleovloopnav(const Arg *arg) ++{ ++ ovloopnav = !ovloopnav; ++} ++ ++static void ++zoomov(const Arg *arg) ++{ ++ zoomovsel(); ++} ++ ++static void ++ovclick(Client *c, int px, int py, int button) ++{ ++ if (button == Button1) { ++ if (c) { ++ zoomovwin(c); ++ } else { ++ int tag = getovexactlayertag(px, py); ++ if (tag >= 0) { ++ Arg a = {.ui = 1 << tag}; ++ view(&a); ++ } else { ++ toggleov(NULL); ++ } ++ } ++ } else if (button == Button3) { ++ toggleov(NULL); ++ } ++} ++ ++static void ++ovjumptag(const Arg *arg) ++{ ++ ovjumptagidx(arg->ui); ++} ++ ++static int ++drain_scroll_events(int is_horiz, int delta) ++{ ++ XEvent next_ev; ++ while (XCheckMaskEvent(dpy, ButtonPressMask, &next_ev)) { ++ int b = next_ev.xbutton.button; ++ unsigned int state = CLEANMASK(next_ev.xbutton.state); ++ int match_neg = is_horiz ? ((b == 6 && !state) || (b == Button4 && state == ShiftMask)) ++ : (b == Button4 && !state); ++ int match_pos = is_horiz ? ((b == 7 && !state) || (b == Button5 && state == ShiftMask)) ++ : (b == Button5 && !state); ++ if (match_neg) ++ delta -= scrollstep; ++ else if (match_pos) ++ delta += scrollstep; ++ else { ++ XPutBackEvent(dpy, &next_ev); ++ break; ++ } ++ } ++ return delta; ++} ++ ++static void ++ovscrollribbon_px(int tag, int delta_px) ++{ ++ int l = layer_by_tag(1 << tag); ++ if (l >= 0) { ++ g_need_center_sel = 0; ++ g_layers[l].scroll_x = CLAMP(g_layers[l].scroll_x + delta_px, 0, MAX(0, g_layers[l].max_scroll_x)); ++ } ++} ++ ++static void ++ovscrollvert_px(int delta_px) ++{ ++ g_need_center_sel = 0; ++ g_ovscroll_y = CLAMP(g_ovscroll_y + delta_px, 0, g_ovmaxscroll_y); ++} ++ ++static void ++ovscrollribbon(const Arg *arg) ++{ ++ if (!isov) ++ return; ++ int dir = (arg && arg->i < 0) ? -1 : +1; ++ int init_d = dir * scrollstep; ++ int x, y; ++ getrootptr(&x, &y); ++ int layer_tag = getovlayertag(x, y); ++ int delta = drain_scroll_events(1, init_d); ++ ovscrollribbon_px(layer_tag, delta); ++ arrangemon(selmon); ++} ++ ++static void ++ovscrollvert(const Arg *arg) ++{ ++ if (!isov) ++ return; ++ int dir = (arg && arg->i < 0) ? -1 : +1; ++ int init_d = dir * scrollstep; ++ if (g_ovmaxscroll_y > 0) { ++ int delta = drain_scroll_events(0, init_d); ++ ovscrollvert_px(delta); ++ arrangemon(selmon); ++ } else { ++ static Time last_layer_move = 0; ++ if ((last_button_time - last_layer_move) > 120) { ++ last_layer_move = last_button_time; ++ focusovlayerdir(dir); ++ } ++ } ++} ++ ++static void ++ovresizemouse(const Arg *arg) ++{ ++ Client *c = selmon->sel; ++ int x, y; ++ XEvent ev; ++ Time lasttime = 0; ++ ++ if (!isov || !c || c->isfloating) ++ return; ++ ++ if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, ++ None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess) ++ return; ++ ++ if (!getrootptr(&x, &y)) { ++ XUngrabPointer(dpy, CurrentTime); ++ return; ++ } ++ ++ float start_cfact = (c->cfact > 0.05f) ? c->cfact : defwinw; ++ int pad_x = ovgappoh; ++ int usable_w = selmon->ww - 2 * pad_x; ++ if (usable_w < 100) usable_w = selmon->ww; ++ ++ do { ++ XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); ++ switch (ev.type) { ++ case ConfigureRequest: ++ case Expose: ++ case MapRequest: ++ handler[ev.type](&ev); ++ break; ++ case MotionNotify: ++ if ((ev.xmotion.time - lasttime) <= (1000 / refreshrate)) ++ continue; ++ lasttime = ev.xmotion.time; ++ ++ float delta = (float)(ev.xmotion.x_root - x) / (float)usable_w; ++ float new_cfact = CLAMP(start_cfact + delta, 0.10f, 1.0f); ++ ++ c->cfact = new_cfact; ++ c->unstacked_cfact = new_cfact; ++ c->is_custom_cfact = 1; ++ syncwincfact(c, new_cfact); ++ arrangemon(selmon); ++ break; ++ } ++ } while (ev.type != ButtonRelease); ++ ++ XUngrabPointer(dpy, CurrentTime); ++ arrangemon(selmon); ++ focus(c); ++ XSync(dpy, False); ++} ++ ++static void ++overview(Monitor *m) ++{ ++ unsigned int in_use = 0; ++ for (Client *c = m->clients; c; c = c->next) ++ if (!c->isfloating) ++ in_use |= (c->tags & TAGMASK); ++ ++ if (!in_use) ++ in_use = m->tagset[m->seltags] & TAGMASK; ++ ++ g_nlayers = 0; ++ for (int i = 0; i < LENGTH(tags); i++) { ++ if (in_use & (1 << i)) { ++ g_layers[g_nlayers].tag = i; ++ g_layers[g_nlayers].nwin = 0; ++ g_layers[g_nlayers].first_win = NULL; ++ g_nlayers++; ++ } ++ } ++ ++ if (g_nlayers == 0) { ++ g_layers[0].tag = 0; ++ g_layers[0].nwin = 0; ++ g_layers[0].first_win = NULL; ++ g_nlayers = 1; ++ } ++ ++ int sel_l = m->sel ? layer_by_tag(m->sel->tags) : (saved_ovtags ? layer_by_tag(saved_ovtags) : -1); ++ if (sel_l >= 0) ++ g_sel_layer = sel_l; ++ g_sel_layer = CLAMP(g_sel_layer, 0, g_nlayers - 1); ++ ++ int mx = m->wx, my = m->wy, mw = m->ww, mh = m->wh; ++ int pad_y = ovgappov; ++ int gap_y = ovlayergap; ++ int pad_x = ovgappoh; ++ int uw = mw - 2 * pad_x; ++ int avail_h = mh - 2 * pad_y; ++ if (avail_h < 100) avail_h = mh; ++ ++ int total_gaps = (g_nlayers - 1) * gap_y; ++ int layer_h; ++ if (ovuniformlayer || g_nlayers == 1) ++ layer_h = (int)(avail_h * ovsingleh); ++ else if (g_nlayers <= ovmaxfit) ++ layer_h = (avail_h - total_gaps) / g_nlayers; ++ else ++ layer_h = (avail_h - (ovmaxfit - 1) * gap_y) / ovmaxfit; ++ ++ if (layer_h < 120) layer_h = 120; ++ ++ int total_h = g_nlayers * layer_h + total_gaps; ++ if (total_h <= avail_h) { ++ int start_y = my + pad_y + (avail_h - total_h) / 2; ++ for (int i = 0; i < g_nlayers; i++) { ++ g_layers[i].y = start_y + i * (layer_h + gap_y); ++ g_layers[i].h = layer_h; ++ } ++ if (m->sel) { ++ int l = layer_by_tag(m->sel->tags); ++ if (l >= 0) g_sel_layer = l; ++ } ++ g_ovscroll_y = 0; ++ g_ovmaxscroll_y = 0; ++ } else { ++ int stride = layer_h + gap_y; ++ int total_h = g_nlayers * layer_h + total_gaps; ++ int max_scroll = MAX(0, total_h - avail_h); ++ g_ovmaxscroll_y = max_scroll; ++ ++ if (g_need_center_sel && !is_dragging && !is_scrolling) { ++ int sel_center = g_sel_layer * stride + layer_h / 2; ++ g_ovscroll_y = CLAMP(sel_center - (avail_h / 2), 0, max_scroll); ++ } ++ g_ovscroll_y = CLAMP(g_ovscroll_y, 0, max_scroll); ++ ++ int start_y = my + pad_y - g_ovscroll_y; ++ for (int i = 0; i < g_nlayers; i++) { ++ g_layers[i].y = start_y + i * stride; ++ g_layers[i].h = layer_h; ++ } ++ ++ if (!m->sel && (is_scrolling || is_dragging)) { ++ int screen_center_y = my + pad_y + avail_h / 2; ++ int best_diff = -1; ++ for (int i = 0; i < g_nlayers; i++) { ++ int layer_center_y = g_layers[i].y + layer_h / 2; ++ int diff = abs(layer_center_y - screen_center_y); ++ if (best_diff < 0 || diff < best_diff) { ++ best_diff = diff; ++ g_sel_layer = i; ++ } ++ } ++ } else if (m->sel) { ++ int l = layer_by_tag(m->sel->tags); ++ if (l >= 0) g_sel_layer = l; ++ } ++ } ++ ++ int in_pad_y = ovinpady; ++ int uh = layer_h - 2 * in_pad_y; ++ if (uh < 60) uh = layer_h; ++ int igap_x = ovgappih; ++ int igap_y = ovgappiv; ++ float S = (float)uh / (float)(mh > 0 ? mh : 1); ++ ++ for (int i = 0; i < g_nlayers; i++) { ++ int tag_idx = g_layers[i].tag; ++ int layer_y = g_layers[i].y; ++ ++ Column tag_cols[MAX_COLS]; ++ int tag_ncol = getlayercols(m, 1 << tag_idx, NULL, tag_cols); ++ g_layers[i].first_win = (tag_ncol > 0) ? tag_cols[0].clients[0] : NULL; ++ g_layers[i].nwin = tag_ncol; ++ if (tag_ncol == 0) ++ continue; ++ ++ int total_ribbon_w = 0; ++ for (int k = 0; k < tag_ncol; k++) { ++ Client *top = tag_cols[k].clients[0]; ++ float factor = CLAMP((top->cfact > 0.05f) ? top->cfact : defwinw, 0.1f, 1.0f); ++ int w = (tag_ncol == 1) ? MIN((int)(uh * 1.6f), (int)(uw * 0.70f)) ++ : (int)(uw * factor * S * 1.3f); ++ tag_cols[k].w = CLAMP(w, 100, uw); ++ total_ribbon_w += tag_cols[k].w + (k > 0 ? igap_x : 0); ++ } ++ ++ int start_x; ++ if (total_ribbon_w <= uw) { ++ start_x = mx + pad_x + (uw - total_ribbon_w) / 2; ++ g_layers[i].scroll_x = 0; ++ g_layers[i].max_scroll_x = 0; ++ } else { ++ int max_scroll = total_ribbon_w - uw; ++ g_layers[i].max_scroll_x = max_scroll; ++ ++ if (g_need_center_sel && !is_dragging && !is_scrolling) { ++ int sel_col = find_col_row(tag_cols, tag_ncol, m->sel, NULL); ++ if (sel_col >= 0) { ++ int cur_col_x = 0; ++ for (int k = 0; k < sel_col; k++) ++ cur_col_x += tag_cols[k].w + igap_x; ++ int target_scroll = (cur_col_x + tag_cols[sel_col].w / 2) - (uw / 2); ++ g_layers[i].scroll_x = CLAMP(target_scroll, 0, max_scroll); ++ } ++ } ++ g_layers[i].scroll_x = CLAMP(g_layers[i].scroll_x, 0, max_scroll); ++ start_x = mx + pad_x - g_layers[i].scroll_x; ++ } ++ ++ int cur_x = start_x; ++ for (int k = 0; k < tag_ncol; k++) { ++ int col_w = tag_cols[k].w; ++ int count = tag_cols[k].count; ++ int total_gap = (count - 1) * igap_y; ++ int win_h = (uh - total_gap) / count; ++ int cur_y = layer_y + in_pad_y; ++ ++ for (int j = 0; j < count; j++) { ++ Client *c = tag_cols[k].clients[j]; ++ int h = (j == count - 1) ? (uh - (cur_y - (layer_y + in_pad_y))) : win_h; ++ if (!is_dragging || c != m->sel) ++ scrollermoveresize(c, cur_x, cur_y, MAX(1, col_w - 2 * c->bw), MAX(1, h - 2 * c->bw)); ++ cur_y += win_h + igap_y; ++ } ++ cur_x += col_w + igap_x; ++ } ++ } ++ if (!m->sel && g_layers[g_sel_layer].first_win) ++ focus(g_layers[g_sel_layer].first_win); ++ g_need_center_sel = 0; ++ XSync(dpy, False); ++} ++ ++#endif /* OVERVIEW_C */ +diff --git a/overview.h b/overview.h +new file mode 100644 +index 0000000..6c35e61 +--- /dev/null ++++ b/overview.h +@@ -0,0 +1,34 @@ ++#ifndef OVERVIEW_H ++#define OVERVIEW_H ++ ++typedef struct { ++ int tag; /* 0-indexed tag (0 to 8) */ ++ int y; /* Y coordinate on screen */ ++ int h; /* Height of this layer */ ++ int nwin; /* Number of windows / columns */ ++ Client *first_win;/* First window in this layer */ ++ int scroll_x; /* Horizontal ribbon scroll offset */ ++ int max_scroll_x; /* Maximum horizontal scroll offset */ ++} OvLayer; ++ ++static void overview(Monitor *m); ++static void setov(int enable); ++static void toggleov(const Arg *arg); ++static void focusovlayer(const Arg *arg); ++static void focusovwin(const Arg *arg); ++static void zoomov(const Arg *arg); ++static void ovjumptag(const Arg *arg); ++static void ovdrop(Client *c, int drop_x, int drop_y); ++static int getovlayertag(int px, int py); ++static void ovscrollribbon(const Arg *arg); ++static void ovscrollvert(const Arg *arg); ++static void ovscrollribbon_px(int tag, int delta_px); ++static void ovscrollvert_px(int delta_px); ++static void ovresizemouse(const Arg *arg); ++static void ovclick(Client *c, int px, int py, int button); ++static void ovmovewin(const Arg *arg); ++static void ovmovewinlayer(const Arg *arg); ++static void toggleovloopnav(const Arg *arg); ++static Client *getovwin(int px, int py); ++ ++#endif /* OVERVIEW_H */ +diff --git a/scrollview.c b/scrollview.c +new file mode 100644 +index 0000000..9929bb5 +--- /dev/null ++++ b/scrollview.c +@@ -0,0 +1,907 @@ ++#include "scrollview.h" ++ ++static int is_scrolling = 0; ++static int is_dragging = 0; ++ ++static Column g_cols[MAX_COLS]; ++static int g_ncol = 0; ++static Client *prev_sel_client = NULL; ++static unsigned int prev_tagset = 0; ++ ++static void ++scrollermoveresize(Client *c, int x, int y, int w, int h) ++{ ++ if (c->x == x && c->y == y && c->w == w && c->h == h) ++ return; ++ ++ if (c->w == w && c->h == h) { ++ c->oldx = c->x; c->x = x; ++ c->oldy = c->y; c->y = y; ++ XMoveWindow(dpy, c->win, x, y); ++ } else { ++ resize(c, x, y, w, h, 0); ++ } ++} ++ ++static int ++find_col_row(const Column *cols, int ncol, const Client *c, int *out_row) ++{ ++ if (out_row) *out_row = 0; ++ if (!c || !cols) return -1; ++ for (int i = 0; i < ncol; i++) ++ for (int j = 0; j < cols[i].count; j++) ++ if (cols[i].clients[j] == c) { ++ if (out_row) *out_row = j; ++ return i; ++ } ++ return -1; ++} ++ ++static inline int ++get_view_geom(Monitor *m, int ncol, int *out_base_x) ++{ ++ int uw = (m->ww - 2 * m->gappoh >= 100) ? m->ww - 2 * m->gappoh : m->ww; ++ int sl = (ncol > 1 && strutleft > 0) ? strutleft : 0; ++ int sr = (ncol > 1 && strutright > 0) ? strutright : 0; ++ int vw = (uw - sl - sr >= 100) ? uw - sl - sr : uw; ++ if (out_base_x) ++ *out_base_x = m->wx + m->gappoh + sl; ++ return vw; ++} ++ ++static inline void ++unstackreorder(Client *c, Client *target, int pos) ++{ ++ reorderclient(c, target, pos); ++ c->cfact = (c->unstacked_cfact > 0.05f) ? c->unstacked_cfact : defwinw; ++ c->is_custom_cfact = IS_CUSTOM_CFACT(c->cfact); ++} ++ ++static inline void ++unstack_to_edge(Client *c, const Column *cols, int c_col, int target_col, int pos) ++{ ++ int is_before = (pos == InsBefore); ++ Client *target_win; ++ if (c_col != target_col) { ++ target_win = is_before ? cols[target_col].clients[0] ++ : cols[target_col].clients[cols[target_col].count - 1]; ++ } else if (cols[c_col].count > 1) { ++ int count = cols[c_col].count; ++ if (is_before) ++ target_win = (cols[c_col].clients[0] == c) ? cols[c_col].clients[1] : cols[c_col].clients[0]; ++ else ++ target_win = (cols[c_col].clients[count - 1] == c) ++ ? cols[c_col].clients[count - 2] ++ : cols[c_col].clients[count - 1]; ++ } else { ++ return; ++ } ++ unstackreorder(c, target_win, pos); ++} ++ ++static inline void ++unstack_client(Client *c, int col_idx) ++{ ++ unstack_to_edge(c, g_cols, col_idx, col_idx, (c == g_cols[col_idx].clients[0]) ? InsBefore : InsAfter); ++} ++ ++static inline void ++stack_client_target(Client *c, Column *col, Client *target_win, int pos) ++{ ++ ENSURE_CFACT(c); ++ for (int j = 0; j < col->count; j++) ++ ENSURE_CFACT(col->clients[j]); ++ ++ float target_cfact = col->clients[0]->cfact; ++ int target_custom = col->clients[0]->is_custom_cfact; ++ reorderclient(c, target_win, pos); ++ c->cfact = target_cfact; ++ c->is_custom_cfact = target_custom; ++} ++ ++static int ++reorder_col_dir(Client *c, const Column *cols, int ncol, int col_idx, int dir, int loop) ++{ ++ if (cols[col_idx].count > 1) { ++ unstack_to_edge(c, cols, col_idx, col_idx, (dir > 0) ? InsAfter : InsBefore); ++ return 1; ++ } ++ ++ if (dir > 0) { ++ if (col_idx < ncol - 1) ++ unstackreorder(c, cols[col_idx + 1].clients[cols[col_idx + 1].count - 1], InsAfter); ++ else if (loop && ncol > 1) ++ unstackreorder(c, cols[0].clients[0], InsBefore); ++ else ++ return 0; ++ } else if (dir < 0) { ++ if (col_idx > 0) ++ unstackreorder(c, cols[col_idx - 1].clients[0], InsBefore); ++ else if (loop && ncol > 1) ++ unstackreorder(c, cols[ncol - 1].clients[cols[ncol - 1].count - 1], InsAfter); ++ else ++ return 0; ++ } else { ++ return 0; ++ } ++ return 1; ++} ++ ++static void ++keep_cursor_inside(Client *c) ++{ ++ int px, py; ++ XEvent ev; ++ ++ if (!c) ++ return; ++ ++ if (getrootptr(&px, &py)) { ++ if (px < c->x || px >= c->x + c->w || py < c->y || py >= c->y + c->h) ++ XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2); ++ } else { ++ XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2); ++ } ++ ++ focus(c); ++ if (c->mon) ++ restack(c->mon); ++ XSync(dpy, False); ++ while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); ++} ++ ++static inline void ++finish_drag_client(Client *c) ++{ ++ c->x = c->y = -9999; ++ selmon->sel = c; ++ arrangemon(selmon); ++ focus(c); ++ keep_cursor_inside(c); ++ XSync(dpy, False); ++} ++ ++static inline int ++get_ribbon_offset(int total_w, int view_w) ++{ ++ if (total_w < view_w && centermode == CenterAlways) ++ return (view_w - total_w) / 2; ++ return 0; ++} ++ ++static void ++scroller_arrange_col(Monitor *m, Column *col, int col_x, int col_w) ++{ ++ int count = col->count; ++ int total_gaps_v = (count - 1) * m->gappiv; ++ int avail_h = m->wh - 2 * m->gappov - total_gaps_v; ++ if (avail_h < count) avail_h = count; ++ int h_each = avail_h / count; ++ int cur_y = m->wy + m->gappov; ++ ++ for (int j = 0; j < count; j++) { ++ Client *c = col->clients[j]; ++ int win_h = (j == count - 1) ? (avail_h - (count - 1) * h_each) : h_each; ++ int bw = c->bw; ++ if (is_dragging && c == m->sel) { ++ cur_y += win_h + m->gappiv; ++ continue; ++ } ++ scrollermoveresize(c, col_x, cur_y, MAX(1, col_w - 2 * bw), MAX(1, win_h - 2 * bw)); ++ cur_y += win_h + m->gappiv; ++ } ++} ++ ++static int ++build_columns(Monitor *m) ++{ ++ Client *c; ++ g_ncol = 0; ++ ++ for (c = nexttiled(m->clients); c && g_ncol < MAX_COLS; c = nexttiled(c->next)) { ++ if (g_ncol == 0 || !c->is_stacked) { ++ g_cols[g_ncol].clients[0] = c; ++ g_cols[g_ncol].count = 1; ++ g_ncol++; ++ } else { ++ if (g_cols[g_ncol - 1].count < MAX_COL_CLIENTS) ++ g_cols[g_ncol - 1].clients[g_cols[g_ncol - 1].count++] = c; ++ } ++ } ++ ++ int view_w = get_view_geom(m, g_ncol, NULL); ++ int cur_x = 0; ++ for (int i = 0; i < g_ncol; i++) { ++ Client *top = g_cols[i].clients[0]; ++ ++ if (g_ncol > 1 && g_cols[i].count == 1) { ++ if (top->unstacked_cfact > 0.05f) ++ top->cfact = top->unstacked_cfact; ++ top->is_custom_cfact = IS_CUSTOM_CFACT(top->cfact); ++ } ++ ++ float factor = top->is_custom_cfact ? ((top->cfact > 0.05f) ? top->cfact : defwinw) ++ : ((g_ncol > 1) ? defwinw : swinw); ++ factor = CLAMP(factor, 0.1f, 1.0f); ++ ++ if (!top->is_custom_cfact) { ++ for (int j = 0; j < g_cols[i].count; j++) ++ g_cols[i].clients[j]->cfact = factor; ++ } ++ ++ int avail_w = view_w - ((factor <= 0.35f) ? 2 * m->gappih : ((factor < 0.99f) ? m->gappih : 0)); ++ int w = CLAMP((int)(avail_w * factor), 80, view_w); ++ ++ g_cols[i].w = w; ++ g_cols[i].x = cur_x; ++ cur_x += w + ((i < g_ncol - 1) ? m->gappih : 0); ++ } ++ ++ return g_ncol; ++} ++ ++void ++trackscroll(const Arg *arg) ++{ ++ int ncol; ++ ++ if (!selmon || selmon->lt[selmon->sellt]->arrange != scroller) ++ return; ++ ++ ncol = build_columns(selmon); ++ if (ncol <= 1) ++ return; ++ ++ int view_w = get_view_geom(selmon, ncol, NULL); ++ int total_w = g_cols[ncol - 1].x + g_cols[ncol - 1].w; ++ int max_scroll = (total_w > view_w) ? (total_w - view_w) : 0; ++ ++ selmon->scroll_x = CLAMP(selmon->scroll_x + arg->i * scrollstep, 0, max_scroll); ++ is_scrolling = 1; ++ arrangemon(selmon); ++ ++ int screen_mid = selmon->scroll_x + view_w / 2; ++ int best_col = 0; ++ int min_dist = 999999; ++ for (int i = 0; i < ncol; i++) { ++ int mid = g_cols[i].x + g_cols[i].w / 2; ++ int dist = abs(mid - screen_mid); ++ if (dist < min_dist) { ++ min_dist = dist; ++ best_col = i; ++ } ++ } ++ ++ Client *target_win = (g_cols[best_col].count > 0) ? g_cols[best_col].clients[0] : selmon->sel; ++ if (target_win) { ++ if (target_win != selmon->sel) ++ focus(target_win); ++ keep_cursor_inside(target_win); ++ } ++ is_scrolling = 0; ++} ++ ++void ++scrollwin(const Arg *arg) ++{ ++ int ncol, cur_col, cur_row = 0; ++ ++ if (!selmon) ++ return; ++ ++ if (selmon->lt[selmon->sellt]->arrange != scroller) { ++ focusstack(arg); ++ return; ++ } ++ ++ ncol = build_columns(selmon); ++ if (ncol <= 1) ++ return; ++ ++ cur_col = find_col_row(g_cols, ncol, selmon->sel, &cur_row); ++ ++ if (cur_col == -1) { ++ int base_x; ++ int view_w = get_view_geom(selmon, ncol, &base_x); ++ int px, py; ++ if (getrootptr(&px, &py)) { ++ int total_w = g_cols[ncol - 1].x + g_cols[ncol - 1].w; ++ int offset_x = get_ribbon_offset(total_w, view_w); ++ int ribbon_x = px - base_x - offset_x + selmon->scroll_x; ++ for (int i = 0; i < ncol; i++) { ++ if (ribbon_x >= g_cols[i].x && ribbon_x <= g_cols[i].x + g_cols[i].w + selmon->gappih) { ++ cur_col = i; ++ break; ++ } ++ } ++ } ++ } ++ if (cur_col == -1) cur_col = 0; ++ ++ int target_col = NAV_WRAP(cur_col, arg->i, ncol, loopnav); ++ if (target_col == cur_col) ++ return; ++ ++ if (g_cols[target_col].count > 0) { ++ int target_row = (cur_row < g_cols[target_col].count) ? cur_row : (g_cols[target_col].count - 1); ++ Client *target_win = g_cols[target_col].clients[target_row]; ++ focus(target_win); ++ restack(selmon); ++ keep_cursor_inside(target_win); ++ } ++} ++ ++void ++focuswinstack(const Arg *arg) ++{ ++ int ncol, cur_col, cur_row; ++ ++ if (!selmon || !selmon->sel) ++ return; ++ ++ if (selmon->lt[selmon->sellt]->arrange != scroller) { ++ focusstack(arg); ++ return; ++ } ++ ++ ncol = build_columns(selmon); ++ cur_col = find_col_row(g_cols, ncol, selmon->sel, &cur_row); ++ ++ if (cur_col != -1 && g_cols[cur_col].count > 1) { ++ int target_row = NAV_WRAP(cur_row, arg->i, g_cols[cur_col].count, loopnav); ++ if (target_row == cur_row) ++ return; ++ Client *target_win = g_cols[cur_col].clients[target_row]; ++ focus(target_win); ++ keep_cursor_inside(target_win); ++ } else if (loopnav) { ++ focusstack(arg); ++ if (selmon->sel) ++ keep_cursor_inside(selmon->sel); ++ } ++} ++ ++void ++stackconsume(const Arg *arg) ++{ ++ Client *c, *target_win = NULL; ++ ++ if (!selmon || selmon->lt[selmon->sellt]->arrange != scroller || !selmon->sel) ++ return; ++ ++ c = selmon->sel; ++ if (arg->i >= 0) { ++ target_win = nexttiled(c->next); ++ } else { ++ Client *p; ++ for (p = selmon->clients; p && p != c; p = p->next) ++ if (!p->isfloating && ISVISIBLE(p)) ++ target_win = p; ++ } ++ ++ if (!target_win || target_win == c) ++ return; ++ ++ ENSURE_CFACT(c); ++ ENSURE_CFACT(target_win); ++ ++ target_win->is_stacked = 1; ++ target_win->cfact = c->cfact; ++ target_win->is_custom_cfact = c->is_custom_cfact; ++ arrangemon(selmon); ++ keep_cursor_inside(selmon->sel); ++} ++ ++void ++stackexpel(const Arg *arg) ++{ ++ if (!selmon || selmon->lt[selmon->sellt]->arrange != scroller || !selmon->sel) ++ return; ++ ++ Client *c = selmon->sel; ++ int ncol = build_columns(selmon); ++ int col_idx = find_col_row(g_cols, ncol, c, NULL); ++ if (col_idx != -1 && g_cols[col_idx].count > 1) { ++ unstack_client(c, col_idx); ++ } else { ++ c->is_stacked = 0; ++ c->cfact = (c->unstacked_cfact > 0.05f) ? c->unstacked_cfact : defwinw; ++ c->is_custom_cfact = IS_CUSTOM_CFACT(c->cfact); ++ } ++ arrangemon(selmon); ++ keep_cursor_inside(selmon->sel); ++} ++ ++void ++togglestack(const Arg *arg) ++{ ++ if (!selmon || selmon->lt[selmon->sellt]->arrange != scroller || !selmon->sel) ++ return; ++ ++ int ncol = build_columns(selmon); ++ int col_idx = find_col_row(g_cols, ncol, selmon->sel, NULL); ++ if (col_idx != -1 && g_cols[col_idx].count > 1) ++ stackexpel(arg); ++ else ++ stackconsume(arg); ++} ++ ++void ++movewin(const Arg *arg) ++{ ++ Client *c = selmon->sel; ++ if (!c || c->isfloating || selmon->lt[selmon->sellt]->arrange != scroller) ++ return; ++ ++ int ncol = build_columns(selmon); ++ if (ncol == 0) ++ return; ++ ++ int col_idx = find_col_row(g_cols, ncol, c, NULL); ++ if (col_idx == -1 || (ncol <= 1 && g_cols[col_idx].count <= 1)) ++ return; ++ ++ if (!reorder_col_dir(c, g_cols, ncol, col_idx, arg->i, loopnav)) ++ return; ++ ++ centerfocused(NULL); ++} ++ ++void ++movewinstack(const Arg *arg) ++{ ++ Client *c = selmon->sel; ++ if (!c || c->isfloating || selmon->lt[selmon->sellt]->arrange != scroller || !arg->i) ++ return; ++ ++ int ncol = build_columns(selmon); ++ if (ncol == 0) ++ return; ++ ++ int cur_row = -1; ++ int col_idx = find_col_row(g_cols, ncol, c, &cur_row); ++ if (col_idx == -1 || cur_row == -1) ++ return; ++ ++ int count = g_cols[col_idx].count; ++ int is_down = (arg->i > 0); ++ ++ if (count <= 1) { ++ if (ncol <= 1) ++ return; ++ int t_col = (col_idx < ncol - 1) ? (col_idx + 1) : (col_idx - 1); ++ int pos = is_down ? StkAfter : StkBefore; ++ Client *target_win = is_down ? g_cols[t_col].clients[g_cols[t_col].count - 1] ++ : g_cols[t_col].clients[0]; ++ stack_client_target(c, &g_cols[t_col], target_win, pos); ++ } else { ++ int at_edge = is_down ? (cur_row == count - 1) : (cur_row == 0); ++ if (at_edge && !loopnav) ++ return; ++ int target_idx = at_edge ? (is_down ? 0 : count - 1) : (cur_row + (is_down ? 1 : -1)); ++ int pos = (at_edge == is_down) ? StkBefore : StkAfter; ++ Client *target_win = g_cols[col_idx].clients[target_idx]; ++ reorderclient(c, target_win, pos); ++ } ++ ++ arrangemon(selmon); ++ keep_cursor_inside(c); ++} ++ ++void ++syncwincfact(Client *c, float f) ++{ ++ int ncol = build_columns(selmon); ++ int col_idx = find_col_row(g_cols, ncol, c, NULL); ++ if (col_idx != -1) { ++ for (int j = 0; j < g_cols[col_idx].count; j++) { ++ g_cols[col_idx].clients[j]->cfact = f; ++ g_cols[col_idx].clients[j]->is_custom_cfact = 1; ++ } ++ } ++} ++ ++void ++cyclewinwidth(const Arg *arg) ++{ ++ int ncol, col_idx; ++ ++ if (!selmon || selmon->lt[selmon->sellt]->arrange != scroller || !selmon->sel) ++ return; ++ ++ Client *c = selmon->sel; ++ ncol = build_columns(selmon); ++ col_idx = find_col_row(g_cols, ncol, c, NULL); ++ ++ float cur_factor = (ncol == 1 && !c->is_custom_cfact) ? 1.0f : c->cfact; ++ int cur_idx = -1; ++ for (int i = 0; i < (int)LENGTH(winsizes); i++) { ++ if (cur_factor >= winsizes[i] - 0.04f && cur_factor <= winsizes[i] + 0.04f) { ++ cur_idx = i; ++ break; ++ } ++ } ++ float next_factor = winsizes[(cur_idx + 1) % LENGTH(winsizes)]; ++ ++ c->cfact = next_factor; ++ c->is_custom_cfact = 1; ++ if (col_idx != -1) { ++ if (g_cols[col_idx].count == 1) ++ c->unstacked_cfact = next_factor; ++ for (int j = 0; j < g_cols[col_idx].count; j++) { ++ g_cols[col_idx].clients[j]->cfact = next_factor; ++ g_cols[col_idx].clients[j]->is_custom_cfact = 1; ++ } ++ } ++ ++ centerfocused(NULL); ++} ++ ++void ++centerfocused(const Arg *arg) ++{ ++ int ncol, sel_col; ++ ++ if (!selmon || selmon->lt[selmon->sellt]->arrange != scroller || !selmon->sel) ++ return; ++ ++ ncol = build_columns(selmon); ++ sel_col = find_col_row(g_cols, ncol, selmon->sel, NULL); ++ if (sel_col == -1) return; ++ ++ int view_w = get_view_geom(selmon, ncol, NULL); ++ int center_col = g_cols[sel_col].x + g_cols[sel_col].w / 2; ++ int total_w = g_cols[ncol - 1].x + g_cols[ncol - 1].w; ++ int max_scroll = (total_w > view_w) ? (total_w - view_w) : 0; ++ ++ selmon->scroll_x = CLAMP(center_col - view_w / 2, 0, max_scroll); ++ arrangemon(selmon); ++ keep_cursor_inside(selmon->sel); ++} ++ ++void ++togglecentering(const Arg *arg) ++{ ++ centermode = (centermode == CenterOnFlow) ? CenterAlways : ++ (centermode == CenterAlways) ? CenterNever : CenterOnFlow; ++ ++ if (selmon && selmon->lt[selmon->sellt]->arrange == scroller) { ++ arrangemon(selmon); ++ keep_cursor_inside(selmon->sel); ++ } ++} ++ ++void ++toggleloopnav(const Arg *arg) ++{ ++ loopnav = !loopnav; ++} ++ ++void ++scroller(Monitor *m) ++{ ++ static int in_scroller = 0; ++ if (in_scroller) ++ return; ++ in_scroller = 1; ++ ++ int ncol = build_columns(m); ++ if (ncol == 0) { ++ m->prev_ncol = 0; ++ m->prev_sel_col = -1; ++ prev_sel_client = NULL; ++ prev_tagset = m->tagset[m->seltags]; ++ in_scroller = 0; ++ return; ++ } ++ ++ unsigned int cur_tagset = m->tagset[m->seltags]; ++ ++ if (cur_tagset == prev_tagset && prev_sel_client && ++ find_col_row(g_cols, ncol, prev_sel_client, NULL) == -1) { ++ int target_col = CLAMP(m->prev_sel_col >= 0 ? m->prev_sel_col : 0, 0, ncol - 1); ++ if (g_cols[target_col].count > 0) { ++ Client *target_win = g_cols[target_col].clients[0]; ++ if (m->sel != target_win) { ++ focus(target_win); ++ restack(m); ++ keep_cursor_inside(target_win); ++ } ++ if (target_col == 0) ++ m->scroll_x = 0; ++ m->prev_sel_col = target_col; ++ } ++ } ++ prev_tagset = cur_tagset; ++ ++ if (m->prev_ncol > 1 && ncol == 1) { ++ for (int j = 0; j < g_cols[0].count; j++) { ++ g_cols[0].clients[j]->is_custom_cfact = 0; ++ g_cols[0].clients[j]->cfact = swinw; ++ } ++ } ++ m->prev_ncol = ncol; ++ ++ int base_x; ++ int view_w = get_view_geom(m, ncol, &base_x); ++ ++ if (ncol == 1) { ++ Client *top = g_cols[0].clients[0]; ++ int col_w = top->is_custom_cfact ? g_cols[0].w : (int)(view_w * swinw); ++ int col_x = m->wx + m->gappoh + ((centerswin || centermode == CenterAlways) ? (view_w - col_w) / 2 : 0); ++ ++ scroller_arrange_col(m, &g_cols[0], col_x, col_w); ++ m->scroll_x = 0; ++ m->prev_sel_col = 0; ++ prev_sel_client = m->sel; ++ XSync(dpy, False); ++ in_scroller = 0; ++ return; ++ } ++ ++ int total_w = g_cols[ncol - 1].x + g_cols[ncol - 1].w; ++ int max_scroll = MAX(0, total_w - view_w); ++ int sel_col = find_col_row(g_cols, ncol, m->sel, NULL); ++ ++ if (!is_scrolling && sel_col != -1) { ++ int col_screen_x = g_cols[sel_col].x - m->scroll_x; ++ int col_w = g_cols[sel_col].w; ++ ++ if (centermode == CenterAlways) { ++ m->scroll_x = (g_cols[sel_col].x + col_w / 2) - (view_w / 2); ++ } else if (centermode == CenterOnFlow) { ++ if (m->prev_sel_col >= 0 && m->prev_sel_col < ncol && m->prev_sel_col != sel_col) { ++ int prev_x = g_cols[m->prev_sel_col].x; ++ int prev_w = g_cols[m->prev_sel_col].w; ++ int pair_span = MAX(prev_x + prev_w, g_cols[sel_col].x + col_w) - MIN(prev_x, g_cols[sel_col].x); ++ ++ if (pair_span > view_w + 1) ++ m->scroll_x = (g_cols[sel_col].x + col_w / 2) - (view_w / 2); ++ else if (col_screen_x < 0) ++ m->scroll_x = g_cols[sel_col].x; ++ else if (col_screen_x + col_w > view_w) ++ m->scroll_x = g_cols[sel_col].x + col_w - view_w; ++ } else { ++ if (col_screen_x < 0) ++ m->scroll_x = g_cols[sel_col].x; ++ else if (col_screen_x + col_w > view_w) ++ m->scroll_x = g_cols[sel_col].x + col_w - view_w; ++ } ++ } else if (centermode == CenterNever) { ++ if (col_screen_x < 0) ++ m->scroll_x = g_cols[sel_col].x; ++ else if (col_screen_x + col_w > view_w) ++ m->scroll_x = g_cols[sel_col].x + col_w - view_w; ++ } ++ m->prev_sel_col = sel_col; ++ } ++ ++ m->scroll_x = CLAMP(m->scroll_x, 0, max_scroll); ++ int offset_x = get_ribbon_offset(total_w, view_w); ++ ++ for (int i = 0; i < ncol; i++) { ++ int col_x = base_x + offset_x + g_cols[i].x - m->scroll_x; ++ scroller_arrange_col(m, &g_cols[i], col_x, g_cols[i].w); ++ } ++ prev_sel_client = m->sel; ++ XSync(dpy, False); ++ in_scroller = 0; ++} ++ ++static void ++detach_unstack(Client *c) ++{ ++ Client **tc, *nxt; ++ ++ if (!c) ++ return; ++ ++ for (nxt = c->next; nxt; nxt = nxt->next) { ++ if (!nxt->isfloating && (nxt->tags & c->tags)) { ++ if (!c->is_stacked && nxt->is_stacked) ++ nxt->is_stacked = 0; ++ break; ++ } ++ } ++ ++ for (tc = &selmon->clients; *tc && *tc != c; tc = &(*tc)->next); ++ if (*tc) ++ *tc = c->next; ++} ++ ++static void ++reorderclient(Client *c, Client *target, int pos) ++{ ++ Client **tc; ++ ++ if (!c || !target || c == target) ++ return; ++ ++ detach_unstack(c); ++ ++ if (pos == InsBefore || pos == StkBefore) { ++ for (tc = &selmon->clients; *tc && *tc != target; tc = &(*tc)->next); ++ c->next = target; ++ *tc = c; ++ c->is_stacked = (pos == StkBefore) ? target->is_stacked : 0; ++ if (pos == StkBefore) ++ target->is_stacked = 1; ++ } else { ++ c->next = target->next; ++ target->next = c; ++ c->is_stacked = (pos == StkAfter); ++ } ++} ++ ++static void ++stack_into_column(Client *c, Column *col, int drop_y) ++{ ++ if (!c || !col || col->count == 0) ++ return; ++ ++ Client *stack_target = NULL; ++ int pos = StkAfter; ++ ++ for (int j = 0; j < col->count; j++) { ++ Client *tj = col->clients[j]; ++ int win_mid_y = tj->y + tj->h / 2; ++ if (drop_y < win_mid_y) { ++ stack_target = tj; ++ pos = StkBefore; ++ break; ++ } ++ stack_target = tj; ++ pos = StkAfter; ++ } ++ ++ if (stack_target && stack_target != c) ++ stack_client_target(c, col, stack_target, pos); ++} ++ ++void ++dragdrop(const Arg *arg) ++{ ++ int x, y, ocx, ocy, nx, ny; ++ Client *c; ++ XEvent ev; ++ Time lasttime = 0; ++ ++ if (!(c = selmon->sel)) ++ return; ++ ++ if ((!isov && selmon->lt[selmon->sellt]->arrange != scroller) || c->isfloating || c->isfullscreen) { ++ movemouse(arg); ++ return; ++ } ++ ++ ocx = c->x; ++ ocy = c->y; ++ if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, ++ None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess) ++ return; ++ ++ if (!getrootptr(&x, &y)) ++ return; ++ ++ XRaiseWindow(dpy, c->win); ++ is_scrolling = 1; ++ is_dragging = 1; ++ ++ int ncol = build_columns(selmon); ++ int view_w = get_view_geom(selmon, ncol, NULL); ++ int total_w = (ncol > 0) ? (g_cols[ncol - 1].x + g_cols[ncol - 1].w) : 0; ++ int max_scroll = MAX(0, total_w - view_w); ++ ++ do { ++ XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); ++ switch (ev.type) { ++ case ConfigureRequest: ++ case Expose: ++ case MapRequest: ++ handler[ev.type](&ev); ++ break; ++ case MotionNotify: ++ if ((ev.xmotion.time - lasttime) <= (1000 / refreshrate)) ++ continue; ++ lasttime = ev.xmotion.time; ++ ++ nx = ocx + (ev.xmotion.x_root - x); ++ ny = ocy + (ev.xmotion.y_root - y); ++ XMoveWindow(dpy, c->win, nx, ny); ++ ++ if (isov) { ++ int scrolled = 0; ++ ++ if (ev.xmotion.y_root < selmon->wy + ovedgezone) { ++ ovscrollvert_px(-ovedgestep); ++ scrolled = 1; ++ } else if (ev.xmotion.y_root > selmon->wy + selmon->wh - ovedgezone) { ++ ovscrollvert_px(+ovedgestep); ++ scrolled = 1; ++ } ++ ++ int layer_tag = getovlayertag(ev.xmotion.x_root, ev.xmotion.y_root); ++ if (ev.xmotion.x_root < selmon->wx + ovedgezone) { ++ ovscrollribbon_px(layer_tag, -ovedgestep); ++ scrolled = 1; ++ } else if (ev.xmotion.x_root > selmon->wx + selmon->ww - ovedgezone) { ++ ovscrollribbon_px(layer_tag, +ovedgestep); ++ scrolled = 1; ++ } ++ ++ if (scrolled) { ++ arrangemon(selmon); ++ XMoveWindow(dpy, c->win, nx, ny); ++ } ++ } else if (ncol > 1) { ++ int prev_sx = selmon->scroll_x; ++ if (ev.xmotion.x_root < selmon->wx + 80) ++ selmon->scroll_x = MAX(0, selmon->scroll_x - 20); ++ else if (ev.xmotion.x_root > selmon->wx + selmon->ww - 80) ++ selmon->scroll_x = MIN(max_scroll, selmon->scroll_x + 20); ++ if (selmon->scroll_x != prev_sx) { ++ arrangemon(selmon); ++ XMoveWindow(dpy, c->win, nx, ny); ++ } ++ } ++ break; ++ } ++ } while (ev.type != ButtonRelease); ++ ++ is_scrolling = 0; ++ is_dragging = 0; ++ XUngrabPointer(dpy, CurrentTime); ++ while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); ++ ++ int drop_x = ev.xbutton.x_root; ++ int drop_y = ev.xbutton.y_root; ++ ++ if (abs(drop_x - x) < (int)snap && abs(drop_y - y) < (int)snap) { ++ if (isov) { ++ Arg a = {.ui = c->tags}; ++ view(&a); ++ focus(c); ++ restack(selmon); ++ return; ++ } ++ finish_drag_client(c); ++ return; ++ } ++ ++ if (isov) { ++ ovdrop(c, drop_x, drop_y); ++ return; ++ } ++ ++ ncol = build_columns(selmon); ++ if (ncol > 0) { ++ int c_col = find_col_row(g_cols, ncol, c, NULL); ++ int base_x; ++ int vw = get_view_geom(selmon, ncol, &base_x); ++ int tot_w = g_cols[ncol - 1].x + g_cols[ncol - 1].w; ++ int ribbon_drop_x = drop_x - base_x - get_ribbon_offset(tot_w, vw) + selmon->scroll_x; ++ ++ if (ribbon_drop_x < g_cols[0].x) { ++ unstack_to_edge(c, g_cols, c_col, 0, InsBefore); ++ } else if (ribbon_drop_x > g_cols[ncol - 1].x + g_cols[ncol - 1].w) { ++ unstack_to_edge(c, g_cols, c_col, ncol - 1, InsAfter); ++ } else { ++ for (int i = 0; i < ncol; i++) { ++ int col_left = g_cols[i].x; ++ int col_right = g_cols[i].x + g_cols[i].w; ++ if (ribbon_drop_x >= col_left && ribbon_drop_x <= col_right + selmon->gappih) { ++ int edge_zone = CLAMP((int)(g_cols[i].w * 0.18), 25, 90); ++ if (ribbon_drop_x < col_left + edge_zone) ++ unstack_to_edge(c, g_cols, c_col, i, InsBefore); ++ else if (ribbon_drop_x > col_right - edge_zone) ++ unstack_to_edge(c, g_cols, c_col, i, InsAfter); ++ else ++ stack_into_column(c, &g_cols[i], drop_y); ++ break; ++ } ++ } ++ } ++ } ++ ++ finish_drag_client(c); ++} +diff --git a/scrollview.h b/scrollview.h +new file mode 100644 +index 0000000..5c516e9 +--- /dev/null ++++ b/scrollview.h +@@ -0,0 +1,52 @@ ++#ifndef SCROLLVIEW_H ++#define SCROLLVIEW_H ++ ++#define MAX_COLS 128 ++#define MAX_COL_CLIENTS 64 ++ ++#define CURRENT_MODE() (isov ? Overview : (Normal | (selmon && \ ++ selmon->lt[selmon->sellt]->arrange == scroller ? Scroll : 0))) ++#define CLAMP(x, lo, hi) ((x) < (lo) ? (lo) : ((x) > (hi) ? (hi) : (x))) ++#define DIFF_ABS(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) ++#define IS_CUSTOM_CFACT(f) (DIFF_ABS((f), defwinw) > 0.01f) ++#define ENSURE_CFACT(c) do { if ((c)->unstacked_cfact <= 0.05f) \ ++ (c)->unstacked_cfact = ((c)->cfact > 0.05f) ? (c)->cfact : defwinw; } while(0) ++#define NAV_WRAP(cur, delta, count, loop) \ ++ ((loop) ? (((cur) + (delta) % (count) + (count)) % (count)) : CLAMP((cur) + (delta), 0, (count) - 1)) ++ ++enum { CenterOnFlow, CenterAlways, CenterNever }; ++enum { InsBefore, InsAfter, StkBefore, StkAfter }; ++ ++typedef struct { ++ Client *clients[MAX_COL_CLIENTS]; ++ int count; ++ int w; ++ int x; ++} Column; ++ ++static void scroller(Monitor *m); ++static void scrollwin(const Arg *arg); ++static void trackscroll(const Arg *arg); ++static void focuswinstack(const Arg *arg); ++static void stackconsume(const Arg *arg); ++static void stackexpel(const Arg *arg); ++static void togglestack(const Arg *arg); ++static void movewin(const Arg *arg); ++static void movewinstack(const Arg *arg); ++static void cyclewinwidth(const Arg *arg); ++void centerfocused(const Arg *arg); ++static void togglecentering(const Arg *arg); ++static void toggleloopnav(const Arg *arg); ++void syncwincfact(Client *c, float f); ++static void dragdrop(const Arg *arg); ++ ++/* Shared functions */ ++static int find_col_row(const Column *cols, int ncol, const Client *c, int *out_row); ++static void scrollermoveresize(Client *c, int x, int y, int w, int h); ++static void reorderclient(Client *c, Client *target, int pos); ++static void unstackreorder(Client *c, Client *target, int pos); ++static void detach_unstack(Client *c); ++static int reorder_col_dir(Client *c, const Column *cols, int ncol, int col_idx, int dir, int loop); ++static void keep_cursor_inside(Client *c); ++ ++#endif /* SCROLLVIEW_H */ +-- +2.55.0 + diff --git a/dwm.suckless.org/patches/scrollview/index.md b/dwm.suckless.org/patches/scrollview/index.md @@ -0,0 +1,45 @@ +scrollview +=========== + +Description +----------- +An interactive scrolling tiling layout and workspace overview inspired by Niri. +Windows are arranged in an infinite horizontal ribbon of columns with vertical +stacking, accompanied by a full-screen interactive workspace overview. + +Applying patch +-------------- +The patch is applied after vanitygaps for better experiance with gaps. +Requires the [vanitygaps-6.4+](https://dwm.suckless.org/patches/vanitygaps/) patch as a prerequisite. +* Non-gap will be added in future for minimal use. + +Centering Modes +---------------- +* CenterOnFlow: Centers the ribbon dynamically when focus moves beyond the +visible screen edges. +* CenterAlways: Keeps the focused window locked dead center at all times. +* CenterNever: Scrolls the viewport only by the minimum amount required to keep +the focused column visible. + +Keybinding Modes +----------------- +A modal dispatch system isolates shortcuts across three distinct modes without +modifier conflicts: +* All: Global shortcut binds. +* Normal: Standard shortcuts active across regular layouts. +* Scroll: Navigation, column resizing, ribbon shifting, and mouse scrolling +active only in the scroller layout. +* Overview: Layer navigation, drag-and-drop workspace migration, and window +organization active only while the overview is open. + +Download +----------- +* [dwm-scrollview-1563572.diff](dwm-scrollview-1563572.diff) (2026-11-21) (85K) + +The latest releases of the patch will always be available on project +[Releases](https://github.com/nonameblank007/dwm-scrollview/releases) page. + +Authors +----------- +* Sourav Nayak <nonameblank007@gmail.com> +