sites

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

dwm-scrollview-1563572.diff (86437B)


      1 From e0589ff26d5882282ee17d83cd28ccb2d3574a10 Mon Sep 17 00:00:00 2001
      2 From: Sourav Nayak <nonameblank007@gmail.com>
      3 Date: Sat, 21 Nov 2026 18:24:50 +0530
      4 Subject: [PATCH] dwm: scrollview 6.8+
      5 
      6 ---
      7  config.def.h | 214 ++++++++----
      8  dwm.c        | 236 ++++++++++++--
      9  overview.c   | 880 +++++++++++++++++++++++++++++++++++++++++++++++++
     10  overview.h   |  34 ++
     11  scrollview.c | 907 +++++++++++++++++++++++++++++++++++++++++++++++++++
     12  scrollview.h |  52 +++
     13  6 files changed, 2237 insertions(+), 86 deletions(-)
     14  create mode 100644 overview.c
     15  create mode 100644 overview.h
     16  create mode 100644 scrollview.c
     17  create mode 100644 scrollview.h
     18 
     19 diff --git a/config.def.h b/config.def.h
     20 index a1d9b6f..b67f040 100644
     21 --- a/config.def.h
     22 +++ b/config.def.h
     23 @@ -46,9 +46,37 @@ static const int refreshrate = 120;  /* refresh rate (per second) for client mov
     24  #define FORCE_VSPLIT 1  /* nrowgrid layout: force two clients to always split vertically */
     25  #include "vanitygaps.c"
     26  
     27 +/* scroller layout settings */
     28 +static int centermode                = CenterOnFlow; /* CenterOnFlow, CenterAlways, CenterNever */
     29 +static const float winsizes[]        = { 0.33333f, 0.50f, 0.66667f, 1.0f }; /* window width presets [0.1..1.0] */
     30 +static const float defwinw           = 0.50f; /* default width factor for multi-window ribbons [0.1..1.0] */
     31 +static const float swinw             = 0.50f; /* default width factor for single window or stack [0.1..1.0] */
     32 +static const int centerswin          = 0;     /* 1 means always center single window */
     33 +static const int scrollstep          = 45;    /* trackpad and mouse wheel scroll step in pixels */
     34 +static const int strutleft           = 55;    /* pixels reserved on left edge for focus jump (0 to disable) */
     35 +static const int strutright          = 55;    /* pixels reserved on right edge for focus jump (0 to disable) */
     36 +static int loopnav                   = 1;     /* 1 means loop navigation */
     37 +
     38 +/* overview layout settings */
     39 +static const int ovgappov            = 16;    /* vert outer padding between overview area and screen edge */
     40 +static const int ovgappoh            = 24;    /* horiz outer padding between overview ribbons and screen edge */
     41 +static const int ovlayergap          = 14;    /* vert gap between workspace layers */
     42 +static const int ovinpady            = 6;     /* vert inner padding inside workspace layer */
     43 +static const int ovgappih            = 8;     /* horiz gap between miniature windows */
     44 +static const int ovgappiv            = 4;     /* vert gap between stacked window panes */
     45 +static const float ovsingleh         = 0.45f; /* single layer window height factor */
     46 +static const int ovuniformlayer      = 1;     /* 0 means scale to fit ovmaxfit */
     47 +static const int ovmaxfit            = 4;     /* max visible workspace layers before vertical scrolling */
     48 +static const int ovedgezone          = 80;    /* edge distance in pixels triggering auto-scroll during drag */
     49 +static const int ovedgestep          = 25;    /* auto-scroll step in pixels per motion event during drag */
     50 +static int ovloopnav                 = 1;     /* 1 means loop navigation */
     51 +
     52 +#include "scrollview.c"
     53 +
     54  static const Layout layouts[] = {
     55  	/* symbol     arrange function */
     56  	{ "[]=",      tile },    /* first entry is default */
     57 +	{ "[|||]",    scroller },
     58  	{ "[M]",      monocle },
     59  	{ "[@]",      spiral },
     60  	{ "[\\]",     dwindle },
     61 @@ -61,6 +89,7 @@ static const Layout layouts[] = {
     62  	{ ":::",      gaplessgrid },
     63  	{ "|M|",      centeredmaster },
     64  	{ ">M>",      centeredfloatingmaster },
     65 +	{ "[⊞]",      overview },
     66  	{ "><>",      NULL },    /* no layout function means floating behavior */
     67  	{ NULL,       NULL },
     68  };
     69 @@ -68,10 +97,12 @@ static const Layout layouts[] = {
     70  /* key definitions */
     71  #define MODKEY Mod1Mask
     72  #define TAGKEYS(KEY,TAG) \
     73 -	{ MODKEY,                       KEY,      view,           {.ui = 1 << TAG} }, \
     74 -	{ MODKEY|ControlMask,           KEY,      toggleview,     {.ui = 1 << TAG} }, \
     75 -	{ MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
     76 -	{ MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} },
     77 +	{ Normal,   MODKEY,                       KEY,      view,             {.ui = 1 << TAG} }, \
     78 +	{ Normal,   MODKEY|ControlMask,           KEY,      toggleview,       {.ui = 1 << TAG} }, \
     79 +	{ Normal,   MODKEY|ShiftMask,             KEY,      tag,              {.ui = 1 << TAG} }, \
     80 +	{ Normal,   MODKEY|ControlMask|ShiftMask, KEY,      toggletag,        {.ui = 1 << TAG} }, \
     81 +	{ Overview, 0,                            KEY,      ovjumptag,  {.ui = TAG} }, \
     82 +	{ Overview, MODKEY,                       KEY,      ovjumptag,  {.ui = TAG} },
     83  
     84  /* helper for spawning shell commands in the pre dwm-5.0 fashion */
     85  #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
     86 @@ -81,50 +112,92 @@ static char dmenumon[8]; /* component of dmenucmd, manipulated in spawn() */
     87  static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
     88  static const char *termcmd[]  = { "st", NULL };
     89  
     90 +#include "overview.c"
     91 +
     92  static const Key keys[] = {
     93 -	/* modifier                     key        function        argument */
     94 -	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
     95 -	{ MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
     96 -	{ MODKEY,                       XK_b,      togglebar,      {0} },
     97 -	{ MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
     98 -	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
     99 -	{ MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
    100 -	{ MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
    101 -	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
    102 -	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
    103 -	{ MODKEY|ShiftMask,             XK_h,      setcfact,       {.f = +0.25} },
    104 -	{ MODKEY|ShiftMask,             XK_l,      setcfact,       {.f = -0.25} },
    105 -	{ MODKEY|ShiftMask,             XK_o,      setcfact,       {.f =  0.00} },
    106 -	{ MODKEY,                       XK_Return, zoom,           {0} },
    107 -	{ MODKEY|Mod4Mask,              XK_u,      incrgaps,       {.i = +1 } },
    108 -	{ MODKEY|Mod4Mask|ShiftMask,    XK_u,      incrgaps,       {.i = -1 } },
    109 -	{ MODKEY|Mod4Mask,              XK_i,      incrigaps,      {.i = +1 } },
    110 -	{ MODKEY|Mod4Mask|ShiftMask,    XK_i,      incrigaps,      {.i = -1 } },
    111 -	{ MODKEY|Mod4Mask,              XK_o,      incrogaps,      {.i = +1 } },
    112 -	{ MODKEY|Mod4Mask|ShiftMask,    XK_o,      incrogaps,      {.i = -1 } },
    113 -	{ MODKEY|Mod4Mask,              XK_6,      incrihgaps,     {.i = +1 } },
    114 -	{ MODKEY|Mod4Mask|ShiftMask,    XK_6,      incrihgaps,     {.i = -1 } },
    115 -	{ MODKEY|Mod4Mask,              XK_7,      incrivgaps,     {.i = +1 } },
    116 -	{ MODKEY|Mod4Mask|ShiftMask,    XK_7,      incrivgaps,     {.i = -1 } },
    117 -	{ MODKEY|Mod4Mask,              XK_8,      incrohgaps,     {.i = +1 } },
    118 -	{ MODKEY|Mod4Mask|ShiftMask,    XK_8,      incrohgaps,     {.i = -1 } },
    119 -	{ MODKEY|Mod4Mask,              XK_9,      incrovgaps,     {.i = +1 } },
    120 -	{ MODKEY|Mod4Mask|ShiftMask,    XK_9,      incrovgaps,     {.i = -1 } },
    121 -	{ MODKEY|Mod4Mask,              XK_0,      togglegaps,     {0} },
    122 -	{ MODKEY|Mod4Mask|ShiftMask,    XK_0,      defaultgaps,    {0} },
    123 -	{ MODKEY,                       XK_Tab,    view,           {0} },
    124 -	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
    125 -	{ MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
    126 -	{ MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
    127 -	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
    128 -	{ MODKEY,                       XK_space,  setlayout,      {0} },
    129 -	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
    130 -	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
    131 -	{ MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
    132 -	{ MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
    133 -	{ MODKEY,                       XK_period, focusmon,       {.i = +1 } },
    134 -	{ MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
    135 -	{ MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
    136 +	/* mode     modifier                      key        function        argument */
    137 +	{ Normal,	MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
    138 +	{ Normal,	MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
    139 +	{ Normal,	MODKEY,                       XK_b,      togglebar,      {0} },
    140 +	{ Normal,	MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
    141 +	{ Normal,	MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
    142 +	{ Normal,	MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
    143 +	{ Normal,	MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
    144 +	{ Normal,	MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
    145 +	{ Normal,	MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
    146 +	{ Normal,	MODKEY|ShiftMask,             XK_h,      setcfact,       {.f = +0.25} },
    147 +	{ Normal,	MODKEY|ShiftMask,             XK_l,      setcfact,       {.f = -0.25} },
    148 +	{ Normal,	MODKEY|ShiftMask,             XK_o,      setcfact,       {.f =  0.00} },
    149 +	{ Normal,	MODKEY,                       XK_Return, zoom,           {0} },
    150 +	{ Normal,	MODKEY|Mod4Mask,              XK_u,      incrgaps,       {.i = +1 } },
    151 +	{ Normal,	MODKEY|Mod4Mask|ShiftMask,    XK_u,      incrgaps,       {.i = -1 } },
    152 +	{ Normal,	MODKEY|Mod4Mask,              XK_i,      incrigaps,      {.i = +1 } },
    153 +	{ Normal,	MODKEY|Mod4Mask|ShiftMask,    XK_i,      incrigaps,      {.i = -1 } },
    154 +	{ Normal,	MODKEY|Mod4Mask,              XK_o,      incrogaps,      {.i = +1 } },
    155 +	{ Normal,	MODKEY|Mod4Mask|ShiftMask,    XK_o,      incrogaps,      {.i = -1 } },
    156 +	{ Normal,	MODKEY|Mod4Mask,              XK_6,      incrihgaps,     {.i = +1 } },
    157 +	{ Normal,	MODKEY|Mod4Mask|ShiftMask,    XK_6,      incrihgaps,     {.i = -1 } },
    158 +	{ Normal,	MODKEY|Mod4Mask,              XK_7,      incrivgaps,     {.i = +1 } },
    159 +	{ Normal,	MODKEY|Mod4Mask|ShiftMask,    XK_7,      incrivgaps,     {.i = -1 } },
    160 +	{ Normal,	MODKEY|Mod4Mask,              XK_8,      incrohgaps,     {.i = +1 } },
    161 +	{ Normal,	MODKEY|Mod4Mask|ShiftMask,    XK_8,      incrohgaps,     {.i = -1 } },
    162 +	{ Normal,	MODKEY|Mod4Mask,              XK_9,      incrovgaps,     {.i = +1 } },
    163 +	{ Normal,	MODKEY|Mod4Mask|ShiftMask,    XK_9,      incrovgaps,     {.i = -1 } },
    164 +	{ Normal,	MODKEY|Mod4Mask,              XK_0,      togglegaps,     {0} },
    165 +	{ Normal,	MODKEY|Mod4Mask|ShiftMask,    XK_0,      defaultgaps,    {0} },
    166 +	{ Normal,	MODKEY,                       XK_Tab,    view,           {0} },
    167 +	{ Normal,	MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
    168 +	{ Normal,	MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
    169 +	{ Normal,   MODKEY,                       XK_s,      setlayout,      {.v = &layouts[1]} },
    170 +	{ Normal,	MODKEY,                       XK_f,      setlayout,      {.v = &layouts[2]} },
    171 +	{ Normal,	MODKEY,                       XK_m,      setlayout,      {.v = &layouts[3]} },
    172 +	{ Normal,	MODKEY,                       XK_space,  setlayout,      {0} },
    173 +	{ Normal,	MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
    174 +	{ Normal,	MODKEY,                       XK_0,      view,           {.ui = ~0 } },
    175 +	{ Normal,	MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
    176 +	{ Normal,	MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
    177 +	{ Normal,	MODKEY,                       XK_period, focusmon,       {.i = +1 } },
    178 +	{ Normal,	MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
    179 +	{ Normal,	MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
    180 +
    181 +	/* scroll */
    182 +	{ Scroll,   MODKEY,                       XK_Left,    scrollwin,           {.i = -1} },
    183 +	{ Scroll,   MODKEY,                       XK_Right,   scrollwin,           {.i = +1} },
    184 +	{ Scroll,   MODKEY,                       XK_Up,      focuswinstack,       {.i = -1} },
    185 +	{ Scroll,   MODKEY,                       XK_Down,    focuswinstack,       {.i = +1} },
    186 +	{ Scroll,   MODKEY,                       XK_Tab,     toggleov, 		   {0} },
    187 +	{ Scroll,   MODKEY,                       XK_o,       toggleov, 		   {0} },
    188 +	{ Scroll,   MODKEY,                       XK_w,       togglestack,         {0} },
    189 +	{ Scroll,   MODKEY,                       XK_r,       cyclewinwidth,       {0} },
    190 +	{ Scroll,   MODKEY,                       XK_c,       centerfocused,       {0} },
    191 +	{ Scroll,   MODKEY|ShiftMask,             XK_c,       togglecentering,     {0} },
    192 +	{ Scroll,   MODKEY|ShiftMask,             XK_Left,    movewin,             {.i = -1} },
    193 +	{ Scroll,   MODKEY|ShiftMask,             XK_Right,   movewin,             {.i = +1} },
    194 +	{ Scroll,   MODKEY|ShiftMask,             XK_Up,      movewinstack,        {.i = -1} },
    195 +	{ Scroll,   MODKEY|ShiftMask,             XK_Down,    movewinstack,        {.i = +1} },
    196 +	{ Scroll,   MODKEY|ControlMask,           XK_n,       toggleloopnav,       {0} },
    197 +	
    198 +	/* overview */
    199 +	{ Overview,	0,                      	  XK_Escape, toggleov,       {0} },
    200 +	{ Overview,	0,					  		  XK_Return, zoomov,         {0} },
    201 +	{ Overview,	MODKEY,                 	  XK_Return, zoomov,         {0} },
    202 +	{ Overview,	0,                      	  XK_Up,     focusovlayer,   {.i = -1} },
    203 +	{ Overview,	0,                      	  XK_Down,   focusovlayer,   {.i = +1} },
    204 +	{ Overview, 0,                      	  XK_k,      focusovlayer,   {.i = -1} },
    205 +	{ Overview,	0,                      	  XK_j,      focusovlayer,   {.i = +1} },
    206 +	{ Overview,	0,					  		  XK_Left,   focusovwin,     {.i = -1} },
    207 +	{ Overview,	0,                            XK_Right,  focusovwin,     {.i = +1} },
    208 +	{ Overview,	0,                      	  XK_h,      focusovwin,     {.i = -1} },
    209 +	{ Overview,	0,                            XK_l,      focusovwin,     {.i = +1} },
    210 +	{ Overview,	MODKEY|ShiftMask,             XK_Left,   ovmovewin,      {.i = -1} },
    211 +	{ Overview,	MODKEY|ShiftMask,             XK_Right,  ovmovewin,      {.i = +1} },
    212 +	{ Overview,	MODKEY|ShiftMask,             XK_h,      ovmovewin,      {.i = -1} },
    213 +	{ Overview,	MODKEY|ShiftMask,             XK_l,      ovmovewin,      {.i = +1} },
    214 +	{ Overview,	MODKEY|ShiftMask,             XK_Up,     ovmovewinlayer, {.i = -1} },
    215 +	{ Overview,	MODKEY|ShiftMask,		      XK_Down,   ovmovewinlayer, {.i = +1} },
    216 +	{ Overview,	MODKEY|ShiftMask,             XK_k,      ovmovewinlayer, {.i = -1} },
    217 +	{ Overview,	MODKEY|ShiftMask,             XK_j,      ovmovewinlayer, {.i = +1} },
    218 +	{ Overview,	MODKEY,                       XK_n,      toggleovloopnav,{0} },
    219  	TAGKEYS(                        XK_1,                      0)
    220  	TAGKEYS(                        XK_2,                      1)
    221  	TAGKEYS(                        XK_3,                      2)
    222 @@ -134,23 +207,44 @@ static const Key keys[] = {
    223  	TAGKEYS(                        XK_7,                      6)
    224  	TAGKEYS(                        XK_8,                      7)
    225  	TAGKEYS(                        XK_9,                      8)
    226 -	{ MODKEY|ShiftMask,             XK_q,      quit,           {0} },
    227 +	{ Normal,	MODKEY|ShiftMask,             XK_q,      quit,           {0} },
    228 +
    229  };
    230  
    231  /* button definitions */
    232  /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
    233  static const Button buttons[] = {
    234 -	/* click                event mask      button          function        argument */
    235 -	{ ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
    236 -	{ ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
    237 -	{ ClkWinTitle,          0,              Button2,        zoom,           {0} },
    238 -	{ ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
    239 -	{ ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
    240 -	{ ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
    241 -	{ ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
    242 -	{ ClkTagBar,            0,              Button1,        view,           {0} },
    243 -	{ ClkTagBar,            0,              Button3,        toggleview,     {0} },
    244 -	{ ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
    245 -	{ ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
    246 +	/* mode     click                 event mask      button          function        argument */
    247 +	{ Normal,	ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
    248 +	{ Normal,	ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
    249 +	{ Normal,	ClkWinTitle,          0,              Button2,        zoom,           {0} },
    250 +	{ Normal,	ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
    251 +	{ All,      ClkClientWin,   	  MODKEY,         Button1,        dragdrop,       {0} },
    252 +	{ Normal,	ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
    253 +	{ All,		ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
    254 +	{ Normal,	ClkTagBar,            0,              Button1,        view,           {0} },
    255 +	{ Normal,	ClkTagBar,            0,              Button3,        toggleview,     {0} },
    256 +	{ Normal,	ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
    257 +	{ Normal,	ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
    258 +	{ Scroll,     ClkClientWin,   MODKEY,         Button4,        scrollwin,      {.i = -1} },
    259 +	{ Scroll,     ClkClientWin,   MODKEY,         Button5,        scrollwin,      {.i = +1} },
    260 +	{ Scroll,     ClkRootWin,     MODKEY,         Button4,        scrollwin,      {.i = -1} },
    261 +	{ Scroll,     ClkRootWin,     MODKEY,         Button5,        scrollwin,      {.i = +1} },
    262 +	{ Scroll,     ClkClientWin,   MODKEY,         6,              trackscroll,    {.i = -1} },
    263 +	{ Scroll,     ClkClientWin,   MODKEY,         7,              trackscroll,    {.i = +1} },
    264 +	{ Scroll,     ClkRootWin,     MODKEY,         6,              trackscroll,    {.i = -1} },
    265 +	{ Scroll,     ClkRootWin,     MODKEY,         7,              trackscroll,    {.i = +1} },
    266 +	{ Overview,   ClkClientWin,   0,              Button4,        ovscrollvert,   {.i = -1} },
    267 +	{ Overview,   ClkClientWin,   0,              Button5,        ovscrollvert,   {.i = +1} },
    268 +	{ Overview,   ClkRootWin,     0,              Button4,        ovscrollvert,   {.i = -1} },
    269 +	{ Overview,   ClkRootWin,     0,              Button5,        ovscrollvert,   {.i = +1} },
    270 +	{ Overview,   ClkClientWin,   ShiftMask,      Button4,        ovscrollribbon, {.i = -1} },
    271 +	{ Overview,   ClkClientWin,   ShiftMask,      Button5,        ovscrollribbon, {.i = +1} },
    272 +	{ Overview,   ClkRootWin,     ShiftMask,      Button4,        ovscrollribbon, {.i = -1} },
    273 +	{ Overview,   ClkRootWin,     ShiftMask,      Button5,        ovscrollribbon, {.i = +1} },
    274 +	{ Overview,   ClkClientWin,   0,              6,              ovscrollribbon, {.i = -1} },
    275 +	{ Overview,   ClkClientWin,   0,              7,              ovscrollribbon, {.i = +1} },
    276 +	{ Overview,   ClkRootWin,     0,              6,              ovscrollribbon, {.i = -1} },
    277 +	{ Overview,   ClkRootWin,     0,              7,              ovscrollribbon, {.i = +1} },
    278  };
    279  
    280 diff --git a/dwm.c b/dwm.c
    281 index da30118..12de80e 100644
    282 --- a/dwm.c
    283 +++ b/dwm.c
    284 @@ -49,7 +49,7 @@
    285  #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
    286  #define INTERSECT(x,y,w,h,m)    (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
    287                                 * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
    288 -#define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
    289 +#define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]) || (isov && C->mon == selmon && !C->isfloating))
    290  #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
    291  #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
    292  #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
    293 @@ -65,6 +65,12 @@ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
    294  enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
    295  enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
    296         ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
    297 +enum {
    298 +	Normal   = 1 << 0, /* active in all layouts except overview */
    299 +	Overview = 1 << 1, /* only active in overview layout */
    300 +	Scroll   = 1 << 2, /* only active in scroller layout */
    301 +	All      = Normal | Overview | Scroll /* active in all layouts */
    302 +};
    303  
    304  typedef union {
    305  	int i;
    306 @@ -74,6 +80,7 @@ typedef union {
    307  } Arg;
    308  
    309  typedef struct {
    310 +	unsigned int mode;
    311  	unsigned int click;
    312  	unsigned int mask;
    313  	unsigned int button;
    314 @@ -87,12 +94,15 @@ struct Client {
    315  	char name[256];
    316  	float mina, maxa;
    317  	float cfact;
    318 +	float unstacked_cfact;
    319 +	int is_custom_cfact;
    320  	int x, y, w, h;
    321  	int oldx, oldy, oldw, oldh;
    322  	int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid;
    323  	int bw, oldbw;
    324  	unsigned int tags;
    325  	int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
    326 +	int is_stacked;
    327  	Client *next;
    328  	Client *snext;
    329  	Monitor *mon;
    330 @@ -100,6 +110,7 @@ struct Client {
    331  };
    332  
    333  typedef struct {
    334 +	unsigned int mode;
    335  	unsigned int mod;
    336  	KeySym keysym;
    337  	void (*func)(const Arg *);
    338 @@ -133,6 +144,9 @@ struct Monitor {
    339  	Client *stack;
    340  	Monitor *next;
    341  	Window barwin;
    342 +	int scroll_x;
    343 +	int prev_ncol;
    344 +	int prev_sel_col;
    345  	const Layout *lt[2];
    346  };
    347  
    348 @@ -189,6 +203,8 @@ static void monocle(Monitor *m);
    349  static void motionnotify(XEvent *e);
    350  static void movemouse(const Arg *arg);
    351  static Client *nexttiled(Client *c);
    352 +static void ovacquireseat(void);
    353 +static void ovreleaseseat(void);
    354  static void pop(Client *c);
    355  static void propertynotify(XEvent *e);
    356  static void quit(const Arg *arg);
    357 @@ -270,7 +286,12 @@ static Clr **scheme;
    358  static Display *dpy;
    359  static Drw *drw;
    360  static Monitor *mons, *selmon;
    361 -static Window root, wmcheckwin;
    362 +static Window root, wmcheckwin, ov_seat_win;
    363 +static int isov = 0;
    364 +static Time last_button_time = 0;
    365 +
    366 +#include "scrollview.h"
    367 +#include "overview.h"
    368  
    369  /* configuration, allows nested code to access above variables */
    370  #include "config.h"
    371 @@ -334,20 +355,25 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
    372  		if (*y + *h + 2 * c->bw < 0)
    373  			*y = 0;
    374  	} else {
    375 -		if (*x >= m->wx + m->ww)
    376 +		if (!isov && m->lt[m->sellt]->arrange != scroller && *x >= m->wx + m->ww)
    377  			*x = m->wx + m->ww - WIDTH(c);
    378 -		if (*y >= m->wy + m->wh)
    379 +		if (!isov && *y >= m->wy + m->wh)
    380  			*y = m->wy + m->wh - HEIGHT(c);
    381 -		if (*x + *w + 2 * c->bw <= m->wx)
    382 +		if (!isov && m->lt[m->sellt]->arrange != scroller && *x + *w + 2 * c->bw <= m->wx)
    383  			*x = m->wx;
    384 -		if (*y + *h + 2 * c->bw <= m->wy)
    385 +		if (!isov && *y + *h + 2 * c->bw <= m->wy)
    386  			*y = m->wy;
    387  	}
    388 -	if (*h < bh)
    389 -		*h = bh;
    390 -	if (*w < bh)
    391 -		*w = bh;
    392 -	if (resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) {
    393 +	if (!isov) {
    394 +		if (*h < bh)
    395 +			*h = bh;
    396 +		if (*w < bh)
    397 +			*w = bh;
    398 +	}
    399 +	if (!isov && (resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange)) {
    400 +		int orig_w = *w;
    401 +		int orig_h = *h;
    402 +
    403  		if (!c->hintsvalid)
    404  			updatesizehints(c);
    405  		/* see last two sentences in ICCCM 4.1.2.3 */
    406 @@ -379,6 +405,12 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
    407  			*w = MIN(*w, c->maxw);
    408  		if (c->maxh)
    409  			*h = MIN(*h, c->maxh);
    410 +
    411 +		/* In tiled/stacked layouts, size hints must never exceed allocated slot bounds */
    412 +		if (!c->isfloating && c->mon->lt[c->mon->sellt]->arrange) {
    413 +			*w = MAX(1, MIN(*w, orig_w));
    414 +			*h = MAX(1, MIN(*h, orig_h));
    415 +		}
    416  	}
    417  	return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
    418  }
    419 @@ -400,6 +432,11 @@ arrange(Monitor *m)
    420  void
    421  arrangemon(Monitor *m)
    422  {
    423 +	if (isov && m == selmon) {
    424 +		snprintf(m->ltsymbol, sizeof(m->ltsymbol), "[⊞]");
    425 +		overview(m);
    426 +		return;
    427 +	}
    428  	snprintf(m->ltsymbol, sizeof(m->ltsymbol), "%s", m->lt[m->sellt]->symbol);
    429  	if (m->lt[m->sellt]->arrange)
    430  		m->lt[m->sellt]->arrange(m);
    431 @@ -424,10 +461,11 @@ buttonpress(XEvent *e)
    432  {
    433  	unsigned int i, x, click;
    434  	Arg arg = {0};
    435 -	Client *c;
    436 +	Client *c = NULL;
    437  	Monitor *m;
    438  	XButtonPressedEvent *ev = &e->xbutton;
    439  
    440 +	last_button_time = ev->time;
    441  	click = ClkRootWin;
    442  	/* focus monitor if necessary */
    443  	if ((m = wintomon(ev->window)) && m != selmon) {
    444 @@ -435,7 +473,19 @@ buttonpress(XEvent *e)
    445  		selmon = m;
    446  		focus(NULL);
    447  	}
    448 -	if (ev->window == selmon->barwin) {
    449 +	if (isov) {
    450 +		XAllowEvents(dpy, AsyncPointer, CurrentTime);
    451 +		c = wintoclient(ev->window);
    452 +		if (!c)
    453 +			c = getovwin(ev->x_root, ev->y_root);
    454 +		if (c) {
    455 +			focus(c);
    456 +			restack(selmon);
    457 +			click = ClkClientWin;
    458 +		} else {
    459 +			click = ClkRootWin;
    460 +		}
    461 +	} else if (ev->window == selmon->barwin) {
    462  		i = x = 0;
    463  		do
    464  			x += TEXTW(tags[i]);
    465 @@ -455,10 +505,20 @@ buttonpress(XEvent *e)
    466  		XAllowEvents(dpy, ReplayPointer, CurrentTime);
    467  		click = ClkClientWin;
    468  	}
    469 +	unsigned int cur_mode = CURRENT_MODE();
    470  	for (i = 0; i < LENGTH(buttons); i++)
    471  		if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
    472 -		&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
    473 +		&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)
    474 +		&& (buttons[i].mode & cur_mode)) {
    475  			buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
    476 +			return;
    477 +		}
    478 +	if (isov) {
    479 +		if (CLEANMASK(ev->state) == 0)
    480 +			ovclick(c, ev->x_root, ev->y_root, ev->button);
    481 +	} else {
    482 +		XAllowEvents(dpy, AsyncPointer, CurrentTime);
    483 +	}
    484  }
    485  
    486  void
    487 @@ -494,6 +554,8 @@ cleanup(void)
    488  		drw_scm_free(drw, scheme[i], 3);
    489  	free(scheme);
    490  	XDestroyWindow(dpy, wmcheckwin);
    491 +	if (ov_seat_win)
    492 +		XDestroyWindow(dpy, ov_seat_win);
    493  	drw_free(drw);
    494  	XSync(dpy, False);
    495  	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
    496 @@ -654,6 +716,7 @@ createmon(void)
    497  	m->gappov = gappov;
    498  	m->lt[0] = &layouts[0];
    499  	m->lt[1] = &layouts[1 % LENGTH(layouts)];
    500 +	m->prev_sel_col = -1;
    501  	snprintf(m->ltsymbol, sizeof(m->ltsymbol), "%s", layouts[0].symbol);
    502  	return m;
    503  }
    504 @@ -671,7 +734,11 @@ destroynotify(XEvent *e)
    505  void
    506  detach(Client *c)
    507  {
    508 -	Client **tc;
    509 +	Client **tc, *nxt;
    510 +
    511 +	nxt = nexttiled(c->next);
    512 +	if (!c->is_stacked && nxt && nxt->is_stacked)
    513 +		nxt->is_stacked = 0;
    514  
    515  	for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next);
    516  	*tc = c->next;
    517 @@ -775,6 +842,8 @@ enternotify(XEvent *e)
    518  	Monitor *m;
    519  	XCrossingEvent *ev = &e->xcrossing;
    520  
    521 +	if (isov)
    522 +		return;
    523  	if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
    524  		return;
    525  	c = wintoclient(ev->window);
    526 @@ -800,11 +869,15 @@ expose(XEvent *e)
    527  void
    528  focus(Client *c)
    529  {
    530 +	XEvent ev;
    531 +	int changed;
    532 +
    533  	if (!c || !ISVISIBLE(c))
    534  		for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
    535  	if (selmon->sel && selmon->sel != c)
    536  		unfocus(selmon->sel, 0);
    537  	if (c) {
    538 +		changed = (c != selmon->sel);
    539  		if (c->mon != selmon)
    540  			selmon = c->mon;
    541  		if (c->isurgent)
    542 @@ -817,9 +890,14 @@ focus(Client *c)
    543  	} else {
    544  		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
    545  		XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
    546 +		changed = 0;
    547  	}
    548  	selmon->sel = c;
    549  	drawbars();
    550 +	if (changed && selmon->lt[selmon->sellt]->arrange == scroller) {
    551 +		arrangemon(selmon);
    552 +		while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
    553 +	}
    554  }
    555  
    556  /* there are some broken focus acquiring clients needing extra handling */
    557 @@ -828,6 +906,11 @@ focusin(XEvent *e)
    558  {
    559  	XFocusChangeEvent *ev = &e->xfocus;
    560  
    561 +	if (isov) {
    562 +		if (ev->window != ov_seat_win)
    563 +			ovacquireseat();
    564 +		return;
    565 +	}
    566  	if (selmon->sel && ev->window != selmon->sel->win)
    567  		setfocus(selmon->sel);
    568  }
    569 @@ -948,16 +1031,26 @@ grabbuttons(Client *c, int focused)
    570  		unsigned int i, j;
    571  		unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
    572  		XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
    573 -		if (!focused)
    574 +		if (isov) {
    575  			XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
    576 +				BUTTONMASK, GrabModeAsync, GrabModeAsync, None, None);
    577 +			return;
    578 +		}
    579 +		if (!focused) {
    580 +			XGrabButton(dpy, Button1, AnyModifier, c->win, False,
    581 +				BUTTONMASK, GrabModeSync, GrabModeSync, None, None);
    582 +			XGrabButton(dpy, Button2, AnyModifier, c->win, False,
    583  				BUTTONMASK, GrabModeSync, GrabModeSync, None, None);
    584 +			XGrabButton(dpy, Button3, AnyModifier, c->win, False,
    585 +				BUTTONMASK, GrabModeSync, GrabModeSync, None, None);
    586 +		}
    587  		for (i = 0; i < LENGTH(buttons); i++)
    588 -			if (buttons[i].click == ClkClientWin)
    589 +			if (buttons[i].click == ClkClientWin && (buttons[i].mode & (Normal | Scroll)))
    590  				for (j = 0; j < LENGTH(modifiers); j++)
    591  					XGrabButton(dpy, buttons[i].button,
    592  						buttons[i].mask | modifiers[j],
    593  						c->win, False, BUTTONMASK,
    594 -						GrabModeAsync, GrabModeSync, None, None);
    595 +						GrabModeAsync, GrabModeAsync, None, None);
    596  	}
    597  }
    598  
    599 @@ -978,8 +1071,7 @@ grabkeys(void)
    600  			return;
    601  		for (k = start; k <= end; k++)
    602  			for (i = 0; i < LENGTH(keys); i++)
    603 -				/* skip modifier codes, we do that ourselves */
    604 -				if (keys[i].keysym == syms[(k - start) * skip])
    605 +				if ((keys[i].mode & (Normal | Scroll)) && keys[i].keysym == syms[(k - start) * skip])
    606  					for (j = 0; j < LENGTH(modifiers); j++)
    607  						XGrabKey(dpy, k,
    608  							 keys[i].mod | modifiers[j],
    609 @@ -1014,14 +1106,29 @@ keypress(XEvent *e)
    610  	unsigned int i;
    611  	KeySym keysym;
    612  	XKeyEvent *ev;
    613 +	unsigned int current_mode = CURRENT_MODE();
    614  
    615  	ev = &e->xkey;
    616  	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
    617 -	for (i = 0; i < LENGTH(keys); i++)
    618 -		if (keysym == keys[i].keysym
    619 +	for (i = 0; i < LENGTH(keys); i++) {
    620 +		if (keys[i].mode == current_mode
    621 +		&& keysym == keys[i].keysym
    622  		&& CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
    623 -		&& keys[i].func)
    624 +		&& keys[i].func) {
    625  			keys[i].func(&(keys[i].arg));
    626 +			return;
    627 +		}
    628 +	}
    629 +
    630 +	for (i = 0; i < LENGTH(keys); i++) {
    631 +		if ((keys[i].mode & current_mode)
    632 +		&& keysym == keys[i].keysym
    633 + 		&& CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
    634 +		&& keys[i].func) {
    635 + 			keys[i].func(&(keys[i].arg));
    636 +			return;
    637 +		}
    638 +	}
    639  }
    640  
    641  void
    642 @@ -1055,7 +1162,6 @@ manage(Window w, XWindowAttributes *wa)
    643  	c->w = c->oldw = wa->width;
    644  	c->h = c->oldh = wa->height;
    645  	c->oldbw = wa->border_width;
    646 -	c->cfact = 1.0;
    647  
    648  	updatetitle(c);
    649  	if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
    650 @@ -1066,6 +1172,10 @@ manage(Window w, XWindowAttributes *wa)
    651  		applyrules(c);
    652  	}
    653  
    654 +	c->cfact = defwinw;
    655 +	c->unstacked_cfact = defwinw;
    656 +	c->is_custom_cfact = 0;
    657 +
    658  	if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww)
    659  		c->x = c->mon->wx + c->mon->ww - WIDTH(c);
    660  	if (c->y + HEIGHT(c) > c->mon->wy + c->mon->wh)
    661 @@ -1098,6 +1208,8 @@ manage(Window w, XWindowAttributes *wa)
    662  	c->mon->sel = c;
    663  	arrange(c->mon);
    664  	XMapWindow(dpy, c->win);
    665 +	if (isov)
    666 +		setov(0);
    667  	focus(NULL);
    668  }
    669  
    670 @@ -1164,10 +1276,18 @@ movemouse(const Arg *arg)
    671  	XEvent ev;
    672  	Time lasttime = 0;
    673  
    674 +	if (isov) {
    675 +		dragdrop(arg);
    676 +		return;
    677 +	}
    678  	if (!(c = selmon->sel))
    679  		return;
    680  	if (c->isfullscreen) /* no support moving fullscreen windows by mouse */
    681  		return;
    682 +	if (selmon->lt[selmon->sellt]->arrange == scroller && !c->isfloating) {
    683 +		dragdrop(arg);
    684 +		return;
    685 +	}
    686  	restack(selmon);
    687  	ocx = c->x;
    688  	ocy = c->y;
    689 @@ -1319,6 +1439,10 @@ resizemouse(const Arg *arg)
    690  	XEvent ev;
    691  	Time lasttime = 0;
    692  
    693 +	if (isov) {
    694 +		ovresizemouse(arg);
    695 +		return;
    696 +	}
    697  	if (!(c = selmon->sel))
    698  		return;
    699  	if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */
    700 @@ -1345,10 +1469,23 @@ resizemouse(const Arg *arg)
    701  
    702  			nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
    703  			nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
    704 +			if (selmon->lt[selmon->sellt]->arrange == scroller && !c->isfloating) {
    705 +				int usable_w = selmon->ww - 2 * selmon->gappoh;
    706 +				if (usable_w < 100) usable_w = selmon->ww;
    707 +				float new_cfact = (float)nw / (float)usable_w;
    708 +				if (new_cfact < 0.10f) new_cfact = 0.10f;
    709 +				if (new_cfact > 1.0f) new_cfact = 1.0f;
    710 +				c->cfact = new_cfact;
    711 +				c->unstacked_cfact = new_cfact;
    712 +				c->is_custom_cfact = 1;
    713 +				syncwincfact(c, new_cfact);
    714 +				arrangemon(selmon);
    715 +				continue;
    716 +			}
    717  			if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww
    718  			&& c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh)
    719  			{
    720 -				if (!c->isfloating && selmon->lt[selmon->sellt]->arrange
    721 +				if (!c->isfloating && selmon->lt[selmon->sellt]->arrange && selmon->lt[selmon->sellt]->arrange != scroller
    722  				&& (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
    723  					togglefloating(NULL);
    724  			}
    725 @@ -1360,6 +1497,12 @@ resizemouse(const Arg *arg)
    726  	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
    727  	XUngrabPointer(dpy, CurrentTime);
    728  	while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
    729 +	if (selmon->lt[selmon->sellt]->arrange == scroller && !c->isfloating) {
    730 +		arrangemon(selmon);
    731 +		focus(c);
    732 +		XSync(dpy, False);
    733 +		return;
    734 +	}
    735  	if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
    736  		sendmon(c, m);
    737  		selmon = m;
    738 @@ -1457,6 +1600,21 @@ setclientstate(Client *c, long state)
    739  		PropModeReplace, (unsigned char *)data, 2);
    740  }
    741  
    742 +void
    743 +ovacquireseat(void)
    744 +{
    745 +	if (!isov)
    746 +		return;
    747 +	XSetInputFocus(dpy, ov_seat_win, RevertToParent, CurrentTime);
    748 +	XGrabKeyboard(dpy, ov_seat_win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
    749 +}
    750 +
    751 +void
    752 +ovreleaseseat(void)
    753 +{
    754 +	XUngrabKeyboard(dpy, CurrentTime);
    755 +}
    756 +
    757  int
    758  sendevent(Client *c, Atom proto)
    759  {
    760 @@ -1485,6 +1643,10 @@ sendevent(Client *c, Atom proto)
    761  void
    762  setfocus(Client *c)
    763  {
    764 +	if (isov) {
    765 +		XSetInputFocus(dpy, ov_seat_win, RevertToParent, CurrentTime);
    766 +		return;
    767 +	}
    768  	if (!c->neverfocus)
    769  		XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
    770  	XChangeProperty(dpy, root, netatom[NetActiveWindow], XA_WINDOW, 32,
    771 @@ -1527,6 +1689,12 @@ setlayout(const Arg *arg)
    772  		selmon->sellt ^= 1;
    773  	if (arg && arg->v)
    774  		selmon->lt[selmon->sellt] = (Layout *)arg->v;
    775 +	if (selmon->lt[selmon->sellt]->arrange == overview) {
    776 +		if (!isov)
    777 +			setov(1);
    778 +	} else if (isov) {
    779 +		setov(0);
    780 +	}
    781  	snprintf(selmon->ltsymbol, sizeof(selmon->ltsymbol), "%s", selmon->lt[selmon->sellt]->symbol);
    782  	if (selmon->sel)
    783  		arrange(selmon);
    784 @@ -1549,6 +1717,10 @@ setcfact(const Arg *arg) {
    785  	else if(f < 0.25 || f > 4.0)
    786  		return;
    787  	c->cfact = f;
    788 +	c->unstacked_cfact = f;
    789 +	c->is_custom_cfact = 1;
    790 +	if (selmon->lt[selmon->sellt]->arrange == scroller)
    791 +		syncwincfact(c, f);
    792  	arrange(selmon);
    793  }
    794  
    795 @@ -1629,6 +1801,12 @@ setup(void)
    796  		PropModeReplace, (unsigned char *) "dwm", 3);
    797  	XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32,
    798  		PropModeReplace, (unsigned char *) &wmcheckwin, 1);
    799 +	wa.override_redirect = True;
    800 +	wa.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | FocusChangeMask;
    801 +	ov_seat_win = XCreateWindow(dpy, root, -1, -1, 1, 1, 0,
    802 +	                            CopyFromParent, InputOnly, CopyFromParent,
    803 +	                            CWOverrideRedirect | CWEventMask, &wa);
    804 +	XMapWindow(dpy, ov_seat_win);
    805  	/* EWMH support per view */
    806  	XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
    807  		PropModeReplace, (unsigned char *) netatom, NetLast);
    808 @@ -1684,6 +1862,10 @@ spawn(const Arg *arg)
    809  	if (arg->v == dmenucmd)
    810  		snprintf(dmenumon, sizeof(dmenumon), "%d", selmon->num);
    811  
    812 +	if (isov) {
    813 +		ovreleaseseat();
    814 +		XSync(dpy, False);
    815 +	}
    816  	if ((pid = fork()) == -1) {
    817  		fprintf(stderr, "dwm: fork failed: %s\n", strerror(errno));
    818  		return;
    819 @@ -2063,7 +2245,9 @@ updatewmhints(Client *c)
    820  void
    821  view(const Arg *arg)
    822  {
    823 -	if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
    824 +	if (isov)
    825 +		setov(0);
    826 +	else if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
    827  		return;
    828  	selmon->seltags ^= 1; /* toggle sel tagset */
    829  	if (arg->ui & TAGMASK)
    830 diff --git a/overview.c b/overview.c
    831 new file mode 100644
    832 index 0000000..ed8951e
    833 --- /dev/null
    834 +++ b/overview.c
    835 @@ -0,0 +1,880 @@
    836 +#ifndef OVERVIEW_C
    837 +#define OVERVIEW_C
    838 +
    839 +#include "overview.h"
    840 +#include "scrollview.h"
    841 +
    842 +static OvLayer g_layers[16];
    843 +static int g_nlayers = 0;
    844 +static int g_sel_layer = 0;
    845 +static int g_ovscroll_y = 0;
    846 +static int g_ovmaxscroll_y = 0;
    847 +static int g_need_center_sel = 1;
    848 +static unsigned int saved_ovtags = 0;
    849 +static const Layout *saved_ovlayout = NULL;
    850 +
    851 +static inline void
    852 +restore_ovlayout(void)
    853 +{
    854 +	const Layout *lt = (saved_ovlayout && saved_ovlayout->arrange != overview)
    855 +	                   ? saved_ovlayout : &layouts[0];
    856 +	saved_ovlayout = NULL;
    857 +	if (selmon->lt[selmon->sellt]->arrange == overview)
    858 +		setlayout(&(Arg){.v = (void *)lt});
    859 +}
    860 +
    861 +static inline int
    862 +layer_by_tag(unsigned int tagmask)
    863 +{
    864 +	for (int i = 0; i < g_nlayers; i++)
    865 +		if (tagmask & (1 << g_layers[i].tag))
    866 +			return i;
    867 +	return -1;
    868 +}
    869 +
    870 +static inline int
    871 +sync_sel_layer(void)
    872 +{
    873 +	int l = selmon->sel ? layer_by_tag(selmon->sel->tags) : -1;
    874 +	if (l < 0)
    875 +		l = (g_sel_layer >= 0 && g_sel_layer < g_nlayers) ? g_sel_layer : 0;
    876 +	return g_sel_layer = l;
    877 +}
    878 +
    879 +static inline void
    880 +ovfocuswin(Client *c)
    881 +{
    882 +	if (!c) return;
    883 +	focus(c);
    884 +	restack(selmon);
    885 +	g_need_center_sel = 1;
    886 +	arrangemon(selmon);
    887 +}
    888 +
    889 +static void
    890 +setov(int enable)
    891 +{
    892 +	if (isov == enable)
    893 +		return;
    894 +	isov = enable;
    895 +	if (enable) {
    896 +		g_ovscroll_y = 0;
    897 +		g_ovmaxscroll_y = 0;
    898 +		g_need_center_sel = 1;
    899 +		ovacquireseat();
    900 +		for (Monitor *m = mons; m; m = m->next)
    901 +			for (Client *c = m->clients; c; c = c->next)
    902 +				grabbuttons(c, 0);
    903 +	} else {
    904 +		ovreleaseseat();
    905 +		grabkeys();
    906 +		restore_ovlayout();
    907 +		for (Monitor *m = mons; m; m = m->next)
    908 +			for (Client *c = m->clients; c; c = c->next)
    909 +				grabbuttons(c, c == m->sel);
    910 +		if (selmon->sel)
    911 +			focus(selmon->sel);
    912 +	}
    913 +}
    914 +
    915 +static void
    916 +toggleov(const Arg *arg)
    917 +{
    918 +	if (isov) {
    919 +		setov(0);
    920 +		if (saved_ovtags)
    921 +			selmon->tagset[selmon->seltags] = saved_ovtags;
    922 +		focus(NULL);
    923 +		arrange(selmon);
    924 +	} else {
    925 +		saved_ovtags = selmon->tagset[selmon->seltags];
    926 +		saved_ovlayout = selmon->lt[selmon->sellt];
    927 +		g_sel_layer = MAX(0, layer_by_tag(saved_ovtags));
    928 +		for (int i = 0; i < LENGTH(layouts); i++) {
    929 +			if (layouts[i].arrange == overview) {
    930 +				selmon->lt[selmon->sellt] = (Layout *)&layouts[i];
    931 +				break;
    932 +			}
    933 +		}
    934 +		g_ovscroll_y = 0;
    935 +		g_ovmaxscroll_y = 0;
    936 +		g_need_center_sel = 1;
    937 +		setov(1);
    938 +		arrange(selmon);
    939 +	}
    940 +}
    941 +
    942 +static int
    943 +getlayercols(Monitor *m, unsigned int tagmask, Client *skip, Column cols[MAX_COLS])
    944 +{
    945 +	int ncol = 0;
    946 +	if (!m)
    947 +		return 0;
    948 +
    949 +	for (Client *c = m->clients; c; c = c->next) {
    950 +		if (c == skip || c->isfloating || !(c->tags & tagmask))
    951 +			continue;
    952 +		if (ncol == 0 || !c->is_stacked) {
    953 +			if (ncol < MAX_COLS) {
    954 +				cols[ncol].clients[0] = c;
    955 +				cols[ncol].count = 1;
    956 +				ncol++;
    957 +			}
    958 +		} else {
    959 +			if (cols[ncol - 1].count < MAX_COL_CLIENTS)
    960 +				cols[ncol - 1].clients[cols[ncol - 1].count++] = c;
    961 +		}
    962 +	}
    963 +	return ncol;
    964 +}
    965 +
    966 +static void
    967 +focusovwindir(int dir)
    968 +{
    969 +	if (g_nlayers == 0)
    970 +		return;
    971 +
    972 +	int cur_layer = sync_sel_layer();
    973 +	Column cols[MAX_COLS];
    974 +	int ncol = getlayercols(selmon, 1 << g_layers[cur_layer].tag, NULL, cols);
    975 +	if (ncol == 0)
    976 +		return;
    977 +
    978 +	int cur_row = 0;
    979 +	int cur_col = find_col_row(cols, ncol, selmon->sel, &cur_row);
    980 +
    981 +	int target_col;
    982 +	if (cur_col == -1) {
    983 +		target_col = (dir > 0) ? 0 : ncol - 1;
    984 +	} else {
    985 +		target_col = NAV_WRAP(cur_col, dir, ncol, ovloopnav);
    986 +		if (target_col == cur_col)
    987 +			return;
    988 +	}
    989 +	int target_row = (cur_col == -1) ? 0 : MIN(cur_row, cols[target_col].count - 1);
    990 +
    991 +	ovfocuswin(cols[target_col].clients[target_row]);
    992 +}
    993 +
    994 +static void
    995 +focusovlayerdir(int dir)
    996 +{
    997 +	if (g_nlayers == 0)
    998 +		return;
    999 +
   1000 +	int cur_layer = sync_sel_layer();
   1001 +	Column cols[MAX_COLS];
   1002 +	int ncol = getlayercols(selmon, 1 << g_layers[cur_layer].tag, NULL, cols);
   1003 +
   1004 +	int cur_row = 0;
   1005 +	int cur_col = find_col_row(cols, ncol, selmon->sel, &cur_row);
   1006 +
   1007 +	if (cur_col != -1 && cols[cur_col].count > 1) {
   1008 +		if ((dir < 0 && cur_row > 0) || (dir > 0 && cur_row < cols[cur_col].count - 1)) {
   1009 +			ovfocuswin(cols[cur_col].clients[cur_row + dir]);
   1010 +			return;
   1011 +		}
   1012 +	}
   1013 +
   1014 +	if (g_nlayers > 1) {
   1015 +		int target_layer = NAV_WRAP(cur_layer, dir, g_nlayers, ovloopnav);
   1016 +		if (target_layer == cur_layer)
   1017 +			return;
   1018 +		Column target_cols[MAX_COLS];
   1019 +		int target_ncol = getlayercols(selmon, 1 << g_layers[target_layer].tag, NULL, target_cols);
   1020 +
   1021 +		if (target_ncol > 0) {
   1022 +			int tcol = CLAMP(cur_col < 0 ? 0 : cur_col, 0, target_ncol - 1);
   1023 +			int trow = (dir > 0) ? 0 : (target_cols[tcol].count - 1);
   1024 +			Client *target_win = target_cols[tcol].clients[MIN(trow, target_cols[tcol].count - 1)];
   1025 +			if (target_win) {
   1026 +				focus(target_win);
   1027 +				restack(selmon);
   1028 +			}
   1029 +		}
   1030 +		g_sel_layer = target_layer;
   1031 +		g_need_center_sel = 1;
   1032 +		arrangemon(selmon);
   1033 +		return;
   1034 +	}
   1035 +
   1036 +	if (cur_col != -1 && cols[cur_col].count > 1) {
   1037 +		if (!ovloopnav)
   1038 +			return;
   1039 +		int trow = (dir < 0) ? (cols[cur_col].count - 1) : 0;
   1040 +		ovfocuswin(cols[cur_col].clients[trow]);
   1041 +	} else {
   1042 +		focusovwindir(dir);
   1043 +	}
   1044 +}
   1045 +
   1046 +static void
   1047 +ovjumptagidx(int tag_idx)
   1048 +{
   1049 +	int l = layer_by_tag(1 << tag_idx);
   1050 +	if (l >= 0) {
   1051 +		g_sel_layer = l;
   1052 +		if (g_layers[l].first_win)
   1053 +			focus(g_layers[l].first_win);
   1054 +		g_need_center_sel = 1;
   1055 +		arrangemon(selmon);
   1056 +		return;
   1057 +	}
   1058 +	view(&(Arg){.ui = 1 << tag_idx});
   1059 +}
   1060 +
   1061 +static void
   1062 +zoomovsel(void)
   1063 +{
   1064 +	if (g_nlayers == 0) {
   1065 +		toggleov(NULL);
   1066 +		return;
   1067 +	}
   1068 +
   1069 +	int tag = g_layers[g_sel_layer].tag;
   1070 +	Client *c = selmon->sel;
   1071 +	view(&(Arg){.ui = 1 << tag});
   1072 +	restore_ovlayout();
   1073 +	focus((c && (c->tags & (1 << tag))) ? c : g_layers[g_sel_layer].first_win);
   1074 +	restack(selmon);
   1075 +}
   1076 +
   1077 +static void
   1078 +zoomovwin(Client *c)
   1079 +{
   1080 +	if (!c)
   1081 +		return;
   1082 +	view(&(Arg){.ui = c->tags});
   1083 +	restore_ovlayout();
   1084 +	focus(c);
   1085 +	restack(selmon);
   1086 +}
   1087 +
   1088 +static int
   1089 +getovexactlayertag(int px, int py)
   1090 +{
   1091 +	for (int i = 0; i < g_nlayers; i++) {
   1092 +		if (py >= g_layers[i].y && py < g_layers[i].y + g_layers[i].h)
   1093 +			return g_layers[i].tag;
   1094 +	}
   1095 +	return -1;
   1096 +}
   1097 +
   1098 +static Client *
   1099 +getovwin(int px, int py)
   1100 +{
   1101 +	int tag = getovexactlayertag(px, py);
   1102 +	if (tag < 0)
   1103 +		return NULL;
   1104 +	unsigned int tagmask = 1 << tag;
   1105 +	for (Client *c = selmon->clients; c; c = c->next) {
   1106 +		if (!c->isfloating && (c->tags & tagmask) &&
   1107 +		    px >= c->x && px < c->x + c->w + 2 * c->bw &&
   1108 +		    py >= c->y && py < c->y + c->h + 2 * c->bw)
   1109 +			return c;
   1110 +	}
   1111 +	return NULL;
   1112 +}
   1113 +
   1114 +static int
   1115 +getovlayertag(int px, int py)
   1116 +{
   1117 +	int best_tag = -1;
   1118 +	long min_dy = -1;
   1119 +
   1120 +	for (int i = 0; i < g_nlayers; i++) {
   1121 +		if (py >= g_layers[i].y && py < g_layers[i].y + g_layers[i].h)
   1122 +			return g_layers[i].tag;
   1123 +
   1124 +		int cy = g_layers[i].y + g_layers[i].h / 2;
   1125 +		long dy = abs(py - cy);
   1126 +		if (min_dy < 0 || dy < min_dy) {
   1127 +			min_dy = dy;
   1128 +			best_tag = g_layers[i].tag;
   1129 +		}
   1130 +	}
   1131 +	return best_tag;
   1132 +}
   1133 +
   1134 +static void
   1135 +ovdrop(Client *c, int drop_x, int drop_y)
   1136 +{
   1137 +	if (!c)
   1138 +		return;
   1139 +
   1140 +	if (drop_y <= selmon->by + bh) {
   1141 +		int i = 0, tx = 0;
   1142 +		do {
   1143 +			tx += TEXTW(tags[i]);
   1144 +		} while (drop_x >= tx && ++i < LENGTH(tags));
   1145 +		if (i < LENGTH(tags)) {
   1146 +			c->tags = 1 << i;
   1147 +			c->is_stacked = 0;
   1148 +			c->cfact = (c->unstacked_cfact > 0.05f) ? c->unstacked_cfact : defwinw;
   1149 +			detach(c);
   1150 +			attach(c);
   1151 +		}
   1152 +	} else {
   1153 +		int target_tag = getovlayertag(drop_x, drop_y);
   1154 +		if (target_tag >= 0) {
   1155 +			unsigned int new_tags = 1 << target_tag;
   1156 +			Column tag_cols[MAX_COLS];
   1157 +			int tag_ncol = getlayercols(selmon, new_tags, c, tag_cols);
   1158 +
   1159 +			c->tags = new_tags;
   1160 +
   1161 +			if (tag_ncol == 0) {
   1162 +				c->is_stacked = 0;
   1163 +				c->cfact = (c->unstacked_cfact > 0.05f) ? c->unstacked_cfact : defwinw;
   1164 +				detach(c);
   1165 +				attach(c);
   1166 +			} else {
   1167 +				Client *first_win = tag_cols[0].clients[0];
   1168 +				Client *last_win = tag_cols[tag_ncol - 1].clients[tag_cols[tag_ncol - 1].count - 1];
   1169 +				int left_bound = first_win->x;
   1170 +				int right_bound = last_win->x + last_win->w + 2 * last_win->bw;
   1171 +
   1172 +				if (drop_x <= left_bound + 10) {
   1173 +					c->is_stacked = 0;
   1174 +					unstackreorder(c, first_win, InsBefore);
   1175 +				} else if (drop_x >= right_bound - 10) {
   1176 +					c->is_stacked = 0;
   1177 +					unstackreorder(c, last_win, InsAfter);
   1178 +				} else {
   1179 +					int placed = 0;
   1180 +					for (int k = 0; k < tag_ncol; k++) {
   1181 +						Client *win_lead = tag_cols[k].clients[0];
   1182 +						int col_x = win_lead->x;
   1183 +						int col_w = win_lead->w + 2 * win_lead->bw;
   1184 +						int next_col_x = (k + 1 < tag_ncol) ? tag_cols[k + 1].clients[0]->x : right_bound;
   1185 +
   1186 +						if (drop_x >= col_x && drop_x < col_x + col_w) {
   1187 +							int edge_zone = MAX(20, (int)(col_w * 0.22));
   1188 +
   1189 +							if (drop_x < col_x + edge_zone) {
   1190 +								c->is_stacked = 0;
   1191 +								unstackreorder(c, win_lead, InsBefore);
   1192 +								placed = 1;
   1193 +								break;
   1194 +							} else if (drop_x > col_x + col_w - edge_zone) {
   1195 +								c->is_stacked = 0;
   1196 +								unstackreorder(c, tag_cols[k].clients[tag_cols[k].count - 1], InsAfter);
   1197 +								placed = 1;
   1198 +								break;
   1199 +							} else {
   1200 +								Client *target_win = win_lead;
   1201 +								for (int j = 0; j < tag_cols[k].count; j++) {
   1202 +									Client *win = tag_cols[k].clients[j];
   1203 +									if (drop_y >= win->y && drop_y <= win->y + win->h + 2 * win->bw) {
   1204 +										target_win = win;
   1205 +										break;
   1206 +									}
   1207 +								}
   1208 +
   1209 +								if (drop_y < target_win->y + target_win->h / 3) {
   1210 +									c->is_stacked = 1;
   1211 +									reorderclient(c, target_win, StkBefore);
   1212 +									c->cfact = target_win->cfact;
   1213 +								} else if (drop_y > target_win->y + (target_win->h * 2) / 3) {
   1214 +									c->is_stacked = 1;
   1215 +									reorderclient(c, target_win, StkAfter);
   1216 +									c->cfact = target_win->cfact;
   1217 +								} else if (drop_x < col_x + col_w / 2) {
   1218 +									c->is_stacked = 0;
   1219 +									unstackreorder(c, win_lead, InsBefore);
   1220 +								} else {
   1221 +									c->is_stacked = 0;
   1222 +									unstackreorder(c, tag_cols[k].clients[tag_cols[k].count - 1], InsAfter);
   1223 +								}
   1224 +								placed = 1;
   1225 +								break;
   1226 +							}
   1227 +						} else if (drop_x >= col_x + col_w && drop_x < next_col_x) {
   1228 +							c->is_stacked = 0;
   1229 +							unstackreorder(c, tag_cols[k].clients[tag_cols[k].count - 1], InsAfter);
   1230 +							placed = 1;
   1231 +							break;
   1232 +						}
   1233 +					}
   1234 +
   1235 +					if (!placed) {
   1236 +						c->is_stacked = 0;
   1237 +						unstackreorder(c, last_win, InsAfter);
   1238 +					}
   1239 +				}
   1240 +			}
   1241 +			int l = layer_by_tag(new_tags);
   1242 +			if (l >= 0) g_sel_layer = l;
   1243 +		}
   1244 +	}
   1245 +	c->x = -9999;
   1246 +	c->y = -9999;
   1247 +	selmon->sel = c;
   1248 +	g_need_center_sel = 1;
   1249 +	arrangemon(selmon);
   1250 +	focus(c);
   1251 +	XSync(dpy, False);
   1252 +}
   1253 +
   1254 +static void
   1255 +focusovlayer(const Arg *arg)
   1256 +{
   1257 +	focusovlayerdir(arg->i);
   1258 +}
   1259 +
   1260 +static void
   1261 +focusovwin(const Arg *arg)
   1262 +{
   1263 +	focusovwindir(arg->i);
   1264 +}
   1265 +
   1266 +static void
   1267 +ovmovewindir(int dir)
   1268 +{
   1269 +	if (!selmon || !selmon->sel || selmon->sel->isfloating || g_nlayers == 0)
   1270 +		return;
   1271 +
   1272 +	Client *c = selmon->sel;
   1273 +	int cur_layer = sync_sel_layer();
   1274 +	if (cur_layer < 0 || cur_layer >= g_nlayers)
   1275 +		return;
   1276 +
   1277 +	Column cols[MAX_COLS];
   1278 +	int ncol = getlayercols(selmon, 1 << g_layers[cur_layer].tag, NULL, cols);
   1279 +	if (ncol == 0)
   1280 +		return;
   1281 +
   1282 +	int cur_col = find_col_row(cols, ncol, c, NULL);
   1283 +	if (cur_col == -1 || (ncol <= 1 && cols[cur_col].count <= 1))
   1284 +		return;
   1285 +
   1286 +	if (!reorder_col_dir(c, cols, ncol, cur_col, dir, ovloopnav))
   1287 +		return;
   1288 +
   1289 +	c->x = -9999;
   1290 +	c->y = -9999;
   1291 +	selmon->sel = c;
   1292 +	g_need_center_sel = 1;
   1293 +	arrangemon(selmon);
   1294 +	focus(c);
   1295 +	keep_cursor_inside(c);
   1296 +}
   1297 +
   1298 +static void
   1299 +ovmovewinlayerdir(int dir)
   1300 +{
   1301 +	if (!selmon || !selmon->sel || selmon->sel->isfloating || g_nlayers <= 1)
   1302 +		return;
   1303 +
   1304 +	Client *c = selmon->sel;
   1305 +	int cur_layer = sync_sel_layer();
   1306 +	if (cur_layer < 0 || cur_layer >= g_nlayers)
   1307 +		return;
   1308 +
   1309 +	int target_layer = NAV_WRAP(cur_layer, dir, g_nlayers, ovloopnav);
   1310 +	if (target_layer == cur_layer)
   1311 +		return;
   1312 +
   1313 +	unsigned int target_tag = g_layers[target_layer].tag;
   1314 +	unsigned int new_tags = 1 << target_tag;
   1315 +
   1316 +	Column cur_cols[MAX_COLS];
   1317 +	int cur_ncol = getlayercols(selmon, 1 << g_layers[cur_layer].tag, NULL, cur_cols);
   1318 +	int cur_col = find_col_row(cur_cols, cur_ncol, c, NULL);
   1319 +
   1320 +	Column target_cols[MAX_COLS];
   1321 +	int target_ncol = getlayercols(selmon, new_tags, c, target_cols);
   1322 +
   1323 +	detach_unstack(c);
   1324 +
   1325 +	c->is_stacked = 0;
   1326 +	ENSURE_CFACT(c);
   1327 +	c->is_custom_cfact = IS_CUSTOM_CFACT(c->cfact);
   1328 +	c->tags = new_tags;
   1329 +
   1330 +	if (target_ncol == 0) {
   1331 +		c->next = selmon->clients;
   1332 +		selmon->clients = c;
   1333 +	} else {
   1334 +		int col_pos = (cur_col < 0) ? target_ncol - 1 : cur_col;
   1335 +		Client **tc;
   1336 +		if (col_pos == 0) {
   1337 +			Client *first_win = target_cols[0].clients[0];
   1338 +			for (tc = &selmon->clients; *tc && *tc != first_win; tc = &(*tc)->next);
   1339 +			c->next = first_win;
   1340 +			*tc = c;
   1341 +		} else {
   1342 +			int t_col = MIN(col_pos, target_ncol) - 1;
   1343 +			Client *prev_win = target_cols[t_col].clients[target_cols[t_col].count - 1];
   1344 +			c->next = prev_win->next;
   1345 +			prev_win->next = c;
   1346 +		}
   1347 +	}
   1348 +
   1349 +	c->x = -9999;
   1350 +	c->y = -9999;
   1351 +	selmon->sel = c;
   1352 +	g_sel_layer = target_layer;
   1353 +	g_need_center_sel = 1;
   1354 +	arrangemon(selmon);
   1355 +	focus(c);
   1356 +	keep_cursor_inside(c);
   1357 +}
   1358 +
   1359 +static void
   1360 +ovmovewin(const Arg *arg)
   1361 +{
   1362 +	ovmovewindir(arg->i);
   1363 +}
   1364 +
   1365 +static void
   1366 +ovmovewinlayer(const Arg *arg)
   1367 +{
   1368 +	ovmovewinlayerdir(arg->i);
   1369 +}
   1370 +
   1371 +static void
   1372 +toggleovloopnav(const Arg *arg)
   1373 +{
   1374 +	ovloopnav = !ovloopnav;
   1375 +}
   1376 +
   1377 +static void
   1378 +zoomov(const Arg *arg)
   1379 +{
   1380 +	zoomovsel();
   1381 +}
   1382 +
   1383 +static void
   1384 +ovclick(Client *c, int px, int py, int button)
   1385 +{
   1386 +	if (button == Button1) {
   1387 +		if (c) {
   1388 +			zoomovwin(c);
   1389 +		} else {
   1390 +			int tag = getovexactlayertag(px, py);
   1391 +			if (tag >= 0) {
   1392 +				Arg a = {.ui = 1 << tag};
   1393 +				view(&a);
   1394 +			} else {
   1395 +				toggleov(NULL);
   1396 +			}
   1397 +		}
   1398 +	} else if (button == Button3) {
   1399 +		toggleov(NULL);
   1400 +	}
   1401 +}
   1402 +
   1403 +static void
   1404 +ovjumptag(const Arg *arg)
   1405 +{
   1406 +	ovjumptagidx(arg->ui);
   1407 +}
   1408 +
   1409 +static int
   1410 +drain_scroll_events(int is_horiz, int delta)
   1411 +{
   1412 +	XEvent next_ev;
   1413 +	while (XCheckMaskEvent(dpy, ButtonPressMask, &next_ev)) {
   1414 +		int b = next_ev.xbutton.button;
   1415 +		unsigned int state = CLEANMASK(next_ev.xbutton.state);
   1416 +		int match_neg = is_horiz ? ((b == 6 && !state) || (b == Button4 && state == ShiftMask))
   1417 +		                         : (b == Button4 && !state);
   1418 +		int match_pos = is_horiz ? ((b == 7 && !state) || (b == Button5 && state == ShiftMask))
   1419 +		                         : (b == Button5 && !state);
   1420 +		if (match_neg)
   1421 +			delta -= scrollstep;
   1422 +		else if (match_pos)
   1423 +			delta += scrollstep;
   1424 +		else {
   1425 +			XPutBackEvent(dpy, &next_ev);
   1426 +			break;
   1427 +		}
   1428 +	}
   1429 +	return delta;
   1430 +}
   1431 +
   1432 +static void
   1433 +ovscrollribbon_px(int tag, int delta_px)
   1434 +{
   1435 +	int l = layer_by_tag(1 << tag);
   1436 +	if (l >= 0) {
   1437 +		g_need_center_sel = 0;
   1438 +		g_layers[l].scroll_x = CLAMP(g_layers[l].scroll_x + delta_px, 0, MAX(0, g_layers[l].max_scroll_x));
   1439 +	}
   1440 +}
   1441 +
   1442 +static void
   1443 +ovscrollvert_px(int delta_px)
   1444 +{
   1445 +	g_need_center_sel = 0;
   1446 +	g_ovscroll_y = CLAMP(g_ovscroll_y + delta_px, 0, g_ovmaxscroll_y);
   1447 +}
   1448 +
   1449 +static void
   1450 +ovscrollribbon(const Arg *arg)
   1451 +{
   1452 +	if (!isov)
   1453 +		return;
   1454 +	int dir = (arg && arg->i < 0) ? -1 : +1;
   1455 +	int init_d = dir * scrollstep;
   1456 +	int x, y;
   1457 +	getrootptr(&x, &y);
   1458 +	int layer_tag = getovlayertag(x, y);
   1459 +	int delta = drain_scroll_events(1, init_d);
   1460 +	ovscrollribbon_px(layer_tag, delta);
   1461 +	arrangemon(selmon);
   1462 +}
   1463 +
   1464 +static void
   1465 +ovscrollvert(const Arg *arg)
   1466 +{
   1467 +	if (!isov)
   1468 +		return;
   1469 +	int dir = (arg && arg->i < 0) ? -1 : +1;
   1470 +	int init_d = dir * scrollstep;
   1471 +	if (g_ovmaxscroll_y > 0) {
   1472 +		int delta = drain_scroll_events(0, init_d);
   1473 +		ovscrollvert_px(delta);
   1474 +		arrangemon(selmon);
   1475 +	} else {
   1476 +		static Time last_layer_move = 0;
   1477 +		if ((last_button_time - last_layer_move) > 120) {
   1478 +			last_layer_move = last_button_time;
   1479 +			focusovlayerdir(dir);
   1480 +		}
   1481 +	}
   1482 +}
   1483 +
   1484 +static void
   1485 +ovresizemouse(const Arg *arg)
   1486 +{
   1487 +	Client *c = selmon->sel;
   1488 +	int x, y;
   1489 +	XEvent ev;
   1490 +	Time lasttime = 0;
   1491 +
   1492 +	if (!isov || !c || c->isfloating)
   1493 +		return;
   1494 +
   1495 +	if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
   1496 +		None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess)
   1497 +		return;
   1498 +
   1499 +	if (!getrootptr(&x, &y)) {
   1500 +		XUngrabPointer(dpy, CurrentTime);
   1501 +		return;
   1502 +	}
   1503 +
   1504 +	float start_cfact = (c->cfact > 0.05f) ? c->cfact : defwinw;
   1505 +	int pad_x = ovgappoh;
   1506 +	int usable_w = selmon->ww - 2 * pad_x;
   1507 +	if (usable_w < 100) usable_w = selmon->ww;
   1508 +
   1509 +	do {
   1510 +		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
   1511 +		switch (ev.type) {
   1512 +		case ConfigureRequest:
   1513 +		case Expose:
   1514 +		case MapRequest:
   1515 +			handler[ev.type](&ev);
   1516 +			break;
   1517 +		case MotionNotify:
   1518 +			if ((ev.xmotion.time - lasttime) <= (1000 / refreshrate))
   1519 +				continue;
   1520 +			lasttime = ev.xmotion.time;
   1521 +
   1522 +			float delta = (float)(ev.xmotion.x_root - x) / (float)usable_w;
   1523 +			float new_cfact = CLAMP(start_cfact + delta, 0.10f, 1.0f);
   1524 +
   1525 +			c->cfact = new_cfact;
   1526 +			c->unstacked_cfact = new_cfact;
   1527 +			c->is_custom_cfact = 1;
   1528 +			syncwincfact(c, new_cfact);
   1529 +			arrangemon(selmon);
   1530 +			break;
   1531 +		}
   1532 +	} while (ev.type != ButtonRelease);
   1533 +
   1534 +	XUngrabPointer(dpy, CurrentTime);
   1535 +	arrangemon(selmon);
   1536 +	focus(c);
   1537 +	XSync(dpy, False);
   1538 +}
   1539 +
   1540 +static void
   1541 +overview(Monitor *m)
   1542 +{
   1543 +	unsigned int in_use = 0;
   1544 +	for (Client *c = m->clients; c; c = c->next)
   1545 +		if (!c->isfloating)
   1546 +			in_use |= (c->tags & TAGMASK);
   1547 +
   1548 +	if (!in_use)
   1549 +		in_use = m->tagset[m->seltags] & TAGMASK;
   1550 +
   1551 +	g_nlayers = 0;
   1552 +	for (int i = 0; i < LENGTH(tags); i++) {
   1553 +		if (in_use & (1 << i)) {
   1554 +			g_layers[g_nlayers].tag = i;
   1555 +			g_layers[g_nlayers].nwin = 0;
   1556 +			g_layers[g_nlayers].first_win = NULL;
   1557 +			g_nlayers++;
   1558 +		}
   1559 +	}
   1560 +
   1561 +	if (g_nlayers == 0) {
   1562 +		g_layers[0].tag = 0;
   1563 +		g_layers[0].nwin = 0;
   1564 +		g_layers[0].first_win = NULL;
   1565 +		g_nlayers = 1;
   1566 +	}
   1567 +
   1568 +	int sel_l = m->sel ? layer_by_tag(m->sel->tags) : (saved_ovtags ? layer_by_tag(saved_ovtags) : -1);
   1569 +	if (sel_l >= 0)
   1570 +		g_sel_layer = sel_l;
   1571 +	g_sel_layer = CLAMP(g_sel_layer, 0, g_nlayers - 1);
   1572 +
   1573 +	int mx = m->wx, my = m->wy, mw = m->ww, mh = m->wh;
   1574 +	int pad_y = ovgappov;
   1575 +	int gap_y = ovlayergap;
   1576 +	int pad_x = ovgappoh;
   1577 +	int uw = mw - 2 * pad_x;
   1578 +	int avail_h = mh - 2 * pad_y;
   1579 +	if (avail_h < 100) avail_h = mh;
   1580 +
   1581 +	int total_gaps = (g_nlayers - 1) * gap_y;
   1582 +	int layer_h;
   1583 +	if (ovuniformlayer || g_nlayers == 1)
   1584 +		layer_h = (int)(avail_h * ovsingleh);
   1585 +	else if (g_nlayers <= ovmaxfit)
   1586 +		layer_h = (avail_h - total_gaps) / g_nlayers;
   1587 +	else
   1588 +		layer_h = (avail_h - (ovmaxfit - 1) * gap_y) / ovmaxfit;
   1589 +
   1590 +	if (layer_h < 120) layer_h = 120;
   1591 +
   1592 +	int total_h = g_nlayers * layer_h + total_gaps;
   1593 +	if (total_h <= avail_h) {
   1594 +		int start_y = my + pad_y + (avail_h - total_h) / 2;
   1595 +		for (int i = 0; i < g_nlayers; i++) {
   1596 +			g_layers[i].y = start_y + i * (layer_h + gap_y);
   1597 +			g_layers[i].h = layer_h;
   1598 +		}
   1599 +		if (m->sel) {
   1600 +			int l = layer_by_tag(m->sel->tags);
   1601 +			if (l >= 0) g_sel_layer = l;
   1602 +		}
   1603 +		g_ovscroll_y = 0;
   1604 +		g_ovmaxscroll_y = 0;
   1605 +	} else {
   1606 +		int stride = layer_h + gap_y;
   1607 +		int total_h = g_nlayers * layer_h + total_gaps;
   1608 +		int max_scroll = MAX(0, total_h - avail_h);
   1609 +		g_ovmaxscroll_y = max_scroll;
   1610 +
   1611 +		if (g_need_center_sel && !is_dragging && !is_scrolling) {
   1612 +			int sel_center = g_sel_layer * stride + layer_h / 2;
   1613 +			g_ovscroll_y = CLAMP(sel_center - (avail_h / 2), 0, max_scroll);
   1614 +		}
   1615 +		g_ovscroll_y = CLAMP(g_ovscroll_y, 0, max_scroll);
   1616 +
   1617 +		int start_y = my + pad_y - g_ovscroll_y;
   1618 +		for (int i = 0; i < g_nlayers; i++) {
   1619 +			g_layers[i].y = start_y + i * stride;
   1620 +			g_layers[i].h = layer_h;
   1621 +		}
   1622 +
   1623 +		if (!m->sel && (is_scrolling || is_dragging)) {
   1624 +			int screen_center_y = my + pad_y + avail_h / 2;
   1625 +			int best_diff = -1;
   1626 +			for (int i = 0; i < g_nlayers; i++) {
   1627 +				int layer_center_y = g_layers[i].y + layer_h / 2;
   1628 +				int diff = abs(layer_center_y - screen_center_y);
   1629 +				if (best_diff < 0 || diff < best_diff) {
   1630 +					best_diff = diff;
   1631 +					g_sel_layer = i;
   1632 +				}
   1633 +			}
   1634 +		} else if (m->sel) {
   1635 +			int l = layer_by_tag(m->sel->tags);
   1636 +			if (l >= 0) g_sel_layer = l;
   1637 +		}
   1638 +	}
   1639 +
   1640 +	int in_pad_y = ovinpady;
   1641 +	int uh = layer_h - 2 * in_pad_y;
   1642 +	if (uh < 60) uh = layer_h;
   1643 +	int igap_x = ovgappih;
   1644 +	int igap_y = ovgappiv;
   1645 +	float S = (float)uh / (float)(mh > 0 ? mh : 1);
   1646 +
   1647 +	for (int i = 0; i < g_nlayers; i++) {
   1648 +		int tag_idx = g_layers[i].tag;
   1649 +		int layer_y = g_layers[i].y;
   1650 +
   1651 +		Column tag_cols[MAX_COLS];
   1652 +		int tag_ncol = getlayercols(m, 1 << tag_idx, NULL, tag_cols);
   1653 +		g_layers[i].first_win = (tag_ncol > 0) ? tag_cols[0].clients[0] : NULL;
   1654 +		g_layers[i].nwin = tag_ncol;
   1655 +		if (tag_ncol == 0)
   1656 +			continue;
   1657 +
   1658 +		int total_ribbon_w = 0;
   1659 +		for (int k = 0; k < tag_ncol; k++) {
   1660 +			Client *top = tag_cols[k].clients[0];
   1661 +			float factor = CLAMP((top->cfact > 0.05f) ? top->cfact : defwinw, 0.1f, 1.0f);
   1662 +			int w = (tag_ncol == 1) ? MIN((int)(uh * 1.6f), (int)(uw * 0.70f))
   1663 +			                        : (int)(uw * factor * S * 1.3f);
   1664 +			tag_cols[k].w = CLAMP(w, 100, uw);
   1665 +			total_ribbon_w += tag_cols[k].w + (k > 0 ? igap_x : 0);
   1666 +		}
   1667 +
   1668 +		int start_x;
   1669 +		if (total_ribbon_w <= uw) {
   1670 +			start_x = mx + pad_x + (uw - total_ribbon_w) / 2;
   1671 +			g_layers[i].scroll_x = 0;
   1672 +			g_layers[i].max_scroll_x = 0;
   1673 +		} else {
   1674 +			int max_scroll = total_ribbon_w - uw;
   1675 +			g_layers[i].max_scroll_x = max_scroll;
   1676 +
   1677 +			if (g_need_center_sel && !is_dragging && !is_scrolling) {
   1678 +				int sel_col = find_col_row(tag_cols, tag_ncol, m->sel, NULL);
   1679 +				if (sel_col >= 0) {
   1680 +					int cur_col_x = 0;
   1681 +					for (int k = 0; k < sel_col; k++)
   1682 +						cur_col_x += tag_cols[k].w + igap_x;
   1683 +					int target_scroll = (cur_col_x + tag_cols[sel_col].w / 2) - (uw / 2);
   1684 +					g_layers[i].scroll_x = CLAMP(target_scroll, 0, max_scroll);
   1685 +				}
   1686 +			}
   1687 +			g_layers[i].scroll_x = CLAMP(g_layers[i].scroll_x, 0, max_scroll);
   1688 +			start_x = mx + pad_x - g_layers[i].scroll_x;
   1689 +		}
   1690 +
   1691 +		int cur_x = start_x;
   1692 +		for (int k = 0; k < tag_ncol; k++) {
   1693 +			int col_w = tag_cols[k].w;
   1694 +			int count = tag_cols[k].count;
   1695 +			int total_gap = (count - 1) * igap_y;
   1696 +			int win_h = (uh - total_gap) / count;
   1697 +			int cur_y = layer_y + in_pad_y;
   1698 +
   1699 +			for (int j = 0; j < count; j++) {
   1700 +				Client *c = tag_cols[k].clients[j];
   1701 +				int h = (j == count - 1) ? (uh - (cur_y - (layer_y + in_pad_y))) : win_h;
   1702 +				if (!is_dragging || c != m->sel)
   1703 +					scrollermoveresize(c, cur_x, cur_y, MAX(1, col_w - 2 * c->bw), MAX(1, h - 2 * c->bw));
   1704 +				cur_y += win_h + igap_y;
   1705 +			}
   1706 +			cur_x += col_w + igap_x;
   1707 +		}
   1708 +	}
   1709 +	if (!m->sel && g_layers[g_sel_layer].first_win)
   1710 +		focus(g_layers[g_sel_layer].first_win);
   1711 +	g_need_center_sel = 0;
   1712 +	XSync(dpy, False);
   1713 +}
   1714 +
   1715 +#endif /* OVERVIEW_C */
   1716 diff --git a/overview.h b/overview.h
   1717 new file mode 100644
   1718 index 0000000..6c35e61
   1719 --- /dev/null
   1720 +++ b/overview.h
   1721 @@ -0,0 +1,34 @@
   1722 +#ifndef OVERVIEW_H
   1723 +#define OVERVIEW_H
   1724 +
   1725 +typedef struct {
   1726 +	int tag;          /* 0-indexed tag (0 to 8) */
   1727 +	int y;            /* Y coordinate on screen */
   1728 +	int h;            /* Height of this layer */
   1729 +	int nwin;         /* Number of windows / columns */
   1730 +	Client *first_win;/* First window in this layer */
   1731 +	int scroll_x;     /* Horizontal ribbon scroll offset */
   1732 +	int max_scroll_x; /* Maximum horizontal scroll offset */
   1733 +} OvLayer;
   1734 +
   1735 +static void overview(Monitor *m);
   1736 +static void setov(int enable);
   1737 +static void toggleov(const Arg *arg);
   1738 +static void focusovlayer(const Arg *arg);
   1739 +static void focusovwin(const Arg *arg);
   1740 +static void zoomov(const Arg *arg);
   1741 +static void ovjumptag(const Arg *arg);
   1742 +static void ovdrop(Client *c, int drop_x, int drop_y);
   1743 +static int getovlayertag(int px, int py);
   1744 +static void ovscrollribbon(const Arg *arg);
   1745 +static void ovscrollvert(const Arg *arg);
   1746 +static void ovscrollribbon_px(int tag, int delta_px);
   1747 +static void ovscrollvert_px(int delta_px);
   1748 +static void ovresizemouse(const Arg *arg);
   1749 +static void ovclick(Client *c, int px, int py, int button);
   1750 +static void ovmovewin(const Arg *arg);
   1751 +static void ovmovewinlayer(const Arg *arg);
   1752 +static void toggleovloopnav(const Arg *arg);
   1753 +static Client *getovwin(int px, int py);
   1754 +
   1755 +#endif /* OVERVIEW_H */
   1756 diff --git a/scrollview.c b/scrollview.c
   1757 new file mode 100644
   1758 index 0000000..9929bb5
   1759 --- /dev/null
   1760 +++ b/scrollview.c
   1761 @@ -0,0 +1,907 @@
   1762 +#include "scrollview.h"
   1763 +
   1764 +static int is_scrolling = 0;
   1765 +static int is_dragging = 0;
   1766 +
   1767 +static Column g_cols[MAX_COLS];
   1768 +static int g_ncol = 0;
   1769 +static Client *prev_sel_client = NULL;
   1770 +static unsigned int prev_tagset = 0;
   1771 +
   1772 +static void
   1773 +scrollermoveresize(Client *c, int x, int y, int w, int h)
   1774 +{
   1775 +	if (c->x == x && c->y == y && c->w == w && c->h == h)
   1776 +		return;
   1777 +
   1778 +	if (c->w == w && c->h == h) {
   1779 +		c->oldx = c->x; c->x = x;
   1780 +		c->oldy = c->y; c->y = y;
   1781 +		XMoveWindow(dpy, c->win, x, y);
   1782 +	} else {
   1783 +		resize(c, x, y, w, h, 0);
   1784 +	}
   1785 +}
   1786 +
   1787 +static int
   1788 +find_col_row(const Column *cols, int ncol, const Client *c, int *out_row)
   1789 +{
   1790 +	if (out_row) *out_row = 0;
   1791 +	if (!c || !cols) return -1;
   1792 +	for (int i = 0; i < ncol; i++)
   1793 +		for (int j = 0; j < cols[i].count; j++)
   1794 +			if (cols[i].clients[j] == c) {
   1795 +				if (out_row) *out_row = j;
   1796 +				return i;
   1797 +			}
   1798 +	return -1;
   1799 +}
   1800 +
   1801 +static inline int
   1802 +get_view_geom(Monitor *m, int ncol, int *out_base_x)
   1803 +{
   1804 +	int uw = (m->ww - 2 * m->gappoh >= 100) ? m->ww - 2 * m->gappoh : m->ww;
   1805 +	int sl = (ncol > 1 && strutleft > 0) ? strutleft : 0;
   1806 +	int sr = (ncol > 1 && strutright > 0) ? strutright : 0;
   1807 +	int vw = (uw - sl - sr >= 100) ? uw - sl - sr : uw;
   1808 +	if (out_base_x)
   1809 +		*out_base_x = m->wx + m->gappoh + sl;
   1810 +	return vw;
   1811 +}
   1812 +
   1813 +static inline void
   1814 +unstackreorder(Client *c, Client *target, int pos)
   1815 +{
   1816 +	reorderclient(c, target, pos);
   1817 +	c->cfact = (c->unstacked_cfact > 0.05f) ? c->unstacked_cfact : defwinw;
   1818 +	c->is_custom_cfact = IS_CUSTOM_CFACT(c->cfact);
   1819 +}
   1820 +
   1821 +static inline void
   1822 +unstack_to_edge(Client *c, const Column *cols, int c_col, int target_col, int pos)
   1823 +{
   1824 +	int is_before = (pos == InsBefore);
   1825 +	Client *target_win;
   1826 +	if (c_col != target_col) {
   1827 +		target_win = is_before ? cols[target_col].clients[0]
   1828 +		                       : cols[target_col].clients[cols[target_col].count - 1];
   1829 +	} else if (cols[c_col].count > 1) {
   1830 +		int count = cols[c_col].count;
   1831 +		if (is_before)
   1832 +			target_win = (cols[c_col].clients[0] == c) ? cols[c_col].clients[1] : cols[c_col].clients[0];
   1833 +		else
   1834 +			target_win = (cols[c_col].clients[count - 1] == c)
   1835 +			             ? cols[c_col].clients[count - 2]
   1836 +			             : cols[c_col].clients[count - 1];
   1837 +	} else {
   1838 +		return;
   1839 +	}
   1840 +	unstackreorder(c, target_win, pos);
   1841 +}
   1842 +
   1843 +static inline void
   1844 +unstack_client(Client *c, int col_idx)
   1845 +{
   1846 +	unstack_to_edge(c, g_cols, col_idx, col_idx, (c == g_cols[col_idx].clients[0]) ? InsBefore : InsAfter);
   1847 +}
   1848 +
   1849 +static inline void
   1850 +stack_client_target(Client *c, Column *col, Client *target_win, int pos)
   1851 +{
   1852 +	ENSURE_CFACT(c);
   1853 +	for (int j = 0; j < col->count; j++)
   1854 +		ENSURE_CFACT(col->clients[j]);
   1855 +
   1856 +	float target_cfact = col->clients[0]->cfact;
   1857 +	int target_custom = col->clients[0]->is_custom_cfact;
   1858 +	reorderclient(c, target_win, pos);
   1859 +	c->cfact = target_cfact;
   1860 +	c->is_custom_cfact = target_custom;
   1861 +}
   1862 +
   1863 +static int
   1864 +reorder_col_dir(Client *c, const Column *cols, int ncol, int col_idx, int dir, int loop)
   1865 +{
   1866 +	if (cols[col_idx].count > 1) {
   1867 +		unstack_to_edge(c, cols, col_idx, col_idx, (dir > 0) ? InsAfter : InsBefore);
   1868 +		return 1;
   1869 +	}
   1870 +
   1871 +	if (dir > 0) {
   1872 +		if (col_idx < ncol - 1)
   1873 +			unstackreorder(c, cols[col_idx + 1].clients[cols[col_idx + 1].count - 1], InsAfter);
   1874 +		else if (loop && ncol > 1)
   1875 +			unstackreorder(c, cols[0].clients[0], InsBefore);
   1876 +		else
   1877 +			return 0;
   1878 +	} else if (dir < 0) {
   1879 +		if (col_idx > 0)
   1880 +			unstackreorder(c, cols[col_idx - 1].clients[0], InsBefore);
   1881 +		else if (loop && ncol > 1)
   1882 +			unstackreorder(c, cols[ncol - 1].clients[cols[ncol - 1].count - 1], InsAfter);
   1883 +		else
   1884 +			return 0;
   1885 +	} else {
   1886 +		return 0;
   1887 +	}
   1888 +	return 1;
   1889 +}
   1890 +
   1891 +static void
   1892 +keep_cursor_inside(Client *c)
   1893 +{
   1894 +	int px, py;
   1895 +	XEvent ev;
   1896 +
   1897 +	if (!c)
   1898 +		return;
   1899 +
   1900 +	if (getrootptr(&px, &py)) {
   1901 +		if (px < c->x || px >= c->x + c->w || py < c->y || py >= c->y + c->h)
   1902 +			XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
   1903 +	} else {
   1904 +		XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
   1905 +	}
   1906 +
   1907 +	focus(c);
   1908 +	if (c->mon)
   1909 +		restack(c->mon);
   1910 +	XSync(dpy, False);
   1911 +	while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
   1912 +}
   1913 +
   1914 +static inline void
   1915 +finish_drag_client(Client *c)
   1916 +{
   1917 +	c->x = c->y = -9999;
   1918 +	selmon->sel = c;
   1919 +	arrangemon(selmon);
   1920 +	focus(c);
   1921 +	keep_cursor_inside(c);
   1922 +	XSync(dpy, False);
   1923 +}
   1924 +
   1925 +static inline int
   1926 +get_ribbon_offset(int total_w, int view_w)
   1927 +{
   1928 +	if (total_w < view_w && centermode == CenterAlways)
   1929 +		return (view_w - total_w) / 2;
   1930 +	return 0;
   1931 +}
   1932 +
   1933 +static void
   1934 +scroller_arrange_col(Monitor *m, Column *col, int col_x, int col_w)
   1935 +{
   1936 +	int count = col->count;
   1937 +	int total_gaps_v = (count - 1) * m->gappiv;
   1938 +	int avail_h = m->wh - 2 * m->gappov - total_gaps_v;
   1939 +	if (avail_h < count) avail_h = count;
   1940 +	int h_each = avail_h / count;
   1941 +	int cur_y = m->wy + m->gappov;
   1942 +
   1943 +	for (int j = 0; j < count; j++) {
   1944 +		Client *c = col->clients[j];
   1945 +		int win_h = (j == count - 1) ? (avail_h - (count - 1) * h_each) : h_each;
   1946 +		int bw = c->bw;
   1947 +		if (is_dragging && c == m->sel) {
   1948 +			cur_y += win_h + m->gappiv;
   1949 +			continue;
   1950 +		}
   1951 +		scrollermoveresize(c, col_x, cur_y, MAX(1, col_w - 2 * bw), MAX(1, win_h - 2 * bw));
   1952 +		cur_y += win_h + m->gappiv;
   1953 +	}
   1954 +}
   1955 +
   1956 +static int
   1957 +build_columns(Monitor *m)
   1958 +{
   1959 +	Client *c;
   1960 +	g_ncol = 0;
   1961 +
   1962 +	for (c = nexttiled(m->clients); c && g_ncol < MAX_COLS; c = nexttiled(c->next)) {
   1963 +		if (g_ncol == 0 || !c->is_stacked) {
   1964 +			g_cols[g_ncol].clients[0] = c;
   1965 +			g_cols[g_ncol].count = 1;
   1966 +			g_ncol++;
   1967 +		} else {
   1968 +			if (g_cols[g_ncol - 1].count < MAX_COL_CLIENTS)
   1969 +				g_cols[g_ncol - 1].clients[g_cols[g_ncol - 1].count++] = c;
   1970 +		}
   1971 +	}
   1972 +
   1973 +	int view_w = get_view_geom(m, g_ncol, NULL);
   1974 +	int cur_x = 0;
   1975 +	for (int i = 0; i < g_ncol; i++) {
   1976 +		Client *top = g_cols[i].clients[0];
   1977 +
   1978 +		if (g_ncol > 1 && g_cols[i].count == 1) {
   1979 +			if (top->unstacked_cfact > 0.05f)
   1980 +				top->cfact = top->unstacked_cfact;
   1981 +			top->is_custom_cfact = IS_CUSTOM_CFACT(top->cfact);
   1982 +		}
   1983 +
   1984 +		float factor = top->is_custom_cfact ? ((top->cfact > 0.05f) ? top->cfact : defwinw)
   1985 +		                                    : ((g_ncol > 1) ? defwinw : swinw);
   1986 +		factor = CLAMP(factor, 0.1f, 1.0f);
   1987 +
   1988 +		if (!top->is_custom_cfact) {
   1989 +			for (int j = 0; j < g_cols[i].count; j++)
   1990 +				g_cols[i].clients[j]->cfact = factor;
   1991 +		}
   1992 +
   1993 +		int avail_w = view_w - ((factor <= 0.35f) ? 2 * m->gappih : ((factor < 0.99f) ? m->gappih : 0));
   1994 +		int w = CLAMP((int)(avail_w * factor), 80, view_w);
   1995 +
   1996 +		g_cols[i].w = w;
   1997 +		g_cols[i].x = cur_x;
   1998 +		cur_x += w + ((i < g_ncol - 1) ? m->gappih : 0);
   1999 +	}
   2000 +
   2001 +	return g_ncol;
   2002 +}
   2003 +
   2004 +void
   2005 +trackscroll(const Arg *arg)
   2006 +{
   2007 +	int ncol;
   2008 +
   2009 +	if (!selmon || selmon->lt[selmon->sellt]->arrange != scroller)
   2010 +		return;
   2011 +
   2012 +	ncol = build_columns(selmon);
   2013 +	if (ncol <= 1)
   2014 +		return;
   2015 +
   2016 +	int view_w = get_view_geom(selmon, ncol, NULL);
   2017 +	int total_w = g_cols[ncol - 1].x + g_cols[ncol - 1].w;
   2018 +	int max_scroll = (total_w > view_w) ? (total_w - view_w) : 0;
   2019 +
   2020 +	selmon->scroll_x = CLAMP(selmon->scroll_x + arg->i * scrollstep, 0, max_scroll);
   2021 +	is_scrolling = 1;
   2022 +	arrangemon(selmon);
   2023 +
   2024 +	int screen_mid = selmon->scroll_x + view_w / 2;
   2025 +	int best_col = 0;
   2026 +	int min_dist = 999999;
   2027 +	for (int i = 0; i < ncol; i++) {
   2028 +		int mid = g_cols[i].x + g_cols[i].w / 2;
   2029 +		int dist = abs(mid - screen_mid);
   2030 +		if (dist < min_dist) {
   2031 +			min_dist = dist;
   2032 +			best_col = i;
   2033 +		}
   2034 +	}
   2035 +
   2036 +	Client *target_win = (g_cols[best_col].count > 0) ? g_cols[best_col].clients[0] : selmon->sel;
   2037 +	if (target_win) {
   2038 +		if (target_win != selmon->sel)
   2039 +			focus(target_win);
   2040 +		keep_cursor_inside(target_win);
   2041 +	}
   2042 +	is_scrolling = 0;
   2043 +}
   2044 +
   2045 +void
   2046 +scrollwin(const Arg *arg)
   2047 +{
   2048 +	int ncol, cur_col, cur_row = 0;
   2049 +
   2050 +	if (!selmon)
   2051 +		return;
   2052 +
   2053 +	if (selmon->lt[selmon->sellt]->arrange != scroller) {
   2054 +		focusstack(arg);
   2055 +		return;
   2056 +	}
   2057 +
   2058 +	ncol = build_columns(selmon);
   2059 +	if (ncol <= 1)
   2060 +		return;
   2061 +
   2062 +	cur_col = find_col_row(g_cols, ncol, selmon->sel, &cur_row);
   2063 +
   2064 +	if (cur_col == -1) {
   2065 +		int base_x;
   2066 +		int view_w = get_view_geom(selmon, ncol, &base_x);
   2067 +		int px, py;
   2068 +		if (getrootptr(&px, &py)) {
   2069 +			int total_w = g_cols[ncol - 1].x + g_cols[ncol - 1].w;
   2070 +			int offset_x = get_ribbon_offset(total_w, view_w);
   2071 +			int ribbon_x = px - base_x - offset_x + selmon->scroll_x;
   2072 +			for (int i = 0; i < ncol; i++) {
   2073 +				if (ribbon_x >= g_cols[i].x && ribbon_x <= g_cols[i].x + g_cols[i].w + selmon->gappih) {
   2074 +					cur_col = i;
   2075 +					break;
   2076 +				}
   2077 +			}
   2078 +		}
   2079 +	}
   2080 +	if (cur_col == -1) cur_col = 0;
   2081 +
   2082 +	int target_col = NAV_WRAP(cur_col, arg->i, ncol, loopnav);
   2083 +	if (target_col == cur_col)
   2084 +		return;
   2085 +
   2086 +	if (g_cols[target_col].count > 0) {
   2087 +		int target_row = (cur_row < g_cols[target_col].count) ? cur_row : (g_cols[target_col].count - 1);
   2088 +		Client *target_win = g_cols[target_col].clients[target_row];
   2089 +		focus(target_win);
   2090 +		restack(selmon);
   2091 +		keep_cursor_inside(target_win);
   2092 +	}
   2093 +}
   2094 +
   2095 +void
   2096 +focuswinstack(const Arg *arg)
   2097 +{
   2098 +	int ncol, cur_col, cur_row;
   2099 +
   2100 +	if (!selmon || !selmon->sel)
   2101 +		return;
   2102 +
   2103 +	if (selmon->lt[selmon->sellt]->arrange != scroller) {
   2104 +		focusstack(arg);
   2105 +		return;
   2106 +	}
   2107 +
   2108 +	ncol = build_columns(selmon);
   2109 +	cur_col = find_col_row(g_cols, ncol, selmon->sel, &cur_row);
   2110 +
   2111 +	if (cur_col != -1 && g_cols[cur_col].count > 1) {
   2112 +		int target_row = NAV_WRAP(cur_row, arg->i, g_cols[cur_col].count, loopnav);
   2113 +		if (target_row == cur_row)
   2114 +			return;
   2115 +		Client *target_win = g_cols[cur_col].clients[target_row];
   2116 +		focus(target_win);
   2117 +		keep_cursor_inside(target_win);
   2118 +	} else if (loopnav) {
   2119 +		focusstack(arg);
   2120 +		if (selmon->sel)
   2121 +			keep_cursor_inside(selmon->sel);
   2122 +	}
   2123 +}
   2124 +
   2125 +void
   2126 +stackconsume(const Arg *arg)
   2127 +{
   2128 +	Client *c, *target_win = NULL;
   2129 +
   2130 +	if (!selmon || selmon->lt[selmon->sellt]->arrange != scroller || !selmon->sel)
   2131 +		return;
   2132 +
   2133 +	c = selmon->sel;
   2134 +	if (arg->i >= 0) {
   2135 +		target_win = nexttiled(c->next);
   2136 +	} else {
   2137 +		Client *p;
   2138 +		for (p = selmon->clients; p && p != c; p = p->next)
   2139 +			if (!p->isfloating && ISVISIBLE(p))
   2140 +				target_win = p;
   2141 +	}
   2142 +
   2143 +	if (!target_win || target_win == c)
   2144 +		return;
   2145 +
   2146 +	ENSURE_CFACT(c);
   2147 +	ENSURE_CFACT(target_win);
   2148 +
   2149 +	target_win->is_stacked = 1;
   2150 +	target_win->cfact = c->cfact;
   2151 +	target_win->is_custom_cfact = c->is_custom_cfact;
   2152 +	arrangemon(selmon);
   2153 +	keep_cursor_inside(selmon->sel);
   2154 +}
   2155 +
   2156 +void
   2157 +stackexpel(const Arg *arg)
   2158 +{
   2159 +	if (!selmon || selmon->lt[selmon->sellt]->arrange != scroller || !selmon->sel)
   2160 +		return;
   2161 +
   2162 +	Client *c = selmon->sel;
   2163 +	int ncol = build_columns(selmon);
   2164 +	int col_idx = find_col_row(g_cols, ncol, c, NULL);
   2165 +	if (col_idx != -1 && g_cols[col_idx].count > 1) {
   2166 +		unstack_client(c, col_idx);
   2167 +	} else {
   2168 +		c->is_stacked = 0;
   2169 +		c->cfact = (c->unstacked_cfact > 0.05f) ? c->unstacked_cfact : defwinw;
   2170 +		c->is_custom_cfact = IS_CUSTOM_CFACT(c->cfact);
   2171 +	}
   2172 +	arrangemon(selmon);
   2173 +	keep_cursor_inside(selmon->sel);
   2174 +}
   2175 +
   2176 +void
   2177 +togglestack(const Arg *arg)
   2178 +{
   2179 +	if (!selmon || selmon->lt[selmon->sellt]->arrange != scroller || !selmon->sel)
   2180 +		return;
   2181 +
   2182 +	int ncol = build_columns(selmon);
   2183 +	int col_idx = find_col_row(g_cols, ncol, selmon->sel, NULL);
   2184 +	if (col_idx != -1 && g_cols[col_idx].count > 1)
   2185 +		stackexpel(arg);
   2186 +	else
   2187 +		stackconsume(arg);
   2188 +}
   2189 +
   2190 +void
   2191 +movewin(const Arg *arg)
   2192 +{
   2193 +	Client *c = selmon->sel;
   2194 +	if (!c || c->isfloating || selmon->lt[selmon->sellt]->arrange != scroller)
   2195 +		return;
   2196 +
   2197 +	int ncol = build_columns(selmon);
   2198 +	if (ncol == 0)
   2199 +		return;
   2200 +
   2201 +	int col_idx = find_col_row(g_cols, ncol, c, NULL);
   2202 +	if (col_idx == -1 || (ncol <= 1 && g_cols[col_idx].count <= 1))
   2203 +		return;
   2204 +
   2205 +	if (!reorder_col_dir(c, g_cols, ncol, col_idx, arg->i, loopnav))
   2206 +		return;
   2207 +
   2208 +	centerfocused(NULL);
   2209 +}
   2210 +
   2211 +void
   2212 +movewinstack(const Arg *arg)
   2213 +{
   2214 +	Client *c = selmon->sel;
   2215 +	if (!c || c->isfloating || selmon->lt[selmon->sellt]->arrange != scroller || !arg->i)
   2216 +		return;
   2217 +
   2218 +	int ncol = build_columns(selmon);
   2219 +	if (ncol == 0)
   2220 +		return;
   2221 +
   2222 +	int cur_row = -1;
   2223 +	int col_idx = find_col_row(g_cols, ncol, c, &cur_row);
   2224 +	if (col_idx == -1 || cur_row == -1)
   2225 +		return;
   2226 +
   2227 +	int count = g_cols[col_idx].count;
   2228 +	int is_down = (arg->i > 0);
   2229 +
   2230 +	if (count <= 1) {
   2231 +		if (ncol <= 1)
   2232 +			return;
   2233 +		int t_col = (col_idx < ncol - 1) ? (col_idx + 1) : (col_idx - 1);
   2234 +		int pos = is_down ? StkAfter : StkBefore;
   2235 +		Client *target_win = is_down ? g_cols[t_col].clients[g_cols[t_col].count - 1]
   2236 +		                             : g_cols[t_col].clients[0];
   2237 +		stack_client_target(c, &g_cols[t_col], target_win, pos);
   2238 +	} else {
   2239 +		int at_edge = is_down ? (cur_row == count - 1) : (cur_row == 0);
   2240 +		if (at_edge && !loopnav)
   2241 +			return;
   2242 +		int target_idx = at_edge ? (is_down ? 0 : count - 1) : (cur_row + (is_down ? 1 : -1));
   2243 +		int pos = (at_edge == is_down) ? StkBefore : StkAfter;
   2244 +		Client *target_win = g_cols[col_idx].clients[target_idx];
   2245 +		reorderclient(c, target_win, pos);
   2246 +	}
   2247 +
   2248 +	arrangemon(selmon);
   2249 +	keep_cursor_inside(c);
   2250 +}
   2251 +
   2252 +void
   2253 +syncwincfact(Client *c, float f)
   2254 +{
   2255 +	int ncol = build_columns(selmon);
   2256 +	int col_idx = find_col_row(g_cols, ncol, c, NULL);
   2257 +	if (col_idx != -1) {
   2258 +		for (int j = 0; j < g_cols[col_idx].count; j++) {
   2259 +			g_cols[col_idx].clients[j]->cfact = f;
   2260 +			g_cols[col_idx].clients[j]->is_custom_cfact = 1;
   2261 +		}
   2262 +	}
   2263 +}
   2264 +
   2265 +void
   2266 +cyclewinwidth(const Arg *arg)
   2267 +{
   2268 +	int ncol, col_idx;
   2269 +
   2270 +	if (!selmon || selmon->lt[selmon->sellt]->arrange != scroller || !selmon->sel)
   2271 +		return;
   2272 +
   2273 +	Client *c = selmon->sel;
   2274 +	ncol = build_columns(selmon);
   2275 +	col_idx = find_col_row(g_cols, ncol, c, NULL);
   2276 +
   2277 +	float cur_factor = (ncol == 1 && !c->is_custom_cfact) ? 1.0f : c->cfact;
   2278 +	int cur_idx = -1;
   2279 +	for (int i = 0; i < (int)LENGTH(winsizes); i++) {
   2280 +		if (cur_factor >= winsizes[i] - 0.04f && cur_factor <= winsizes[i] + 0.04f) {
   2281 +			cur_idx = i;
   2282 +			break;
   2283 +		}
   2284 +	}
   2285 +	float next_factor = winsizes[(cur_idx + 1) % LENGTH(winsizes)];
   2286 +
   2287 +	c->cfact = next_factor;
   2288 +	c->is_custom_cfact = 1;
   2289 +	if (col_idx != -1) {
   2290 +		if (g_cols[col_idx].count == 1)
   2291 +			c->unstacked_cfact = next_factor;
   2292 +		for (int j = 0; j < g_cols[col_idx].count; j++) {
   2293 +			g_cols[col_idx].clients[j]->cfact = next_factor;
   2294 +			g_cols[col_idx].clients[j]->is_custom_cfact = 1;
   2295 +		}
   2296 +	}
   2297 +
   2298 +	centerfocused(NULL);
   2299 +}
   2300 +
   2301 +void
   2302 +centerfocused(const Arg *arg)
   2303 +{
   2304 +	int ncol, sel_col;
   2305 +
   2306 +	if (!selmon || selmon->lt[selmon->sellt]->arrange != scroller || !selmon->sel)
   2307 +		return;
   2308 +
   2309 +	ncol = build_columns(selmon);
   2310 +	sel_col = find_col_row(g_cols, ncol, selmon->sel, NULL);
   2311 +	if (sel_col == -1) return;
   2312 +
   2313 +	int view_w = get_view_geom(selmon, ncol, NULL);
   2314 +	int center_col = g_cols[sel_col].x + g_cols[sel_col].w / 2;
   2315 +	int total_w = g_cols[ncol - 1].x + g_cols[ncol - 1].w;
   2316 +	int max_scroll = (total_w > view_w) ? (total_w - view_w) : 0;
   2317 +
   2318 +	selmon->scroll_x = CLAMP(center_col - view_w / 2, 0, max_scroll);
   2319 +	arrangemon(selmon);
   2320 +	keep_cursor_inside(selmon->sel);
   2321 +}
   2322 +
   2323 +void
   2324 +togglecentering(const Arg *arg)
   2325 +{
   2326 +	centermode = (centermode == CenterOnFlow) ? CenterAlways :
   2327 +	             (centermode == CenterAlways) ? CenterNever : CenterOnFlow;
   2328 +
   2329 +	if (selmon && selmon->lt[selmon->sellt]->arrange == scroller) {
   2330 +		arrangemon(selmon);
   2331 +		keep_cursor_inside(selmon->sel);
   2332 +	}
   2333 +}
   2334 +
   2335 +void
   2336 +toggleloopnav(const Arg *arg)
   2337 +{
   2338 +	loopnav = !loopnav;
   2339 +}
   2340 +
   2341 +void
   2342 +scroller(Monitor *m)
   2343 +{
   2344 +	static int in_scroller = 0;
   2345 +	if (in_scroller)
   2346 +		return;
   2347 +	in_scroller = 1;
   2348 +
   2349 +	int ncol = build_columns(m);
   2350 +	if (ncol == 0) {
   2351 +		m->prev_ncol = 0;
   2352 +		m->prev_sel_col = -1;
   2353 +		prev_sel_client = NULL;
   2354 +		prev_tagset = m->tagset[m->seltags];
   2355 +		in_scroller = 0;
   2356 +		return;
   2357 +	}
   2358 +
   2359 +	unsigned int cur_tagset = m->tagset[m->seltags];
   2360 +
   2361 +	if (cur_tagset == prev_tagset && prev_sel_client &&
   2362 +	    find_col_row(g_cols, ncol, prev_sel_client, NULL) == -1) {
   2363 +		int target_col = CLAMP(m->prev_sel_col >= 0 ? m->prev_sel_col : 0, 0, ncol - 1);
   2364 +		if (g_cols[target_col].count > 0) {
   2365 +			Client *target_win = g_cols[target_col].clients[0];
   2366 +			if (m->sel != target_win) {
   2367 +				focus(target_win);
   2368 +				restack(m);
   2369 +				keep_cursor_inside(target_win);
   2370 +			}
   2371 +			if (target_col == 0)
   2372 +				m->scroll_x = 0;
   2373 +			m->prev_sel_col = target_col;
   2374 +		}
   2375 +	}
   2376 +	prev_tagset = cur_tagset;
   2377 +
   2378 +	if (m->prev_ncol > 1 && ncol == 1) {
   2379 +		for (int j = 0; j < g_cols[0].count; j++) {
   2380 +			g_cols[0].clients[j]->is_custom_cfact = 0;
   2381 +			g_cols[0].clients[j]->cfact = swinw;
   2382 +		}
   2383 +	}
   2384 +	m->prev_ncol = ncol;
   2385 +
   2386 +	int base_x;
   2387 +	int view_w = get_view_geom(m, ncol, &base_x);
   2388 +
   2389 +	if (ncol == 1) {
   2390 +		Client *top = g_cols[0].clients[0];
   2391 +		int col_w = top->is_custom_cfact ? g_cols[0].w : (int)(view_w * swinw);
   2392 +		int col_x = m->wx + m->gappoh + ((centerswin || centermode == CenterAlways) ? (view_w - col_w) / 2 : 0);
   2393 +
   2394 +		scroller_arrange_col(m, &g_cols[0], col_x, col_w);
   2395 +		m->scroll_x = 0;
   2396 +		m->prev_sel_col = 0;
   2397 +		prev_sel_client = m->sel;
   2398 +		XSync(dpy, False);
   2399 +		in_scroller = 0;
   2400 +		return;
   2401 +	}
   2402 +
   2403 +	int total_w = g_cols[ncol - 1].x + g_cols[ncol - 1].w;
   2404 +	int max_scroll = MAX(0, total_w - view_w);
   2405 +	int sel_col = find_col_row(g_cols, ncol, m->sel, NULL);
   2406 +
   2407 +	if (!is_scrolling && sel_col != -1) {
   2408 +		int col_screen_x = g_cols[sel_col].x - m->scroll_x;
   2409 +		int col_w = g_cols[sel_col].w;
   2410 +
   2411 +		if (centermode == CenterAlways) {
   2412 +			m->scroll_x = (g_cols[sel_col].x + col_w / 2) - (view_w / 2);
   2413 +		} else if (centermode == CenterOnFlow) {
   2414 +			if (m->prev_sel_col >= 0 && m->prev_sel_col < ncol && m->prev_sel_col != sel_col) {
   2415 +				int prev_x = g_cols[m->prev_sel_col].x;
   2416 +				int prev_w = g_cols[m->prev_sel_col].w;
   2417 +				int pair_span = MAX(prev_x + prev_w, g_cols[sel_col].x + col_w) - MIN(prev_x, g_cols[sel_col].x);
   2418 +
   2419 +				if (pair_span > view_w + 1)
   2420 +					m->scroll_x = (g_cols[sel_col].x + col_w / 2) - (view_w / 2);
   2421 +				else if (col_screen_x < 0)
   2422 +					m->scroll_x = g_cols[sel_col].x;
   2423 +				else if (col_screen_x + col_w > view_w)
   2424 +					m->scroll_x = g_cols[sel_col].x + col_w - view_w;
   2425 +			} else {
   2426 +				if (col_screen_x < 0)
   2427 +					m->scroll_x = g_cols[sel_col].x;
   2428 +				else if (col_screen_x + col_w > view_w)
   2429 +					m->scroll_x = g_cols[sel_col].x + col_w - view_w;
   2430 +			}
   2431 +		} else if (centermode == CenterNever) {
   2432 +			if (col_screen_x < 0)
   2433 +				m->scroll_x = g_cols[sel_col].x;
   2434 +			else if (col_screen_x + col_w > view_w)
   2435 +				m->scroll_x = g_cols[sel_col].x + col_w - view_w;
   2436 +		}
   2437 +		m->prev_sel_col = sel_col;
   2438 +	}
   2439 +
   2440 +	m->scroll_x = CLAMP(m->scroll_x, 0, max_scroll);
   2441 +	int offset_x = get_ribbon_offset(total_w, view_w);
   2442 +
   2443 +	for (int i = 0; i < ncol; i++) {
   2444 +		int col_x = base_x + offset_x + g_cols[i].x - m->scroll_x;
   2445 +		scroller_arrange_col(m, &g_cols[i], col_x, g_cols[i].w);
   2446 +	}
   2447 +	prev_sel_client = m->sel;
   2448 +	XSync(dpy, False);
   2449 +	in_scroller = 0;
   2450 +}
   2451 +
   2452 +static void
   2453 +detach_unstack(Client *c)
   2454 +{
   2455 +	Client **tc, *nxt;
   2456 +
   2457 +	if (!c)
   2458 +		return;
   2459 +
   2460 +	for (nxt = c->next; nxt; nxt = nxt->next) {
   2461 +		if (!nxt->isfloating && (nxt->tags & c->tags)) {
   2462 +			if (!c->is_stacked && nxt->is_stacked)
   2463 +				nxt->is_stacked = 0;
   2464 +			break;
   2465 +		}
   2466 +	}
   2467 +
   2468 +	for (tc = &selmon->clients; *tc && *tc != c; tc = &(*tc)->next);
   2469 +	if (*tc)
   2470 +		*tc = c->next;
   2471 +}
   2472 +
   2473 +static void
   2474 +reorderclient(Client *c, Client *target, int pos)
   2475 +{
   2476 +	Client **tc;
   2477 +
   2478 +	if (!c || !target || c == target)
   2479 +		return;
   2480 +
   2481 +	detach_unstack(c);
   2482 +
   2483 +	if (pos == InsBefore || pos == StkBefore) {
   2484 +		for (tc = &selmon->clients; *tc && *tc != target; tc = &(*tc)->next);
   2485 +		c->next = target;
   2486 +		*tc = c;
   2487 +		c->is_stacked = (pos == StkBefore) ? target->is_stacked : 0;
   2488 +		if (pos == StkBefore)
   2489 +			target->is_stacked = 1;
   2490 +	} else {
   2491 +		c->next = target->next;
   2492 +		target->next = c;
   2493 +		c->is_stacked = (pos == StkAfter);
   2494 +	}
   2495 +}
   2496 +
   2497 +static void
   2498 +stack_into_column(Client *c, Column *col, int drop_y)
   2499 +{
   2500 +	if (!c || !col || col->count == 0)
   2501 +		return;
   2502 +
   2503 +	Client *stack_target = NULL;
   2504 +	int pos = StkAfter;
   2505 +
   2506 +	for (int j = 0; j < col->count; j++) {
   2507 +		Client *tj = col->clients[j];
   2508 +		int win_mid_y = tj->y + tj->h / 2;
   2509 +		if (drop_y < win_mid_y) {
   2510 +			stack_target = tj;
   2511 +			pos = StkBefore;
   2512 +			break;
   2513 +		}
   2514 +		stack_target = tj;
   2515 +		pos = StkAfter;
   2516 +	}
   2517 +
   2518 +	if (stack_target && stack_target != c)
   2519 +		stack_client_target(c, col, stack_target, pos);
   2520 +}
   2521 +
   2522 +void
   2523 +dragdrop(const Arg *arg)
   2524 +{
   2525 +	int x, y, ocx, ocy, nx, ny;
   2526 +	Client *c;
   2527 +	XEvent ev;
   2528 +	Time lasttime = 0;
   2529 +
   2530 +	if (!(c = selmon->sel))
   2531 +		return;
   2532 +
   2533 +	if ((!isov && selmon->lt[selmon->sellt]->arrange != scroller) || c->isfloating || c->isfullscreen) {
   2534 +		movemouse(arg);
   2535 +		return;
   2536 +	}
   2537 +
   2538 +	ocx = c->x;
   2539 +	ocy = c->y;
   2540 +	if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
   2541 +		None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess)
   2542 +		return;
   2543 +
   2544 +	if (!getrootptr(&x, &y))
   2545 +		return;
   2546 +
   2547 +	XRaiseWindow(dpy, c->win);
   2548 +	is_scrolling = 1;
   2549 +	is_dragging = 1;
   2550 +
   2551 +	int ncol = build_columns(selmon);
   2552 +	int view_w = get_view_geom(selmon, ncol, NULL);
   2553 +	int total_w = (ncol > 0) ? (g_cols[ncol - 1].x + g_cols[ncol - 1].w) : 0;
   2554 +	int max_scroll = MAX(0, total_w - view_w);
   2555 +
   2556 +	do {
   2557 +		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
   2558 +		switch (ev.type) {
   2559 +		case ConfigureRequest:
   2560 +		case Expose:
   2561 +		case MapRequest:
   2562 +			handler[ev.type](&ev);
   2563 +			break;
   2564 +		case MotionNotify:
   2565 +			if ((ev.xmotion.time - lasttime) <= (1000 / refreshrate))
   2566 +				continue;
   2567 +			lasttime = ev.xmotion.time;
   2568 +
   2569 +			nx = ocx + (ev.xmotion.x_root - x);
   2570 +			ny = ocy + (ev.xmotion.y_root - y);
   2571 +			XMoveWindow(dpy, c->win, nx, ny);
   2572 +
   2573 +			if (isov) {
   2574 +				int scrolled = 0;
   2575 +
   2576 +				if (ev.xmotion.y_root < selmon->wy + ovedgezone) {
   2577 +					ovscrollvert_px(-ovedgestep);
   2578 +					scrolled = 1;
   2579 +				} else if (ev.xmotion.y_root > selmon->wy + selmon->wh - ovedgezone) {
   2580 +					ovscrollvert_px(+ovedgestep);
   2581 +					scrolled = 1;
   2582 +				}
   2583 +
   2584 +				int layer_tag = getovlayertag(ev.xmotion.x_root, ev.xmotion.y_root);
   2585 +				if (ev.xmotion.x_root < selmon->wx + ovedgezone) {
   2586 +					ovscrollribbon_px(layer_tag, -ovedgestep);
   2587 +					scrolled = 1;
   2588 +				} else if (ev.xmotion.x_root > selmon->wx + selmon->ww - ovedgezone) {
   2589 +					ovscrollribbon_px(layer_tag, +ovedgestep);
   2590 +					scrolled = 1;
   2591 +				}
   2592 +
   2593 +				if (scrolled) {
   2594 +					arrangemon(selmon);
   2595 +					XMoveWindow(dpy, c->win, nx, ny);
   2596 +				}
   2597 +			} else if (ncol > 1) {
   2598 +				int prev_sx = selmon->scroll_x;
   2599 +				if (ev.xmotion.x_root < selmon->wx + 80)
   2600 +					selmon->scroll_x = MAX(0, selmon->scroll_x - 20);
   2601 +				else if (ev.xmotion.x_root > selmon->wx + selmon->ww - 80)
   2602 +					selmon->scroll_x = MIN(max_scroll, selmon->scroll_x + 20);
   2603 +				if (selmon->scroll_x != prev_sx) {
   2604 +					arrangemon(selmon);
   2605 +					XMoveWindow(dpy, c->win, nx, ny);
   2606 +				}
   2607 +			}
   2608 +			break;
   2609 +		}
   2610 +	} while (ev.type != ButtonRelease);
   2611 +
   2612 +	is_scrolling = 0;
   2613 +	is_dragging = 0;
   2614 +	XUngrabPointer(dpy, CurrentTime);
   2615 +	while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
   2616 +
   2617 +	int drop_x = ev.xbutton.x_root;
   2618 +	int drop_y = ev.xbutton.y_root;
   2619 +
   2620 +	if (abs(drop_x - x) < (int)snap && abs(drop_y - y) < (int)snap) {
   2621 +		if (isov) {
   2622 +			Arg a = {.ui = c->tags};
   2623 +			view(&a);
   2624 +			focus(c);
   2625 +			restack(selmon);
   2626 +			return;
   2627 +		}
   2628 +		finish_drag_client(c);
   2629 +		return;
   2630 +	}
   2631 +
   2632 +	if (isov) {
   2633 +		ovdrop(c, drop_x, drop_y);
   2634 +		return;
   2635 +	}
   2636 +
   2637 +	ncol = build_columns(selmon);
   2638 +	if (ncol > 0) {
   2639 +		int c_col = find_col_row(g_cols, ncol, c, NULL);
   2640 +		int base_x;
   2641 +		int vw = get_view_geom(selmon, ncol, &base_x);
   2642 +		int tot_w = g_cols[ncol - 1].x + g_cols[ncol - 1].w;
   2643 +		int ribbon_drop_x = drop_x - base_x - get_ribbon_offset(tot_w, vw) + selmon->scroll_x;
   2644 +
   2645 +		if (ribbon_drop_x < g_cols[0].x) {
   2646 +			unstack_to_edge(c, g_cols, c_col, 0, InsBefore);
   2647 +		} else if (ribbon_drop_x > g_cols[ncol - 1].x + g_cols[ncol - 1].w) {
   2648 +			unstack_to_edge(c, g_cols, c_col, ncol - 1, InsAfter);
   2649 +		} else {
   2650 +			for (int i = 0; i < ncol; i++) {
   2651 +				int col_left = g_cols[i].x;
   2652 +				int col_right = g_cols[i].x + g_cols[i].w;
   2653 +				if (ribbon_drop_x >= col_left && ribbon_drop_x <= col_right + selmon->gappih) {
   2654 +					int edge_zone = CLAMP((int)(g_cols[i].w * 0.18), 25, 90);
   2655 +					if (ribbon_drop_x < col_left + edge_zone)
   2656 +						unstack_to_edge(c, g_cols, c_col, i, InsBefore);
   2657 +					else if (ribbon_drop_x > col_right - edge_zone)
   2658 +						unstack_to_edge(c, g_cols, c_col, i, InsAfter);
   2659 +					else
   2660 +						stack_into_column(c, &g_cols[i], drop_y);
   2661 +					break;
   2662 +				}
   2663 +			}
   2664 +		}
   2665 +	}
   2666 +
   2667 +	finish_drag_client(c);
   2668 +}
   2669 diff --git a/scrollview.h b/scrollview.h
   2670 new file mode 100644
   2671 index 0000000..5c516e9
   2672 --- /dev/null
   2673 +++ b/scrollview.h
   2674 @@ -0,0 +1,52 @@
   2675 +#ifndef SCROLLVIEW_H
   2676 +#define SCROLLVIEW_H
   2677 +
   2678 +#define MAX_COLS 128
   2679 +#define MAX_COL_CLIENTS 64
   2680 +
   2681 +#define CURRENT_MODE() (isov ? Overview : (Normal | (selmon && \
   2682 +	selmon->lt[selmon->sellt]->arrange == scroller ? Scroll : 0)))
   2683 +#define CLAMP(x, lo, hi)   ((x) < (lo) ? (lo) : ((x) > (hi) ? (hi) : (x)))
   2684 +#define DIFF_ABS(a, b)     (((a) > (b)) ? ((a) - (b)) : ((b) - (a)))
   2685 +#define IS_CUSTOM_CFACT(f) (DIFF_ABS((f), defwinw) > 0.01f)
   2686 +#define ENSURE_CFACT(c)    do { if ((c)->unstacked_cfact <= 0.05f) \
   2687 +	(c)->unstacked_cfact = ((c)->cfact > 0.05f) ? (c)->cfact : defwinw; } while(0)
   2688 +#define NAV_WRAP(cur, delta, count, loop) \
   2689 +	((loop) ? (((cur) + (delta) % (count) + (count)) % (count)) : CLAMP((cur) + (delta), 0, (count) - 1))
   2690 +
   2691 +enum { CenterOnFlow, CenterAlways, CenterNever };
   2692 +enum { InsBefore, InsAfter, StkBefore, StkAfter };
   2693 +
   2694 +typedef struct {
   2695 +	Client *clients[MAX_COL_CLIENTS];
   2696 +	int count;
   2697 +	int w;
   2698 +	int x;
   2699 +} Column;
   2700 +
   2701 +static void scroller(Monitor *m);
   2702 +static void scrollwin(const Arg *arg);
   2703 +static void trackscroll(const Arg *arg);
   2704 +static void focuswinstack(const Arg *arg);
   2705 +static void stackconsume(const Arg *arg);
   2706 +static void stackexpel(const Arg *arg);
   2707 +static void togglestack(const Arg *arg);
   2708 +static void movewin(const Arg *arg);
   2709 +static void movewinstack(const Arg *arg);
   2710 +static void cyclewinwidth(const Arg *arg);
   2711 +void centerfocused(const Arg *arg);
   2712 +static void togglecentering(const Arg *arg);
   2713 +static void toggleloopnav(const Arg *arg);
   2714 +void syncwincfact(Client *c, float f);
   2715 +static void dragdrop(const Arg *arg);
   2716 +
   2717 +/* Shared functions */
   2718 +static int find_col_row(const Column *cols, int ncol, const Client *c, int *out_row);
   2719 +static void scrollermoveresize(Client *c, int x, int y, int w, int h);
   2720 +static void reorderclient(Client *c, Client *target, int pos);
   2721 +static void unstackreorder(Client *c, Client *target, int pos);
   2722 +static void detach_unstack(Client *c);
   2723 +static int reorder_col_dir(Client *c, const Column *cols, int ncol, int col_idx, int dir, int loop);
   2724 +static void keep_cursor_inside(Client *c);
   2725 +
   2726 +#endif /* SCROLLVIEW_H */
   2727 -- 
   2728 2.55.0
   2729