diff options
Diffstat (limited to 'home/.config')
| -rw-r--r-- | home/.config/sway/config | 3 | ||||
| -rwxr-xr-x | home/.config/sway/display-toggle.sh | 56 |
2 files changed, 42 insertions, 17 deletions
diff --git a/home/.config/sway/config b/home/.config/sway/config index b8c10c7..2d85a6c 100644 --- a/home/.config/sway/config +++ b/home/.config/sway/config @@ -37,12 +37,12 @@ seat * hide_cursor 3000 # ── Output ──────────────────────────────────────────────────────────────────── output * bg #282828 solid_color -output * pos 0 0 # ── Window rules ────────────────────────────────────────────────────────────── for_window [class="feh"] floating enable for_window [app_id="imv"] floating enable for_window [class="Tor Browser"] floating enable +for_window [app_id="at.yrlf.wl_mirror"] fullscreen enable # ── Standard keybinds (sway defaults) ───────────────────────────────────────── bindsym $mod+Return exec $term @@ -155,3 +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" diff --git a/home/.config/sway/display-toggle.sh b/home/.config/sway/display-toggle.sh index 882a122..c2d2447 100755 --- a/home/.config/sway/display-toggle.sh +++ b/home/.config/sway/display-toggle.sh @@ -1,38 +1,62 @@ #!/bin/sh # Cycle display mode: mirror → laptop-off → side-by-side -# Bound to F7 in sway config +# Usage: display-toggle.sh [init] +# Bound to F7 in sway config; also runs at startup with "init" STATE_FILE="${XDG_RUNTIME_DIR:-/tmp}/display-mode" -CURRENT=$(cat "$STATE_FILE" 2>/dev/null || echo "mirror") +MIRROR_PID="${XDG_RUNTIME_DIR:-/tmp}/wl-mirror.pid" 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') if [ -z "$EXTERNAL" ]; then - notify-send "Display" "No external display connected" + [ -z "$1" ] && notify-send "Display" "No external display connected" exit 0 fi -# Get laptop panel width for side-by-side positioning -LAPTOP_WIDTH=$(swaymsg -t get_outputs -r | jq -r ".[] | select(.name == \"$LAPTOP\") | .rect.width") +# Stop any running wl-mirror +if [ -f "$MIRROR_PID" ]; then + kill "$(cat "$MIRROR_PID")" 2>/dev/null + rm -f "$MIRROR_PID" +fi + +LAPTOP_WIDTH=$(swaymsg -t get_outputs -r | jq -r ".[] | select(.name == \"$LAPTOP\") | .current_mode.width") [ -z "$LAPTOP_WIDTH" ] && LAPTOP_WIDTH=1920 -case "$CURRENT" in +# On init, go straight to mirror; otherwise cycle +if [ "$1" = "init" ]; then + NEXT="mirror" +else + CURRENT=$(cat "$STATE_FILE" 2>/dev/null || echo "mirror") + case "$CURRENT" in + mirror) NEXT="laptop-off" ;; + laptop-off) NEXT="side-by-side" ;; + *) NEXT="mirror" ;; + esac +fi + +case "$NEXT" in mirror) + swaymsg output "$LAPTOP" enable + swaymsg output "$EXTERNAL" enable + swaymsg focus output "$EXTERNAL" + wl-mirror "$LAPTOP" & + echo $! > "$MIRROR_PID" + sleep 0.3 + swaymsg focus output "$LAPTOP" + echo "mirror" > "$STATE_FILE" + [ -z "$1" ] && notify-send "Display" "Mirror mode" + ;; + laptop-off) swaymsg output "$LAPTOP" disable + swaymsg output "$EXTERNAL" enable echo "laptop-off" > "$STATE_FILE" - notify-send "Display" "Laptop screen off" + [ -z "$1" ] && notify-send "Display" "Laptop screen off" ;; - laptop-off) + side-by-side) swaymsg output "$LAPTOP" enable pos 0 0 - swaymsg output "$EXTERNAL" pos "$LAPTOP_WIDTH" 0 + swaymsg output "$EXTERNAL" enable pos "$LAPTOP_WIDTH" 0 echo "side-by-side" > "$STATE_FILE" - notify-send "Display" "Side by side" - ;; - side-by-side|*) - swaymsg output "$LAPTOP" enable pos 0 0 - swaymsg output "$EXTERNAL" pos 0 0 - echo "mirror" > "$STATE_FILE" - notify-send "Display" "Mirror mode" + [ -z "$1" ] && notify-send "Display" "Side by side" ;; esac |
