From 6693de67ecad803a5052b36e3283e5575467b262 Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Wed, 12 Sep 2018 14:12:23 +0300 Subject: [PATCH] when turning off displays, turn of the disconnected too --- skel/disp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/skel/disp b/skel/disp index 15046e4..b39bf1e 100644 --- a/skel/disp +++ b/skel/disp @@ -19,6 +19,13 @@ WORKSTATIONLEFT=$MAIN WORKSTATIONRIGHT=$DIGITAL ' +_allon() { + _list_connected | while read display; do + _xrandr --output $display --auto + done + exit +} + _display_main() { [[ -f "$CONFIG" ]] || { echo "ERROR: You do not have configuration yet" @@ -29,7 +36,7 @@ _display_main() { _allon } _xrandr --output "$MAIN" --auto --gamma $g:$g:$g - xrandr | grep " connected" | awk '{ print $1 }' | grep -v "$MAIN" | while read display; do + _list_all | grep -v "$MAIN" | while read display; do _xrandr --output $display --off done @@ -40,7 +47,7 @@ _display_presentation() { echo "Display MAIN=$MAIN is not connected, trying to turn all on. Please check your setup: $CONFIG" _allon } - xrandr | grep " connected" | awk '{ print $1 }' | while read display; do + _list_connected | while read display; do _xrandr --output $display --mode 1024x768 --pos 0x0 --gamma $g:$g:$g done } @@ -60,7 +67,7 @@ _display_workstation() { if [ -z "$WORKSTATIONRIGHT" ];then # Single display setup _xrandr --output "$WORKSTATIONLEFT" --auto --gamma $g:$g:$g - xrandr | grep " connected" | awk '{ print $1 }' | grep -v "$WORKSTATIONLEFT" | while read display; do + _list_all | grep -v "$WORKSTATIONLEFT" | while read display; do _xrandr --output $display --off done return @@ -71,7 +78,7 @@ _display_workstation() { _allon } _xrandr --output "$WORKSTATIONLEFT" --auto --gamma $g:$g:$g --output "$WORKSTATIONRIGHT" --auto --gamma $g:$g:$g --right-of "$WORKSTATIONLEFT" - xrandr | grep " connected" | awk '{ print $1 }' | grep -v "$WORKSTATIONLEFT" | grep -v "$WORKSTATIONRIGHT" | while read display; do + _list_all | grep -v "$WORKSTATIONLEFT" | grep -v "$WORKSTATIONRIGHT" | while read display; do _xrandr --output $display --off done @@ -79,11 +86,11 @@ _display_workstation() { _isconnected() { xrandr | grep -q "${1} connected" } -_allon() { - xrandr | grep " connected" | awk '{ print $1 }' | while read display; do - _xrandr --output $display --auto - done - exit +_list_all() { + xrandr | grep -e " connected" -e " disconnected" | awk '{ print $1 }' +} +_list_connected() { + xrandr | grep -e " connected" | awk '{ print $1 }' } _setup() { @@ -95,7 +102,7 @@ _setup() { xrandr | grep connected | awk '{ print "#"$1": "$2 }' echo "$TEMPLATE" } > "$CONFIG" - FIRST=$( xrandr | grep connected | head -n1 | awk '{ print $1 }' ) + FIRST=$( _list_all | head -n1 ) sed -i 's,^MAIN=.*,MAIN='$FIRST',' "$CONFIG" } echo '# Current configuration:'