aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-07-09 23:30:38 +0200
committerdec05eba <dec05eba@protonmail.com>2023-07-09 23:30:38 +0200
commitf38ed36271ab417fbff005452e721a57c53641fe (patch)
treee72ca594bc8afd22c4ccfeb782482977daf135ab /src/utils.c
parente158cb2a8b38176db6a187e2f17ddd8fef764c88 (diff)
Test fix using correct gpu when multiple gpus are connected
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/utils.c b/src/utils.c
index bee57f3..0c57a4f 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -4,6 +4,8 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
+#include <xf86drmMode.h>
+#include <fcntl.h>
double clock_get_monotonic_seconds(void) {
struct timespec ts;
@@ -109,7 +111,19 @@ bool gl_get_gpu_info(Display *dpy, gsr_gpu_info *info) {
bool gsr_get_valid_card_path(char *output) {
for(int i = 0; i < 10; ++i) {
sprintf(output, "/dev/dri/card%d", i);
- if(access(output, F_OK) == 0)
+ int fd = open(output, O_RDONLY);
+ if(fd == -1)
+ continue;
+
+ bool is_display_card = false;
+ drmModeResPtr resources = drmModeGetResources(fd);
+ if(resources) {
+ is_display_card = true;
+ drmModeFreeResources(resources);
+ }
+ close(fd);
+
+ if(is_display_card)
return true;
}
return false;