From 0df89887a07d970bddcc87e9fcbfd2072de8513b Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sat, 16 Aug 2025 17:41:23 +1000 Subject: toggle: improvements Closes #40 --- src/caelestia/subcommands/toggle.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/caelestia/subcommands/toggle.py') 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") -- cgit v1.2.3-freya