diff options
Diffstat (limited to 'home/.config/sway')
| -rw-r--r-- | home/.config/sway/config | 2 | ||||
| -rwxr-xr-x | home/.config/sway/display-toggle.sh | 29 |
2 files changed, 25 insertions, 6 deletions
diff --git a/home/.config/sway/config b/home/.config/sway/config index 2d85a6c..854cb39 100644 --- a/home/.config/sway/config +++ b/home/.config/sway/config @@ -155,4 +155,4 @@ bar { exec systemctl --user import-environment WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP exec dbus-update-activation-environment --systemd WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP exec mako -exec "sleep 1 && ~/.config/sway/display-toggle.sh init" +exec "sleep 2 && ~/.config/sway/display-toggle.sh init" diff --git a/home/.config/sway/display-toggle.sh b/home/.config/sway/display-toggle.sh index dd0660a..ea04464 100755 --- a/home/.config/sway/display-toggle.sh +++ b/home/.config/sway/display-toggle.sh @@ -1,26 +1,40 @@ #!/bin/sh -# Cycle display mode: mirror → laptop-off → side-by-side +# Cycle display mode: laptop-off → side-by-side → mirror # Usage: display-toggle.sh [init] # Bound to F7 in sway config; also runs at startup with "init" +set -e + STATE_FILE="${XDG_RUNTIME_DIR:-/tmp}/display-mode" MIRROR_PID="${XDG_RUNTIME_DIR:-/tmp}/wl-mirror.pid" +LOG="${XDG_RUNTIME_DIR:-/tmp}/display-toggle.log" + +log() { echo "$(date +%T) $*" >> "$LOG"; } -LAPTOP=$(swaymsg -t get_outputs -r | jq -r '.[] | select(.name | test("eDP")) | .name') -EXTERNAL=$(swaymsg -t get_outputs -r | jq -r '[.[] | select(.name | test("eDP") | not) | .name] | first // empty') +OUTPUTS=$(swaymsg -t get_outputs -r) +LAPTOP=$(echo "$OUTPUTS" | jq -r '[.[] | select(.name | test("^eDP")) | .name] | first // empty') +EXTERNAL=$(echo "$OUTPUTS" | jq -r '[.[] | select(.name | test("^eDP") | not) | .name] | first // empty') + +log "laptop=$LAPTOP external=$EXTERNAL arg=$1" if [ -z "$EXTERNAL" ]; then [ -z "$1" ] && notify-send "Display" "No external display connected" + log "no external display, exiting" + exit 0 +fi + +if [ -z "$LAPTOP" ]; then + log "no laptop display detected, exiting" exit 0 fi # Stop any running wl-mirror if [ -f "$MIRROR_PID" ]; then - kill "$(cat "$MIRROR_PID")" 2>/dev/null + kill "$(cat "$MIRROR_PID")" 2>/dev/null || true rm -f "$MIRROR_PID" fi -LAPTOP_WIDTH=$(swaymsg -t get_outputs -r | jq -r ".[] | select(.name == \"$LAPTOP\") | .current_mode.width") +LAPTOP_WIDTH=$(echo "$OUTPUTS" | jq -r ".[] | select(.name == \"$LAPTOP\") | .current_mode.width") [ -z "$LAPTOP_WIDTH" ] && LAPTOP_WIDTH=1920 # On init, go straight to laptop-off; otherwise cycle @@ -35,6 +49,8 @@ else esac fi +log "switching to $NEXT" + case "$NEXT" in mirror) swaymsg output "$LAPTOP" enable @@ -52,6 +68,7 @@ case "$NEXT" in swaymsg output "$EXTERNAL" enable swaymsg workspace number 1 echo "laptop-off" > "$STATE_FILE" + log "disabled $LAPTOP" [ -z "$1" ] && notify-send "Display" "Laptop screen off" ;; side-by-side) @@ -61,3 +78,5 @@ case "$NEXT" in [ -z "$1" ] && notify-send "Display" "Side by side" ;; esac + +log "done" |
