tags are like kinda done but not really, still need to switch focus

This commit is contained in:
Harrison DiAmbrosio 2025-11-29 21:59:14 -05:00
parent 8dbaae8d03
commit 689b48acd7
5 changed files with 190 additions and 117 deletions

View file

@ -10,78 +10,152 @@ end
mez.path.config = mez.fs.joinpath(env_conf, "mez", "init.lua") mez.path.config = mez.fs.joinpath(env_conf, "mez", "init.lua")
package.path = package.path..";"..mez.fs.joinpath(env_conf, "mez", "lua", "?.lua") package.path = package.path..";"..mez.fs.joinpath(env_conf, "mez", "lua", "?.lua")
function print_table (t) function print_table(tbl, indent, seen)
for key, value in pairs(t) do indent = indent or 0
print(key .. ":" .. value) seen = seen or {}
-- Prevent infinite loops from circular references
if seen[tbl] then
print(string.rep(" ", indent) .. "...(circular reference)")
return
end
seen[tbl] = true
for key, value in pairs(tbl) do
local formatting = string.rep(" ", indent) .. tostring(key) .. ": "
if type(value) == "table" then
print(formatting .. "{")
print_table(value, indent + 1, seen)
print(string.rep(" ", indent) .. "}")
elseif type(value) == "string" then
print(formatting .. '"' .. value .. '"')
else
print(formatting .. tostring(value))
end
end end
end end
local master = function() local master = function()
local config = {
tag_count = 5,
}
local ctx = { local ctx = {
master_ratio = 0.5, master_ratio = 0.5,
tags = {},
tag_id = 1
}
local tile_onscreen = function(tag_id, res)
print("positioning tag " .. tag_id .. " ONscreen")
if ctx.tags[tag_id].master == nil then
return
end
if #ctx.tags[tag_id].stack == 0 then
mez.view.set_size(ctx.tags[tag_id].master, res.width, res.height)
mez.view.set_position(ctx.tags[tag_id].master, 0, 0)
else
mez.view.set_size(ctx.tags[tag_id].master, res.width * ctx.master_ratio, res.height)
mez.view.set_position(ctx.tags[tag_id].master, 0, 0)
for i, stack_id in ipairs(ctx.tags[tag_id].stack) do
mez.view.set_size(stack_id, res.width * (1 - ctx.master_ratio), res.height / #ctx.tags[tag_id].stack)
mez.view.set_position(stack_id, res.width * ctx.master_ratio, (res.height / #ctx.tags[tag_id].stack * (i - 1)))
end
end
end
local tile_offscreen = function(tag_id, res)
if ctx.tags[tag_id].master == nil then
return
end
mez.view.set_position(ctx.tags[tag_id].master, 0, -res.height)
mez.view.set_size(ctx.tags[tag_id].master, res.width, res.height)
for _, view in ipairs(ctx.tags[tag_id].stack) do
mez.view.set_position(view, 0, -res.height)
mez.view.set_size(view, res.width, res.height)
end
end
local tile_all = function ()
local res = mez.output.get_resolution(0)
for id = 1,config.tag_count do
if id == ctx.tag_id then
tile_onscreen(id, res)
else
tile_offscreen(id, res)
end
end
end
for i = 1,config.tag_count do
ctx.tags[#ctx.tags + 1] = {
stack = {}, stack = {},
master = nil, master = nil,
} }
mez.input.add_keymap("alt", "" .. i, {
local tile_views = function () press = function ()
local res = mez.output.get_resolution(0) ctx.tag_id = i
tile_all()
if #ctx.stack == 0 then
mez.view.set_size(ctx.master, res.width, res.height)
mez.view.set_position(ctx.master, 0, 0)
else
mez.view.set_size(ctx.master, res.width * ctx.master_ratio, res.height)
mez.view.set_position(ctx.master, 0, 0)
for i, stack_id in ipairs(ctx.stack) do
mez.view.set_size(stack_id, res.width * (1 - ctx.master_ratio), res.height / #ctx.stack)
mez.view.set_position(stack_id, res.width * ctx.master_ratio, (res.height / #ctx.stack * (i - 1)))
end
end end
})
end end
mez.hook.add("ViewMapPre", { mez.hook.add("ViewMapPre", {
callback = function(v) callback = function(v)
mez.view.set_focused(v) if ctx.tags[ctx.tag_id].master == nil then
if ctx.master == nil then ctx.tags[ctx.tag_id].master = v
ctx.master = v
else else
table.insert(ctx.stack, #ctx.stack + 1, v) table.insert(ctx.tags[ctx.tag_id].stack, #ctx.tags[ctx.tag_id].stack + 1, v)
end end
tile_views() mez.view.set_focused(v)
tile_all()
end end
}) })
mez.hook.add("ViewUnmapPost", { mez.hook.add("ViewUnmapPost", {
callback = function(v) callback = function(v)
if v == ctx.master then if v == ctx.tags[ctx.tag_id].master then
if #ctx.stack > 0 then if #ctx.tags[ctx.tag_id].stack > 0 then
ctx.master = table.remove(ctx.stack, 1) ctx.tags[ctx.tag_id].master = table.remove(ctx.tags[ctx.tag_id].stack, 1)
mez.view.set_focused(ctx.master) mez.view.set_focused(ctx.tags[ctx.tag_id].master)
else else
ctx.master = nil ctx.tags[ctx.tag_id].master = nil
end end
else else
for i, id in ipairs(ctx.stack) do for i, id in ipairs(ctx.tags[ctx.tag_id].stack) do
if id == v then if id == v then
if i == 1 then if i == 1 then
mez.view.set_focused(ctx.master) mez.view.set_focused(ctx.tags[ctx.tag_id].master)
elseif i == #ctx.stack then elseif i == #ctx.tags[ctx.tag_id].stack then
mez.view.set_focused(ctx.stack[i - 1]) mez.view.set_focused(ctx.tags[ctx.tag_id].stack[i - 1])
else else
mez.view.set_focused(ctx.stack[i + 1]) mez.view.set_focused(ctx.tags[ctx.tag_id].stack[i + 1])
end end
table.remove(ctx.stack, i) table.remove(ctx.tags[ctx.tag_id].stack, i)
end end
end end
end end
tile_views() tile_all()
end end
}) })
mez.input.add_keymap("alt", "p", {
press = function()
print("no luancher")
end,
})
mez.input.add_keymap("alt|shift", "Return", { mez.input.add_keymap("alt|shift", "Return", {
press = function() press = function()
mez.api.spawn("alacritty") mez.api.spawn("alacritty")
@ -104,17 +178,17 @@ local master = function()
press = function() press = function()
local focused = mez.view.get_focused_id() local focused = mez.view.get_focused_id()
if focused == ctx.master then return end if focused == ctx.tags[ctx.tag_id].master then return end
for i, id in ipairs(ctx.stack) do for i, id in ipairs(ctx.tags[ctx.tag_id].stack) do
if focused == id then if focused == id then
local t = ctx.master local t = ctx.tags[ctx.tag_id].master
ctx.master = ctx.stack[i] ctx.tags[ctx.tag_id].master = ctx.tags[ctx.tag_id].stack[i]
ctx.stack[i] = t ctx.tags[ctx.tag_id].stack[i] = t
end end
end end
tile_views() tile_all()
end, end,
}) })
@ -122,15 +196,15 @@ local master = function()
press = function () press = function ()
local focused = mez.view.get_focused_id() local focused = mez.view.get_focused_id()
if focused == ctx.master then if focused == ctx.tags[ctx.tag_id].master then
mez.view.set_focused(ctx.stack[1]) mez.view.set_focused(ctx.tags[ctx.tag_id].stack[1])
elseif focused == ctx.stack[#ctx.stack] then elseif focused == ctx.tags[ctx.tag_id].stack[#ctx.tags[ctx.tag_id].stack] then
mez.view.set_focused(ctx.master) mez.view.set_focused(ctx.tags[ctx.tag_id].master)
else else
for i, id in ipairs(ctx.stack) do for i, id in ipairs(ctx.tags[ctx.tag_id].stack) do
-- TODO: use table.find -- TODO: use table.find
if focused == id then if focused == id then
mez.view.set_focused(ctx.stack[i + 1]) mez.view.set_focused(ctx.tags[ctx.tag_id].stack[i + 1])
end end
end end
end end
@ -141,15 +215,15 @@ local master = function()
press = function () press = function ()
local focused = mez.view.get_focused_id() local focused = mez.view.get_focused_id()
if focused == ctx.master then if focused == ctx.tags[ctx.tag_id].master then
mez.view.set_focused(ctx.stack[#ctx.stack]) mez.view.set_focused(ctx.tags[ctx.tag_id].stack[#ctx.tags[ctx.tag_id].stack])
elseif focused == ctx.stack[1] then elseif focused == ctx.tags[ctx.tag_id].stack[1] then
mez.view.set_focused(ctx.master) mez.view.set_focused(ctx.tags[ctx.tag_id].master)
else else
for i, id in ipairs(ctx.stack) do for i, id in ipairs(ctx.tags[ctx.tag_id].stack) do
-- TODO: use table.find -- TODO: use table.find
if focused == id then if focused == id then
mez.view.set_focused(ctx.stack[i - 1]) mez.view.set_focused(ctx.tags[ctx.tag_id].stack[i - 1])
end end
end end
end end
@ -160,7 +234,7 @@ local master = function()
press = function() press = function()
if ctx.master_ratio > 0.15 then if ctx.master_ratio > 0.15 then
ctx.master_ratio = ctx.master_ratio - 0.05 ctx.master_ratio = ctx.master_ratio - 0.05
tile_views() tile_all()
end end
end end
}) })
@ -169,7 +243,7 @@ local master = function()
press = function() press = function()
if ctx.master_ratio < 0.85 then if ctx.master_ratio < 0.85 then
ctx.master_ratio = ctx.master_ratio + 0.05 ctx.master_ratio = ctx.master_ratio + 0.05
tile_views() tile_all()
end end
end end
}) })
@ -187,64 +261,12 @@ local master = function()
end end
end end
}) })
end
master()
for i = 1, 12 do for i = 1, 12 do
mez.input.add_keymap("ctrl|alt", "XF86Switch_VT_"..i, { mez.input.add_keymap("ctrl|alt", "XF86Switch_VT_"..i, {
press = function() mez.api.change_vt(i) end press = function() mez.api.change_vt(i) end
}) })
end end
local test = function()
-- View tests
mez.api.spawn("alacritty")
local focused_view = mez.view.get_focused_id()
print(focused_view)
for i = 0,4 do
mez.api.spawn("alacritty")
end end
local view_ids = mez.view.get_all_ids() master()
for _, id in ipairs(view_ids) do
print(id)
mez.view.close(id)
end
print(mez.view.get_title(0))
print(mez.view.get_title(focused_view))
print(mez.view.get_app_id(0))
print(mez.view.get_app_id(focused_view))
mez.view.set_position(0, 100, 100)
mez.view.set_position(focused_view, 200, 200)
mez.view.set_size(0, 100, 100)
mez.view.set_size(focused_view, 200, 200)
-- Output tests
local focused_output = mez.output.get_focused_id()
print(focused_output)
local output_ids = mez.output.get_all_ids()
for _, id in ipairs(output_ids) do
print(id)
end
print(mez.output.get_name(0))
print(mez.output.get_name(focused_output))
print(mez.output.get_description(0))
print(mez.output.get_description(focused_output))
print(mez.output.get_model(0))
print(mez.output.get_model(focused_output))
print(mez.output.get_make(0))
print(mez.output.get_make(focused_output))
print(mez.output.get_serial(0))
print(mez.output.get_serial(focused_output))
print(mez.output.get_rate(0))
print(mez.output.get_rate(focused_output))
local res = mez.output.get_resolution(0)
print(res.width .. ", " .. res.height)
end

