Created
August 13, 2012 19:25
-
-
Save magcius/3343465 to your computer and use it in GitHub Desktop.
List the current mode of the CRTC.
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 listmode listmode.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; | |
drmModeEncoder *encoder = NULL; | |
drmModeCrtc *crtc = NULL; | |
fd = open ("/dev/dri/card0", O_RDWR); | |
if (fd < 0) | |
{ | |
g_warning ("Unable to open DRI device"); | |
exit (1); | |
} | |
resources = drmModeGetResources (fd); | |
/* 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); | |
} | |
/* Find the CRTC. */ | |
encoder = drmModeGetEncoder (fd, connector->encoder_id); | |
crtc = drmModeGetCrtc (fd, encoder->crtc_id); | |
g_print ("The active connector's CRTC is %d, and is showing " | |
"framebuffer %d, offset +%d,%d, mode %s.\n", | |
crtc->crtc_id, crtc->buffer_id, | |
crtc->x, crtc->y, crtc->mode.name); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment