XF86VIDMODE(3)

πŸ’– XF86VIDMODE πŸ’–

bestie. welcome to the XF86VIDMODE(3) manual page β€” it's a library functions manual and it's literally the extension library for the XFree86-VidMode X extension. yes that's a lot of capital letters, we love her for it. πŸ’…


✨ NAME ✨

okay so this page is a whole squad of functions, and they all live together under one name. Introducing the girlies:

XF86VidModeQueryExtension, XF86VidModeQueryVersion, XF86VidModeSetClientVersion, XF86VidModeGetModeLine, XF86VidModeGetAllModeLines, XF86VidModeAddModeLine, XF86VidModeDeleteModeLine, XF86VidModeModModeLine, XF86VidModeValidateModeLine, XF86VidModeSwitchMode, XF86VidModeSwitchToMode, XF86VidModeLockModeSwitch, XF86VidModeGetMonitor, XF86VidModeGetViewPort, XF86VidModeSetViewPort, XF86VidModeGetDotClocks, XF86VidModeGetGamma, XF86VidModeSetGamma, XF86VidModeGetGammaRamp, XF86VidModeSetGammaRamp, XF86VidModeGetGammaRampSize, XF86VidModeGetPermissions

…and what are they? Extension library for the XFree86-VidMode X extension πŸ¦‹ periodt.


🌸 SYNOPSIS 🌸

first things first, you gotta include the header, no cap:

#include <X11/extensions/xf86vmode.h>

and now the full cast list of prototypes, verbatim, character for character, don't you dare touch them:

Bool XF86VidModeQueryExtension(
    Display *display,
    int *event_base_return,
    int *error_base_return);

Bool XF86VidModeQueryVersion(
    Display *display,
    int *major_version_return,
    int *minor_version_return);

Bool XF86VidModeSetClientVersion(
    Display *display);

Bool XF86VidModeGetModeLine(
    Display *display,
    int screen,
    int *dotclock_return,
    XF86VidModeModeLine *modeline);

Bool XF86VidModeGetAllModeLines(
    Display *display,
    int screen,
    int *modecount_return,
    XF86VidModeModeInfo ***modesinfo);

Bool XF86VidModeAddModeLine(
    Display *display,
    int screen,
    XF86VidModeModeInfo *modeline
    XF86VidModeModeInfo *aftermode);

Bool XF86VidModeDeleteModeLine(
    Display *display,
    int screen,
    XF86VidModeModeInfo *modeline);

Bool XF86VidModeModModeLine(
    Display *display,
    int screen,
    XF86VidModeModeLine *modeline);

Status XF86VidModeValidateModeLine(
    Display *display,
    int screen,
    XF86VidModeModeLine *modeline);

Bool XF86VidModeSwitchMode(
    Display *display,
    int screen,
    int zoom);

Bool XF86VidModeSwitchToMode(
    Display *display,
    int screen,
    XF86VidModeModeInfo *modeline);

Bool XF86VidModeLockModeSwitch(
    Display *display,
    int screen,
    int lock);

Bool XF86VidModeGetMonitor(
    Display *display,
    int screen,
    XF86VidModeMonitor *monitor);

Bool XF86VidModeGetViewPort(
    Display *display,
    int screen,
    int *x_return,
    int *y_return);

Bool XF86VidModeSetViewPort(
    Display *display,
    int screen,
    int x,
    int y);

XF86VidModeGetDotClocks(
    Display *display,
    int screen,
    int *flags return,
    int *number of clocks return,
    int *max dot clock return,
    int **clocks return);

XF86VidModeGetGamma(
    Display *display,
    int screen,
    XF86VidModeGamma *Gamma);

XF86VidModeSetGamma(
    Display *display,
    int screen,
    XF86VidModeGamma *Gamma);

XF86VidModeGetGammaRamp(
    Display *display,
    int screen,
    int size,
    unsigned short *red array,
    unsigned short *green array,
    unsigned short *blue array);