View file

@ -0,0 +1,51 @@
local test = function()
-- View tests
mez.api.spawn("alacritty")
local focused_view = mez.view.get_focused_id()
print(focused_view)
for i = 0,4 do
mez.api.spawn("alacritty")
end
local view_ids = mez.view.get_all_ids()
for _, id in ipairs(view_ids) do
print(id)
mez.view.close(id)
end
print(mez.view.get_title(0))
print(mez.view.get_title(focused_view))
print(mez.view.get_app_id(0))
print(mez.view.get_app_id(focused_view))
mez.view.set_position(0, 100, 100)
mez.view.set_position(focused_view, 200, 200)
mez.view.set_size(0, 100, 100)
mez.view.set_size(focused_view, 200, 200)
-- Output tests
local focused_output = mez.output.get_focused_id()
print(focused_output)
local output_ids = mez.output.get_all_ids()
for _, id in ipairs(output_ids) do
print(id)
end
print(mez.output.get_name(0))
print(mez.output.get_name(focused_output))
print(mez.output.get_description(0))
print(mez.output.get_description(focused_output))
print(mez.output.get_model(0))
print(mez.output.get_model(focused_output))
print(mez.output.get_make(0))
print(mez.output.get_make(focused_output))
print(mez.output.get_serial(0))
print(mez.output.get_serial(focused_output))
print(mez.output.get_rate(0))
print(mez.output.get_rate(focused_output))
local res = mez.output.get_resolution(0)
print(res.width .. ", " .. res.height)
end

