From 7337e99c265bc2841f276f1f6bd96d6ae4d4d31d Mon Sep 17 00:00:00 2001 From: Gardouille Date: Fri, 23 Oct 2020 10:15:41 +0200 Subject: [PATCH] Use LVDS for laptop or first connected output --- ecran | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ecran b/ecran index 0dbe32c..c0b213f 100755 --- a/ecran +++ b/ecran @@ -59,6 +59,28 @@ get_primary_output_name() { # {{{ if [ -n "${local_primary_output_name}" ]; then debug_message "get_primary_output_name − \ An output is defined as primary: ${local_primary_output_name}". + + else + ## Then check if an output starting with "LVD" (typically a laptop) is connected + local_primary_output_name=$(xrandr | grep "^LVD" | grep " connected" | awk 'NR==1{ print $1 }') + if [ -n "${local_primary_output_name}" ]; then + debug_message "get_primary_output_name − \ +The primary output seems to be a laptop screen: ${local_primary_output_name}". + + else + ## Then check if any output is connected and take the first one + local_primary_output_name=$(xrandr | grep " connected" | awk 'NR==1{ print $1 }') + if [ -n "${local_primary_output_name}" ]; then + debug_message "get_primary_output_name − \ +Take the first connected output as primary: ${local_primary_output_name}". + + else + debug_message "get_primary_output_name − \ +Unable to get primary output name! +Ensure to have a primary, LVDS or any connected output in xrandr." + exit 2 + fi + fi fi readonly MAIN_OUTPUT_NAME="${local_primary_output_name}"