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 1ce5e3219ee64524419c3e7a2debbe81522ce882
parent b1ecf7d8bda17f752f01612c3b9e431dcab04630
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Sun, 23 Dec 2018 12:43:48 +0100

Add option to mirror displays

Diffstat:
Mlinks/bin/displayselect | 72++++++++++++++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 48 insertions(+), 24 deletions(-)

diff --git a/links/bin/displayselect b/links/bin/displayselect @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash # A UI for detecting and selecting all displays. # Probes xrandr for connected displays and lets user select one to use. @@ -6,43 +6,67 @@ # I plan on adding a routine from multi-monitor setups later. twoscreen() { # If multi-monitor is selected and there are two screens. - 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 --output "$secondary" --"$direction"-of "$primary" --auto - } + mirror=$(printf "no\\nyes" | dmenu -i -p "Mirror displays?") + if [ "$mirror" = "yes" ]; then + screen1=$(echo "$screens" | head -n 1) + screen2=$(echo "$screens" | tail -n 1) + + xrandr --output "$screen1" \ + --output "$screen2" --same-as "$screen1" + 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 --output "$secondary" \ + --"$direction"-of "$primary" --auto + fi +} morescreen() { # If multi-monitor is selected and there are more than two screens. primary=$(echo "$screens" | dmenu -i -p "asdf") - secondary=$(echo "$screens" | grep -v "$primary" | dmenu -i -p "Select secondary display:") - direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?") - tertiary=$(echo "$screens" | grep -v "$primary" | grep -v "$secondary" | dmenu -i -p "Select third display:") - xrandr --output "$primary" --auto --output "$secondary" --"$direction"-of "$primary" --auto --output "$tertiary" --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" --auto - } + secondary=$(echo "$screens" | grep -v "$primary" | \ + dmenu -i -p "Select secondary display:") + direction=$(printf "left\\nright" | \ + dmenu -i -p "What side of $primary should $secondary be on?") + tertiary=$(echo "$screens" | grep -v "$primary" | \ + grep -v "$secondary" | dmenu -i -p "Select third display:") + xrandr --output "$primary" --auto \ + --output "$secondary" --"$direction"-of "$primary" --auto \ + --output "$tertiary" \ + --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" \ + --auto +} -multimon() { # Multi-monitor handler. +multimon() { # Multi-monitor handler case "$(echo "$screens" | wc -l)" in - 1) xrandr $(echo "$allposs" | awk '{print "--output", $1, "--off"}' | tr '\n' ' ') ;; + 1) xrandr $(echo "$allposs" | awk '{print "--output", $1, "--off"}' \ + | tr '\n' ' ') ;; 2) twoscreen ;; *) morescreen ;; - esac ;} + esac ; +} -# Get all possible displays +# Get all possible display devices allposs=$(xrandr -q | grep "connected") -# Get all connected screens. +# Get all connected display devices screens=$(echo "$allposs" | grep " connected" | awk '{print $1}') +notify-send "<b>Connected displays:</b> $screens" # Get user choice including multi-monitor and manual selection: -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 $(echo "$screens" | grep -v "$chosen" | awk '{print "--output", $1, "--off"}' | tr '\n' ' ') ;; -esac +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 $(echo "$screens" | grep -v "$chosen" | awk '{print "--output", $1, "--off"}' | tr '\n' ' ') ;; + esac +fi # Fix feh background if screen size/arangement has changed. -feh --bg-scale "$HOME/.config/wall.png" +~/bin/wallpaper.sh # Re-remap keys if keyboard added (for laptop bases) #remaps -#xrandr --output LVDS1 --rate 60 --mode 1920x1080 --fb 1920x1080 --panning 1920x1080* --output HDMI1 --mode 1920x1080 --same-as LVDS1