Ver Fonte

fix(yabai): update logic for application switching

Joe há 5 meses atrás
pai
commit
738a0dae4a
3 ficheiros alterados com 72 adições e 39 exclusões
  1. 2 2
      .config/skhd/skhdrc
  2. 57 35
      .config/yabai/yabai.py
  3. 13 2
      .scripts/open_application.zsh

+ 2 - 2
.config/skhd/skhdrc

@@ -14,8 +14,8 @@ cmd - 2 : /bin/zsh $DOTFILES_DIR/.scripts/open_application.zsh browser
 cmd - 3 : /bin/zsh $DOTFILES_DIR/.scripts/open_application.zsh finder
 cmd - 4 : /bin/zsh $DOTFILES_DIR/.scripts/open_application.zsh communications
 cmd - 5 : /bin/zsh $DOTFILES_DIR/.scripts/open_application.zsh music
-cmd - 6 : /bin/zsh $DOTFILES_DIR/.scripts/open_application.zsh notetaking
+cmd - 6 : /bin/zsh $DOTFILES_DIR/.scripts/open_application.zsh projectdocs
 cmd - 7 : /bin/zsh $DOTFILES_DIR/.scripts/open_application.zsh videocall
 cmd - 8 : /bin/zsh $DOTFILES_DIR/.scripts/open_application.zsh projecttracking
-cmd - 9 : /bin/zsh $DOTFILES_DIR/.scripts/open_application.zsh timetracking
+cmd - 9 : /bin/zsh $DOTFILES_DIR/.scripts/open_application.zsh mail
 cmd - 0 : /bin/zsh $DOTFILES_DIR/.scripts/open_application.zsh

+ 57 - 35
.config/yabai/yabai.py

@@ -123,19 +123,18 @@ class Yabai(CLIWrapper):
     def __init__(self):
         self._dual_display = len(self.get_displays()) > 1
         self.spaces.append(
-                (
-                    "Communication",
-                    False,
-                    ["Slack", "Signal", "Spotify"],
-                    False,
-                )
+            (
+                "Communication",
+                False,
+                ["Slack", "Signal", "Spotify"],
+                False,
             )
+        )
+        self.spaces.append(("Notetaking", True, ["Obsidian", "Asana", "Notion"], True))
+        self.spaces.append(("Admin", True, ["Notion Calendar", "Notion Mail"], True))
         if self._dual_display:
             for application in [
                 "Google Meet",
-                "Obsidian",
-                "Asana",
-                "Notion",
                 "Netflix",
                 "YouTube",
             ]:
@@ -147,12 +146,12 @@ class Yabai(CLIWrapper):
                         False,
                     )
                 )
-        else:
-            self.spaces.append(("Notetaking", True, ["Obsidian", "Asana", "Notion"], False))
 
     def __enter__(self):
         self._initial_window = self.get_focused_window()
-        self._initial_spaces = [s for s in  self.get_spaces() if s.is_visible and len(s.label)]
+        self._initial_spaces = [
+            s for s in self.get_spaces() if s.is_visible and len(s.label)
+        ]
         return self
 
     def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any):
@@ -188,7 +187,9 @@ class Yabai(CLIWrapper):
     def get_main_display(
         self, displays: set[YabaiDisplay] | None = None
     ) -> YabaiDisplay:
-        return sorted(list(displays if displays is not None else self.get_displays()))[-1]
+        return sorted(list(displays if displays is not None else self.get_displays()))[
+            -1
+        ]
 
     def is_blank_space(self, space: Space) -> bool:
         return (
@@ -276,16 +277,28 @@ class Yabai(CLIWrapper):
         if self._dual_display:
             display_by_space_label = {s[0]: 1 if s[-1] else 2 for s in self.spaces}
             spaces = self.get_spaces()
-            wrong_spaces = [s for s in spaces
-                            if s.label in display_by_space_label and
-                            s.display != display_by_space_label[s.label]]
+            wrong_spaces = [
+                s
+                for s in spaces
+                if s.label in display_by_space_label
+                and s.display != display_by_space_label[s.label]
+            ]
             wrong_main_spaces = [s for s in wrong_spaces if s.display != 1]
             wrong_secondary_spaces = [s for s in wrong_spaces if s.display != 2]
-            while len(wrong_main_spaces) and len (wrong_secondary_spaces):
-                self.message([ "space", wrong_main_spaces.pop().label, "--swap", wrong_secondary_spaces.pop().label ])
+            while len(wrong_main_spaces) and len(wrong_secondary_spaces):
+                self.message(
+                    [
+                        "space",
+                        wrong_main_spaces.pop().label,
+                        "--swap",
+                        wrong_secondary_spaces.pop().label,
+                    ]
+                )
             wrong_spaces = wrong_main_spaces + wrong_secondary_spaces
             while len(wrong_spaces) and (space := wrong_spaces.pop().label):
-                self.message([ "space", space, "--display", display_by_space_label[space]])
+                self.message(
+                    ["space", space, "--display", display_by_space_label[space]]
+                )
         info(f"Spaces configured: {sorted(self.get_spaces())}")
 
     def set_space_background(self, space: SpaceSel):
@@ -302,7 +315,9 @@ class Yabai(CLIWrapper):
             ]
         )
 
