diff --git a/meta-digi-arm/dynamic-layers/stm-st-stm32mp/recipes-graphics/wayland/weston-init/weston_profile.sh b/meta-digi-arm/dynamic-layers/stm-st-stm32mp/recipes-graphics/wayland/weston-init/weston_profile.sh index 5efd2b5bc..0a8e56f34 100644 --- a/meta-digi-arm/dynamic-layers/stm-st-stm32mp/recipes-graphics/wayland/weston-init/weston_profile.sh +++ b/meta-digi-arm/dynamic-layers/stm-st-stm32mp/recipes-graphics/wayland/weston-init/weston_profile.sh @@ -1,4 +1,38 @@ -if [ "$USER" == "root" ]; then +find_wayland_display() +{ + if [ -e "$XDG_RUNTIME_DIR/wayland-0" ]; then + export WAYLAND_DISPLAY=wayland-0 + return 0 + fi + + if [ -e "$XDG_RUNTIME_DIR/wayland-1" ]; then + export WAYLAND_DISPLAY=wayland-1 + return 0 + fi + + return 1 +} + +has_connected_drm_display() +{ + local drm_status + local drm_status_found=false + local drm_state + + for drm_status in /sys/class/drm/card*-*/status; do + [ -e "$drm_status" ] || continue + + drm_status_found=true + read -r drm_state < "$drm_status" || continue + if [ "$drm_state" = "connected" ]; then + return 0 + fi + done + + [ "$drm_status_found" = "false" ] +} + +if [ "$USER" = "root" ]; then export XDG_RUNTIME_DIR=/run/user/`id -u root` export ELM_ENGINE=wayland_shm @@ -8,20 +42,16 @@ if [ "$USER" == "root" ]; then export PULSE_RUNTIME_PATH=/run/user/`id -u root`/pulse export USE_PLAYBIN3=1 - # Wait for 10 seconds until a Wayland socket is available - for i in {1..10}; do - if [ -e $XDG_RUNTIME_DIR/wayland-0 ]; then - export WAYLAND_DISPLAY=wayland-0 - break - elif [ -e $XDG_RUNTIME_DIR/wayland-1 ]; then - export WAYLAND_DISPLAY=wayland-1 - break - else + if ! find_wayland_display && has_connected_drm_display; then + # Weston may still be creating its socket after the login prompt + # appears, but do not delay headless serial logins. + for i in {1..10}; do sleep 1 - fi - done - - if [ -z "$WAYLAND_DISPLAY" ]; then - echo "WARNING: No Wayland socket found" + find_wayland_display && break + done fi + [ -z "$WAYLAND_DISPLAY" ] && echo "WARNING: No Wayland socket found" fi + +unset -f find_wayland_display +unset -f has_connected_drm_display