drmModeGetResources(3)
π drmModeGetResources β a.k.a. drmModeGetResources(3), Direct Rendering Manager, section 3 of your man pages π
okay so bestie, sit down, grab a strawb π, because we're about to meet the function that tells you literally everything about how your display is set up right now.
β¨ NAME β¨
drmModeGetResources β retrieve current display configuration information. that's it. that's the whole job. she just... hands you the tea β about your screens.
πΈ SYNOPSIS πΈ
#include <xf86drm.h>
#include <xf86drmMode.h>
drmModeResPtr drmModeGetResources(int fd);
π¦ DESCRIPTION π¦
so drmModeGetResources allocates, populates, and returns a drmModeRes structure containing info about the current display configuration. like she builds the whole thing for you, no cap. π
the structure has these fields, and yes you need all of them:
typedef struct _drmModeRes {
int count_fbs;
uint32_t *fbs;
int count_crtcs;
uint32_t *crtcs;
int count_connectors;
uint32_t *connectors;
int count_encoders;
uint32_t *encoders;
uint32_t min_width, max_width;
uint32_t min_height, max_height;
} drmModeRes, *drmModeResPtr;
now let's break down every single one, because each of these is a whole personality π
count_fbsandfbsβ these tell you the number of currently allocated framebuffer objects. i.e., objects that can be attached to a given CRTC or sprite for display. they're the things that actually get shown on screen πΌοΈcount_crtcsandcrtcsβ these list the available CRTCs in the configuration. and what's a CRTC? it's simply an object that can scan out a framebuffer to a display sink, and it contains mode timing and relative position information. CRTCs drive encoders, which are the ones responsible for converting the pixel stream into a specific display protocol (e.g.,MIPIorHDMI). so like, CRTC is the vibe-setter, encoder is the translator π§count_connectorsandconnectorsβ these list the available physical connectors on the system. β οΈ note that some of these may not be exposed from the chassis (e.g.,LVDSoreDP). sorry bestie, not every connector is an extrovert. Connectors are attached to encoders and contain information about the attached display sink (e.g., width and height in mm, subpixel ordering, and various other properties). so they know the ~deets~ of what's plugged in πcount_encodersandencodersβ these list the available encoders on the device. Each encoder may be associated with a CRTC, and may be used to drive a particular encoder. yes, that's what it says. encoders containing multitudes, icon behavior honestly β¨min_*andmax_*β themin_width,max_width,min_height,max_heightfields indicate the maximum size of a framebuffer for this device (i.e., the scanout size limit). so like, this is the ceiling, the absolute limit, the "don't even try it" zone π
π₯ RETURN VALUE π₯
drmModeGetResources returns a drmModeRes structure pointer on success, and NULL on failure. π
π¨ IMPORTANT β the returned structure must be freed with drmModeFreeResources(3). do not just leave her hanging. free your resources bestie, that's self care π
π REPORTING BUGS π
found a bug in this function? don't suffer in silence, report it to <https://gitlab.freedesktop.org/mesa/libdrm/-/issues> π«Ά
π SEE ALSO π
the whole friend group shows up here:
drm(7)drm-kms(7)drmModeGetFB(3)drmModeAddFB(3)drmModeAddFB2(3)drmModeRmFB(3)drmModeDirtyFB(3)drmModeGetCrtc(3)drmModeSetCrtc(3)drmModeGetEncoder (3)drmModeGetConnector(3)
π and that's the whole page, bestie!! go forth and query your display config. ily, stay hydrated, and always free your structs π
this lil page is from September 2012, Direct Rendering Manager, page drmModeGetResources(3) β vintage but still serving β¨π
π¦ where this page comes from
- arch rolling: libdrm 2.4.134-1 Β· MIT
- fedora 44: libdrm-devel 2.4.131-1.fc44 Β· MIT
- fedora 44: libdrm-devel 2.4.131-1.fc44 Β· MIT
- fedora 44: libdrm-devel 2.4.134-1.fc44 Β· MIT
- fedora 44: libdrm-devel 2.4.134-1.fc44 Β· MIT
- nixos 26.05: libdrm 2.4.133
- ubuntu resolute: libdrm-dev 2.4.131-1 Β· MIT
- ubuntu stonking: libdrm-dev 2.4.134-3 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms