commit b3eae430707d49b0133d269c7a2a2e028c4b5667 Author: Gbanyan Date: Mon Mar 6 01:24:40 2023 +0800 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9735178 --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +# Created by https://www.toptal.com/developers/gitignore/api/macos +# Edit at https://www.toptal.com/developers/gitignore?templates=macos + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +# End of https://www.toptal.com/developers/gitignore/api/macos diff --git a/scripts/focusWindow.sh b/scripts/focusWindow.sh new file mode 100644 index 0000000..fd35e3c --- /dev/null +++ b/scripts/focusWindow.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +inputAction=$1 +is_zoom_fullscree=$(yabai -m query --windows --window | jq -re '."zoom-fullscreen"') +is_zoom_fullscree_new=$(yabai -m query --windows --window | jq -re '."has-fullscreen-zoom"') +is_floating=$(yabai -m query --windows --window | jq -re ".floating") +is_floating_new=$(yabai -m query --windows --window | jq -re '."is-floating"') + +# if window is in fullscreen, toggle to shrink it. +if [[ "$is_zoom_fullscree" == "1" || "$is_zoom_fullscree_new" == "true" ]] ; then + yabai -m window --toggle zoom-fullscreen +fi + +if [[ "$is_floating" == "1" || "$is_floating_new" == "true" ]] ; then + # do move for floating mode. + case $inputAction in + 'left') + yabai -m window --grid 1:2:0:0:1:1 + ;; + 'right') + yabai -m window --grid 1:2:1:0:1:1 + ;; + 'up') + yabai -m window --grid 1:1:0:0:1:1 + ;; + 'down') + yabai -m window --grid 12:12:1:1:9:9 + ;; + *) + ;; + esac +else + # do focus for tilling mode. + case $inputAction in + 'left') + yabai -m window --focus west + ;; + 'right') + yabai -m window --focus east + ;; + 'up') + yabai -m window --focus north + ;; + 'down') + yabai -m window --focus south + ;; + *) + ;; + esac +fi diff --git a/scripts/moveWindowToLeft.sh b/scripts/moveWindowToLeft.sh new file mode 100644 index 0000000..e8bf9f8 --- /dev/null +++ b/scripts/moveWindowToLeft.sh @@ -0,0 +1,17 @@ +#!/bin/sh +curWindowId="$(yabai -m query --windows --window | jq -re ".id")" + +inputAction=$1 + +case $inputAction in +'display') + $(yabai -m window --display prev || yabai -m window --display last) + ;; +'space') + $(yabai -m window --space prev || yabai -m window --space last) + ;; +*) + $(yabai -m window --space "$inputAction") +esac + +$(yabai -m window --focus "$curWindowId") \ No newline at end of file diff --git a/scripts/moveWindowToRight.sh b/scripts/moveWindowToRight.sh new file mode 100644 index 0000000..669e0d8 --- /dev/null +++ b/scripts/moveWindowToRight.sh @@ -0,0 +1,18 @@ +#!/bin/sh +curWindowId="$(yabai -m query --windows --window | jq -re ".id")" + +inputAction=$1 + +case $inputAction in +'display') + $(yabai -m window --display next || yabai -m window --display first) + ;; +'space') + $(yabai -m window --space next || yabai -m window --space first) + ;; +*) + $(yabai -m window --space $inputAction) + ;; +esac + +$(yabai -m window --focus "$curWindowId") \ No newline at end of file diff --git a/scripts/taggleShowHideDesktop.sh b/scripts/taggleShowHideDesktop.sh new file mode 100755 index 0000000..4f3c2e1 --- /dev/null +++ b/scripts/taggleShowHideDesktop.sh @@ -0,0 +1,10 @@ +#!/bin/dash + +is_hide_desktop=$(defaults read com.apple.finder CreateDesktop) + +if [ $is_hide_desktop -eq "1" ]; then + defaults write com.apple.finder CreateDesktop -bool FALSE; +else + defaults write com.apple.finder CreateDesktop -bool TRUE; +fi +killall Finder; \ No newline at end of file diff --git a/scripts/windowFocusOnDestroy.sh b/scripts/windowFocusOnDestroy.sh new file mode 100644 index 0000000..1474244 --- /dev/null +++ b/scripts/windowFocusOnDestroy.sh @@ -0,0 +1,8 @@ +#!/bin/dash + +isFocused=$(yabai -m query --windows --window | jq -re ".id") +echo $isFocused +if [[ -z "$isFocused" ]]; then # -z >> true if it's null + $(yabai -m window --focus $(yabai -m query --windows | jq -re ".[] | select((.visible == 1) and .focused != 1).id" | head -n 1)) + echo hi +fi \ No newline at end of file diff --git a/skhd/skhdrc b/skhd/skhdrc new file mode 100644 index 0000000..a0d2ce3 --- /dev/null +++ b/skhd/skhdrc @@ -0,0 +1,82 @@ +# skhdrc edited by Gbanyan, 2022/12/12 + +## Equalize size of windows (0x2A : "|") +alt + cmd - 0x2A : yabai -m space --balance + +## full screen / un-full screen +alt + cmd - space : yabai -m window --toggle zoom-fullscreen + +## focus window +alt + cmd - left : sh ~/.config/yabai/scripts/focusWindow.sh left +alt + cmd - right : sh ~/.config/yabai/scripts/focusWindow.sh right +alt + cmd - up : sh ~/.config/yabai/scripts/focusWindow.sh up +alt + cmd - down : sh ~/.config/yabai/scripts/focusWindow.sh down + +# move window in floating mode +alt + cmd - home : yabai -m window --grid 2:2:0:0:1:1 +alt + cmd - end : yabai -m window --grid 2:2:1:1:1:1 +alt + cmd - pagedown : yabai -m window --grid 2:2:0:1:1:1 +alt + cmd - pageup : yabai -m window --grid 2:2:1:0:1:1 + +## Enable / Disable gaps in current workspace +alt + cmd - g : yabai -m space --toggle padding; yabai -m space --toggle gap + +## Rotate windows clockwise and anticlockwise +alt + cmd - r : yabai -m space --rotate 270 +shift + alt + cmd - r : yabai -m space --rotate 90 + +## float / Unfloat window +ctrl + alt + cmd - space : yabai -m window --toggle float ; yabai -m window --grid 12:12:1:1:9:9 + +## stack window +# Note that this only works when the active window does *not* already belong to a stack +shift + alt + cmd - s : yabai -m space --layout stack +shift + alt + cmd - b : yabai -m space --layout bsp +shift + alt + cmd - left : yabai -m window west --stack $(yabai -m query --windows --window | jq -r '.id') +shift + alt + cmd - right : yabai -m window east --stack $(yabai -m query --windows --window | jq -r '.id') +shift + alt + cmd - up : yabai -m window south --stack $(yabai -m query --windows --window | jq -r '.id') +shift + alt + cmd - down : yabai -m window north --stack $(yabai -m query --windows --window | jq -r '.id') + +# Focus window up/down in stack +shift + alt + cmd - up : yabai -m window --focus stack.prev || yabai -m window --focus stack.last +shift + alt + cmd - down : yabai -m window --focus stack.next || yabai -m window --focus stack.first + +## swap window & move window in floating mode +ctrl + alt + cmd - left : yabai -m window --swap west +ctrl + alt + cmd - right : yabai -m window --swap east +ctrl + alt + cmd - up : yabai -m window --swap north +ctrl + alt + cmd - down : yabai -m window --swap south + +## window resize +ctrl + alt + cmd - home : yabai -m window --resize left:-20:0 || yabai -m window --resize right:-20:0 +ctrl + alt + cmd - end : yabai -m window --resize right:20:0 || yabai -m window --resize left:20:0 +ctrl + alt + cmd - pageup : yabai -m window --resize top:0:-20 || yabai -m window --resize bottom:0:-20 +ctrl + alt + cmd - pagedown : yabai -m window --resize top:0:20 || yabai -m window --resize bottom:0:20 + +alt + cmd - 3 : yabai -m window --ratio abs:0.66 + +## send window to next monitor and follow focus +ctrl + alt - left : sh ~/.config/yabai/scripts/moveWindowToLeft.sh display +ctrl + alt - right : sh ~/.config/yabai/scripts/moveWindowToRight.sh display + +## send window to next space on and follow focus +ctrl + cmd - left : sh ~/.config/yabai/scripts/moveWindowToLeft.sh space +ctrl + cmd - right : sh ~/.config/yabai/scripts/moveWindowToRight.sh space + +## send window to specify space +ctrl + cmd - 1 : sh ~/.config/yabai/scripts/moveWindowToLeft.sh 1 +ctrl + cmd - 2 : sh ~/.config/yabai/scripts/moveWindowToLeft.sh 2 +ctrl + cmd - 3 : sh ~/.config/yabai/scripts/moveWindowToLeft.sh 3 +ctrl + cmd - 4 : sh ~/.config/yabai/scripts/moveWindowToLeft.sh 4 +ctrl + cmd - 5 : sh ~/.config/yabai/scripts/moveWindowToLeft.sh 5 +ctrl + cmd - 6 : sh ~/.config/yabai/scripts/moveWindowToLeft.sh 6 +ctrl + cmd - 7 : sh ~/.config/yabai/scripts/moveWindowToLeft.sh 7 +ctrl + cmd - 8 : sh ~/.config/yabai/scripts/moveWindowToLeft.sh 8 +ctrl + cmd - 9 : sh ~/.config/yabai/scripts/moveWindowToLeft.sh 9 + +## focus display +ctrl + alt - 1 : yabai -m window --display 1 ; yabai -m display --focus 1 +ctrl + alt - 2 : yabai -m window --display 2 ; yabai -m display --focus 2 +ctrl + alt - 3 : yabai -m window --display 3 ; yabai -m display --focus 3 + + diff --git a/yabai/yabairc b/yabai/yabairc new file mode 100755 index 0000000..a134202 --- /dev/null +++ b/yabai/yabairc @@ -0,0 +1,85 @@ +#!/usr/bin/env sh +# yabairc configuration by Gbanyan, 2022/12/11 +# some options need script addition to enable + +## global settings +yabai -m config external_bar off +yabai -m config mouse_follows_focus off +yabai -m config focus_follows_mouse off + +## New window spawns to the right if vertical split, or bottom if horizontal split +yabai -m config window_placement second_child + +## Windows layout and management +yabai -m config layout bsp +yabai -m config window_topmost on +yabai -m config window_animation_duration 0.5 +yabai -m config window_shadow off +yabai -m config insert_feedback_color 0xffd75f5f +yabai -m config auto_balance on +yabai -m config split_ratio 0.50 + +## Windows_opacity +yabai -m config window_opacity off +yabai -m config window_opacity_duration 0.4 +yabai -m config active_window_opacity 1.0 +yabai -m config normal_window_opacity 0.2 + +## Windows border +yabai -m config window_border off # (on | off) +yabai -m config window_border_width 6 +yabai -m config window_border_hidpi on +yabai -m config active_window_border_color 0xff775759 +yabai -m config normal_window_border_color 0xff555555 + +## Windows gap +yabai -m config top_padding 8 +yabai -m config bottom_padding 8 +yabai -m config left_padding 8 +yabai -m config right_padding 8 +yabai -m config window_gap 8 + +## set mouse interaction modifier key (default: fn) +yabai -m config mouse_modifier fn +# set modifier + left-click drag to resize window (default: move) +yabai -m config mouse_action1 move +# set modifier + right-click drag to resize window (default: resize) +yabai -m config mouse_action2 resize +yabai -m config mouse_drop_action stack + +# My custom space names for my 3 monitor setup. These names are used in some of my scripts. +yabai -m space 1 --label one +yabai -m space 2 --label two +yabai -m space 3 --label three +yabai -m space 4 --label four +yabai -m space 5 --label five +yabai -m space 6 --label six +yabai -m space 9 --label nine + +# Windows Exception +#yabai -m rule --add app="^IINA$" sticky=on layer=above manage=off +yabai -m rule --add app="^App Store$" sticky=on layer=above manage=off +yabai -m rule --add app="^系統設定$" sticky=on layer=above manage=off +yabai -m rule --add app="^System Preferences$" sticky=on layer=above manage=off +yabai -m rule --add app="^系統資訊$" sticky=on layer=above manage=off +yabai -m rule --add app="^System Information$" sticky=on layer=above manage=off +yabai -m rule --add app="^活動監視器$" sticky=on layer=above manage=off +yabai -m rule --add app="^Activity Monitor$" sticky=on layer=above manage=off +# yabai -m rule --add app="^LINE$" sticky=on layer=normal manage=off +# yabai -m rule --add app="^Finder$" sticky=on layer=above manage=off +yabai -m rule --add app="^計算機$" sticky=on layer=above manage=off +yabai -m rule --add app="^Alfred Preferences$" sticky=on layer=above manage=off +yabai -m rule --add app="^Disk Utility$" sticky=on layer=above manage=off +yabai -m rule --add app="^磁碟工具程式$" sticky=on layer=above manage=off +yabai -m rule --add app="^天氣$" manage=off +yabai -m rule --add app="^音樂$" manage=off +yabai -m rule --add app="^Fate/GO$" manage=off + +## If I close the active window, focus on any other visible window. +yabai -m signal --add event=window_destroyed action="bash ~/.config/yabai/scripts/windowFocusOnDestroy.sh" + +# yabai -m signal --add event=space_changed action="export CUR_ACTIVE_APP=\"iTerm2\"" + +echo "yabai configuration loaded.." + +#END