Created
August 13, 2012 17:56
-
-
Save magcius/3342756 to your computer and use it in GitHub Desktop.
Try and find the active connector.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* gcc -o listconnectors listconnectors.c $(pkg-config --cflags --libs glib-2.0 libdrm) */ | |
#include <glib.h> | |
#include <fcntl.h> | |
#include <stdlib.h> | |
#include <xf86drm.h> | |
#include <xf86drmMode.h> | |
int | |
main (int argc, char **argv) | |
{ | |
int i; | |
int fd; | |
drmModeRes *resources = NULL; | |
drmModeConnector *connector = NULL; | |
fd = open ("/dev/dri/card0", O_RDWR); | |
if (fd < 0) | |
{ | |
g_warning ("Unable to open DRI device"); | |
exit (1); | |
} | |
resources = drmModeGetResources (fd); | |
g_print ("There are %d connectors in total\n", resources->count_connectors); | |
/* Find the first active connector to display on. */ | |
for (i = 0; i < resources->count_connectors; i++) | |
{ | |
connector = drmModeGetConnector (fd, resources->connectors[i]); | |
if (connector == NULL) | |
continue; | |
if (connector->connection == DRM_MODE_CONNECTED && | |
connector->count_modes > 0) | |
break; | |
drmModeFreeConnector(connector); | |
} | |
if (i == resources->count_connectors) | |
{ | |
g_warning ("Could not find an active connector"); | |
exit (1); | |
} | |
g_print ("The active connector is %d, of type %d\n", | |
connector->connector_id, connector->connector_type); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment