Currently, I have this setup (scrolling layout):
-- Niri-style maximize-column toggle for the scrolling layout
local SNAP_WIDTHS = { 0.333, 0.5, 0.667 }
local DEFAULT_WIDTH = 0.5
local MOVE_DIR = "move -col" -- flip to "move +col" if restore scrolls the wrong way
local MAX_SCROLL_STEPS = 12
local TOL = 0.02
local saved = {} -- address -> { width, anchor }
local function dims(w)
local mon = w.monitor
if not mon then return nil end
local mon_x = (mon.position and (mon.position.x or mon.position[1])) or mon.x or 0
local mon_w = mon.width or mon.w or (mon.size and (mon.size.x or mon.size[1]))
local win_x = (w.at and (w.at.x or w.at[1])) or (w.position and (w.position.x or w.position[1])) or w.x
local win_w = w.width or w.w or (w.size and (w.size.x or w.size[1]))
if not (mon_w and win_x and win_w) or mon_w == 0 then return nil end
return { width = win_w / mon_w, anchor = (win_x - mon_x) / mon_w }
end
local function snap(width)
local best, best_dist = DEFAULT_WIDTH, math.huge
for _, v in ipairs(SNAP_WIDTHS) do
local d = math.abs(width - v)
if d < best_dist then best, best_dist = v, d end
end
return best
end
hl.bind(mainMod .. " + F", function()
local w = hl.get_active_window()
if w == nil then return end
local addr = w.address
if addr and saved[addr] then
-- un-maximize: restore width, then scroll the tape back to where it was
local s = saved[addr]
saved[addr] = nil
hl.dispatch(hl.dsp.layout("colresize " .. tostring(s.width)))
local target = s.anchor or 0
if target > TOL then
local last = -1
for _ = 1, MAX_SCROLL_STEPS do
local cw = hl.get_active_window()
local d = cw and dims(cw)
local cur = d and d.anchor
if not cur or cur >= target - TOL then break end
if math.abs(cur - last) < 0.004 then break end
last = cur
hl.dispatch(hl.dsp.layout(MOVE_DIR))
end
end
else
-- maximize: remember state, then take full monitor width
local d = dims(w)
if addr then
saved[addr] = { width = d and snap(d.width) or DEFAULT_WIDTH, anchor = d and d.anchor or 0 }
end
hl.dispatch(hl.dsp.layout("colresize 1.0"))
end
end, { description = "Toggle maximize active column (scrolling)" })
-- don't leak state when windows close
hl.on("window.close", function(w)
if w and w.address then saved[w.address] = nil end
end)
I saw that version 0.56 introduced a new “fit expand” and “fit_into_view” argument but I cannot figure out how to use them. Any help?