XF86VidModeSetGammaRamp(
    Display *display,
    int screen,
    int size,
    unsigned short *red array,
    unsigned short *green array,
    unsigned short *blue array);

XF86VidModeGetGammaRampSize(
    Display *display,
    int screen,
    int *size);
ngl, some of those parameter names up there have literal spaces in them instead of underscores. that's how they're written in the page, so that's how we're keeping them. no editing, no "fixing", we respect the source. πŸ™ˆ

πŸŽ€ ARGUMENTS πŸŽ€

the whole group chat of parameters, explained. let's get into it:

  • display β€” Specifies the connection to the X server. (your lil line to the X server, bestie, everything goes through her.)
  • screen β€” Specifies which screen number the setting apply to.
  • event_base_return β€” Returns the base event number for the extension.
  • error_base_return β€” Returns the base error number for the extension.
  • major_version_return β€” Returns the major version number of the extension.
  • minor_version_return β€” Returns the minor version number of the extension.
  • dotclock_return β€” Returns the clock for the mode line.
  • modecount_return β€” Returns the number of video modes available in the server.
  • zoom β€” If greater than zero, indicates that the server should switch to the next mode, otherwise switch to the previous mode. (so: positive = forward, everything else = back it up πŸ¦‹)
  • lock β€” Indicates that mode switching should be locked, if non-zero.
  • modeline β€” Specifies or returns the timing values for a video mode.
  • aftermode β€” Specifies the timing values for the video mode after which the new mode will added.
  • modesinfo β€” Returns the timing values and dotclocks for all of the available video modes.
  • monitor β€” Returns information about the monitor.
  • x β€” Specifies the desired X location for the viewport.
  • x_return β€” Returns the current X location of the viewport.
  • y β€” Specifies the desired Y location for the viewport.
  • y_return β€” Returns the current Y location of the viewport.

πŸ¦‹ STRUCTURES πŸ¦‹

okay this part is the main character energy of the whole page β€” all the structs you're gonna be passing around. copy them exactly, they're load-bearing. πŸ’…

πŸ’œ Video Mode Settings πŸ’œ

the classic. the blueprint. the moment.

typedef struct {
    unsigned short      hdisplay;       /βˆ— Number of display pixels horizontally */
    unsigned short      hsyncstart;     /βˆ— Horizontal sync start */
    unsigned short      hsyncend;       /βˆ— Horizontal sync end */
    unsigned short      htotal;         /βˆ— Total horizontal pixels */
    unsigned short      vdisplay;       /βˆ— Number of display pixels vertically */
    unsigned short      vsyncstart;     /βˆ— Vertical sync start */
    unsigned short      vsyncend;       /βˆ— Vertical sync start */
    unsigned short      vtotal;         /βˆ— Total vertical pixels */
    unsigned int        flags;          /βˆ— Mode flags */
    int privsize;                       /βˆ— Size of private */
    INT32       *private;               /βˆ— Server privates */
} XF86VidModeModeLine;

typedef struct {
    unsigned int        dotclock;       /βˆ— Pixel clock */
    unsigned short      hdisplay;       /βˆ— Number of display pixels horizontally */
    unsigned short      hsyncstart;     /βˆ— Horizontal sync start */
    unsigned short      hsyncend;       /βˆ— Horizontal sync end */
    unsigned short      htotal;         /βˆ— Total horizontal pixels */
    unsigned short      vdisplay;       /βˆ— Number of display pixels vertically */
    unsigned short      vsyncstart;     /βˆ— Vertical sync start */
    unsigned short      vsyncend;       /βˆ— Vertical sync start */
    unsigned short      vtotal;         /βˆ— Total vertical pixels */
    unsigned int        flags;          /βˆ— Mode flags */
    int privsize;                       /βˆ— Size of private */
    INT32       *private;               /βˆ— Server privates */
} XF86VidModeModeInfo;

notice how XF86VidModeModeInfo is just XF86VidModeModeLine but with a dotclock at the top? yeah. she showed up early and now she's part of the family. 🌸

🌈 Monitor information 🌈

