From acb95648e66872fc7590b877b92dccc5e427b7f1 Mon Sep 17 00:00:00 2001 From: Harrison DiAmbrosio Date: Sat, 29 Nov 2025 22:07:25 -0500 Subject: [PATCH] added view unfocusing --- runtime/share/mezzaluna/init.lua | 7 +++++++ src/lua/view.zig | 13 ++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/runtime/share/mezzaluna/init.lua b/runtime/share/mezzaluna/init.lua index c8a12bb..dc21260 100644 --- a/runtime/share/mezzaluna/init.lua +++ b/runtime/share/mezzaluna/init.lua @@ -102,6 +102,13 @@ local master = function() mez.input.add_keymap("alt", "" .. i, { press = function () ctx.tag_id = i + + if ctx.tags[i].master then + mez.view.set_focused(ctx.tags[i].master) + else + mez.view.set_focused(nil) + end + tile_all() end }) diff --git a/src/lua/view.zig b/src/lua/view.zig index 8017416..6c7e684 100644 --- a/src/lua/view.zig +++ b/src/lua/view.zig @@ -100,11 +100,18 @@ pub fn set_size(L: *zlua.Lua) i32 { } // ---Remove focus from current view, and set to given id -// ---@param view_id view_id +// ---@param view_id view_id Id of the view to be focused, or nil to remove focus pub fn set_focused(L: *zlua.Lua) i32 { - const view_id: u64 = @intCast(L.checkInteger(1)); + const view_id: ?c_longlong = L.optInteger(1); - if(server.root.viewById(view_id)) |view| { + if(view_id == null and server.seat.focused_view != null) { + server.seat.focused_view.?.focused = false; + server.seat.focused_view = null; + L.pushNil(); + return 1; + } + + if(server.root.viewById(@intCast(view_id.?))) |view| { view.setFocused(); L.pushNil(); return 1;