-    def set_global_config( self,):
+    def set_global_config(
+        self,
+    ):
         self.message(["config", "auto_balance", "on"])
         self.message(["config", "mouse_follows_focus", "on"])
 
@@ -411,15 +426,6 @@ class Yabai(CLIWrapper):
             ]
         )
 
-        self.message(
-            [
-                "signal",
-                "--add",
-                "event=display_added",
-                "label=DisplayBrightnessManager",
-                "action=/bin/zsh $DOTFILES_DIR/.scripts/display_brightness.zsh",
-            ]
-        )
         if self._dual_display:
             self.message(
                 [
@@ -442,10 +448,19 @@ class Yabai(CLIWrapper):
                     "signal",
                     "--add",
                     f"event={trigger}",
-                    f"label=DisplayChange{trigger}",
+                    f"label=DisplayChangeYabai{trigger}",
                     f"action=/usr/bin/env python3 {HOME}/.config/yabai.py manage",
                 ]
             )
+            self.message(
+                [
+                    "signal",
+                    "--add",
+                    f"event={trigger}",
+                    f"label=DisplayChangeDisplay{trigger}",
+                    "action=/bin/zsh $DOTFILES_DIR/.scripts/display_brightness.zsh",
+                ]
+            )
 
         # Rules that differ for one or multiple displays
         if not self._dual_display:
@@ -475,6 +490,17 @@ class Yabai(CLIWrapper):
                     "manage=on",
                 ]
             )
+        else:
+            self.message(
+                [
+                    "rule",
+                    "--add",
+                    "label=SlackVideoCallFloatingWindowRule",
+                    "app=Slack",
+                    "title=Huddle.*",
+                    "space=Google Meet",
+                ]
+            )
 
     def move_spaces_to_displays(self):
         if not self._dual_display:
@@ -588,10 +614,6 @@ if __name__ == "__main__":
             yabai.manage_spaces()
         if argv[1] == "initialize":
             yabai.set_rules_and_signals()
-        if (
-            argv[1] == "move"
-            or argv[1] == "manage"
-            or argv[1] == "initialize"
-        ):
+        if argv[1] == "move" or argv[1] == "manage" or argv[1] == "initialize":
             yabai.enable_exit_with_refocus()
             yabai.move_spaces_to_displays()

+ 13 - 2
.scripts/open_application.zsh

@@ -6,12 +6,19 @@ export COMMUNICATIONS_PATH=/Applications/Slack.app/
 export MUSIC_PATH=/Applications/Spotify.app/
 export NOTETAKING_PATH=/Applications/Obsidian.app/
 export PROJECTTRACKING_PATH=/Applications/Asana.app/
+export MAIL_PATH=/Applications/Notion\ Mail.app//
 export PROJECTDOCS_PATH=/Applications/Notion.app/
 export VIDEOCALL_PATH=$HOME/Applications/Google\ Meet.app/
 
 export ALT_COMMUNICATIONS_PATH=/Applications/Signal.app/
 export ALT_NOTETAKING_PATH=/Applications/Obsidian.app/
 
+focus() {
+    local id
+    id=$(yabai -m query --windows | jq -e "$1") || return 1
+    yabai -m window --focus "$id"
+}
+
 valid_selection=true
 case $1 in
     terminal)
@@ -19,20 +26,24 @@ case $1 in
     browser)
         open $BROWSER_PATH ;;
     finder)
-        yabai -m window --focus $(yabai -m query --windows | jq 'map(select(.app=="Finder")) | first | .id') || open $FINDER_PATH ;;
+        focus 'map(select(.app=="Finder")) | first | .id' || open $FINDER_PATH ;;
     communications)
+        focus 'first(.[] | select(.app == "Slack" and (.title | startswith("Huddle: ") | not))).id' || \
         open $COMMUNICATIONS_PATH || open $ALT_COMMUNICATIONS_PATH ;;
     music)
         open $MUSIC_PATH ;;
     notetaking)
         open $ALT_NOTETAKING_PATH || open $NOTETAKING_PATH ;;
     videocall)
-        yabai -m window --focus $(yabai -m query --windows | jq 'map(select(.app == "Google Meet")) | first | .id') || \
+        focus 'first(.[] | select(.app == "Slack" and (.title | startswith("Huddle: ")))).id' || \
+        focus 'map(select(.app == "Google Meet")) | first | .id' || \
         open $VIDEOCALL_PATH || open $ALT_COMMUNICATIONS_PATH ;;
     projecttracking)
         open $PROJECTTRACKING_PATH ;;
     projectdocs)
         open $PROJECTDOCS_PATH ;;
+    mail)
+        open $MAIL_PATH ;;
     *)
         valid_selection=false
 esac