### Get Current DPMS Status and Timeouts Source: https://context7.com/xorg/lib/llms.txt Retrieves the current DPMS power state (enabled/disabled, current level) and configured timeouts for standby, suspend, and off modes. Assumes DPMS is initialized. ```c /* Get current DPMS state and timeouts */ void print_dpms_status(Display *dpy) { CARD16 power_level; BOOL state; CARD16 standby, suspend, off; DPMSInfo(dpy, &power_level, &state); printf("DPMS is %s\n", state ? "enabled" : "disabled"); const char *level_str; switch (power_level) { case DPMSModeOn: level_str = "On"; break; case DPMSModeStandby: level_str = "Standby"; break; case DPMSModeSuspend: level_str = "Suspend"; break; case DPMSModeOff: level_str = "Off"; break; default: level_str = "Unknown"; break; } printf("Current power level: %s\n", level_str); DPMSGetTimeouts(dpy, &standby, &suspend, &off); printf("Timeouts - Standby: %ds, Suspend: %ds, Off: %ds\n", standby, suspend, off); } ``` -------------------------------- ### Create and Use Fence Source: https://context7.com/xorg/lib/llms.txt Demonstrates creating a Sync fence, checking its triggered state, manually triggering it, resetting it, and finally destroying it. Fences are used for synchronization between X clients. ```c /* Create and use a fence for synchronization */ void fence_example(Display *dpy, Window win) { XSyncFence fence; Bool triggered; /* Create fence in non-triggered state */ fence = XSyncCreateFence(dpy, win, False); printf("Created fence %lu\n", fence); /* Check fence state */ XSyncQueryFence(dpy, fence, &triggered); printf("Fence triggered: %s\n", triggered ? "yes" : "no"); /* Trigger the fence */ XSyncTriggerFence(dpy, fence); XSyncQueryFence(dpy, fence, &triggered); printf("After trigger: %s\n", triggered ? "yes" : "no"); /* Reset for reuse */ XSyncResetFence(dpy, fence); /* Clean up */ XSyncDestroyFence(dpy, fence); } ``` -------------------------------- ### Create and Use Custom Counter Source: https://context7.com/xorg/lib/llms.txt Demonstrates creating a custom counter, setting its value, querying it, and modifying it. Includes cleanup by destroying the counter. ```c /* Create and use a custom counter */ void counter_example(Display *dpy) { XSyncCounter counter; XSyncValue value, new_value, result; /* Create counter with initial value 0 */ XSyncIntToValue(&value, 0); counter = XSyncCreateCounter(dpy, value); printf("Created counter %lu\n", counter); /* Set counter to 100 */ XSyncIntToValue(&new_value, 100); XSyncSetCounter(dpy, counter, new_value); /* Query current value */ XSyncQueryCounter(dpy, counter, &result); printf("Counter value: %d\n", XSyncValueLow32(result)); /* Increment counter by 50 */ XSyncIntToValue(&value, 50); XSyncChangeCounter(dpy, counter, value); XSyncQueryCounter(dpy, counter, &result); printf("Counter value after change: %d\n", XSyncValueLow32(result)); /* Clean up */ XSyncDestroyCounter(dpy, counter); } ``` -------------------------------- ### Initialize Security Extension Source: https://context7.com/xorg/lib/llms.txt Checks for the availability of the Security extension and retrieves its version. Include X11/extensions/security.h. ```c #include #include /* Query Security extension */ Bool init_security(Display *dpy) { int major, minor; if (!XSecurityQueryExtension(dpy, &major, &minor)) { fprintf(stderr, "Security extension not available\n"); return False; } printf("Security extension version %d.%d\n", major, minor); return True; } ``` -------------------------------- ### Initialize Multibuffer Extension Source: https://context7.com/xorg/lib/llms.txt Initializes the Multibuffer extension and queries its version. Returns false if the extension is not available. ```c #include #include /* Initialize multibuffer extension */ Bool init_multibuf(Display *dpy, int *event_base, int *error_base) { int major, minor; if (!XmbufQueryExtension(dpy, event_base, error_base)) { fprintf(stderr, "Multibuffer extension not available\n"); return False; } XmbufGetVersion(dpy, &major, &minor); printf("Multibuffer version %d.%d\n", major, minor); return True; } ``` -------------------------------- ### Implement Custom X11 Extension Handler Source: https://context7.com/xorg/lib/llms.txt Uses extutil macros to manage display lifecycle and verify extension availability for custom X11 extensions. ```c #include #include /* Example: Creating a custom extension handler */ /* Global extension info structure */ static XExtensionInfo *my_ext_info = NULL; static const char *my_ext_name = "MyExtension"; /* Extension hooks for display lifecycle */ static XExtensionHooks my_ext_hooks = { NULL, /* create_gc */ NULL, /* copy_gc */ NULL, /* flush_gc */ NULL, /* free_gc */ NULL, /* create_font */ NULL, /* free_font */ my_close_display, /* close_display */ NULL, /* wire_to_event */ NULL, /* event_to_wire */ NULL, /* error */ NULL /* error_string */ }; /* Generate find_display function using macro */ static XEXT_GENERATE_FIND_DISPLAY(find_display, my_ext_info, my_ext_name, &my_ext_hooks, 0, NULL) /* Generate close_display function using macro */ static XEXT_GENERATE_CLOSE_DISPLAY(my_close_display, my_ext_info) /* Check if extension is present for a display */ Bool MyExtensionPresent(Display *dpy) { XExtDisplayInfo *info = find_display(dpy); return XextHasExtension(info); } /* Example extension function with error checking */ Status MyExtensionDoSomething(Display *dpy, Window win) { XExtDisplayInfo *info = find_display(dpy); /* Check extension is present */ XextCheckExtension(dpy, info, my_ext_name, 0); /* Extension is available, proceed with protocol request */ LockDisplay(dpy); /* ... send protocol request ... */ UnlockDisplay(dpy); SyncHandle(); return 1; } /* Clean up extension on program exit */ void MyExtensionCleanup(void) { if (my_ext_info) { XextDestroyExtension(my_ext_info); my_ext_info = NULL; } } ``` -------------------------------- ### Initialize EVI Extension Source: https://context7.com/xorg/lib/llms.txt Checks for the availability of the Extended Visual Information (EVI) extension and retrieves its version. Include X11/extensions/XEVI.h. ```c #include #include /* Query EVI extension */ Bool init_evi(Display *dpy) { int major, minor; if (!XeviQueryExtension(dpy)) { fprintf(stderr, "EVI extension not available\n"); return False; } XeviQueryVersion(dpy, &major, &minor); printf("EVI version %d.%d\n", major, minor); return True; } ``` -------------------------------- ### Initialize Sync Extension Source: https://context7.com/xorg/lib/llms.txt Initializes the Sync extension and retrieves its major and minor version numbers. Returns false if the extension is not available or initialization fails. ```c #include #include /* Initialize Sync extension */ Bool init_sync_extension(Display *dpy, int *event_base, int *error_base) { int major, minor; if (!XSyncQueryExtension(dpy, event_base, error_base)) { fprintf(stderr, "Sync extension not available\n"); return False; } if (!XSyncInitialize(dpy, &major, &minor)) { fprintf(stderr, "Failed to initialize Sync extension\n"); return False; } printf("Sync extension version %d.%d\n", major, minor); return True; } ``` -------------------------------- ### Create Triple Buffer Context Source: https://context7.com/xorg/lib/llms.txt Creates a context for managing triple buffering, initializing three off-screen buffers for a window. Returns NULL if fewer than two buffers can be created. ```c /* Create triple-buffered window for animation */ typedef struct { Display *dpy; Window window; Multibuffer buffers[3]; int num_buffers; int current; GC gc; } TripleBufferContext; TripleBufferContext *create_triple_buffer(Display *dpy, Window win) { TripleBufferContext *ctx = malloc(sizeof(TripleBufferContext)); ctx->dpy = dpy; ctx->window = win; ctx->current = 0; /* Create 3 buffers with background update action */ ctx->num_buffers = XmbufCreateBuffers(dpy, win, 3, MultibufferUpdateActionBackground, MultibufferUpdateHintFrequent, ctx->buffers); if (ctx->num_buffers < 2) { fprintf(stderr, "Could only create %d buffers\n", ctx->num_buffers); if (ctx->num_buffers > 0) { XmbufDestroyBuffers(dpy, ctx->window); } free(ctx); return NULL; } printf("Created %d buffers\n", ctx->num_buffers); ctx->gc = XCreateGC(dpy, ctx->buffers[0], 0, NULL); return ctx; } ``` -------------------------------- ### Query Screen Buffer Information Source: https://context7.com/xorg/lib/llms.txt Retrieves and prints information about available mono and stereo buffer configurations for a given screen. ```c /* Query screen buffer capabilities */ void query_buffer_info(Display *dpy, Window win) { XmbufBufferInfo *mono_info, *stereo_info; int n_mono, n_stereo; XmbufGetScreenInfo(dpy, win, &n_mono, &mono_info, &n_stereo, &stereo_info); printf("Mono buffer configurations: %d\n", n_mono); for (int i = 0; i < n_mono; i++) { printf(" Visual 0x%lx: max %d buffers, depth %d\n", mono_info[i].visualid, mono_info[i].max_buffers, mono_info[i].depth); } if (n_stereo > 0) { printf("Stereo buffer configurations: %d\n", n_stereo); } if (mono_info) XFree(mono_info); if (stereo_info) XFree(stereo_info); } ``` -------------------------------- ### Implement Double Buffering with Xdbe Source: https://context7.com/xorg/lib/llms.txt Provides functions to query DBE availability, allocate back buffers, perform drawing operations, and swap buffers for X11 windows. ```c #include #include /* Check DBE availability and get visual info */ Bool setup_double_buffering(Display *dpy, Window root) { int major, minor; XdbeScreenVisualInfo *info; int num_screens = 1; Drawable screens[1]; if (!XdbeQueryExtension(dpy, &major, &minor)) { fprintf(stderr, "DBE extension not available\n"); return False; } printf("DBE version %d.%d\n", major, minor); /* Get visuals that support double buffering */ screens[0] = root; info = XdbeGetVisualInfo(dpy, screens, &num_screens); if (info && info->count > 0) { printf("Found %d double-buffer capable visuals:\n", info->count); for (int i = 0; i < info->count; i++) { printf(" Visual 0x%lx, depth %d, perf level %d\n", info->visinfo[i].visual, info->visinfo[i].depth, info->visinfo[i].perflevel); } XdbeFreeVisualInfo(info); return True; } return False; } /* Create double-buffered window rendering context */ typedef struct { Display *dpy; Window window; XdbeBackBuffer back_buffer; GC gc; } DoubleBufferContext; DoubleBufferContext *create_double_buffer(Display *dpy, Window win) { DoubleBufferContext *ctx = malloc(sizeof(DoubleBufferContext)); ctx->dpy = dpy; ctx->window = win; /* Allocate back buffer with undefined swap action */ ctx->back_buffer = XdbeAllocateBackBufferName(dpy, win, XdbeUndefined); if (!ctx->back_buffer) { free(ctx); return NULL; } /* Create graphics context for drawing */ ctx->gc = XCreateGC(dpy, ctx->back_buffer, 0, NULL); return ctx; } /* Draw to the back buffer */ void draw_frame(DoubleBufferContext *ctx, int frame_num) { XWindowAttributes attr; XGetWindowAttributes(ctx->dpy, ctx->window, &attr); /* Clear back buffer */ XSetForeground(ctx->dpy, ctx->gc, BlackPixel(ctx->dpy, 0)); XFillRectangle(ctx->dpy, ctx->back_buffer, ctx->gc, 0, 0, attr.width, attr.height); /* Draw animation frame */ XSetForeground(ctx->dpy, ctx->gc, WhitePixel(ctx->dpy, 0)); int x = (frame_num * 5) % attr.width; XFillRectangle(ctx->dpy, ctx->back_buffer, ctx->gc, x, attr.height/2 - 25, 50, 50); } /* Swap front and back buffers */ void swap_buffers(DoubleBufferContext *ctx) { XdbeSwapInfo swap_info; swap_info.swap_window = ctx->window; swap_info.swap_action = XdbeUndefined; XdbeSwapBuffers(ctx->dpy, &swap_info, 1); XSync(ctx->dpy, False); } /* Clean up double buffer resources */ void destroy_double_buffer(DoubleBufferContext *ctx) { XdbeDeallocateBackBufferName(ctx->dpy, ctx->back_buffer); XFreeGC(ctx->dpy, ctx->gc); free(ctx); } ``` -------------------------------- ### Configure DPMS Timeouts and Enable Source: https://context7.com/xorg/lib/llms.txt Sets the inactivity timeouts for DPMS standby, suspend, and off states in seconds, and then enables DPMS power management. Ensure DPMS is capable before calling. ```c /* Configure DPMS timeouts and enable */ void configure_dpms(Display *dpy, int standby_secs, int suspend_secs, int off_secs) { /* Set timeouts (in seconds) */ DPMSSetTimeouts(dpy, standby_secs, suspend_secs, off_secs); /* Enable DPMS */ DPMSEnable(dpy); printf("DPMS configured: standby=%ds, suspend=%ds, off=%ds\n", standby_secs, suspend_secs, off_secs); } ``` -------------------------------- ### Check DPMS Support and Version Source: https://context7.com/xorg/lib/llms.txt Verifies if the DPMS extension is available and retrieves its version. Requires including X11/Xlib.h and X11/extensions/dpms.h. ```c #include #include /* Check DPMS support and get version */ Bool check_dpms_support(Display *dpy) { int event_base, error_base; int major, minor; if (!DPMSQueryExtension(dpy, &event_base, &error_base)) { fprintf(stderr, "DPMS extension not available\n"); return False; } DPMSGetVersion(dpy, &major, &minor); printf("DPMS version %d.%d\n", major, minor); if (DPMSCapable(dpy)) { printf("Display is DPMS capable\n"); return True; } printf("Display does not support DPMS\n"); return False; } ``` -------------------------------- ### Print Extended Visual Information for All Visuals Source: https://context7.com/xorg/lib/llms.txt Retrieves and prints detailed information for all visuals on the default screen, including transparency, colormap capabilities, and conflicts. Requires X11/extensions/XEVI.h. Frees the allocated memory for visual info. ```c #include #include /* Get extended info for all visuals on default screen */ void print_visual_info(Display *dpy) { ExtendedVisualInfo *evi_info; int n_info; /* Pass NULL to get all visuals */ if (XeviGetVisualInfo(dpy, NULL, 0, &evi_info, &n_info) != Success) { fprintf(stderr, "Failed to get visual info\n"); return; } printf("Extended info for %d visuals:\n", n_info); for (int i = 0; i < n_info; i++) { printf("\nVisual 0x%lx (screen %d):\n", evi_info[i].core_visual_id, evi_info[i].screen); printf(" Level: %d\n", evi_info[i].level); const char *trans_type; switch (evi_info[i].transparency_type) { case 0: trans_type = "None"; break; case 1: trans_type = "Pixel"; break; case 2: trans_type = "Mask"; break; default: trans_type = "Unknown"; break; } printf(" Transparency: %s", trans_type); if (evi_info[i].transparency_type != 0) { printf(" (value: %u)", evi_info[i].transparency_value); } printf("\n"); printf(" Hardware colormaps: %u-%u\n", evi_info[i].min_hw_colormaps, evi_info[i].max_hw_colormaps); if (evi_info[i].num_colormap_conflicts > 0) { printf(" Colormap conflicts: %u\n", evi_info[i].num_colormap_conflicts); } } XFree(evi_info); } ``` -------------------------------- ### Implement MIT-SHM Shared Memory Operations Source: https://context7.com/xorg/lib/llms.txt Provides functions to query extension availability, allocate shared memory segments for XImages, perform fast blitting, and clean up resources. Requires linking against X11 and Xext libraries. ```c #include #include #include #include /* Check if shared memory extension is available */ Bool use_shared_memory(Display *dpy) { int major, minor; Bool shared_pixmaps; if (!XShmQueryExtension(dpy)) { fprintf(stderr, "MIT-SHM extension not available\n"); return False; } XShmQueryVersion(dpy, &major, &minor, &shared_pixmaps); printf("MIT-SHM version %d.%d, shared pixmaps: %s\n", major, minor, shared_pixmaps ? "yes" : "no"); return True; } /* Create a shared memory XImage for fast blitting */ XImage *create_shm_image(Display *dpy, Visual *visual, unsigned int depth, unsigned int width, unsigned int height, XShmSegmentInfo *shminfo) { XImage *image; /* Create the XImage structure */ image = XShmCreateImage(dpy, visual, depth, ZPixmap, NULL, shminfo, width, height); if (!image) return NULL; /* Allocate shared memory segment */ shminfo->shmid = shmget(IPC_PRIVATE, image->bytes_per_line * image->height, IPC_CREAT | 0777); if (shminfo->shmid < 0) { XDestroyImage(image); return NULL; } /* Attach shared memory to process */ shminfo->shmaddr = image->data = shmat(shminfo->shmid, 0, 0); shminfo->readOnly = False; /* Attach shared memory to X server */ if (!XShmAttach(dpy, shminfo)) { shmdt(shminfo->shmaddr); shmctl(shminfo->shmid, IPC_RMID, 0); XDestroyImage(image); return NULL; } /* Mark segment for deletion when all processes detach */ shmctl(shminfo->shmid, IPC_RMID, 0); return image; } /* Put shared memory image to window */ void draw_shm_image(Display *dpy, Window win, GC gc, XImage *image, int x, int y) { XShmPutImage(dpy, win, gc, image, 0, 0, /* src_x, src_y */ x, y, /* dst_x, dst_y */ image->width, image->height, False); /* send_event */ XSync(dpy, False); } /* Clean up shared memory resources */ void cleanup_shm_image(Display *dpy, XImage *image, XShmSegmentInfo *shminfo) { XShmDetach(dpy, shminfo); XDestroyImage(image); shmdt(shminfo->shmaddr); } ``` -------------------------------- ### Create Authorization for Untrusted Client Source: https://context7.com/xorg/lib/llms.txt Generates an authorization token for an untrusted client with a specified timeout. Requires X11/extensions/security.h. The generated authorization must be explicitly revoked later. ```c #include #include /* Generate authorization for untrusted client */ Xauth *create_untrusted_auth(Display *dpy, unsigned int timeout_secs) { Xauth *auth_in, *auth_out; XSecurityAuthorizationAttributes attr; XSecurityAuthorization auth_id; unsigned long mask = 0; /* Allocate input auth structure */ auth_in = XSecurityAllocXauth(); auth_in->name = "MIT-MAGIC-COOKIE-1"; auth_in->name_length = strlen(auth_in->name); /* Set untrusted level with timeout */ attr.trust_level = XSecurityClientUntrusted; mask |= XSecurityTrustLevel; attr.timeout = timeout_secs; mask |= XSecurityTimeout; /* Generate the authorization */ auth_out = XSecurityGenerateAuthorization(dpy, auth_in, mask, &attr, &auth_id); if (auth_out) { printf("Generated auth ID %lu for untrusted client\n", auth_id); printf("Auth data length: %d bytes\n", auth_out->data_length); } XSecurityFreeXauth(auth_in); return auth_out; } ``` -------------------------------- ### List System Counters Source: https://context7.com/xorg/lib/llms.txt Retrieves and prints a list of available system-wide synchronization counters. Frees the list after use. ```c /* List available system counters */ void list_system_counters(Display *dpy) { XSyncSystemCounter *counters; int n_counters; counters = XSyncListSystemCounters(dpy, &n_counters); printf("Found %d system counters:\n", n_counters); for (int i = 0; i < n_counters; i++) { printf(" %s (ID: %lu)\n", counters[i].name, counters[i].counter); } XSyncFreeSystemCounterList(counters); } ``` -------------------------------- ### XCup Extension Operations Source: https://context7.com/xorg/lib/llms.txt Functions for querying the XCup extension, retrieving reserved colormap entries, and storing colors with sharing support. ```c #include #include /* Query XCup extension */ Bool init_xcup(Display *dpy) { int major, minor; if (!XcupQueryVersion(dpy, &major, &minor)) { fprintf(stderr, "XCup extension not available\n"); return False; } printf("XCup version %d.%d\n", major, minor); return True; } /* Get reserved colormap entries for a screen */ void print_reserved_colors(Display *dpy, int screen) { XColor *colors; int n_colors; if (XcupGetReservedColormapEntries(dpy, screen, &colors, &n_colors) != Success) { fprintf(stderr, "Failed to get reserved entries\n"); return; } printf("Reserved colormap entries for screen %d: %d\n", screen, n_colors); for (int i = 0; i < n_colors; i++) { printf(" Pixel %lu: RGB(%u, %u, %u)\n", colors[i].pixel, colors[i].red >> 8, colors[i].green >> 8, colors[i].blue >> 8); } XFree(colors); } /* Store colors with sharing support */ void store_shared_colors(Display *dpy, Colormap cmap) { XColor colors[3]; /* Define colors to store */ colors[0].red = 65535; colors[0].green = 0; colors[0].blue = 0; colors[1].red = 0; colors[1].green = 65535; colors[1].blue = 0; colors[2].red = 0; colors[2].green = 0; colors[2].blue = 65535; colors[0].flags = colors[1].flags = colors[2].flags = DoRed|DoGreen|DoBlue; /* XcupStoreColors tries to use existing matching entries */ if (XcupStoreColors(dpy, cmap, colors, 3) == Success) { printf("Stored colors at pixels: %lu, %lu, %lu\n", colors[0].pixel, colors[1].pixel, colors[2].pixel); } } ``` -------------------------------- ### XGE Extension Operations Source: https://context7.com/xorg/lib/llms.txt Functions for querying the XGE extension version and configuring generic event masks. ```c #include #include /* Query XGE extension */ Bool init_xge(Display *dpy) { int event_base, error_base; int major, minor; if (!XGEQueryExtension(dpy, &event_base, &error_base)) { fprintf(stderr, "XGE extension not available\n"); return False; } if (!XGEQueryVersion(dpy, &major, &minor)) { fprintf(stderr, "Failed to query XGE version\n"); return False; } printf("XGE version %d.%d\n", major, minor); printf("Event base: %d, Error base: %d\n", event_base, error_base); return True; } /* Example generic event mask setup */ void setup_generic_events(XGenericEventMask *mask, unsigned char extension, unsigned int event_mask) { mask->extension = extension; mask->pad0 = 0; mask->pad1 = 0; mask->evmask = event_mask; } ``` -------------------------------- ### Display Current Buffer Source: https://context7.com/xorg/lib/llms.txt Displays the content of the current off-screen buffer and advances the buffer index for the next frame. ```c /* Display the current buffer */ void display_buffer(TripleBufferContext *ctx) { XmbufDisplayBuffers(ctx->dpy, 1, &ctx->buffers[ctx->current], 0, 0); ctx->current = (ctx->current + 1) % ctx->num_buffers; } ``` -------------------------------- ### Query Specific Visual Information Source: https://context7.com/xorg/lib/llms.txt Retrieves and prints specific extended information for a given visual ID. Requires X11/extensions/XEVI.h. Frees the allocated memory for visual info. ```c #include #include /* Get info for specific visual */ void query_visual(Display *dpy, VisualID visual_id) { ExtendedVisualInfo *info; VisualID query = visual_id; int n_info; if (XeviGetVisualInfo(dpy, &query, 1, &info, &n_info) == Success && n_info > 0) { printf("Visual 0x%lx: level=%d, hw_colormaps=%u-%u\n", visual_id, info->level, info->min_hw_colormaps, info->max_hw_colormaps); XFree(info); } } ``` -------------------------------- ### Turn Off Display Immediately Source: https://context7.com/xorg/lib/llms.txt A convenience function to enable DPMS and immediately force the display into the DPMSModeOff state. ```c /* Example: Turn off display immediately */ void turn_off_display(Display *dpy) { DPMSEnable(dpy); DPMSForceLevel(dpy, DPMSModeOff); } ``` -------------------------------- ### Manage X11 Shape Extension Source: https://context7.com/xorg/lib/llms.txt Functions for querying extension availability, applying circular or rectangular masks, monitoring events, and retrieving current shape data. ```c #include #include /* Query if shape extension is available */ Bool check_shape_extension(Display *dpy) { int event_base, error_base; int major, minor; if (!XShapeQueryExtension(dpy, &event_base, &error_base)) { fprintf(stderr, "Shape extension not available\n"); return False; } XShapeQueryVersion(dpy, &major, &minor); printf("Shape extension version %d.%d\n", major, minor); return True; } /* Create a circular window shape */ void make_circular_window(Display *dpy, Window win, int width, int height) { XGCValues gcv; Pixmap shape_mask; GC gc; /* Create a pixmap for the shape mask */ shape_mask = XCreatePixmap(dpy, win, width, height, 1); gc = XCreateGC(dpy, shape_mask, 0, &gcv); /* Clear the pixmap (transparent) */ XSetForeground(dpy, gc, 0); XFillRectangle(dpy, shape_mask, gc, 0, 0, width, height); /* Draw filled circle (opaque region) */ XSetForeground(dpy, gc, 1); XFillArc(dpy, shape_mask, gc, 0, 0, width, height, 0, 360*64); /* Apply shape to window bounding region */ XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, shape_mask, ShapeSet); XFreeGC(dpy, gc); XFreePixmap(dpy, shape_mask); } /* Create window with custom rectangular cutouts */ void make_window_with_hole(Display *dpy, Window win, int width, int height, int hole_x, int hole_y, int hole_w, int hole_h) { XRectangle rects[4]; /* Define rectangles around the hole */ rects[0] = (XRectangle){0, 0, width, hole_y}; /* Top */ rects[1] = (XRectangle){0, hole_y, hole_x, hole_h}; /* Left */ rects[2] = (XRectangle){hole_x + hole_w, hole_y, width - hole_x - hole_w, hole_h}; /* Right */ rects[3] = (XRectangle){0, hole_y + hole_h, width, height - hole_y - hole_h}; /* Bottom */ XShapeCombineRectangles(dpy, win, ShapeBounding, 0, 0, rects, 4, ShapeSet, Unsorted); } /* Monitor shape changes on a window */ void setup_shape_events(Display *dpy, Window win) { XShapeSelectInput(dpy, win, ShapeNotifyMask); } /* Get the current shape rectangles */ void print_window_shape(Display *dpy, Window win) { XRectangle *rects; int count, ordering; rects = XShapeGetRectangles(dpy, win, ShapeBounding, &count, &ordering); if (rects) { printf("Window has %d shape rectangles:\n", count); for (int i = 0; i < count; i++) { printf(" [%d] x=%d y=%d w=%d h=%d\n", i, rects[i].x, rects[i].y, rects[i].width, rects[i].height); } XFree(rects); } } ``` -------------------------------- ### Create Threshold Alarm Source: https://context7.com/xorg/lib/llms.txt Creates a Sync alarm that triggers when a specified counter reaches a certain threshold. Configures the alarm to auto-reset and request events upon triggering. ```c /* Create an alarm that triggers when counter reaches threshold */ XSyncAlarm create_threshold_alarm(Display *dpy, XSyncCounter counter, int threshold) { XSyncAlarmAttributes attr; unsigned long mask = 0; /* Set trigger counter */ attr.trigger.counter = counter; mask |= XSyncCACounter; /* Trigger when counter >= threshold */ attr.trigger.value_type = XSyncAbsolute; mask |= XSyncCAValueType; XSyncIntToValue(&attr.trigger.wait_value, threshold); mask |= XSyncCAValue; attr.trigger.test_type = XSyncPositiveComparison; mask |= XSyncCATestType; /* Auto-reset delta */ XSyncIntToValue(&attr.delta, 1); mask |= XSyncCADelta; /* Request events */ attr.events = True; mask |= XSyncCAEvents; return XSyncCreateAlarm(dpy, mask, &attr); } ``` -------------------------------- ### Render Animation Frame to Buffer Source: https://context7.com/xorg/lib/llms.txt Renders a single animation frame to the current off-screen buffer. Clears the buffer before drawing. ```c /* Render animation frame to current buffer */ void render_to_buffer(TripleBufferContext *ctx, int frame) { Multibuffer buf = ctx->buffers[ctx->current]; XWindowAttributes attr; XGetWindowAttributes(ctx->dpy, ctx->window, &attr); /* Clear buffer */ XSetForeground(ctx->dpy, ctx->gc, BlackPixel(ctx->dpy, 0)); XmbufClearBufferArea(ctx->dpy, buf, 0, 0, attr.width, attr.height, False); /* Draw animated content */ XSetForeground(ctx->dpy, ctx->gc, WhitePixel(ctx->dpy, 0)); int x = (int)(attr.width/2 + sin(frame * 0.1) * 100); int y = (int)(attr.height/2 + cos(frame * 0.1) * 100); XFillArc(ctx->dpy, buf, ctx->gc, x-25, y-25, 50, 50, 0, 360*64); } ``` -------------------------------- ### Force Display Power State Source: https://context7.com/xorg/lib/llms.txt Immediately forces the display to a specific DPMS power level (e.g., DPMSModeOn, DPMSModeOff). XSync is called to ensure the command is sent. ```c /* Force display to specific power state */ void set_display_power(Display *dpy, CARD16 level) { DPMSForceLevel(dpy, level); XSync(dpy, False); } ``` -------------------------------- ### Destroy Triple Buffer Context Source: https://context7.com/xorg/lib/llms.txt Frees all resources associated with the triple buffer context, including the off-screen buffers and graphics context. ```c /* Clean up */ void destroy_triple_buffer(TripleBufferContext *ctx) { XmbufDestroyBuffers(ctx->dpy, ctx->window); XFreeGC(ctx->dpy, ctx->gc); free(ctx); } ``` -------------------------------- ### Revoke Authorization Source: https://context7.com/xorg/lib/llms.txt Revokes a previously generated authorization token using its ID. Requires X11/extensions/security.h. ```c #include #include /* Revoke a previously generated authorization */ void revoke_authorization(Display *dpy, XSecurityAuthorization auth_id) { if (XSecurityRevokeAuthorization(dpy, auth_id)) { printf("Authorization %lu revoked\n", auth_id); } else { fprintf(stderr, "Failed to revoke authorization\n"); } } ``` -------------------------------- ### Disable DPMS Power Management Source: https://context7.com/xorg/lib/llms.txt Disables the DPMS power management system for the display. This will prevent the display from entering standby, suspend, or off states automatically or via DPMS commands. ```c /* Disable DPMS power management */ void disable_dpms(Display *dpy) { DPMSDisable(dpy); printf("DPMS disabled\n"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.