#!/usr/bin/env bash
set -euo pipefail

# CONTRACT: keyboard opening targets Sway's focused output, never a fixed name.
output="$(swaymsg -t get_outputs -r | jq -r '.[] | select(.focused == true) | .name' | head -n 1)"
[[ -n "$output" ]] || exit 1
for attempt in 1 2 3 4 5; do
    if quickshell ipc -c labfy-sway call "applicationsUi-$output" toggle >/dev/null 2>&1; then
        exit 0
    fi
    sleep 0.1
done
exit 1
