diff options
Diffstat (limited to 'src/caelestia/subcommands')
| -rw-r--r-- | src/caelestia/subcommands/clipboard.py | 11 | ||||
| -rw-r--r-- | src/caelestia/subcommands/emoji.py | 11 | ||||
| -rw-r--r-- | src/caelestia/subcommands/pip.py | 11 | ||||
| -rw-r--r-- | src/caelestia/subcommands/record.py | 11 | ||||
| -rw-r--r-- | src/caelestia/subcommands/scheme.py | 11 | ||||
| -rw-r--r-- | src/caelestia/subcommands/screenshot.py | 11 | ||||
| -rw-r--r-- | src/caelestia/subcommands/shell.py | 41 | ||||
| -rw-r--r-- | src/caelestia/subcommands/toggle.py | 82 | ||||
| -rw-r--r-- | src/caelestia/subcommands/variant.py | 11 | ||||
| -rw-r--r-- | src/caelestia/subcommands/wallpaper.py | 11 | ||||
| -rw-r--r-- | src/caelestia/subcommands/wsaction.py | 18 |
11 files changed, 229 insertions, 0 deletions
diff --git a/src/caelestia/subcommands/clipboard.py b/src/caelestia/subcommands/clipboard.py new file mode 100644 index 0000000..37f9a2b --- /dev/null +++ b/src/caelestia/subcommands/clipboard.py @@ -0,0 +1,11 @@ +from argparse import Namespace + + +class Command: + args: Namespace + + def __init__(self, args: Namespace) -> None: + self.args = args + + def run(self) -> None: + pass diff --git a/src/caelestia/subcommands/emoji.py b/src/caelestia/subcommands/emoji.py new file mode 100644 index 0000000..37f9a2b --- /dev/null +++ b/src/caelestia/subcommands/emoji.py @@ -0,0 +1,11 @@ +from argparse import Namespace + + +class Command: + args: Namespace + + def __init__(self, args: Namespace) -> None: + self.args = args + + def run(self) -> None: + pass diff --git a/src/caelestia/subcommands/pip.py b/src/caelestia/subcommands/pip.py new file mode 100644 index 0000000..37f9a2b --- /dev/null +++ b/src/caelestia/subcommands/pip.py @@ -0,0 +1,11 @@ +from argparse import Namespace + + +class Command: + args: Namespace + + def __init__(self, args: Namespace) -> None: + self.args = args + + def run(self) -> None: + pass diff --git a/src/caelestia/subcommands/record.py b/src/caelestia/subcommands/record.py new file mode 100644 index 0000000..37f9a2b --- /dev/null +++ b/src/caelestia/subcommands/record.py @@ -0,0 +1,11 @@ +from argparse import Namespace + + +class Command: + args: Namespace + + def __init__(self, args: Namespace) -> None: + self.args = args + + def run(self) -> None: + pass diff --git a/src/caelestia/subcommands/scheme.py b/src/caelestia/subcommands/scheme.py new file mode 100644 index 0000000..37f9a2b --- /dev/null +++ b/src/caelestia/subcommands/scheme.py @@ -0,0 +1,11 @@ +from argparse import Namespace + + +class Command: + args: Namespace + + def __init__(self, args: Namespace) -> None: + self.args = args + + def run(self) -> None: + pass diff --git a/src/caelestia/subcommands/screenshot.py b/src/caelestia/subcommands/screenshot.py new file mode 100644 index 0000000..37f9a2b --- /dev/null +++ b/src/caelestia/subcommands/screenshot.py @@ -0,0 +1,11 @@ +from argparse import Namespace + + +class Command: + args: Namespace + + def __init__(self, args: Namespace) -> None: + self.args = args + + def run(self) -> None: + pass diff --git a/src/caelestia/subcommands/shell.py b/src/caelestia/subcommands/shell.py new file mode 100644 index 0000000..2d8d14e --- /dev/null +++ b/src/caelestia/subcommands/shell.py @@ -0,0 +1,41 @@ +import subprocess +from argparse import Namespace + +from caelestia import data + + +class Command: + args: Namespace + + def __init__(self, args: Namespace) -> None: + self.args = args + + def run(self) -> None: + if self.args.show: + # Print the ipc + self.print_ipc() + elif self.args.log: + # Print the log + self.print_log() + elif self.args.message: + # Send a message + self.message(*self.args.message) + else: + # Start the shell + self.shell() + + def shell(self, *args: list[str]) -> str: + return subprocess.check_output(["qs", "-p", data.c_data_dir / "shell", *args], text=True) + + def print_ipc(self) -> None: + print(self.shell("ipc", "show"), end="") + + def print_log(self) -> None: + log = self.shell("log") + # FIXME: remove when logging rules are added/warning is removed + for line in log.splitlines(): + if "QProcess: Destroyed while process" not in line: + print(line) + + def message(self, *args: list[str]) -> None: + print(self.shell("ipc", "call", *args), end="") diff --git a/src/caelestia/subcommands/toggle.py b/src/caelestia/subcommands/toggle.py new file mode 100644 index 0000000..2122910 --- /dev/null +++ b/src/caelestia/subcommands/toggle.py @@ -0,0 +1,82 @@ +from argparse import Namespace + +from caelestia.utils import hypr + + +class Command: + args: Namespace + clients: list[dict[str, any]] = None + app2unit: str = None + + def __init__(self, args: Namespace) -> None: + self.args = args + + def run(self) -> None: + getattr(self, self.args.workspace)() + + def get_clients(self) -> list[dict[str, any]]: + if self.clients is None: + self.clients = hypr.message("clients") + + return self.clients + + def get_app2unit(self) -> str: + if self.app2unit is None: + import shutil + + self.app2unit = shutil.which("app2unit") + + return self.app2unit + + def move_client(self, selector: callable, workspace: str) -> None: + for client in self.get_clients(): + if selector(client): + hypr.dispatch("movetoworkspacesilent", f"special:{workspace},address:{client['address']}") + + def spawn_client(self, selector: callable, spawn: list[str]) -> bool: + exists = any(selector(client) for client in self.get_clients()) + + if not exists: + import subprocess + + subprocess.Popen([self.get_app2unit(), "--", *spawn], start_new_session=True) + + return not exists + + def spawn_or_move(self, selector: callable, spawn: list[str], workspace: str) -> None: + if not self.spawn_client(selector, spawn): + self.move_client(selector, workspace) + + def communication(self) -> None: + self.spawn_or_move(lambda c: c["class"] == "discord", ["discord"], "communication") + self.move_client(lambda c: c["class"] == "whatsapp", "communication") + + def music(self) -> None: + self.spawn_or_move( + lambda c: c["class"] == "Spotify" or c["initialTitle"] == "Spotify" or c["initialTitle"] == "Spotify Free", + ["spicetify", "watch", "-s"], + "music", + ) + self.move_client(lambda c: c["class"] == "feishin", "music") + + def sysmon(self) -> None: + self.spawn_client( + lambda c: c["class"] == "btop" and c["title"] == "btop" and c["workspace"]["name"] == "special:sysmon", + ["foot", "-a", "btop", "-T", "btop", "--", "btop"], + "sysmon", + ) + + def todo(self) -> None: + self.spawn_or_move(lambda c: c["class"] == "Todoist", ["todoist"], "todo") + + def specialws(self) -> None: + workspaces = hypr.message("workspaces") + on_special_ws = any(ws["name"] == "special:special" for ws in workspaces) + toggle_ws = "special" + + if not on_special_ws: + active_ws = hypr.message("activewindow")["workspace"]["name"] + if active_ws.startswith("special:"): + toggle_ws = active_ws[8:] + + hypr.dispatch("togglespecialworkspace", toggle_ws) diff --git a/src/caelestia/subcommands/variant.py b/src/caelestia/subcommands/variant.py new file mode 100644 index 0000000..37f9a2b --- /dev/null +++ b/src/caelestia/subcommands/variant.py @@ -0,0 +1,11 @@ +from argparse import Namespace + + +class Command: + args: Namespace + + def __init__(self, args: Namespace) -> None: + self.args = args + + def run(self) -> None: + pass diff --git a/src/caelestia/subcommands/wallpaper.py b/src/caelestia/subcommands/wallpaper.py new file mode 100644 index 0000000..37f9a2b --- /dev/null +++ b/src/caelestia/subcommands/wallpaper.py @@ -0,0 +1,11 @@ +from argparse import Namespace + + +class Command: + args: Namespace + + def __init__(self, args: Namespace) -> None: + self.args = args + + def run(self) -> None: + pass diff --git a/src/caelestia/subcommands/wsaction.py b/src/caelestia/subcommands/wsaction.py new file mode 100644 index 0000000..d496381 --- /dev/null +++ b/src/caelestia/subcommands/wsaction.py @@ -0,0 +1,18 @@ +from argparse import Namespace + +from caelestia.utils import hypr + + +class Command: + args: Namespace + + def __init__(self, args: Namespace) -> None: + self.args = args + + def run(self) -> None: + active_ws = hypr.message("activeworkspace")["id"] + + if self.args.group: + hypr.dispatch(self.args.dispatcher, (self.args.workspace - 1) * 10 + active_ws % 10) + else: + hypr.dispatch(self.args.dispatcher, int((active_ws - 1) / 10) * 10 + self.args.workspace) |