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}"