feat: Move set-workspace to compositor-control

This commit is contained in:
Leni Aniva 2024-06-02 06:21:36 -07:00
parent 9ca97466a1
commit 9147fa3fff
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
3 changed files with 18 additions and 5 deletions

View File

@ -65,7 +65,7 @@
(for workspace in workspaces (for workspace in workspaces
(button (button
:class "${workspace.class}" :class "${workspace.class}"
:onclick "scripts/workspace.sh ${workspace.id}" :onclick "scripts/compositor-control set-workspace ${workspace.id}"
"${workspace.text}")) "${workspace.text}"))
)) ))
(deflisten workspaces :initial "[]" (deflisten workspaces :initial "[]"

View File

@ -67,6 +67,8 @@ class CompositorHandler:
pass pass
def listen_active_window_title(self): def listen_active_window_title(self):
pass pass
def set_workspace(self, i):
pass
class HyprlandHandler(CompositorHandler): class HyprlandHandler(CompositorHandler):
def __init__(self, socket_addr): def __init__(self, socket_addr):
@ -125,6 +127,15 @@ class HyprlandHandler(CompositorHandler):
print(title, flush=True) print(title, flush=True)
self.listen(callback) self.listen(callback)
@override
def set_workspace(self, i):
result = os.popen(f"hyprctl dispatch workspace {i}").read()
if result != "ok\n":
raise RuntimeError(f"Failed to set workspace: {result}")
# FIXME: Set the wallpaper too.
# ~/.config/hypr/wallpaper.sh $1
class SwayHandler(CompositorHandler): class SwayHandler(CompositorHandler):
@staticmethod @staticmethod
@ -163,5 +174,11 @@ if __name__ == "__main__":
handler.listen_workspaces() handler.listen_workspaces()
elif key == "active-title": elif key == "active-title":
handler.listen_active_window_title() handler.listen_active_window_title()
elif key == "set-workspace":
if len(sys.argv) != 3:
print(f"Set workspace must be accompanied by an argument", file=sys.stderr)
arg = sys.argv[2]
handler.set_workspace(arg)
else: else:
print(f"Unknown key: {key}", file=sys.stderr) print(f"Unknown key: {key}", file=sys.stderr)

View File

@ -1,4 +0,0 @@
#!/bin/bash
hyprctl dispatch workspace $1
~/.config/hypr/wallpaper.sh $1