now the structs that tell you about the actual monitor, plus a sync range, plus an event, plus gamma. four for one, a whole bundle deal. πŸŽ€

typedef struct {
    char*       vendor;                /βˆ— Name of manufacturer */
    char*       model;                 /βˆ— Model name */
    float       EMPTY;                 /βˆ— unused, for backward compatibility */
    unsigned char nhsync;              /βˆ— Number of horiz sync ranges */
    XF86VidModeSyncRange* hsync;       /βˆ— Horizontal sync ranges */
    unsigned char nvsync;              /βˆ— Number of vert sync ranges */
    XF86VidModeSyncRange* vsync;       /βˆ— Vertical sync ranges */
} XF86VidModeMonitor;

typedef struct {
    float       hi;     /βˆ— Top of range */
    float       lo;     /βˆ— Bottom of range */
} XF86VidModeSyncRange;

typedef struct {
    int type;                   /βˆ— of event */
    unsigned long serial;       /βˆ— # of last request processed by server */
    Bool send_event;            /βˆ— true if this came from a SendEvent req */
    Display *display;           /βˆ— Display the event was read from */
    Window root;                /βˆ— root window of event screen */
    int state;                  /βˆ— What happened */
    int kind;                   /βˆ— What happened */
    Bool forced;                /βˆ— extents of new region */
    Time time;                  /βˆ— event timestamp */
} XF86VidModeNotifyEvent;

typedef struct {
    float red;                  /βˆ— Red Gamma value */
    float green;                /βˆ— Green Gamma value */
    float blue;                 /βˆ— Blue Gamma value */
} XF86VidModeGamma;
tiny heads up: EMPTY is literally named EMPTY and it's unused, for backward compatibility. she's not doing anything, she's just here for the vibes and the ABI. iconic honestly. ✨

and that's part one of the lore, bestie β€” there's more coming, don't go anywhere πŸ’–

✨ DESCRIPTION ✨

Okay bestie, here's the tea β˜• β€” these functions are your backstage pass to the server extension called XFree86-VidModeExtension, which lets you query video modes, adjust them dynamically, and control mode switching like the main character you are. And listen β€” apps that use these functions must be linked with -lXxf86vm. No cap, don't forget that flag or nothing works. πŸ’…


πŸŽ€ MODELINE FUNCTIONS πŸŽ€

So XF86VidModeGetModeLine is the one you call when you wanna know what the currently selected video mode is set to. Your calling program should hand it a pointer to a XF86VidModeModeLine structure that it already allocated (you bring the container, it fills it up πŸ“). Then the function just... fills in all the fields for you. Iconic behaviour honestly.

Now, if there are any server private values hanging around (and heads up β€” that's currently only a thing for the S3 server), this function will allocate storage for them. So if the privsize field comes back non-zero, you gotta call Xfree(private) to free that storage. Clean up after yourself, bestie, it's giving responsible. 🧹

XF86VidModeGetAllModeLines is the greedy one β€” it returns the settings for all the video modes. 🌈 You supply the address of a pointer, and the function sets it to point at an array of XF86VidModeModeInfo structures. That array's memory is dynamically allocated by XF86VidModeGetAllModeLines itself, and it should be freed by the caller (yes, that's you 🫡). Fun fact: the first element of the array corresponds to the current video mode. Obsessed with that little detail.

XF86VidModeModModeLine lets you change the settings of the current video mode β€” but only if the requested settings are valid, okay? Like, they can't exceed the capabilities of the monitor. Respect the hardware. πŸ–₯️✨

Wanna add a whole new mode to the list of available modes? That's XF86VidModeAddModeLine energy. Assuming the settings are valid, the video mode gets added after the existing mode that matches the timings specified by the aftermode parameter. And to count as a match, all the fields of the given XF86VidModeModeInfo structure have to match β€” the only exceptions are the privsize and private fields. If the aftermode parameter is zero, the mode gets added after the current mode. Periodt.

