Skip to content

Instantly share code, notes, and snippets.

@magcius
Created August 13, 2012 18:09
Show Gist options
  • Save magcius/3342834 to your computer and use it in GitHub Desktop.
Save magcius/3342834 to your computer and use it in GitHub Desktop.
List all connectors on the machine.
/* 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);
/* List all connectors on the machine. */
for (i = 0; i < resources->count_connectors; i++)
{
connector = drmModeGetConnector (fd, resources->connectors[i]);
if (connector == NULL)
continue;
g_print ("Connector %d is of type %d\n",
connector->connector_id, connector->connector_type);
drmModeFreeConnector(connector);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment