From 5e23ba15d139bd3028a9d9ec74bbd570737f2d80 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Fri, 23 Oct 2020 11:20:09 +0200 Subject: [PATCH] Try to guess second output name if not already set --- ecran | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ecran b/ecran index af55161..17d53e5 100755 --- a/ecran +++ b/ecran @@ -43,15 +43,15 @@ define_vars() { # {{{ debug_message "define_vars − \ The primary output is: ${PRIMARY_OUTPUT_NAME}." ## }}} - - return_second_output_name="0" - - SECOND_OUTPUT_NAME=$(xrandr | grep " connected" | grep -v "${MAIN_OUTPUT_NAME}" | awk 'NR==1{ print $1 }') - - debug_message "define_vars − \ -The second connected output is: ${SECOND_OUTPUT_NAME}." - - return "${return_second_output_name}" + ## Second output {{{ + ### If the second output wasn't manually defined, + ### try to get it's name + if [ -z "${SECOND_OUTPUT_NAME}" ]; then + SECOND_OUTPUT_NAME=$(xrandr | grep " connected" | grep -v "${PRIMARY_OUTPUT_NAME}" | awk 'NR==1{ print $1 }') + debug_message "define_vars − \ +The second output is: ${SECOND_OUTPUT_NAME}." + fi + ## }}} } # }}} @@ -130,10 +130,10 @@ define_vars # This code can't be in a function due to arguments case "${1}" in primary | off ) - ## TODO : One command to enable main screen and a loop to disable all other connected output - xrandr --output "${MAIN_OUTPUT_NAME:=/dev/null}" --auto --output "${SECOND_OUTPUT_NAME:=/dev/null}" --off --output VGA-1 --off --output HDMI-3 --off --output "${SECOND_OUTPUT_NAME:=/dev/null}" --off - xrandr --output VGA --off - printf "%b\n" 'Desactivate all video output' + ## TODO : One command to enable primary screen and a loop to disable all other connected output + xrandr --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" --auto + if [ -n "${SECOND_OUTPUT_NAME}" ]; then xrandr --output "${SECOND_OUTPUT_NAME:=/dev/null}" --off ; fi + printf "%b\n" 'Enable only primary output' ;; leftof | left-of | ds | dock | dockstation | work ) #xrandr --output VGA-1 --mode 1024x768 --left-of "${PRIMARY_OUTPUT_NAME:=/dev/null}" --output "${PRIMARY_OUTPUT_NAME:=/dev/null}" --mode 1366x768