Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow seeing urgent windows and workspaces from hyprland #104

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions ignis/services/hyprland/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def __init__(self):
self._active_workspace: dict[str, Any] = {}
self._kb_layout: str = ""
self._active_window: dict[str, Any] = {}
self._urgent_windows: set[str] = set()

if self.is_available:
self.__listen_events()
Expand All @@ -114,6 +115,29 @@ def workspaces(self) -> list[dict[str, Any]]:
"""
return self._workspaces

@GObject.Property
def urgent_windows(self) -> list[str]:
"""
- read-only

A list of urgent windows.
"""
return list(self._urgent_windows)

@GObject.Property
def urgent_workspaces(self) -> list[str]:
"""
- read-only

A list of urgent workspaces.
"""
clients = json.loads(self.send_command("j/clients"))
urgent_workspaces = []
for i in clients:
if i["address"][len("0x"):] in self._urgent_windows:
urgent_workspaces.append(i["workspace"]["id"])
return urgent_workspaces

@GObject.Property
def active_workspace(self) -> dict[str, Any]:
"""
Expand Down Expand Up @@ -161,6 +185,9 @@ def __on_event_received(self, event: str) -> None:
elif event.startswith("activewindow>>"):
self.__sync_active_window()

elif event.startswith("urgent>>"):
self.__sync_urgent(event[len("urgent>>"):])

def __sync_workspaces(self) -> None:
self._workspaces = sorted(
json.loads(self.send_command("j/workspaces")), key=lambda x: x["id"]
Expand All @@ -177,7 +204,18 @@ def __sync_kb_layout(self) -> None:

def __sync_active_window(self) -> None:
self._active_window = json.loads(self.send_command("j/activewindow"))
if self._active_window:
active_window_id = self._active_window["address"][len("0x"):]
if active_window_id in self._urgent_windows:
self._urgent_windows.remove(active_window_id)
self.notify("active_window")
self.notify("urgent_windows")
self.notify("urgent_workspaces")

def __sync_urgent(self, urgent_window) -> None:
self._urgent_windows.add(urgent_window)
self.notify("urgent_windows")
self.notify("urgent_workspaces")

def send_command(self, cmd: str) -> str:
"""
Expand Down