going to try to add tags

This commit is contained in:
Harrison DiAmbrosio 2025-11-28 11:25:31 -05:00
parent 53b9ba2f88
commit 8dbaae8d03

View file

@ -17,7 +17,7 @@ function print_table (t)
end end
local master = function() local master = function()
local mast = { local ctx = {
master_ratio = 0.5, master_ratio = 0.5,
stack = {}, stack = {},
master = nil, master = nil,
@ -26,16 +26,16 @@ local master = function()
local tile_views = function () local tile_views = function ()
local res = mez.output.get_resolution(0) local res = mez.output.get_resolution(0)
if #mast.stack == 0 then if #ctx.stack == 0 then
mez.view.set_size(mast.master, res.width, res.height) mez.view.set_size(ctx.master, res.width, res.height)
mez.view.set_position(mast.master, 0, 0) mez.view.set_position(ctx.master, 0, 0)
else else
mez.view.set_size(mast.master, res.width * mast.master_ratio, res.height) mez.view.set_size(ctx.master, res.width * ctx.master_ratio, res.height)
mez.view.set_position(mast.master, 0, 0) mez.view.set_position(ctx.master, 0, 0)
for i, stack_id in ipairs(mast.stack) do for i, stack_id in ipairs(ctx.stack) do
mez.view.set_size(stack_id, res.width * (1 - mast.master_ratio), res.height / #mast.stack) mez.view.set_size(stack_id, res.width * (1 - ctx.master_ratio), res.height / #ctx.stack)
mez.view.set_position(stack_id, res.width * mast.master_ratio, (res.height / #mast.stack * (i - 1))) mez.view.set_position(stack_id, res.width * ctx.master_ratio, (res.height / #ctx.stack * (i - 1)))
end end
end end
end end
@ -43,11 +43,10 @@ local master = function()
mez.hook.add("ViewMapPre", { mez.hook.add("ViewMapPre", {
callback = function(v) callback = function(v)
mez.view.set_focused(v) mez.view.set_focused(v)
if ctx.master == nil then
if mast.master == nil then ctx.master = v
mast.master = v
else else
table.insert(mast.stack, #mast.stack + 1, v) table.insert(ctx.stack, #ctx.stack + 1, v)
end end
tile_views() tile_views()
@ -56,24 +55,25 @@ local master = function()
mez.hook.add("ViewUnmapPost", { mez.hook.add("ViewUnmapPost", {
callback = function(v) callback = function(v)
if v == mast.master then if v == ctx.master then
if #mast.stack > 0 then if #ctx.stack > 0 then
mast.master = table.remove(mast.stack, 1) ctx.master = table.remove(ctx.stack, 1)
mez.view.set_focused(ctx.master)
else else
mast.master = nil ctx.master = nil
end end
else else
for i, id in ipairs(mast.stack) do for i, id in ipairs(ctx.stack) do
if id == v then if id == v then
if i == 1 then if i == 1 then
mez.view.set_focused(mast.master) mez.view.set_focused(ctx.master)
elseif i == #mast.stack then elseif i == #ctx.stack then
mez.view.set_focused(mast.stack[i - 1]) mez.view.set_focused(ctx.stack[i - 1])
else else
mez.view.set_focused(mast.stack[i + 1]) mez.view.set_focused(ctx.stack[i + 1])
end end
table.remove(mast.stack, i) table.remove(ctx.stack, i)
end end
end end
end end
@ -104,13 +104,13 @@ local master = function()
press = function() press = function()
local focused = mez.view.get_focused_id() local focused = mez.view.get_focused_id()
if focused == mast.master then return end if focused == ctx.master then return end
for i, id in ipairs(mast.stack) do for i, id in ipairs(ctx.stack) do
if focused == id then if focused == id then
local t = mast.master local t = ctx.master
mast.master = mast.stack[i] ctx.master = ctx.stack[i]
mast.stack[i] = t ctx.stack[i] = t
end end
end end
@ -122,15 +122,15 @@ local master = function()
press = function () press = function ()
local focused = mez.view.get_focused_id() local focused = mez.view.get_focused_id()
if focused == mast.master then if focused == ctx.master then
mez.view.set_focused(mast.stack[1]) mez.view.set_focused(ctx.stack[1])
elseif focused == mast.stack[#mast.stack] then elseif focused == ctx.stack[#ctx.stack] then
mez.view.set_focused(mast.master) mez.view.set_focused(ctx.master)
else else
for i, id in ipairs(mast.stack) do for i, id in ipairs(ctx.stack) do
-- TODO: use table.find -- TODO: use table.find
if focused == id then if focused == id then
mez.view.set_focused(mast.stack[i + 1]) mez.view.set_focused(ctx.stack[i + 1])
end end
end end
end end
@ -141,15 +141,15 @@ local master = function()
press = function () press = function ()
local focused = mez.view.get_focused_id() local focused = mez.view.get_focused_id()
if focused == mast.master then if focused == ctx.master then
mez.view.set_focused(mast.stack[#mast.stack]) mez.view.set_focused(ctx.stack[#ctx.stack])
elseif focused == mast.stack[1] then elseif focused == ctx.stack[1] then
mez.view.set_focused(mast.master) mez.view.set_focused(ctx.master)
else else
for i, id in ipairs(mast.stack) do for i, id in ipairs(ctx.stack) do
-- TODO: use table.find -- TODO: use table.find
if focused == id then if focused == id then
mez.view.set_focused(mast.stack[i - 1]) mez.view.set_focused(ctx.stack[i - 1])
end end
end end
end end
@ -158,8 +158,8 @@ local master = function()
mez.input.add_keymap("alt", "h", { mez.input.add_keymap("alt", "h", {
press = function() press = function()
if mast.master_ratio > 0.15 then if ctx.master_ratio > 0.15 then
mast.master_ratio = mast.master_ratio - 0.05 ctx.master_ratio = ctx.master_ratio - 0.05
tile_views() tile_views()
end end
end end
@ -167,8 +167,8 @@ local master = function()
mez.input.add_keymap("alt", "l", { mez.input.add_keymap("alt", "l", {
press = function() press = function()
if mast.master_ratio < 0.85 then if ctx.master_ratio < 0.85 then
mast.master_ratio = mast.master_ratio + 0.05 ctx.master_ratio = ctx.master_ratio + 0.05
tile_views() tile_views()
end end
end end