diff options
Diffstat (limited to 'home/.config/sway/display-toggle.sh')
| -rwxr-xr-x | home/.config/sway/display-toggle.sh | 29 |
1 files changed, 3 insertions, 26 deletions
diff --git a/home/.config/sway/display-toggle.sh b/home/.config/sway/display-toggle.sh index a3a11e7..f39bf9b 100755 --- a/home/.config/sway/display-toggle.sh +++ b/home/.config/sway/display-toggle.sh @@ -1,10 +1,8 @@ #!/bin/sh -# Cycle display mode: laptop-off → side-by-side → mirror -# Usage: display-toggle.sh [init] +# Toggle display mode: laptop-off ↔ side-by-side # Bound to F7 in sway config; also runs at startup with "init" STATE_FILE="${XDG_RUNTIME_DIR:-/tmp}/display-mode" -MIRROR_PID="${XDG_RUNTIME_DIR:-/tmp}/wl-mirror.pid" OUTPUTS=$(swaymsg -t get_outputs -r) LAPTOP=$(echo "$OUTPUTS" | jq -r '[.[] | select(.name | test("^eDP")) | .name] | first // empty') @@ -15,43 +13,22 @@ if [ -z "$EXTERNAL" ]; then exit 0 fi -if [ -z "$LAPTOP" ]; then - exit 0 -fi - -# Stop any running wl-mirror -if [ -f "$MIRROR_PID" ]; then - kill "$(cat "$MIRROR_PID")" 2>/dev/null || true - rm -f "$MIRROR_PID" -fi +[ -z "$LAPTOP" ] && exit 0 -LAPTOP_WIDTH=$(echo "$OUTPUTS" | jq -r ".[] | select(.name == \"$LAPTOP\") | .current_mode.width") +LAPTOP_WIDTH=$(echo "$OUTPUTS" | jq -r ".[] | select(.name == \"$LAPTOP\") | .current_mode.width // .modes[0].width") [ -z "$LAPTOP_WIDTH" ] && LAPTOP_WIDTH=1920 -# On init, go straight to laptop-off; otherwise cycle if [ "$1" = "init" ]; then NEXT="laptop-off" else CURRENT=$(cat "$STATE_FILE" 2>/dev/null || echo "laptop-off") case "$CURRENT" in laptop-off) NEXT="side-by-side" ;; - side-by-side) NEXT="mirror" ;; *) NEXT="laptop-off" ;; esac fi case "$NEXT" in - mirror) - swaymsg output "$LAPTOP" enable || true - swaymsg output "$EXTERNAL" enable || true - swaymsg focus output "$EXTERNAL" || true - wl-mirror "$LAPTOP" & - echo $! > "$MIRROR_PID" - sleep 0.3 - swaymsg focus output "$LAPTOP" || true - echo "mirror" > "$STATE_FILE" - [ -z "$1" ] && notify-send "Display" "Mirror mode" - ;; laptop-off) swaymsg output "$LAPTOP" disable || true swaymsg output "$EXTERNAL" enable || true |
