From 45613fb4a7ece7f128adf3459912d96187d58b36 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Fri, 23 Oct 2020 09:03:36 +0200 Subject: [PATCH] Try to get primary output name --- ecran | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/ecran b/ecran index ac51447..0dbe32c 100755 --- a/ecran +++ b/ecran @@ -13,7 +13,8 @@ readonly RESET='\033[0m' readonly COLOR_DEBUG="${PURPLE}" ## First and main screen (laptop screen,…) -readonly MAIN_OUTPUT_NAME="LVDS-1" +## It can be forced here or the script will try to discover it's name +#readonly MAIN_OUTPUT_NAME="LVDS-1" # }}} @@ -29,6 +30,16 @@ debug_message() { # {{{ # }}} define_vars() { # {{{ + ## Primary output {{{ + ### If the primary output wasn't manually defined, + ### try to get it's name + if [ -z "${MAIN_OUTPUT_NAME}" ]; then + get_primary_output_name + fi + debug_message "define_vars − \ +The primary output is: ${MAIN_OUTPUT_NAME}." + ## }}} + return_second_output_name="0" SECOND_OUTPUT_NAME=$(xrandr | grep " connected" | grep -v "${MAIN_OUTPUT_NAME}" | awk 'NR==1{ print $1 }') @@ -39,6 +50,20 @@ The second connected output is: ${SECOND_OUTPUT_NAME}." return "${return_second_output_name}" } # }}} +get_primary_output_name() { # {{{ + + ## First, check if an output is already defined as primary + local_primary_output_name=$(xrandr | grep " primary" | awk 'NR==1{ print $1 }') + + ## If the var contains something + if [ -n "${local_primary_output_name}" ]; then + debug_message "get_primary_output_name − \ +An output is defined as primary: ${local_primary_output_name}". + fi + + readonly MAIN_OUTPUT_NAME="${local_primary_output_name}" +} +# }}} is_proc_running() { # {{{ local_proc_pattern="${1}"