View file

@ -64,10 +64,14 @@ pub fn close(L: *zlua.Lua) i32 {
// ---@param x number x position for view // ---@param x number x position for view
// ---@param y number y position for view // ---@param y number y position for view
pub fn set_position(L: *zlua.Lua) i32 { pub fn set_position(L: *zlua.Lua) i32 {
std.log.debug("repositioning", .{});
const view_id: u64 = @intCast(L.checkInteger(1)); const view_id: u64 = @intCast(L.checkInteger(1));
const x: i32 = @intFromFloat(@round(L.checkNumber(2))); const x: i32 = @intFromFloat(@round(L.checkNumber(2)));
const y: i32 = @intFromFloat(@round(L.checkNumber(3))); const y: i32 = @intFromFloat(@round(L.checkNumber(3)));
std.log.debug("position to set: ({d}, {d})", .{x, y});
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id); const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
if(view) |v| { if(view) |v| {
v.setPosition(x, y); v.setPosition(x, y);

View file

@ -186,7 +186,6 @@ fn handleNewXdgToplevelDecoration(
_: *wl.Listener(*wlr.XdgToplevelDecorationV1), _: *wl.Listener(*wlr.XdgToplevelDecorationV1),
decoration: *wlr.XdgToplevelDecorationV1 decoration: *wlr.XdgToplevelDecorationV1
) void { ) void {
std.log.debug("Request for decorations", .{});
if(server.root.viewById(@intFromPtr(decoration.toplevel))) |view| { if(server.root.viewById(@intFromPtr(decoration.toplevel))) |view| {
view.xdg_toplevel_decoration = decoration; view.xdg_toplevel_decoration = decoration;
} }

View file

@ -132,7 +132,6 @@ pub fn setSize(self: *View, width: i32, height: i32) void {
// --------- XdgTopLevel event handlers --------- // --------- XdgTopLevel event handlers ---------
fn handleMap(listener: *wl.Listener(void)) void { fn handleMap(listener: *wl.Listener(void)) void {
const view: *View = @fieldParentPtr("map", listener); const view: *View = @fieldParentPtr("map", listener);
std.log.debug("Mapping view '{s}'", .{view.xdg_toplevel.title orelse "(unnamed)"});
server.events.exec("ViewMapPre", .{view.id}); server.events.exec("ViewMapPre", .{view.id});
@ -222,8 +221,6 @@ fn handleRequestMove(
) void { ) void {
// const view: *View = @fieldParentPtr("request_move", listener); // const view: *View = @fieldParentPtr("request_move", listener);
std.log.debug("The clients should not be request moves", .{});
// server.cursor.moveView(view); // server.cursor.moveView(view);
// server.cursor.grabbed_view = view; // server.cursor.grabbed_view = view;
// server.cursor.mode = .move; // server.cursor.mode = .move;