From 5e9ebb4bcca0f0c5034be7b3bb6ba13f5b0d8c64 Mon Sep 17 00:00:00 2001 From: Marcin Banach Date: Sun, 10 May 2026 20:55:56 +0200 Subject: [PATCH] fix(HyprlandService): when using Hyprland Lua config, use Lua dispatch syntax --- examples/bar/config.py | 7 +++++-- ignis/services/hyprland/service.py | 22 +++++++++++++++++++++- ignis/services/hyprland/workspace.py | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/examples/bar/config.py b/examples/bar/config.py index ed394383..1814dbb9 100644 --- a/examples/bar/config.py +++ b/examples/bar/config.py @@ -65,7 +65,7 @@ def workspace_button(workspace) -> widgets.Button: def hyprland_scroll_workspaces(direction: str) -> None: - current = hyprland.active_workspace["id"] + current = hyprland.active_workspace.id if direction == "up": target = current - 1 hyprland.switch_to_workspace(target) @@ -299,7 +299,10 @@ def create_exec_task(cmd: str) -> None: def logout() -> None: if hyprland.is_available: - create_exec_task("hyprctl dispatch exit 0") + if hyprland.uses_lua_config: + create_exec_task("hyprctl dispatch 'hl.dsp.exit(0)'") + else: + create_exec_task("hyprctl dispatch exit 0") elif niri.is_available: create_exec_task("niri msg action quit") else: diff --git a/ignis/services/hyprland/service.py b/ignis/services/hyprland/service.py index 4a75faa5..691c4df3 100644 --- a/ignis/services/hyprland/service.py +++ b/ignis/services/hyprland/service.py @@ -92,7 +92,10 @@ def __init__(self): ), } + self._uses_lua_config: bool = False + if self.is_available: + self._uses_lua_config = self.__detect_lua_config() self.__listen_events() self.__initial_sync_obj_list(type_="workspace") @@ -136,6 +139,13 @@ def is_available(self) -> bool: """ return os.path.exists(HYPR_SOCKET_DIR) + @IgnisProperty + def uses_lua_config(self) -> bool: + """ + Whether Hyprland is using a Lua config. + """ + return self._uses_lua_config + @IgnisProperty def workspaces(self) -> list[HyprlandWorkspace]: """ @@ -438,6 +448,13 @@ def __change_special_ws_on_monitor( data={"specialWorkspace": {"id": workspace_id, "name": workspace_name}}, ) + def __detect_lua_config(self) -> bool: + status = self.send_command("status") + for line in status.splitlines(): + if line.startswith("configProvider:"): + return line.split(":", 1)[1].strip() == "lua" + return False + def send_command(self, cmd: str) -> str: """ Send a command to the Hyprland IPC. @@ -467,7 +484,10 @@ def switch_to_workspace(self, workspace_id: int) -> None: Args: workspace_id: The ID of the workspace to switch to. """ - self.send_command(f"dispatch workspace {workspace_id}") + if self._uses_lua_config: + self.send_command(f"dispatch hl.dsp.focus({{workspace = {workspace_id}}})") + else: + self.send_command(f"dispatch workspace {workspace_id}") def get_workspace_by_id(self, workspace_id: int) -> HyprlandWorkspace | None: """ diff --git a/ignis/services/hyprland/workspace.py b/ignis/services/hyprland/workspace.py index 925227e2..e07b2215 100644 --- a/ignis/services/hyprland/workspace.py +++ b/ignis/services/hyprland/workspace.py @@ -100,4 +100,4 @@ def switch_to(self) -> None: """ Switch to this workspace. """ - self.__service.send_command(f"dispatch workspace {self.id}") + self.__service.switch_to_workspace(self.id)