From 13afdf1a412a3857a99c4b10de29fade5625ebab Mon Sep 17 00:00:00 2001 From: Bartek Stalewski Date: Mon, 16 Aug 2021 18:05:47 +0200 Subject: [PATCH] New approach to display selector. --- _suckless/_scripts/rofi_display | 49 +++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/_suckless/_scripts/rofi_display b/_suckless/_scripts/rofi_display index 88167bb..e6dd73d 100755 --- a/_suckless/_scripts/rofi_display +++ b/_suckless/_scripts/rofi_display @@ -1,18 +1,37 @@ #!/bin/sh -both() { # If both is selected and there are two screens. - primary=$(echo "$screens" | rofi -dmenu -i -p "Select primary display:") - secondary=$(echo "$screens" | grep -v "$primary") - direction=$(printf "left\\nright" | rofi -dmenu -i -p "What side of $primary should $secondary be on?") - xrandr --output "$primary" --mode 1920x1080 --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --mode 2560x1440 --scale 1.0x1.0 +twoscreen() { + mirror=$(printf "no\\nyes" | rofi -dmenu -i -p "Mirror displays?") + if [ "$mirror" = "yes" ]; then + external=$(echo "$screens" | rofi -dmenu -i -p "Optimize resolution for") + internal=$(echo "$screens" | grep -v "$external") + res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \ + tail -n 1 | awk '{print $1}') + res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" | \ + tail -n 1 | awk '{print $1}') + res_ext_x=$(echo "$res_external" | sed 's/x.*//') + res_ext_y=$(echo "$res_external" | sed 's/.*x//') + res_int_x=$(echo "$res_internal" | sed 's/x.*//') + res_int_y=$(echo "$res_internal" | sed 's/.*x//') + scale_x=$(echo "$res_ext_x / $res_int_x" | bc -l) + scale_y=$(echo "$res_ext_y / $res_int_y" | bc -l) + xrandr --output "$external" --auto --scale 1.0x1.0 \ + --output "$internal" --auto --same-as "$external" \ + --scale "$scale_x"x"$scale_y" + else + primary=$(echo "$screens" | rofi -dmenu -i -p "Select primary display") + secondary=$(echo "$screens" | grep -v "$primary") + direction=$(printf "left\\nright" | rofi -dmenu -i -p "What side of $primary should $secondary be on?") + xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0 + fi +} + +home() { + xrandr --output "DisplayPort-0" --mode 2560x1440 $(echo "$allposs" | grep -v "\bDisplayPort-0" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -) } onescreen() { - case "$1" in - eDP) xrandr --output "$1" --mode 1920x1080 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -) ;; - DisplayPort*) xrandr --output "$1" --mode 2560x1440 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -) ;; - *) xrandr --output "$1" --auto $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -) ;; - esac + xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -) } postrun() { @@ -28,13 +47,15 @@ screens=$(echo "$allposs" | awk '/ connected/ {print $1}') # If there's only one screen [ "$(echo "$screens" | wc -l)" -lt 2 ] && - { onescreen "$screens"; postrun; exit ;} + { onescreen "$screens"; postrun; exit ;} # Get user choice including both and manual selection: -chosen=$(printf "%s\\nboth" "$screens" | rofi -dmenu -i -p "Select display arangement:") && +chosen=$(printf -- "home\\n----\\n%s\\n----\\nmulti" "$screens" | rofi -dmenu -i -p "Select display arangement") && case "$chosen" in - "both") both ;; - *) onescreen "$chosen" ;; + "home") home ;; + "multi") twoscreen ;; + "----") exit ;; + *) onescreen "$chosen" ;; esac postrun