ctucx.git: nixfiles

ctucx' nixfiles

commit 2571d07ccc18111dbda9bd6c6851ed43983b9d81
parent e534f9857c6b39c444ab13c06f9d27d9bfcc3c6d
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sun, 20 Mar 2022 18:25:39 +0100

machines/blechbuechse: add yabai and skhd for i3/sway feeling UwU
3 files changed, 186 insertions(+), 0 deletions(-)
M
machines/blechbuechse/darwin-configuration.nix
|
4
++++
A
machines/blechbuechse/skhd.nix
|
114
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A
machines/blechbuechse/yabai.nix
|
68
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
diff --git a/machines/blechbuechse/darwin-configuration.nix b/machines/blechbuechse/darwin-configuration.nix
@@ -28,6 +28,8 @@ in {
     ../../configurations/programs/cli/utilities.nix
     ../../configurations/programs/cli/network-utilities.nix
     ../../configurations/programs/cli/scripts.nix
+    ./yabai.nix
+    ./skhd.nix
     ./keyboard.nix
   ];
 

@@ -144,6 +146,8 @@ in {
       tilesize                = 50;
       minimize-to-application = true;
       show-recents            = false;
+      # Dont rearrange my workspaces automagicly, thanks
+      mru-spaces              = false;
 
       # Disable all hot corners
       wvous-tl-corner         = 1;
diff --git a/machines/blechbuechse/skhd.nix b/machines/blechbuechse/skhd.nix
@@ -0,0 +1,114 @@
+{ config, pkgs, ... }:
+
+let
+  newTerminal = pkgs.writeScript "newTerminalWindow.sh" ''
+    #!/usr/bin/env bash
+    # Open iTerm2 with single instance
+
+    # Detects if iTerm2 is running
+    if ! pgrep -f "iTerm" > /dev/null; then
+      open -a "$HOME/Applications/iTerm.app"
+    else
+      # Create a new window
+      if ! osascript -e 'tell application "iTerm2" to create window with default profile' > /dev/null; then
+        # Get pids for any app with "iTerm" and kill
+        for i in $(pgrep -f "iTerm"); do kill -15 "$i"; done
+        open  -a "$HOME/Applications/iTerm.app"
+      fi
+    fi
+  '';
+
+  toggleFloating = pkgs.writeScript "yabaiToggleFloating.sh" ''
+    #!/usr/bin/env bash
+    PATH=$(eval echo $PATH)
+
+    # Toggle the workspace layout between float and bsp
+    read -r curType index <<< $(echo $(yabai -m query --spaces --space | jq '.type, .index'))
+
+    if [ $curType = '"bsp"' ]; then
+      yabai -m space --layout float
+      osascript -e "display notification \"Change the layout of workspace $index to float\" with title \"yabai\""
+    else
+      yabai -m space --layout bsp
+      osascript -e "display notification \"Change the layout of workspace $index to bsp\" with title \"yabai\""
+    fi
+  '';
+
+in {
+
+  home-manager.users.leah.home.packages = [ pkgs.skhd ];
+
+  services.skhd = {
+    enable     = true;
+    skhdConfig = ''
+      # spawn new terminal window
+      lalt - return : ${newTerminal}
+
+      # sleep
+      lalt - z : pmset sleepnow
+
+      # kill focused window
+      lalt + shift - q : yabai -m window --close
+
+      # float / unfloat window and center on screen
+      lalt - space : yabai -m window --toggle float; yabai -m window --grid 4:4:1:1:2:2
+
+      # enter fullscreen mode for the focused window
+      lalt - f : yabai -m window --toggle zoom-fullscreen
+
+      # change layout of desktop
+      lalt - e : ${toggleFloating}
+
+      # rotate tree
+      lalt - r : yabai -m space --rotate 90
+
+      # change focus (using arrow keys)
+      lalt - left  : yabai -m window --focus west
+      lalt - right : yabai -m window --focus east
+      lalt - down  : yabai -m window --focus south
+      lalt - up    : yabai -m window --focus north
+
+      # move managed window
+      shift + lalt - left  : yabai -m window --warp west
+      shift + lalt - right : yabai -m window --warp east
+      shift + lalt - down  : yabai -m window --warp south
+      shift + lalt - up    : yabai -m window --warp north
+
+      # move between workspaces
+      # when SIP is disabled and scripting-additions are loaded yabai can switch workspaces
+      lalt - 1 : yabai -m space --focus 1
+      lalt - 2 : yabai -m space --focus 2
+      lalt - 3 : yabai -m space --focus 3
+      lalt - 4 : yabai -m space --focus 4
+      lalt - 5 : yabai -m space --focus 5
+      lalt - 6 : yabai -m space --focus 6
+      lalt - 7 : yabai -m space --focus 7
+      lalt - 8 : yabai -m space --focus 8
+      lalt - 9 : yabai -m space --focus 9
+      # switch workspaces when SIP enabled (since yabai can't do it w/o scripting-additions). dont forget to enable the needed keybinds in system settings!
+      #lalt - 1 : ${pkgs.skhd}/bin/skhd -k "ctrl - 1"
+      #lalt - 2 : ${pkgs.skhd}/bin/skhd -k "ctrl - 2"
+      #lalt - 3 : ${pkgs.skhd}/bin/skhd -k "ctrl - 3"
+      #lalt - 4 : ${pkgs.skhd}/bin/skhd -k "ctrl - 4"
+      #lalt - 5 : ${pkgs.skhd}/bin/skhd -k "ctrl - 5"
+      #lalt - 6 : ${pkgs.skhd}/bin/skhd -k "ctrl - 6"
+      #lalt - 7 : ${pkgs.skhd}/bin/skhd -k "ctrl - 7"
+      #lalt - 8 : ${pkgs.skhd}/bin/skhd -k "ctrl - 8"
+      #lalt - 9 : ${pkgs.skhd}/bin/skhd -k "ctrl - 9"
+      # go back to previous workspace (kind of like back_and_forth in i3)
+      lalt - 0 : yabai -m space --focus recent
+
+      # move focused window to workspace
+      lalt + shift - 1 : yabai -m window --space 1
+      lalt + shift - 2 : yabai -m window --space 2
+      lalt + shift - 3 : yabai -m window --space 3
+      lalt + shift - 4 : yabai -m window --space 4
+      lalt + shift - 5 : yabai -m window --space 5
+      lalt + shift - 6 : yabai -m window --space 6
+      lalt + shift - 7 : yabai -m window --space 7
+      lalt + shift - 8 : yabai -m window --space 8
+      lalt + shift - 9 : yabai -m window --space 9
+    '';
+  };
+
+}
diff --git a/machines/blechbuechse/yabai.nix b/machines/blechbuechse/yabai.nix
@@ -0,0 +1,68 @@
+{ config, pkgs, ... }:
+
+let
+  yabai       = pkgs.callPackage ../../pkgs/yabai.nix {};
+
+in {
+
+  environment.etc."sudoers.d/yabai".text = ''
+    leah ALL = (root) NOPASSWD: ${yabai}/bin/yabai --load-sa
+  '';
+
+  services.yabai = {
+    enable                  = true;
+    # currently not working :'(
+    # enableScriptingAddition = true;
+    package                 = yabai;
+    config                  = {
+      layout              = "bsp";
+
+      window_placement    = "second_child";
+      window_topmost      = "on";
+      window_shadow       = "off";
+      window_opacity      = "off";
+
+      focus_follows_mouse = "autofocus";
+      mouse_follows_focus = "off";
+
+      mouse_modifier      = "alt";
+      mouse_action1       = "move";
+      mouse_action2       = "resize";
+
+    };
+
+    extraConfig = ''
+      sudo yabai --load-sa
+
+      # load scripting-additions when Dock.app restarts
+      yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"
+
+      # fix focus when closing windows
+      yabai -m signal --add event=window_destroyed action="yabai -m query --windows --window &> /dev/null || yabai -m window --focus mouse"
+      yabai -m signal --add event=application_terminated action="yabai -m query --windows --window &> /dev/null || yabai -m window --focus mouse"
+
+      # float system preferences
+      yabai -m rule --add app='^System Information$' manage=off layer=above
+      yabai -m rule --add app='^System Preferences$' manage=off layer=above
+      yabai -m rule --add title='Preferences$' manage=off layer=above
+
+      # float settings and file windows
+      yabai -m rule --add title='Settings$' manage=off layer=above
+      yabai -m rule --add title='Opening$' manage=off layer=above
+
+      # float Finder and AppStore
+      #yabai -m rule --add app='Finder' manage=off layer=above
+      #yabai -m rule --add app='App Store' manage=off layer=above
+
+      #float firefox PiP window
+      yabai -m rule --add label="Firfox PIP" app="^Firefox$" title="^(Picture-in-Picture)$" manage=off layer=above sticky=on
+
+      yabai -m rule --add app='pinentry-mac' manage=off layer=above sticky=on
+
+      yabai -m rule --add app='Firefox' space=1
+      yabai -m rule --add app='Mail'    space=2
+      yabai -m rule --add app='Finder'  space=6
+    '';
+  };
+
+}