mirror of
https://github.com/caelestia-dots/cli.git
synced 2026-06-08 16:29:28 -05:00
refactor: enforce stricter type hints (#91)
LSP was screaming at me so I decided to just address it to get it off my screen. + Fixed the type hints := Modified and added type hints for certain functions and variables in most of the files in the utils/ folder (and some in the subcommands/ folder) for clarity and so pyright's type checker wouldn't cry. :+ To resolve certain type issues, I had to add a bit more tiny additional code such as, additional checks if a variable is None, a tiny class in utils/material/generator.py to resolve the constructor usage mismatch between what the DynamicScheme accepts and what the code actually passes, and etc. - Renamed certain functions and variables for clarity and also for some to not collide with pre-existing definitions from well-known library imports. + PIL has reorganized their code a bit, so the code is made to reflect their new definitions. = Reorganized the single import statement for "colourfulness" in utils/wallpaper.py to be close to the top. (I think that's it) Side Effects?: Everything should work the same as no logic change was done whatsover (unless we consider the added if statements for type checking as a logic change). I've tested it, everything seems to be in urdir.
This commit is contained in:
@@ -3,6 +3,7 @@ import shlex
|
||||
import shutil
|
||||
from argparse import Namespace
|
||||
from collections import ChainMap
|
||||
from typing import Any, Callable, cast
|
||||
|
||||
from caelestia.utils import hypr
|
||||
from caelestia.utils.paths import user_config_path
|
||||
@@ -52,8 +53,8 @@ class DeepChainMap(ChainMap):
|
||||
|
||||
class Command:
|
||||
args: Namespace
|
||||
cfg: dict[str, dict[str, dict[str, any]]] | DeepChainMap
|
||||
clients: list[dict[str, any]] = None
|
||||
cfg: dict[str, dict[str, dict[str, Any]]] | DeepChainMap
|
||||
clients: list[dict[str, Any]] | None = None
|
||||
|
||||
def __init__(self, args: Namespace) -> None:
|
||||
self.args = args
|
||||
@@ -120,27 +121,27 @@ class Command:
|
||||
if not spawned:
|
||||
hypr.dispatch("togglespecialworkspace", self.args.workspace)
|
||||
|
||||
def get_clients(self) -> list[dict[str, any]]:
|
||||
def get_clients(self) -> list[dict[str, Any]]:
|
||||
if self.clients is None:
|
||||
self.clients = hypr.message("clients")
|
||||
|
||||
self.clients = cast(list[dict[str, Any]], hypr.message("clients"))
|
||||
return self.clients
|
||||
|
||||
def move_client(self, selector: callable, workspace: str) -> None:
|
||||
def move_client(self, selector: Callable, workspace: str) -> None:
|
||||
for client in self.get_clients():
|
||||
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]) -> bool:
|
||||
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()
|
||||
):
|
||||
hypr.dispatch("exec", f"[workspace special:{self.args.workspace}] app2unit -- {shlex.join(spawn)}")
|
||||
return True
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
def handle_client_config(self, client: dict[str, any]) -> bool:
|
||||
def selector(c: dict[str, any]) -> bool:
|
||||
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"]:
|
||||
if is_subset(c, match):
|
||||
@@ -156,5 +157,8 @@ class Command:
|
||||
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")
|
||||
monitors = cast(list[dict[str, Any]], hypr.message("monitors"))
|
||||
target = next((m for m in monitors if m.get("focused")), None)
|
||||
if target:
|
||||
special = target.get("specialWorkspace", {}).get("name", "")[8:] or "special"
|
||||
hypr.dispatch("togglespecialworkspace", special)
|
||||
|
||||
Reference in New Issue
Block a user