diff --git a/scripts/workspaces.sh b/scripts/workspaces.sh index eaf1323..85e381e 100755 --- a/scripts/workspaces.sh +++ b/scripts/workspaces.sh @@ -1,39 +1,62 @@ #!/bin/bash -# Set workspace names/number +# === CONFIG === ws1=1 ws2=2 ws3=3 ws5=5 ws6=6 +# === FUNCTION === +# move_when_ready +move_when_ready() { + local cmd="$1" + local match_type="$2" # "app_id" or "title" + local match_value="$3" + local target_ws="$4" + local timeout="${5:-30}" # default timeout: 30 seconds -#Split the binary and the options so we can optionally run w/ or w/o the option -# full path to the toolwait binary itself -TOOLWAITBIN="/home/kellya/.config/sway/scripts/i3-toolwait" -# Options to pass -TOOLWAITOPTIONS="--nocheck" -# binary, with options -TOOLWAIT="$TOOLWAITBIN $TOOLWAITOPTIONS" + echo "▶ Launching: $cmd (waiting for $match_type=$match_value, timeout ${timeout}s)" + eval "$cmd" & + local waited=0 + local interval=0.5 + local max_wait=$(echo "$timeout / $interval" | bc) -swaymsg workspace $ws6 -$TOOLWAIT --waitfor org.mozilla.thunderbird /usr/bin/thunderbird -$TOOLWAIT --waitfor logseq /home/kellya/bin/logseq + while true; do + if swaymsg -t get_tree | grep -q "\"$match_type\": \"$match_value\""; then + echo "✓ Found $match_type=$match_value — moving to workspace $target_ws" + swaymsg "[${match_type}=\"${match_value}\"] move to workspace ${target_ws}" >/dev/null + break + fi -# Start spotify -swaymsg workspace $ws5 -$TOOLWAIT -- /usr/bin/flatpak run --branch=stable --arch=x86_64 --command=spotify --file-forwarding com.spotify.Client + sleep $interval + waited=$((waited+1)) + if [ "$waited" -ge "$max_wait" ]; then + echo "⏰ Timeout waiting for $match_type=$match_value after ${timeout}s" + break + fi + done +} +# === APPS === -swaymsg workspace $ws2 -$TOOLWAITBIN --waitfor slack -- flatpak run com.slack.Slack -$TOOLWAIT --waitfor teams-for-linux -- /opt/teams-for-linux/teams-for-linux --optInTeamsV2 true +move_when_ready "/usr/bin/thunderbird" "app_id" "net.thunderbird.Thunderbird" "$ws6" -swaymsg workspace $ws1 -$TOOLWAITBIN --waitfor org.mozilla.firefox firefox +move_when_ready "/home/kellya/bin/logseq" "class" "Logseq" "$ws6" + +move_when_ready "flatpak run com.spotify.Client" "instance" "spotify" "$ws5" + +move_when_ready "flatpak run com.slack.Slack" "instance" "slack" "$ws2" + +move_when_ready "/opt/teams-for-linux/teams-for-linux --optInTeamsV2 true" "instance" "teams-for-linux" "$ws2" + +move_when_ready "ghostty" "app_id" "com.mitchellh.ghostty" "$ws3" + +move_when_ready "1password" "instance" "1password" "$ws3" + +move_when_ready "firefox" "app_id" "org.mozilla.firefox" "$ws1" + +swaymsg workspace "$ws1" +swaymsg workspace "$ws3" -# Switch to the terminal/email workspace by default -swaymsg workspace $ws3 -$TOOLWAIT --waitfor kitty kitty -$TOOLWAIT --waitfor 1password 1password