Skip to content

Instantly share code, notes, and snippets.

@magcius
Created August 13, 2012 17:56
Show Gist options
  • Save magcius/3342756 to your computer and use it in GitHub Desktop.
Save magcius/3342756 to your computer and use it in GitHub Desktop.
Try and find the active connector.
/* 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