From d6d17e55e0fd9aeebc418b2c7b9f25b99492b9dc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 10 Jul 2023 01:29:43 +0200 Subject: Attempt to make active card detection more robust --- src/utils.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/utils.c b/src/utils.c index 0c57a4f..22b29af 100644 --- a/src/utils.c +++ b/src/utils.c @@ -4,8 +4,9 @@ #include #include #include -#include #include +#include +#include double clock_get_monotonic_seconds(void) { struct timespec ts; @@ -115,15 +116,32 @@ bool gsr_get_valid_card_path(char *output) { if(fd == -1) continue; - bool is_display_card = false; - drmModeResPtr resources = drmModeGetResources(fd); - if(resources) { - is_display_card = true; - drmModeFreeResources(resources); + drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); + + drmModePlaneResPtr planes = drmModeGetPlaneResources(fd); + if(!planes) { + close(fd); + continue; + } + + bool found_screen_card = false; + for(uint32_t i = 0; i < planes->count_planes; ++i) { + drmModePlanePtr plane = drmModeGetPlane(fd, planes->planes[i]); + if(!plane) + continue; + + if(plane->fb_id) + found_screen_card = true; + + drmModeFreePlane(plane); + + if(found_screen_card) + break; } + close(fd); - if(is_display_card) + if(found_screen_card) return true; } return false; -- cgit v1.2.3