commit 4bdf4af94c0db2d4fc948c01434bfe992041a50c parent fd32bd649002ca266d09857d01623d656a114389 Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe> Date: Tue, 10 May 2022 13:25:52 -0500 Added displayselect script Diffstat:
| A | linux/.local/bin/displayselect | | | 71 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 71 insertions(+), 0 deletions(-)
diff --git a/linux/.local/bin/displayselect b/linux/.local/bin/displayselect @@ -0,0 +1,71 @@ +#!/bin/sh + +onescreen() { # If only one output available or chosen. + xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -) +} + +postrun() { # Stuff to run to clean up. + { + killall dunst + setsid -f dunst + } >/dev/null 2>&1 # Restart dunst to ensure proper location on screen +} + +# Get all possible displays +allposs=$(xrandr -q | grep "connected") + +# Get all connected screens. +screens=$(echo "$allposs" | awk '/ connected/ {print $1}') + +# If there's only one screen +[ "$(echo "$screens" | wc -l)" -lt 2 ] && + { + onescreen "$screens" + notify-send "💻 Only one screen detected." "Using it in its optimal settings..." + exit + } + +# Get user choice including multi-monitor and manual selection: +chosen=$(printf "%s\\ntwoscreens\nmanual selection" "$screens" | dmenu -i -p "Select display arangement:") && + case "$chosen" in + "manual selection") + arandr + exit + ;; + "twoscreens") + mirror=$(printf "no\\nyes" | dmenu -i -p "Mirror displays?") + # Mirror displays using native resolution of external display and a scaled + # version for the internal display + if [ "$mirror" = "yes" ]; then + external=$(echo "$screens" | 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" | dmenu -i -p "Select primary display:") + secondary=$(echo "$screens" | grep -v "$primary") + direction=$(printf "left\\nright" | 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 + + ;; + *) onescreen "$chosen" ;; + esac + +postrun