|
|
@@ -4,15 +4,16 @@ from logging import NOTSET, basicConfig, debug, info
|
|
|
from os import getenv
|
|
|
from subprocess import CalledProcessError, check_output
|
|
|
from sys import argv
|
|
|
-from typing import TypeAlias
|
|
|
+from typing import Any, TypeAlias
|
|
|
|
|
|
HOME = getenv("HOME")
|
|
|
XDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME")
|
|
|
TARGET_DISPLAY_WIDTH = 1680
|
|
|
TARGET_DISPLAY_HEIGHT = 1050
|
|
|
|
|
|
+
|
|
|
class Window:
|
|
|
- def __init__(self, data: dict):
|
|
|
+ def __init__(self, data: dict[str, Any]):
|
|
|
self.id: int = data["id"]
|
|
|
self.app: str = data["app"]
|
|
|
self.space: str = data["space"]
|
|
|
@@ -34,10 +35,10 @@ class Window:
|
|
|
|
|
|
def __gt__(self, other: "Window"):
|
|
|
return self.id.__gt__(other.id)
|
|
|
-
|
|
|
+
|
|
|
|
|
|
class Space:
|
|
|
- def __init__(self, data: dict):
|
|
|
+ def __init__(self, data: dict[str, Any]):
|
|
|
self.id: int = data["id"]
|
|
|
self.index: int = data["index"]
|
|
|
self.label: str = data["label"]
|
|
|
@@ -58,14 +59,14 @@ class Space:
|
|
|
|
|
|
|
|
|
class Display:
|
|
|
- def __init__(self, data: dict):
|
|
|
+ def __init__(self, data: dict[str, Any]):
|
|
|
self.id: int = data["id"]
|
|
|
self.uuid: str = data["uuid"]
|
|
|
self.index: int = data["index"]
|
|
|
self.label: str = data["label"]
|
|
|
self.has_focus: bool = data["has-focus"]
|
|
|
self.spaces: list[str] = data["spaces"]
|
|
|
- self.frame: dict = data["frame"]
|
|
|
+ self.frame: dict[str, int] = data["frame"]
|
|
|
|
|
|
def __repr__(self) -> str:
|
|
|
return (
|
|
|
@@ -97,15 +98,16 @@ class Yabai:
|
|
|
self._initial_window = self.get_focused_window()
|
|
|
return self
|
|
|
|
|
|
- def __exit__(self, exc_type, exc_value, traceback):
|
|
|
+ def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any):
|
|
|
if exc_type is not None:
|
|
|
debug(f"Exited with {exc_type} {exc_value}")
|
|
|
self.message(["rule", "--apply"])
|
|
|
- self.message(["window", "--focus", self._initial_window])
|
|
|
+ if self._initial_window is not None:
|
|
|
+ self.message(["window", "--focus", self._initial_window])
|
|
|
if exc_type is None:
|
|
|
debug(f"Executed successfully")
|
|
|
|
|
|
- def execute(self, *args, **kwargs):
|
|
|
+ def execute(self, *args: Any, **kwargs: Any) -> Any:
|
|
|
debug(f"Executing: ({args}), ({kwargs})")
|
|
|
return check_output(*args, **kwargs)
|
|
|
|
|
|
@@ -113,13 +115,17 @@ class Yabai:
|
|
|
return self.execute(["yabai", "-m"] + [str(arg) for arg in args]).decode("utf8")
|
|
|
|
|
|
def get_windows(self) -> set[Window]:
|
|
|
- return { Window(window) for window in loads(self.message(["query", "--windows"])) }
|
|
|
+ return {
|
|
|
+ Window(window) for window in loads(self.message(["query", "--windows"]))
|
|
|
+ }
|
|
|
|
|
|
def get_spaces(self) -> set[Space]:
|
|
|
return {Space(space) for space in loads(self.message(["query", "--spaces"]))}
|
|
|
|
|
|
def get_displays(self) -> set[Display]:
|
|
|
- return { Display(display) for display in loads(self.message(["query", "--displays"])) }
|
|
|
+ return {
|
|
|
+ Display(display) for display in loads(self.message(["query", "--displays"]))
|
|
|
+ }
|
|
|
|
|
|
def get_main_display(self, displays: set[Display] | None = None) -> Display:
|
|
|
return sorted(list(displays if displays != None else self.get_displays()))[-1]
|
|
|
@@ -159,7 +165,7 @@ class Yabai:
|
|
|
spaces = self.get_spaces()
|
|
|
blank_spaces = {space for space in spaces if self.is_blank_space(space)}
|
|
|
created_space_labels: set[tuple[str, bool]] = set()
|
|
|
- for space_label, space_fullscreen, space_apps in self.spaces:
|
|
|
+ for space_label, space_fullscreen, _ in self.spaces:
|
|
|
if any(space.label == space_label for space in spaces):
|
|
|
continue
|
|
|
space = blank_spaces.pop()
|
|
|
@@ -178,12 +184,16 @@ class Yabai:
|
|
|
main_display = self.get_main_display()
|
|
|
for label, fullscreen in created_space_labels:
|
|
|
self.set_space_background(label)
|
|
|
- for label, fullscreen, apps in self.spaces:
|
|
|
+ for label, fullscreen, _ in self.spaces:
|
|
|
self.set_config(
|
|
|
label,
|
|
|
fullscreen=fullscreen,
|
|
|
- horizontal_padding=(main_display.frame["w"] - TARGET_DISPLAY_WIDTH) / 2,
|
|
|
- vertical_padding=(main_display.frame["h"] - TARGET_DISPLAY_HEIGHT) / 2,
|
|
|
+ horizontal_padding=int(
|
|
|
+ (main_display.frame["w"] - TARGET_DISPLAY_WIDTH) / 2
|
|
|
+ ),
|
|
|
+ vertical_padding=int(
|
|
|
+ (main_display.frame["h"] - TARGET_DISPLAY_HEIGHT) / 2
|
|
|
+ ),
|
|
|
)
|
|
|
if len(created_space_labels) > 0:
|
|
|
self.message(["window", "--focus", initial_window])
|