commit 234bbaeedc9e271c6ff8a949271776df4e0eddbd parent 028570a945fa8d09078dc6aef6bf54973618a142 Author: Alex Balgavy <alexander.balgavy@spaceapplications.com> Date: Thu, 18 Apr 2024 18:56:30 +0200 dmenu-displays: fix switching Diffstat:
M | scripts/dmenu-displays | | | 29 | ++++++++++++++++------------- |
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/scripts/dmenu-displays b/scripts/dmenu-displays @@ -1,23 +1,26 @@ #!/bin/sh - +substring() { + needle="$1" + haystack="$2" + [ "${haystack#*"$needle"}" != "$haystack" ] +} +current="$(xrandr | grep '^[^[:blank:]]')" case "$(printf 'Single display\nMirror\nAuto' | dmenu -i -l 5 -p "Display config:")" in 'Single display') - xrandr \ - --output eDP-1 --off \ - --output HDMI-1 --off \ - --output DP-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal \ - --output DP-2 --off + cmd="xrandr --output eDP-1 --off" + substring "HDMI-1 connected" "$current" && cmd="$cmd --output HDMI-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal" + substring " DP-1 connected" "$current" && cmd="$cmd --output DP-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal" + substring " DP-2 connected" "$current" && cmd="$cmd --output DP-2 --off" + $cmd ;; 'Mirror') - xrandr \ - --output eDP-1 --mode 1920x1080 --pos 0x0 --rotate normal \ - --output HDMI-1 --off \ - --output DP-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal \ - --output DP-2 --off + cmd="xrandr --output eDP-1 --mode 1920x1080 --pos 0x0 --rotate normal" + substring "HDMI-1 connected" "$current" && cmd="$cmd --output HDMI-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal" + substring " DP-1 connected" "$current" && cmd="$cmd --output DP-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal" + substring " DP-2 connected" "$current" && cmd="$cmd --output DP-2 --off" + $cmd ;; 'Auto') xrandr --auto;; *);; esac -# -