From 1d12c563323bc3ce09823ca35ba66fba6491fc69 Mon Sep 17 00:00:00 2001 From: Subs Date: Thu, 13 Oct 2022 17:02:26 +0200 Subject: [PATCH] [DRM] Use a GFX card with connected monitors --- extlibs/headers/drm/drm-common.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/extlibs/headers/drm/drm-common.c b/extlibs/headers/drm/drm-common.c index 700914739..7fdd422b0 100644 --- a/extlibs/headers/drm/drm-common.c +++ b/extlibs/headers/drm/drm-common.c @@ -170,6 +170,26 @@ static int get_resources(int fd, drmModeRes **resources) return 0; } +static int has_monitor_connected(int fd, drmModeRes* resources) +{ + int i; + drmModeConnector *connector; + for (i = 0; i < resources->count_connectors; i++) + { + connector = drmModeGetConnector(fd, resources->connectors[i]); + if (connector->connection == DRM_MODE_CONNECTED) + { + /* There is a monitor connected */ + drmModeFreeConnector(connector); + connector = NULL; + return 1; + } + drmModeFreeConnector(connector); + connector = NULL; + } + return 0; +} + #define MAX_DRM_DEVICES 64 static int find_drm_device(drmModeRes **resources) @@ -199,7 +219,11 @@ static int find_drm_device(drmModeRes **resources) if (fd < 0) continue; ret = get_resources(fd, resources); - if (!ret) + if(getenv("SFML_DRM_DEBUG")) + { + printf("DRM device used: %d\n", i); + } + if(!ret && has_monitor_connected(fd, *resources) != 0) break; close(fd); fd = -1;