dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit cfea52e1aa94a00173efd092cf543f9a70934407
parent 5a39c9c87d85e742f9344f73eb3639c00f11feac
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Fri, 25 Sep 2020 14:11:02 +0200

displayselect: rewrite to make simpler and use mon

Diffstat:
M.local/bin/displayselect | 75+++++++++++++--------------------------------------------------------------
1 file changed, 13 insertions(+), 62 deletions(-)

diff --git a/.local/bin/displayselect b/.local/bin/displayselect @@ -1,67 +1,18 @@ #!/bin/sh +set -e -twoscreen() { # If multi-monitor is selected and there are two screens. +ext_screens="$(xrandr | awk '{if (match($0, / connected/)) {if (i>0) {print $1}; i++}}')" - 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" --primary --auto --scale 1.0x1.0 \ - --output "$secondary" --"$direction"-of "$primary" \ - --auto --scale 1.0x1.0 - fi -} - -multimon() { # Multi-monitor handler - case "$(echo "$screens" | wc -l)" in - 1) xrandr "$(echo "$allposs" | awk '{print "--output", $1, "--off"}' \ - | tr '\n' ' ')" ;; - *) twoscreen ;; - esac ; -} - -# Get all possible display devices -allposs=$(xrandr -q | grep "connected") - -# Get all connected display devices -screens=$(echo "$allposs" | grep " connected" | awk '{print $1}') - -# Get user choice including multi-monitor and manual selection: -if [ "$(echo "$screens" | wc -l)" -gt 1 ]; then - chosen=$(printf "%s\\nmulti-monitor\\nmanual selection" "$screens" \ - | dmenu -i -p "Select display arangement:") && - case "$chosen" in - "manual selection") arandr ; exit ;; - "multi-monitor") multimon ;; - *) xrandr --output "$chosen" --auto --scale 1.0x1.0 \ - $(echo "$screens" | grep -v "$chosen" | \ - awk '{print "--output", $1, "--off"}' | tr '\n' ' ') ;; - esac +if [ -z "$ext_screens" ]; then + mon int else - xrandr --auto --scale 1.0x1.0 + mode="$(printf 'ext\ndual\nmirror' | dmenu -i -p "mode:")" + printf '"%s"\n' "$mode" + if [ "$(printf '%s' "$ext_screens" | wc -w)" -eq 1 ]; then + ext="${ext_screens}" + else + ext="$(printf '%s' "$ext_screens" | dmenu -i -p "external:")" + fi + printf '"%s"\n' "$ext" + EXT="$ext" mon "$mode" fi