summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/caelestia/parser.py4
-rw-r--r--src/caelestia/subcommands/toggle.py27
2 files changed, 19 insertions, 12 deletions
diff --git a/src/caelestia/parser.py b/src/caelestia/parser.py
index 35266b2..838a608 100644
--- a/src/caelestia/parser.py
+++ b/src/caelestia/parser.py
@@ -28,9 +28,7 @@ def parse_args() -> (argparse.ArgumentParser, argparse.Namespace):
# Create parser for toggle opts
toggle_parser = command_parser.add_parser("toggle", help="toggle a special workspace")
toggle_parser.set_defaults(cls=toggle.Command)
- toggle_parser.add_argument(
- "workspace", choices=["communication", "music", "sysmon", "specialws", "todo"], help="the workspace to toggle"
- )
+ toggle_parser.add_argument("workspace", help="the workspace to toggle")
# Create parser for scheme opts
scheme_parser = command_parser.add_parser("scheme", help="manage the colour scheme")
diff --git a/src/caelestia/subcommands/toggle.py b/src/caelestia/subcommands/toggle.py
index f082ce2..ba5a351 100644
--- a/src/caelestia/subcommands/toggle.py
+++ b/src/caelestia/subcommands/toggle.py
@@ -1,6 +1,6 @@
import json
+import shlex
import shutil
-import subprocess
from argparse import Namespace
from collections import ChainMap
@@ -111,10 +111,14 @@ class Command:
self.specialws()
return
- for client in self.cfg[self.args.workspace].values():
- if "enable" in client and client["enable"]:
- self.handle_client_config(client)
- hypr.dispatch("togglespecialworkspace", self.args.workspace)
+ spawned = False
+ if self.args.workspace in self.cfg:
+ for client in self.cfg[self.args.workspace].values():
+ if "enable" in client and client["enable"] and self.handle_client_config(client):
+ spawned = True
+
+ if not spawned:
+ hypr.dispatch("togglespecialworkspace", self.args.workspace)
def get_clients(self) -> list[dict[str, any]]:
if self.clients is None:
@@ -127,13 +131,15 @@ class Command:
if selector(client) and client["workspace"]["name"] != f"special:{workspace}":
hypr.dispatch("movetoworkspacesilent", f"special:{workspace},address:{client['address']}")
- def spawn_client(self, selector: callable, spawn: list[str]) -> None:
+ def spawn_client(self, selector: callable, spawn: list[str]) -> bool:
if (spawn[0].endswith(".desktop") or shutil.which(spawn[0])) and not any(
selector(client) for client in self.get_clients()
):
- subprocess.Popen(["app2unit", "--", *spawn], start_new_session=True)
+ hypr.dispatch("exec", f"[workspace special:{self.args.workspace}] app2unit -- {shlex.join(spawn)}")
+ return True
+ return False
- def handle_client_config(self, client: dict[str, any]) -> None:
+ def handle_client_config(self, client: dict[str, any]) -> bool:
def selector(c: dict[str, any]) -> bool:
# Each match is or, inside matches is and
for match in client["match"]:
@@ -141,11 +147,14 @@ class Command:
return True
return False
+ spawned = False
if "command" in client and client["command"]:
- self.spawn_client(selector, client["command"])
+ spawned = self.spawn_client(selector, client["command"])
if "move" in client and client["move"]:
self.move_client(selector, self.args.workspace)
+ return spawned
+
def specialws(self) -> None:
special = next(m for m in hypr.message("monitors") if m["focused"])["specialWorkspace"]["name"]
hypr.dispatch("togglespecialworkspace", special[8:] or "special")