Deleting modes is XF86VidModeDeleteModeLine. The mode you specify has to match an existing mode β€” and again, to be considered a match, all the fields of the given XF86VidModeModeInfo structure must match, except privsize and private. If the mode you're deleting happens to be the current mode, a mode switch to the next mode will occur first. And ⚠️ the last remaining mode can not be deleted. That one's load-bearing, bestie, don't even try it.

Want a vibe check on whether a mode is even usable? XF86VidModeValidateModeLine has you. If the specified mode can be used by the server (i.e. it meets all the constraints placed upon a mode by the combination of the server, card, and monitor), the function returns MODE_OK. Otherwise it returns a value indicating the reason the mode is invalid β€” as defined in xf86.h. So like, it'll tell you why it's not serving. πŸ’€


πŸ”₯ MODE SWITCH FUNCTIONS πŸ”₯

When you call XF86VidModeSwitchMode, the server changes the video mode to the next (or previous) video mode. Flip through them like a playlist. 🎡

And XF86VidModeSwitchToMode lets you jump directly to the specified mode β€” no scrolling, straight to the banger. Matching works exactly as described in the XF86VidModeAddModeLine description up above. πŸ‘†

Then there's XF86VidModeLockModeSwitch, which lets you allow or disallow mode switching entirely β€” and this applies whether the request to switch modes comes from a call to the XF86VidModeSwitchMode or XF86VidModeSwitchToMode functions, or from one of the mode switch key sequences. Locking it down, no exceptions. πŸ”’

Note: Because of the asynchronous nature of the X protocol, a call to XFlush is needed if the application wants to see the mode change immediately. And if you want to be informed of the execution status of the request, a custom error handler should be installed using XSetErrorHandler before calling the mode switching function. Do it in that order, okay? Timing matters. ⏰

πŸ’œ MONITOR FUNCTIONS πŸ’œ

Everything the server knows about the monitor comes back from XF86VidModeGetMonitor. The hsync and vsync fields each point to an array of XF86VidModeSyncRange structures, and those arrays contain nhsync and nvsync elements respectively. Also, the hi and low values will be equal if a discrete value was given in the XF86Config file. πŸ“Ί

Oh and heads up β€” the vendor, model, hsync, and vsync fields point to dynamically allocated storage that should be freed by the caller. Yes, you. Again. Free your memory, it's self-care. 🫢


πŸ¦‹ VIEWPORT FUNCTIONS πŸ¦‹

XF86VidModeGetViewPort and XF86VidModeSetViewPort can be used to, respectively, query and change the location of the upper left corner of the viewport into the virtual screen. That's it, that's the whole vibe β€” get and set, peek and poke. πŸŽ€


🌸 OTHER FUNCTIONS 🌸

XF86VidModeQueryVersion can be used to determine the version of the extension built into the server. Know your version, bestie, it's giving informed. ⭐

And XF86VidModeQueryExtension returns the lowest numbered error and event values assigned to the extension. Lowest numbered. Keep that detail, it's important. πŸ‘‘


πŸ’€ BUGS πŸ’€

Okay so, not me having to tell you this, but the following functions need to be documented:

  • XF86VidModeSetClientVersion
  • XF86VidModeGetDotClocks
  • XF86VidModeGetGamma
  • XF86VidModeSetGamma
  • XF86VidModeSetGammaRamp
  • XF86VidModeGetGammaRamp
  • XF86VidModeGetGammaRampSize
  • XF86VidModeGetPermissions

In the meantime, check the source code for information about how to use them. Like, that's genuinely the advice. Go read the source, iykyk. 😭


🌈 SEE ALSO 🌈


πŸ‘‘ AUTHORS πŸ‘‘

The legends themselves: Kaleb Keithley, Jon Tombs, David Dawes, and Joe Moss. Absolute icons, we stan. 🫢✨


And that's the whole page, bestie! πŸŽ‰ This lil masterpiece ships with X Version 11, it's libXxf86vm 1.1.6, and it's filed under XF86VIDMODE(3). Go forth and switch modes responsibly, mwah πŸ’‹πŸŒΈ