Bladeren bron

fix(yabai): move rotation logic to `open_application.zsh` for lower latency

Joe 1 jaar geleden
bovenliggende
commit
d97fb5443c
3 gewijzigde bestanden met toevoegingen van 15 en 30 verwijderingen
  1. 1 1
      .config/skhd/skhdrc
  2. 2 29
      .config/yabai/yabai.py
  3. 12 0
      .scripts/open_application.zsh

+ 1 - 1
.config/skhd/skhdrc

@@ -5,7 +5,7 @@ cmd - n : \
 		yabai -m window --focus next || yabai -m window --focus first; \
 	fi
 
-cmd + shift - n : /opt/homebrew/bin/yabai --restart-service && sleep 0.5 && /bin/zsh $XDG_CONFIG_HOME/yabai/yabairc
+cmd + shift - n : /bin/zsh $XDG_CONFIG_HOME/yabai/yabairc
 cmd + shift - d: /bin/zsh $HOME/.scripts/lightmode.zsh toggle
 
 cmd - 1 : /bin/zsh $HOME/.scripts/open_application.zsh terminal

+ 2 - 29
.config/yabai/yabai.py

@@ -319,31 +319,6 @@ class Yabai:
                 f"action=/bin/zsh {HOME}/.scripts/lightmode.zsh",
             ]
         )
-        # When focusing an that may share a space with at least two others, rotate the
-        # space's windows to ensure that the focused window is the largest.
-        for label, _, apps in self.spaces:
-            if len(apps) < 3:
-                continue
-            for app in apps:
-                self.message(
-                [
-                    "signal",
-                    "--add",
-                    "event=window_focused",
-                    f"app={app}",
-                    f"label={app}RotateToFocus",
-                    f"action=python3 {XDG_CONFIG_HOME}/yabai/yabai.py rotate",
-                ]
-            )
-
-    def rotate(self) -> None:
-        windows = self.get_windows()
-        focus_window = next(w for w in windows if w.has_focus)
-        same_space_windows = sorted((w for w in windows if w.space == focus_window.space), key = lambda w: w.size)
-        if same_space_windows[-1].has_focus:
-            return
-        self.message(["window", focus_window.id, "--swap", same_space_windows[-1].id])
-        return
 
     def get_focused_window(self) -> int:
         return [
@@ -356,11 +331,9 @@ class Yabai:
 if __name__ == "__main__":
     basicConfig(level=NOTSET)
     debug(f"Called with parameters {argv}")
-    if argv[1] == "manage" or argv[1] == "initialize":
-        with Yabai() as yabai:
+    with Yabai() as yabai:
+        if argv[1] == "manage" or argv[1] == "initialize":
             yabai.manage_displays()
             yabai.manage_spaces()
         if argv[1] == "initialize":
             yabai.set_rules_and_signals()
-    if argv[1] == "rotate":
-        Yabai().rotate()

+ 12 - 0
.scripts/open_application.zsh

@@ -33,3 +33,15 @@ case $1 in
     projectdocs)
         open $PROJECTDOCS_PATH ;;
 esac
+
+# If there are 3+ windows in the space, then make selected the largest window
+windows=$(yabai -m query --windows)
+active_space=$(jq 'map(select(."has-focus"==true)) | map(.space) | first' <<< $windows)
+shared_windows=$(jq --argjson space "$active_space" 'map(select(.space==$space)) | map( { ("size"): (.frame.w * .frame.h), "id": .id, "focus": ."has-focus", "title": .title } ) | sort_by(.size)' <<< $windows)
+if [ $(jq 'length' <<< $shared_windows ) -gt 2 ]; then
+    focused_window=$(jq 'map(select(.focus)) | first | .id' <<< $shared_windows)
+    largest_window=$(jq 'last | .id' <<< $shared_windows)
+    if [ "$focused_window" != "$largest_window" ]; then
+        yabai -m window $focused_window --swap $largest_window
+    fi
+fi