From 1681bea42dd2f11ba3fe6df05560d0b231de3c76 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Wed, 6 May 2026 13:56:12 +0100 Subject: config/lua: add simple layout API (#14258) Adds a simple layout lua api --- meta/generateLuaStubs.py | 62 ++++++++++++++++++++++++++++++++++++++++++++---- meta/hl.meta.lua | 34 ++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 4 deletions(-) (limited to 'meta') diff --git a/meta/generateLuaStubs.py b/meta/generateLuaStubs.py index 7ef70bab..0e94aa6e 100644 --- a/meta/generateLuaStubs.py +++ b/meta/generateLuaStubs.py @@ -87,18 +87,18 @@ def merge_node(dst: ApiNode, src: ApiNode) -> None: def parse_binding_tree(root: Path) -> tuple[ApiNode, set[str]]: - bindings_dir = root / "src/config/lua/bindings" + lua_dir = root / "src/config/lua" root_node = ApiNode() callable_namespaces: set[str] = set() register_header = re.compile( - r"void\s+Internal::register\w+Bindings\s*\([^)]*\)\s*\{", re.MULTILINE + r"void\s+(?:(?:Config::Lua::Bindings::)?Internal::)?register\w+Bindings\s*\([^)]*\)\s*\{", re.MULTILINE ) - set_fn = re.compile(r'Internal::set(?:Mgr)?Fn\(\s*L\s*,(?:\s*mgr\s*,)?\s*"([^"]+)"\s*,') + set_fn = re.compile(r'(?:Internal::)?set(?:Mgr)?Fn\(\s*L\s*,(?:\s*mgr\s*,)?\s*"([^"]+)"\s*,') set_field = re.compile(r'lua_setfield\(L,\s*-2,\s*"([^"]+)"\s*\);') - for cpp in sorted(bindings_dir.glob("*.cpp")): + for cpp in sorted(lua_dir.rglob("*.cpp")): source = read_text(cpp) for _, body in extract_function_bodies(source, register_header): local_root = ApiNode() @@ -503,6 +503,7 @@ def generate_stub(root: Path) -> str: "hl.get_current_submap": "fun(): string", "hl.notification.create": "fun(opts?: HL.NotificationOptions): HL.Notification", "hl.notification.get": "fun(): HL.Notification[]", + "hl.layout.register": "fun(name: string, provider: HL.LayoutProvider): nil", "hl.exec_cmd": "fun(cmd: string, rules?: table): nil", } api_signatures.update(query_overrides) @@ -539,6 +540,59 @@ def generate_stub(root: Path) -> str: ) lines.append("") + lines.extend( + emit_class_block( + "HL.Box", + [ + ("x", "number", False), + ("y", "number", False), + ("w", "number", False), + ("h", "number", False), + ], + ) + ) + lines.append("") + + lines.extend( + emit_class_block( + "HL.LayoutTarget", + [ + ("index", "integer", False), + ("window", "HL.Window|nil", False), + ("box", "HL.Box", False), + ("place", "fun(self: HL.LayoutTarget, box: HL.Box): nil", False), + ("set_box", "fun(self: HL.LayoutTarget, box: HL.Box): nil", False), + ], + ) + ) + lines.append("") + + lines.extend( + emit_class_block( + "HL.LayoutContext", + [ + ("area", "HL.Box", False), + ("targets", "HL.LayoutTarget[]", False), + ("grid_cell", "fun(self: HL.LayoutContext, i: integer, cols: integer, rows?: integer): HL.Box", False), + ("column", "fun(self: HL.LayoutContext, i: integer, n: integer): HL.Box", False), + ("row", "fun(self: HL.LayoutContext, i: integer, n: integer): HL.Box", False), + ("split", "fun(self: HL.LayoutContext, box: HL.Box, side: 'left'|'right'|'top'|'bottom'|'up'|'down', ratio: number): HL.Box", False), + ], + ) + ) + lines.append("") + + lines.extend( + emit_class_block( + "HL.LayoutProvider", + [ + ("recalculate", "fun(ctx: HL.LayoutContext): nil", False), + ("layout_msg", "fun(ctx: HL.LayoutContext, msg: string): boolean|string|nil", True), + ], + ) + ) + lines.append("") + lines.extend( emit_class_block( "HL.BindOptions", diff --git a/meta/hl.meta.lua b/meta/hl.meta.lua index 6ea875ae..6e34ff34 100644 --- a/meta/hl.meta.lua +++ b/meta/hl.meta.lua @@ -387,6 +387,35 @@ local __HL_Dispatcher = {} ---@field y number local __HL_Vec2 = {} +---@class HL.Box +---@field x number +---@field y number +---@field w number +---@field h number +local __HL_Box = {} + +---@class HL.LayoutTarget +---@field index integer +---@field window HL.Window|nil +---@field box HL.Box +---@field place fun(self: HL.LayoutTarget, box: HL.Box): nil +---@field set_box fun(self: HL.LayoutTarget, box: HL.Box): nil +local __HL_LayoutTarget = {} + +---@class HL.LayoutContext +---@field area HL.Box +---@field targets HL.LayoutTarget[] +---@field grid_cell fun(self: HL.LayoutContext, i: integer, cols: integer, rows?: integer): HL.Box +---@field column fun(self: HL.LayoutContext, i: integer, n: integer): HL.Box +---@field row fun(self: HL.LayoutContext, i: integer, n: integer): HL.Box +---@field split fun(self: HL.LayoutContext, box: HL.Box, side: 'left'|'right'|'top'|'bottom'|'up'|'down', ratio: number): HL.Box +local __HL_LayoutContext = {} + +---@class HL.LayoutProvider +---@field recalculate fun(ctx: HL.LayoutContext): nil +---@field layout_msg? fun(ctx: HL.LayoutContext, msg: string): boolean|string|nil +local __HL_LayoutProvider = {} + ---@class HL.BindOptions ---@field repeating? boolean ---@field locked? boolean @@ -783,6 +812,7 @@ local __HL_Workspace = {} ---@field window_rule fun(spec: HL.WindowRuleSpec): HL.WindowRule ---@field workspace_rule fun(spec: HL.WorkspaceRuleSpec): nil ---@field dsp HL.DspNamespace +---@field layout HL.LayoutNamespace ---@field notification HL.NotificationNamespace ---@field plugin HL.PluginNamespace local __HL_API = {} @@ -855,6 +885,10 @@ local __HL_DspWindowNamespace = {} ---@field toggle_special fun(...): HL.Dispatcher local __HL_DspWorkspaceNamespace = {} +---@class HL.LayoutNamespace +---@field register fun(name: string, provider: HL.LayoutProvider): nil +local __HL_LayoutNamespace = {} + ---@class HL.NotificationNamespace ---@field create fun(opts?: HL.NotificationOptions): HL.Notification ---@field get fun(): HL.Notification[] -- cgit v1.2.3