aboutsummaryrefslogtreecommitdiff
path: root/users/ryan/modules/simple-bar/simple-bar-source/lib/scripts/init-yabai.sh
diff options
context:
space:
mode:
Diffstat (limited to 'users/ryan/modules/simple-bar/simple-bar-source/lib/scripts/init-yabai.sh')
-rwxr-xr-xusers/ryan/modules/simple-bar/simple-bar-source/lib/scripts/init-yabai.sh102
1 files changed, 102 insertions, 0 deletions
diff --git a/users/ryan/modules/simple-bar/simple-bar-source/lib/scripts/init-yabai.sh b/users/ryan/modules/simple-bar/simple-bar-source/lib/scripts/init-yabai.sh
new file mode 100755
index 0000000..5dbbfe3
--- /dev/null
+++ b/users/ryan/modules/simple-bar/simple-bar-source/lib/scripts/init-yabai.sh
@@ -0,0 +1,102 @@
1# Assign input arguments to variables
2yabai_path=$1
3display_skhd_mode=$2
4disable_signals=$3
5enable_window_title_changed_signal=$4
6
7# Check if yabai is running
8pgrep -x yabai > /dev/null
9
10# If yabai is not running, output an error message and exit
11if [ $? -eq 1 ]; then
12 echo "yabaiError"
13 exit 0
14fi
15
16# Get the System Integrity Protection (SIP) status
17SIP=$(csrutil status)
18# Get the current window shadow configuration from yabai
19shadow_enabled=$($yabai_path -m config window_shadow)
20
21# Query yabai for spaces, windows, and displays information
22spaces=$($yabai_path -m query --spaces)
23windows=$($yabai_path -m query --windows)
24displays=$($yabai_path -m query --displays)
25
26# Retry querying spaces if the initial query was empty
27if [ -z "$spaces" ]; then
28 spaces=$($yabai_path -m query --spaces)
29fi
30
31# Retry querying windows if the initial query was empty and remove backslashes
32if [ -z "$windows" ]; then
33 windows=$($yabai_path -m query --windows | sed 's/\\.//g;')
34fi
35
36# Retry querying displays if the initial query was empty
37if [ -z "$displays" ]; then
38 displays=$($yabai_path -m query --displays)
39fi
40
41# Add or remove signals based on the disable_signals flag
42if [ $disable_signals = "false" ]; then
43 # Add signals to refresh the simple-bar widget on various yabai events
44 $yabai_path -m signal --add event=window_focused action="osascript -e 'tell application id \"tracesOf.Uebersicht\" to refresh widget id \"simple-bar-index-jsx\"'" label="Refresh simple-bar when focused application changes"
45 $yabai_path -m signal --add event=window_minimized action="osascript -e 'tell application id \"tracesOf.Uebersicht\" to refresh widget id \"simple-bar-index-jsx\"'" label="Refresh simple-bar when a window is minimized"
46 $yabai_path -m signal --add event=window_resized action="osascript -e 'tell application id \"tracesOf.Uebersicht\" to refresh widget id \"simple-bar-index-jsx\"'" label="Refresh simple-bar when a window is resized"
47 $yabai_path -m signal --add event=window_destroyed action="osascript -e 'tell application id \"tracesOf.Uebersicht\" to refresh widget id \"simple-bar-index-jsx\"'" label="Refresh simple-bar when an application window is closed"
48 $yabai_path -m signal --add event=space_changed action="osascript -e 'tell application id \"tracesOf.Uebersicht\" to refresh widget id \"simple-bar-index-jsx\"'" label="Refresh simple-bar on space change"
49 $yabai_path -m signal --add event=display_changed action="osascript -e 'tell application id \"tracesOf.Uebersicht\" to refresh widget id \"simple-bar-index-jsx\"'" label="Refresh simple-bar on display focus change"
50
51 # Add signal for window title change if enabled
52 if [ $enable_window_title_changed_signal = "true" ]; then
53 $yabai_path -m signal --add event=window_title_changed action="osascript -e 'tell application id \"tracesOf.Uebersicht\" to refresh widget id \"simple-bar-index-jsx\"'" label="Refresh simple-bar when current window title changes"
54 fi
55
56 # Add signals for space creation and destruction if yabai version is 6 or higher
57 yabai_major_version=$($yabai_path -v | awk -F '.' '{print $1}' | sed 's/yabai-v//')
58 if [ $yabai_major_version -ge 6 ]; then
59 $yabai_path -m signal --add event=space_destroyed action="osascript -e 'tell application id \"tracesOf.Uebersicht\" to refresh widget id \"simple-bar-index-jsx\"'" label="Refresh simple-bar on space removal"
60 $yabai_path -m signal --add event=space_created action="osascript -e 'tell application id \"tracesOf.Uebersicht\" to refresh widget id \"simple-bar-index-jsx\"'" label="Refresh simple-bar on space creation"
61 fi
62else
63 # Remove signals if disable_signals is true
64 $yabai_path -m signal --remove label="Refresh simple-bar when focused application changes" >/dev/null 2>&1 || true
65 $yabai_path -m signal --remove label="Refresh simple-bar when a window is minimized" >/dev/null 2>&1 || true
66 $yabai_path -m signal --remove label="Refresh simple-bar when a window is resized" >/dev/null 2>&1 || true
67 $yabai_path -m signal --remove label="Refresh simple-bar when an application window is closed" >/dev/null 2>&1 || true
68 $yabai_path -m signal --remove label="Refresh simple-bar on space change" >/dev/null 2>&1 || true
69 $yabai_path -m signal --remove label="Refresh simple-bar on display focus change" >/dev/null 2>&1 || true
70 $yabai_path -m signal --remove label="Refresh simple-bar when current window title changes" >/dev/null 2>&1 || true
71 $yabai_path -m signal --remove label="Refresh simple-bar on space removal" >/dev/null 2>&1 || true
72 $yabai_path -m signal --remove label="Refresh simple-bar on space creation" >/dev/null 2>&1 || true
73fi
74
75# Determine skhd mode based on the display_skhd_mode flag and disable_signals flag
76if [ $display_skhd_mode = "true" ]; then
77 SCRIPT_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
78 if [ $disable_signals = "false" ]; then
79 skhd_mode=$(cat "$("${SCRIPT_DIR}"/yabai-set-mode.sh --query)")
80 else
81 skhd_mode=$(cat "$("${SCRIPT_DIR}"/yabai-set-mode-server.sh --query)")
82 fi
83else
84 skhd_mode="{}"
85fi
86
87# Output the collected information as a JSON object
88echo $(cat <<-EOF
89 {
90 "spaces": $spaces,
91 "windows": $windows,
92 "displays": $displays,
93 "SIP": "$SIP",
94 "shadow": "$shadow_enabled",
95 "skhdMode": $skhd_mode
96 }
97EOF
98) | \
99 # Remove invisible U+200E Left-To-Right Mark character
100 sed "s/\xe2\x80\x8e//g" | \
101 # Remove newlines from output (handling Google Chrome JSON parse error caused by "search in page")
102 tr -d '\n'