### Complete Multi-Monitor Setup Example Source: https://context7.com/xorg/lib/llms.txt Configures two monitors side-by-side using Xrandr. Requires connected outputs and appropriate display modes. Sets the total screen size and positions each monitor. ```c #include #include #include #include /* Configure dual monitors side by side */ int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); XRRScreenResources *res = XRRGetScreenResources(dpy, root); /* Collect connected outputs with their info */ typedef struct { RROutput id; XRROutputInfo *info; RRMode preferred_mode; int width, height; } OutputConfig; OutputConfig outputs[10]; int noutputs = 0; for (int i = 0; i < res->noutput && noutputs < 10; i++) { XRROutputInfo *info = XRRGetOutputInfo(dpy, res, res->outputs[i]); if (info->connection == RR_Connected && info->ncrtc > 0 && info->nmode > 0) { outputs[noutputs].id = res->outputs[i]; outputs[noutputs].info = info; outputs[noutputs].preferred_mode = info->modes[0]; /* Find mode dimensions */ for (int j = 0; j < res->nmode; j++) { if (res->modes[j].id == info->modes[0]) { outputs[noutputs].width = res->modes[j].width; outputs[noutputs].height = res->modes[j].height; break; } } noutputs++; } else { XRRFreeOutputInfo(info); } } printf("Found %d connected outputs\n", noutputs); if (noutputs >= 2) { /* Calculate total screen size */ int total_width = outputs[0].width + outputs[1].width; int max_height = outputs[0].height > outputs[1].height ? outputs[0].height : outputs[1].height; /* Set screen size first */ XRRSetScreenSize(dpy, root, total_width, max_height, total_width / 4, max_height / 4); /* ~96 DPI */ /* Configure first output at origin */ XRRCrtcInfo *crtc0 = XRRGetCrtcInfo(dpy, res, outputs[0].info->crtcs[0]); Status s1 = XRRSetCrtcConfig(dpy, res, outputs[0].info->crtcs[0], crtc0->timestamp, 0, 0, /* x, y */ outputs[0].preferred_mode, RR_Rotate_0, &outputs[0].id, 1); XRRFreeCrtcInfo(crtc0); /* Configure second output to the right of first */ XRRCrtcInfo *crtc1 = XRRGetCrtcInfo(dpy, res, outputs[1].info->crtcs[0]); Status s2 = XRRSetCrtcConfig(dpy, res, outputs[1].info->crtcs[0], crtc1->timestamp, outputs[0].width, 0, /* x, y */ outputs[1].preferred_mode, RR_Rotate_0, &outputs[1].id, 1); XRRFreeCrtcInfo(crtc1); /* Set first output as primary */ XRRSetOutputPrimary(dpy, root, outputs[0].id); if (s1 == RRSetConfigSuccess && s2 == RRSetConfigSuccess) { printf("Configured dual monitor setup:\n"); printf(" %s: %dx%d at (0, 0) [PRIMARY]\n", outputs[0].info->name, outputs[0].width, outputs[0].height); printf(" %s: %dx%d at (%d, 0)\n", outputs[1].info->name, outputs[1].width, outputs[1].height, outputs[0].width); printf("Total desktop: %dx%d\n", total_width, max_height); } else { printf("Configuration failed: status1=%d status2=%d\n", s1, s2); } } /* Cleanup */ for (int i = 0; i < noutputs; i++) { XRRFreeOutputInfo(outputs[i].info); } XRRFreeScreenResources(res); XCloseDisplay(dpy); return 0; } ``` -------------------------------- ### Set and Get Primary Output with XRRSetOutputPrimary / XRRGetOutputPrimary Source: https://context7.com/xorg/lib/llms.txt Manages the primary display output, used for default window placement. This example demonstrates how to get the current primary output and set a new one. Requires X11 and Xrandr headers. ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); XRRScreenResources *res = XRRGetScreenResources(dpy, root); /* Get current primary */ RROutput primary = XRRGetOutputPrimary(dpy, root); if (primary != None) { XRROutputInfo *info = XRRGetOutputInfo(dpy, res, primary); printf("Current primary output: %s\n", info->name); XRRFreeOutputInfo(info); } else { printf("No primary output set\n"); } /* Set first connected output as primary */ for (int i = 0; i < res->noutput; i++) { XRROutputInfo *info = XRRGetOutputInfo(dpy, res, res->outputs[i]); if (info->connection == RR_Connected) { XRRSetOutputPrimary(dpy, root, res->outputs[i]); printf("Set %s as primary output\n", info->name); XRRFreeOutputInfo(info); break; } XRRFreeOutputInfo(info); } XRRFreeScreenResources(res); XCloseDisplay(dpy); return 0; } ``` -------------------------------- ### XRRGetScreenSizeRange - Get Screen Size Range Source: https://context7.com/xorg/lib/llms.txt Queries the minimum and maximum virtual screen sizes supported by the display. ```APIDOC ## XRRGetScreenSizeRange ### Description Queries the minimum and maximum virtual screen sizes supported. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); int minWidth, minHeight, maxWidth, maxHeight; if (XRRGetScreenSizeRange(dpy, root, &minWidth, &minHeight, &maxWidth, &maxHeight)) { printf("Screen size range:\n"); printf(" Minimum: %dx%d\n", minWidth, minHeight); printf(" Maximum: %dx%d\n", maxWidth, maxHeight); } XCloseDisplay(dpy); return 0; } ``` ### Response #### Success Response (200) Output format is text-based, showing the minimum and maximum supported screen dimensions. #### Response Example ``` Screen size range: Minimum: 320x200 Maximum: 16384x16384 ``` ``` -------------------------------- ### Get and Parse Screen Configuration Source: https://context7.com/xorg/lib/llms.txt Use XRRGetScreenInfo to retrieve the current screen configuration, including available resolutions and refresh rates. Remember to free the returned configuration using XRRFreeScreenConfigInfo. ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); XRRScreenConfiguration *config = XRRGetScreenInfo(dpy, root); if (!config) { fprintf(stderr, "Failed to get screen info\n"); return 1; } /* Get current configuration */ Rotation current_rotation; SizeID current_size = XRRConfigCurrentConfiguration(config, ¤t_rotation); short current_rate = XRRConfigCurrentRate(config); printf("Current size index: %d\n", current_size); printf("Current rotation: %d\n", current_rotation); printf("Current refresh rate: %d Hz\n", current_rate); /* Get available sizes */ int nsizes; XRRScreenSize *sizes = XRRConfigSizes(config, &nsizes); printf("\nAvailable sizes:\n"); for (int i = 0; i < nsizes; i++) { printf(" [%d] %dx%d (%dmm x %dmm)\n", i, sizes[i].width, sizes[i].height, sizes[i].mwidth, sizes[i].mheight); /* Get refresh rates for this size */ int nrates; short *rates = XRRConfigRates(config, i, &nrates); printf(" Rates: "); for (int j = 0; j < nrates; j++) { printf("%d ", rates[j]); } printf("Hz\n"); } XRRFreeScreenConfigInfo(config); XCloseDisplay(dpy); return 0; } /* Output: Current size index: 0 Current rotation: 1 Current refresh rate: 60 Hz Available sizes: [0] 1920x1080 (508mm x 285mm) Rates: 60 50 Hz [1] 1680x1050 (508mm x 285mm) Rates: 60 Hz */ ``` -------------------------------- ### Get Output Information with XRRGetOutputInfo Source: https://context7.com/xorg/lib/llms.txt Retrieves and prints details about connected and disconnected outputs, including their status, physical dimensions, and available modes. Requires X11 and Xrandr headers. ```c #include #include const char* connection_name(Connection c) { switch(c) { case RR_Connected: return "Connected"; case RR_Disconnected: return "Disconnected"; default: return "Unknown"; } } int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); XRRScreenResources *res = XRRGetScreenResources(dpy, root); for (int i = 0; i < res->noutput; i++) { XRROutputInfo *output = XRRGetOutputInfo(dpy, res, res->outputs[i]); printf("Output: %s\n", output->name); printf(" Status: %s\n", connection_name(output->connection)); printf(" Physical size: %lumm x %lumm\n", output->mm_width, output->mm_height); if (output->connection == RR_Connected) { printf(" Available CRTCs: %d\n", output->ncrtc); printf(" Available modes: %d (preferred: %d)\n", output->nmode, output->npreferred); /* Print preferred modes */ printf(" Preferred modes:\n"); for (int j = 0; j < output->npreferred && j < 3; j++) { for (int k = 0; k < res->nmode; k++) { if (res->modes[k].id == output->modes[j]) { printf(" %s\n", res->modes[k].name); break; } } } } printf("\n"); XRRFreeOutputInfo(output); } XRRFreeScreenResources(res); XCloseDisplay(dpy); return 0; } /* Output: Output: HDMI-1 Status: Connected Physical size: 527mm x 296mm Available CRTCs: 2 Available modes: 18 (preferred: 1) Preferred modes: 1920x1080 Output: DP-1 Status: Disconnected Physical size: 0mm x 0mm */ ``` -------------------------------- ### XRRSetOutputPrimary / XRRGetOutputPrimary Source: https://context7.com/xorg/lib/llms.txt Functions to get or set the primary display output used for default window placement. ```APIDOC ## XRRSetOutputPrimary / XRRGetOutputPrimary ### Description Sets or gets the primary output. The primary output is used for default window placement and identifying the main display. ### Method C Function Call ### Parameters - **dpy** (Display*) - Required - The X display connection. - **window** (Window) - Required - The root window. - **output** (RROutput) - Required (for Set) - The output ID to set as primary. ``` -------------------------------- ### Retrieve Monitor Definitions with XRRGetMonitors Source: https://context7.com/xorg/lib/llms.txt Use XRRGetMonitors to get information about active monitors. This function requires a display connection and the root window. It returns an array of XRRMonitorInfo structures. ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); int nmonitors; XRRMonitorInfo *monitors = XRRGetMonitors(dpy, root, True, &nmonitors); printf("Found %d active monitors:\n\n", nmonitors); for (int i = 0; i < nmonitors; i++) { char *name = XGetAtomName(dpy, monitors[i].name); printf("Monitor: %s\n", name); printf(" Primary: %s\n", monitors[i].primary ? "yes" : "no"); printf(" Automatic: %s\n", monitors[i].automatic ? "yes" : "no"); printf(" Geometry: %dx%d+%d+%d\n", monitors[i].width, monitors[i].height, monitors[i].x, monitors[i].y); printf(" Physical: %dmm x %dmm\n", monitors[i].mwidth, monitors[i].mheight); printf(" Outputs: %d\n", monitors[i].noutput); printf("\n"); XFree(name); } XRRFreeMonitors(monitors); XCloseDisplay(dpy); return 0; } /* Output: Found 2 active monitors: Monitor: HDMI-1 Primary: yes Automatic: yes Geometry: 1920x1080+0+0 Physical: 527mm x 296mm Outputs: 1 Monitor: DP-2 Primary: no Automatic: yes Geometry: 1920x1080+1920+0 Physical: 597mm x 336mm Outputs: 1 */ ``` -------------------------------- ### XRRSetScreenSize - Set Screen Size Source: https://context7.com/xorg/lib/llms.txt Sets the virtual screen size. This is used in conjunction with CRTC configuration for multi-monitor setups. ```APIDOC ## XRRSetScreenSize ### Description Sets the virtual screen size. Used in conjunction with CRTC configuration for multi-monitor setups. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); /* Set screen to 3840x1080 for dual 1920x1080 monitors side by side */ /* Physical size in mm (approximate) */ int width = 3840; int height = 1080; int mmWidth = 1016; /* ~40 inches */ int mmHeight = 285; /* ~11 inches */ XRRSetScreenSize(dpy, root, width, height, mmWidth, mmHeight); XSync(dpy, False); printf("Screen size set to %dx%d\n", width, height); XCloseDisplay(dpy); return 0; } ``` ### Response #### Success Response (200) Output format is text-based, confirming the screen size has been set. #### Response Example ``` Screen size set to 3840x1080 ``` ``` -------------------------------- ### XRRGetScreenResources - Get Screen Resources Source: https://context7.com/xorg/lib/llms.txt Retrieves detailed screen resources including all CRTCs, outputs, and available modes. This function forces a probe of connected displays, which may be slow. ```APIDOC ## XRRGetScreenResources ### Description Retrieves detailed screen resources including all CRTCs, outputs, and available modes. This forces a probe of connected displays which may be slow. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); XRRScreenResources *res = XRRGetScreenResources(dpy, root); if (!res) { fprintf(stderr, "Failed to get screen resources\n"); return 1; } printf("Screen Resources:\n"); printf(" CRTCs: %d\n", res->ncrtc); printf(" Outputs: %d\n", res->noutput); printf(" Modes: %d\n", res->nmode); printf("\nAvailable Modes:\n"); for (int i = 0; i < res->nmode; i++) { XRRModeInfo *mode = &res->modes[i]; double rate = (double)mode->dotClock / ((double)mode->hTotal * (double)mode->vTotal); printf(" %s: %ux%u @ %.2f Hz (id: %lu)\n", mode->name, mode->width, mode->height, rate, mode->id); } XRRFreeScreenResources(res); XCloseDisplay(dpy); return 0; } ``` ### Response #### Success Response (200) Output format is text-based, detailing screen resources and available display modes. #### Response Example ``` Screen Resources: CRTCs: 2 Outputs: 3 Modes: 24 Available Modes: 1920x1080: 1920x1080 @ 60.00 Hz (id: 69) 1680x1050: 1680x1050 @ 59.95 Hz (id: 70) ``` ``` -------------------------------- ### XRRGetScreenResourcesCurrent - Get Cached Screen Resources Source: https://context7.com/xorg/lib/llms.txt Returns cached screen resources without probing for new displays. This is much faster than XRRGetScreenResources but may not reflect recent hot-plug events. ```APIDOC ## XRRGetScreenResourcesCurrent ### Description Returns cached screen resources without probing for new displays. Much faster than XRRGetScreenResources but may not reflect recent hot-plug events. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); /* Fast - uses cached data */ XRRScreenResources *res = XRRGetScreenResourcesCurrent(dpy, root); printf("Cached resources: %d CRTCs, %d outputs, %d modes\n", res->ncrtc, res->noutput, res->nmode); XRRFreeScreenResources(res); XCloseDisplay(dpy); return 0; } ``` ### Response #### Success Response (200) Output format is text-based, indicating the number of cached CRTCs, outputs, and modes. #### Response Example ``` Cached resources: 2 CRTCs, 3 outputs, 24 modes ``` ``` -------------------------------- ### Get CRTC Information with XRRGetCrtcInfo Source: https://context7.com/xorg/lib/llms.txt Retrieves configuration details for each CRTC (display controller), including its position, size, active mode, rotation, and connected outputs. Requires X11 and Xrandr headers. ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); XRRScreenResources *res = XRRGetScreenResources(dpy, root); for (int i = 0; i < res->ncrtc; i++) { XRRCrtcInfo *crtc = XRRGetCrtcInfo(dpy, res, res->crtcs[i]); printf("CRTC %d (id: %lu):\n", i, res->crtcs[i]); printf(" Position: %d, %d\n", crtc->x, crtc->y); printf(" Size: %ux%u\n", crtc->width, crtc->height); printf(" Rotation: %d\n", crtc->rotation); printf(" Active outputs: %d\n", crtc->noutput); if (crtc->mode != None) { /* Find mode name */ for (int j = 0; j < res->nmode; j++) { if (res->modes[j].id == crtc->mode) { printf(" Mode: %s\n", res->modes[j].name); break; } } } else { printf(" Mode: disabled\n"); } printf("\n"); XRRFreeCrtcInfo(crtc); } XRRFreeScreenResources(res); XCloseDisplay(dpy); return 0; } /* Output: CRTC 0 (id: 63): Position: 0, 0 Size: 1920x1080 Rotation: 1 Active outputs: 1 Mode: 1920x1080 CRTC 1 (id: 64): Position: 0, 0 Size: 0x0 Rotation: 1 Active outputs: 0 Mode: disabled */ ``` -------------------------------- ### XRRRates - Get Refresh Rates Source: https://context7.com/xorg/lib/llms.txt Retrieves the supported refresh rates for a given screen size index. This function is useful for determining the available display frequencies for a specific resolution. ```APIDOC ## XRRRates ### Description Returns refresh rates supported for a given size index. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); int screen = DefaultScreen(dpy); int nsizes; XRRScreenSize *sizes = XRRSizes(dpy, screen, &nsizes); for (int i = 0; i < nsizes; i++) { int nrates; short *rates = XRRRates(dpy, screen, i, &nrates); printf("%dx%d: ", sizes[i].width, sizes[i].height); for (int j = 0; j < nrates; j++) { printf("%dHz ", rates[j]); } printf("\n"); } XCloseDisplay(dpy); return 0; } ``` ### Response #### Success Response (200) Output format is text-based, listing resolutions and their supported refresh rates. #### Response Example ``` 1920x1080: 60Hz 50Hz 1680x1050: 60Hz 1280x1024: 75Hz 60Hz ``` ``` -------------------------------- ### Control CRTC Gamma with XRRGetCrtcGamma / XRRSetCrtcGamma Source: https://context7.com/xorg/lib/llms.txt Get and set the gamma correction ramp for a CRTC, useful for color calibration and effects. Allocates gamma ramp memory using XRRAllocGamma and applies it. ```c #include #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); XRRScreenResources *res = XRRGetScreenResources(dpy, root); RRCrtc crtc = res->crtcs[0]; /* Get gamma ramp size */ int gamma_size = XRRGetCrtcGammaSize(dpy, crtc); printf("Gamma ramp size: %d\n", gamma_size); /* Get current gamma */ XRRCrtcGamma *gamma = XRRGetCrtcGamma(dpy, crtc); if (gamma) { printf("Current gamma (first 5 entries):\n"); for (int i = 0; i < 5 && i < gamma->size; i++) { printf(" [%%d] R:%%u G:%%u B:%%u\n", i, gamma->red[i], gamma->green[i], gamma->blue[i]); } XRRFreeGamma(gamma); } /* Create and apply a warm (redshift-like) gamma */ XRRCrtcGamma *new_gamma = XRRAllocGamma(gamma_size); double red_brightness = 1.0; double green_brightness = 0.8; /* Reduce green */ double blue_brightness = 0.6; /* Reduce blue more */ for (int i = 0; i < gamma_size; i++) { double value = (double)i / (gamma_size - 1); new_gamma->red[i] = (unsigned short)(value * red_brightness * 65535); new_gamma->green[i] = (unsigned short)(value * green_brightness * 65535); new_gamma->blue[i] = (unsigned short)(value * blue_brightness * 65535); } XRRSetCrtcGamma(dpy, crtc, new_gamma); printf("Applied warm color temperature\n"); XRRFreeGamma(new_gamma); XRRFreeScreenResources(res); XCloseDisplay(dpy); return 0; } /* Output: Gamma ramp size: 256 Current gamma (first 5 entries): [0] R:0 G:0 B:0 [1] R:257 G:257 B:257 [2] R:514 G:514 B:514 [3] R:771 G:771 B:771 [4] R:1028 G:1028 B:1028 Applied warm color temperature */ ``` -------------------------------- ### Query RandR Extension Version Source: https://context7.com/xorg/lib/llms.txt Call XRRQueryVersion to get the RandR extension version supported by the X server. This helps determine feature availability, such as CRTC/Output APIs (1.2+), Transform/Panning APIs (1.3+), and Monitor APIs (1.5+). ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); int major, minor; if (XRRQueryVersion(dpy, &major, &minor)) { printf("RandR version: %d.%d\n", major, minor); if (major > 1 || (major == 1 && minor >= 2)) { printf("CRTC/Output API available\n"); } if (major > 1 || (major == 1 && minor >= 3)) { printf("Transform/Panning API available\n"); } if (major > 1 || (major == 1 && minor >= 5)) { printf("Monitor API available\n"); } } XCloseDisplay(dpy); return 0; } /* Output: RandR version: 1.5 CRTC/Output API available Transform/Panning API available Monitor API available */ ``` -------------------------------- ### Create and Add Custom Display Mode in C Source: https://context7.com/xorg/lib/llms.txt Demonstrates allocating a mode structure, creating the mode on the server, and assigning it to connected outputs. Requires linking against Xrandr and X11 libraries. ```c #include #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); /* Create a custom 1920x1080@75Hz mode */ /* Timing values from cvt or gtf calculator */ XRRModeInfo *mode = XRRAllocModeInfo("1920x1080_75", 13); mode->width = 1920; mode->height = 1080; mode->dotClock = 220750000; /* 220.75 MHz */ mode->hSyncStart = 1968; mode->hSyncEnd = 2000; mode->hTotal = 2080; mode->hSkew = 0; mode->vSyncStart = 1083; mode->vSyncEnd = 1088; mode->vTotal = 1119; mode->modeFlags = 0; RRMode mode_id = XRRCreateMode(dpy, root, mode); if (mode_id != None) { printf("Created mode with ID: %lu\n", mode_id); /* Add mode to an output */ XRRScreenResources *res = XRRGetScreenResources(dpy, root); for (int i = 0; i < res->noutput; i++) { XRROutputInfo *output = XRRGetOutputInfo(dpy, res, res->outputs[i]); if (output->connection == RR_Connected) { XRRAddOutputMode(dpy, res->outputs[i], mode_id); printf("Added mode to output: %s\n", output->name); } XRRFreeOutputInfo(output); } /* To remove and destroy: */ /* XRRDeleteOutputMode(dpy, output_id, mode_id); */ /* XRRDestroyMode(dpy, mode_id); */ XRRFreeScreenResources(res); } XRRFreeModeInfo(mode); XCloseDisplay(dpy); return 0; } ``` -------------------------------- ### Gamma Control Functions Source: https://context7.com/xorg/lib/llms.txt Functions for getting and setting the gamma correction ramp for a CRTC. ```APIDOC ## XRRGetCrtcGamma / XRRSetCrtcGamma ### Description Gets and sets the gamma correction ramp for a CRTC. Used for color calibration and effects like night light/redshift. ### Methods - **XRRGetCrtcGamma**: Retrieves the current gamma ramp. - **XRRSetCrtcGamma**: Applies a new gamma ramp. ### Parameters - **dpy** (Display*) - Required - The X display connection. - **crtc** (RRCrtc) - Required - The CRTC to modify. - **gamma** (XRRCrtcGamma*) - Required - The gamma structure containing red, green, and blue ramps. ``` -------------------------------- ### XRRSetCrtcTransform / XRRGetCrtcTransform Source: https://context7.com/xorg/lib/llms.txt Functions to set or get the transformation matrix for a CRTC, enabling scaling and rotation. ```APIDOC ## XRRSetCrtcTransform / XRRGetCrtcTransform ### Description Sets or gets the transformation matrix for a CRTC. Enables scaling, rotation by arbitrary angles, and other affine transformations. ### Parameters - **dpy** (Display*) - Required - The X display connection. - **crtc** (RRCrtc) - Required - The CRTC identifier. - **transform** (XTransform*) - Required (Set) - The transformation matrix to apply. - **filter** (char*) - Required (Set) - The filter name (e.g., "bilinear"). ### Response - **attr** (XRRCrtcTransformAttributes*) - The current transformation attributes retrieved via XRRGetCrtcTransform. ``` -------------------------------- ### Configure Panning with XRRGetPanning and XRRSetPanning Source: https://context7.com/xorg/lib/llms.txt Enables virtual desktop support by defining panning areas and tracking regions for a CRTC. Requires Xrandr version 1.3 or higher. ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); XRRScreenResources *res = XRRGetScreenResources(dpy, root); RRCrtc crtc = res->crtcs[0]; /* Get current panning */ XRRPanning *panning = XRRGetPanning(dpy, res, crtc); if (panning) { printf("Current panning:\n"); printf(" Area: %ux%u at (%u, %u)\n", panning->width, panning->height, panning->left, panning->top); printf(" Tracking: %ux%u at (%u, %u)\n", panning->track_width, panning->track_height, panning->track_left, panning->track_top); printf(" Borders: L=%d T=%d R=%d B=%d\n", panning->border_left, panning->border_top, panning->border_right, panning->border_bottom); /* Set up panning for 3840x2160 virtual desktop on 1920x1080 display */ panning->left = 0; panning->top = 0; panning->width = 3840; panning->height = 2160; panning->track_left = 0; panning->track_top = 0; panning->track_width = 3840; panning->track_height = 2160; panning->border_left = 0; panning->border_top = 0; panning->border_right = 0; panning->border_bottom = 0; Status status = XRRSetPanning(dpy, res, crtc, panning); if (status == RRSetConfigSuccess) { printf("Panning configured for 3840x2160 virtual desktop\n"); } XRRFreePanning(panning); } XRRFreeScreenResources(res); XCloseDisplay(dpy); return 0; } ``` -------------------------------- ### XRRSizes Source: https://context7.com/xorg/lib/llms.txt Returns available screen sizes without requiring a full configuration fetch. Safe to call even if RandR is not supported. ```APIDOC ## XRRSizes ### Description Returns available screen sizes without requiring a full configuration fetch. Safe to call even if RandR is not supported. ### Method (Implicitly a function call within C code, not a direct HTTP method) ### Endpoint (N/A - this is a C library function) ### Parameters - **dpy** (Display *) - Pointer to the X display connection. - **screen** (int) - The screen number. - **nsizes** (int *) - Pointer to an integer to store the number of sizes returned. ### Request Example (N/A - this is a C library function) ### Response #### Success Response - **sizes** (XRRScreenSize *) - Pointer to an array of XRRScreenSize structures, each containing width, height, and physical dimensions. #### Response Example (Refer to C code example for accessing returned sizes) ``` -------------------------------- ### Change screen configuration with XRRSetScreenConfig Source: https://context7.com/xorg/lib/llms.txt Modifies screen size and rotation using timestamps to ensure configuration consistency. Requires an active X display connection. ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); XRRScreenConfiguration *config = XRRGetScreenInfo(dpy, root); /* Get timestamps */ Time config_timestamp; Time timestamp = XRRConfigTimes(config, &config_timestamp); /* Get current state */ Rotation current_rotation; SizeID current_size = XRRConfigCurrentConfiguration(config, ¤t_rotation); /* Change to size index 1 (if available) */ int nsizes; XRRScreenSize *sizes = XRRConfigSizes(config, &nsizes); if (nsizes > 1) { Status status = XRRSetScreenConfig(dpy, config, root, 1, /* size_index */ current_rotation, timestamp); switch (status) { case RRSetConfigSuccess: printf("Configuration changed successfully\n"); break; case RRSetConfigInvalidConfigTime: printf("Configuration timestamp invalid - need to refresh\n"); break; case RRSetConfigInvalidTime: printf("Timestamp invalid\n"); break; case RRSetConfigFailed: printf("Configuration change failed\n"); break; } } XRRFreeScreenConfigInfo(config); XCloseDisplay(dpy); return 0; } ``` -------------------------------- ### Query Screen Size Range with XRRGetScreenSizeRange Source: https://context7.com/xorg/lib/llms.txt Queries the minimum and maximum virtual screen dimensions supported by the X server. ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); int minWidth, minHeight, maxWidth, maxHeight; if (XRRGetScreenSizeRange(dpy, root, &minWidth, &minHeight, &maxWidth, &maxHeight)) { printf("Screen size range:\n"); printf(" Minimum: %dx%d\n", minWidth, minHeight); printf(" Maximum: %dx%d\n", maxWidth, maxHeight); } XCloseDisplay(dpy); return 0; } ``` -------------------------------- ### Create and Delete Custom Monitors with XRRSetMonitor/XRRDeleteMonitor Source: https://context7.com/xorg/lib/llms.txt Use XRRSetMonitor to create custom monitor definitions spanning multiple outputs, or XRRDeleteMonitor to remove them. This requires obtaining screen resources and identifying connected outputs. ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); XRRScreenResources *res = XRRGetScreenResources(dpy, root); /* Find all connected outputs */ RROutput connected[10]; int nconnected = 0; for (int i = 0; i < res->noutput && nconnected < 10; i++) { XRROutputInfo *info = XRRGetOutputInfo(dpy, res, res->outputs[i]); if (info->connection == RR_Connected) { connected[nconnected++] = res->outputs[i]; } XRRFreeOutputInfo(info); } if (nconnected >= 2) { /* Create a monitor spanning two outputs */ Atom monitor_name = XInternAtom(dpy, "SpannedMonitor", False); XRRMonitorInfo *monitor = XRRAllocateMonitor(dpy, 2); monitor->name = monitor_name; monitor->primary = False; monitor->automatic = False; monitor->x = 0; monitor->y = 0; monitor->width = 3840; /* Combined width */ monitor->height = 1080; monitor->mwidth = 1054; /* Combined physical width */ monitor->mheight = 296; monitor->outputs[0] = connected[0]; monitor->outputs[1] = connected[1]; XRRSetMonitor(dpy, root, monitor); printf("Created spanned monitor across 2 outputs\n"); XFree(monitor); /* To delete: */ /* XRRDeleteMonitor(dpy, root, monitor_name); */ } XRRFreeScreenResources(res); XCloseDisplay(dpy); return 0; } ``` -------------------------------- ### Configure Screen Size with XRRSetScreenSize Source: https://context7.com/xorg/lib/llms.txt Sets the virtual screen size, typically used when configuring multi-monitor layouts. ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); /* Set screen to 3840x1080 for dual 1920x1080 monitors side by side */ /* Physical size in mm (approximate) */ int width = 3840; int height = 1080; int mmWidth = 1016; /* ~40 inches */ int mmHeight = 285; /* ~11 inches */ XRRSetScreenSize(dpy, root, width, height, mmWidth, mmHeight); XSync(dpy, False); printf("Screen size set to %dx%d\n", width, height); XCloseDisplay(dpy); return 0; } ``` -------------------------------- ### Set screen configuration and refresh rate with XRRSetScreenConfigAndRate Source: https://context7.com/xorg/lib/llms.txt Updates screen settings including a specific refresh rate. Preferred over XRRSetScreenConfig when rate control is necessary. ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); XRRScreenConfiguration *config = XRRGetScreenInfo(dpy, root); Time config_timestamp; Time timestamp = XRRConfigTimes(config, &config_timestamp); Rotation current_rotation; SizeID current_size = XRRConfigCurrentConfiguration(config, ¤t_rotation); /* Get available rates for current size */ int nrates; short *rates = XRRConfigRates(config, current_size, &nrates); if (nrates > 0) { /* Set to first available rate */ Status status = XRRSetScreenConfigAndRate(dpy, config, root, current_size, current_rotation, rates[0], /* rate in Hz */ timestamp); if (status == RRSetConfigSuccess) { printf("Set refresh rate to %d Hz\n", rates[0]); } } XRRFreeScreenConfigInfo(config); XCloseDisplay(dpy); return 0; } ``` -------------------------------- ### Query available screen sizes with XRRSizes Source: https://context7.com/xorg/lib/llms.txt Retrieves supported screen resolutions. This function is safe to execute even if the RandR extension is not supported by the server. ```c #include #include int main() { Display *dpy = XOpenDisplay(NULL); int screen = DefaultScreen(dpy); int nsizes; XRRScreenSize *sizes = XRRSizes(dpy, screen, &nsizes); if (nsizes == 0) { printf("RandR not supported or no sizes available\n"); } else { printf("Available screen sizes:\n"); for (int i = 0; i < nsizes; i++) { printf(" %dx%d pixels (%dx%d mm)\n", sizes[i].width, sizes[i].height, sizes[i].mwidth, sizes[i].mheight); } } XCloseDisplay(dpy); return 0; } ``` -------------------------------- ### Update Xlib configuration with XRRUpdateConfiguration Source: https://context7.com/xorg/lib/llms.txt Synchronizes Xlib's internal screen configuration cache with the X server. Essential when handling screen change or root window configure events. ```c #include #include void handle_event(Display *dpy, XEvent *event, int event_base) { if (event->type == event_base + RRScreenChangeNotify) { /* Update Xlib's internal view of the screen */ int result = XRRUpdateConfiguration(event); if (result) { printf("Xlib configuration updated\n"); /* Now Xlib functions return correct values */ int screen = DefaultScreen(dpy); printf("New screen dimensions: %dx%d\n", DisplayWidth(dpy, screen), DisplayHeight(dpy, screen)); } } else if (event->type == ConfigureNotify) { /* Root window configure events also need to update Xlib */ XRRUpdateConfiguration(event); } } int main() { Display *dpy = XOpenDisplay(NULL); Window root = DefaultRootWindow(dpy); int event_base, error_base; XRRQueryExtension(dpy, &event_base, &error_base); XRRSelectInput(dpy, root, RRScreenChangeNotifyMask); /* Also select for ConfigureNotify on root window */ XSelectInput(dpy, root, StructureNotifyMask); printf("Monitoring for configuration changes...\n"); for (int i = 0; i < 10; i++) { /* Process 10 events */ XEvent event; XNextEvent(dpy, &event); handle_event(dpy, &event, event_base); } XCloseDisplay(dpy); return 0; } ``` -------------------------------- ### XRRSetScreenConfig Source: https://context7.com/xorg/lib/llms.txt Changes the screen configuration to a specified size and rotation. Uses timestamps to ensure the client has current configuration information before making changes. ```APIDOC ## XRRSetScreenConfig ### Description Changes the screen configuration to a specified size and rotation. Uses timestamps to ensure the client has current configuration information before making changes. ### Method (Implicitly a function call within C code, not a direct HTTP method) ### Endpoint (N/A - this is a C library function) ### Parameters (Refer to C function signature and example for details) ### Request Example (N/A - this is a C library function) ### Response #### Success Response (RRSetConfigSuccess) - **status** (int) - Indicates success of the configuration change. #### Response Example (Refer to C code example for status handling) ```