This commit is contained in:
Harrison DiAmbrosio 2026-03-01 23:44:02 -05:00
parent 6d95f33446
commit ea66866789
2 changed files with 22 additions and 15 deletions

View file

@ -7,7 +7,7 @@
---@field builtins Builtins ---@field builtins Builtins
local M = {}; local M = {};
M.builtins = require("master.builtins") -- M.builtins = require("master.builtins")
---@class MasterConfig ---@class MasterConfig
---@field master_ratio number ---@field master_ratio number
@ -21,8 +21,8 @@ local default_config = {
tag_count = 5, tag_count = 5,
focus_on_spawn = true, focus_on_spawn = true,
refocus_on_kill = true, refocus_on_kill = true,
screen_gap = 10, screen_gap = 12,
tile_gap = 10 tile_gap = 7
} }
---@class MasterTag ---@class MasterTag
@ -45,8 +45,9 @@ local create_state = function(config)
end end
return { return {
tag_id = 0, tag_id = 1,
tags = tags tags = tags,
master_ratio = config.master_ratio
} }
end end
@ -60,6 +61,8 @@ M.setup = function(config)
--- Here we need to validate the config --- Here we need to validate the config
--- DON'T FORGET TO VALIDATE THE CONFIG --- DON'T FORGET TO VALIDATE THE CONFIG
config = default_config
M.state = create_state(config) M.state = create_state(config)
---@param tag_id number ---@param tag_id number
@ -69,41 +72,43 @@ M.setup = function(config)
local res = mez.output.get_resolution(0) local res = mez.output.get_resolution(0)
if #tag.stack == 0 then if #tag.stack == 0 then
print("MASTER: tiling just master")
mez.view.set_position(tag.master, config.screen_gap, config.screen_gap) mez.view.set_position(tag.master, config.screen_gap, config.screen_gap)
mez.view.set_size( mez.view.set_size(
tag.master, tag.master,
res.width - config.screen_gap * 2, res.width - config.screen_gap * 2,
res.height - config.screen_gap * 2) res.height - config.screen_gap * 2)
else else
print("MASTER: master and stack")
mez.view.set_position(tag.master, config.screen_gap, config.screen_gap) mez.view.set_position(tag.master, config.screen_gap, config.screen_gap)
mez.view.set_size( mez.view.set_size(
tag.master, tag.master,
res.width * M.state.master_ratio - config.screen_gap - config.tile_gap, res.width * M.state.master_ratio - config.screen_gap - config.tile_gap,
res.height - config.screen_gap * 2) res.height - config.screen_gap * 2)
local stack_x = (res.width * (1 - M.state.master_ratio)) - config.tile_gap - config.screen_gap local stack_x = (res.width * (1 - M.state.master_ratio))
local stack_width = res.width * (1 - M.state.master_ratio) - config.tile_gap - config.screen_gap local stack_width = res.width * (1 - M.state.master_ratio) - config.tile_gap - config.screen_gap
local stack_height = (res.height - (config.screen_gap * 2) - ((#tag.stack - 1) * config.tile_gap)) / #tag.stack
for i, view_id in ipairs(tag.stack) do for i, view_id in ipairs(tag.stack) do
mez.view.set_position(view_id, mez.view.set_position(view_id,
stack_x, stack_x,
(res.height / #tag.stack + config.tile_gap) * (i - 1) + config.screen_gap) (stack_height + config.tile_gap) * (i - 1) + config.screen_gap)
mez.view.set_size(view_id, mez.view.set_size(view_id, stack_width, stack_height)
stack_width,
res.height / #tag.stack - config.screen_gap * 2 - config.tile_gap * (#tag.stack - 1))
end end
end end
end end
mez.hook.add("ViewMapPre", { mez.hook.add("ViewMapPre", {
callback = function(view_id) callback = function(view_id)
local curr_tag = M.state.tags[M.state.tag_id]
if curr_tag.master == nil then local tag = M.state.tags[M.state.tag_id]
curr_tag.master = view_id
if tag.master == nil then
tag.master = view_id
else else
table.insert(curr_tag.stack, #curr_tag.stack + 1, view_id) table.insert(tag.stack, #tag.stack + 1, view_id)
end end
if config.focus_on_spawn then mez.view.set_focused(view_id) end if config.focus_on_spawn then mez.view.set_focused(view_id) end
@ -123,7 +128,9 @@ M.setup = function(config)
---@type number | nil ---@type number | nil
local view_idx = nil local view_idx = nil
for i, curr_tag in ipairs[M.state.tags] do print("made it here")
for i, curr_tag in ipairs(M.state.tags) do
local t = M.state.tags[i] local t = M.state.tags[i]
--- If view is the master --- If view is the master