Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions examples/bar/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 21 additions & 1 deletion ignis/services/hyprland/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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]:
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
"""
Expand Down
2 changes: 1 addition & 1 deletion ignis/services/hyprland/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)