Skip to content

Instantly share code, notes, and snippets.

@Ckath
Last active September 30, 2025 15:07
Show Gist options
  • Select an option

  • Save Ckath/5ac994e690aed1f305c906dfbdc7f4c4 to your computer and use it in GitHub Desktop.

Select an option

Save Ckath/5ac994e690aed1f305c906dfbdc7f4c4 to your computer and use it in GitHub Desktop.
x output loopenings, expected to error at end, not before
/* compile: gcc -o x x.c -lXrandr -lX11 */
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
int main(void) {
Display *dpy = XOpenDisplay(NULL);
if (!dpy) {
fprintf(stderr,"failed to open display\n");
return 1;
}
Window w = DefaultRootWindow(dpy);
XRRScreenResources *sr = XRRGetScreenResources(dpy, w);
printf("looping to i < noutput, this shouldn't error:\n");
for (int i = 0; i < sr->noutput; ++i) {
XRROutputInfo* oinf = XRRGetOutputInfo(dpy, sr, sr->outputs[i]);
if (oinf) {
printf("name: %s, connected: %s\n", oinf->name,
oinf->connection == RR_Connected ? "yes" : "no");
}
XRRFreeOutputInfo(oinf);
}
printf("\nthis should error:\n");
XRROutputInfo* oinf = XRRGetOutputInfo(dpy, sr, sr->outputs[sr->noutput]);
if (oinf) {
printf("name: %s, connected: %s\n", oinf->name,
oinf->connection == RR_Connected ? "yes" : "no");
}
printf("reached end (this doesnt happen on X11)\n");
XRRFreeOutputInfo(oinf);
XRRFreeScreenResources(sr);
XCloseDisplay(dpy);
return 0;
}
@Ckath
Copy link
Author

Ckath commented Sep 29, 2025

expected output

looping to i < noutput, this shouldn't error:
name: DisplayPort-1, connected: yes
name: DisplayPort-0, connected: yes
name: DisplayPort-2, connected: yes
name: HDMI-A-0, connected: yes
name: DVI-D-0, connected: no
name: VGA-1-1, connected: yes

this should error:
X Error of failed request:  BadRROutput (invalid Output parameter)
  Major opcode of failed request:  140 (RANDR)
  Minor opcode of failed request:  9 (RRGetOutputInfo)
  Serial number of failed request:  18
  Current serial number in output stream:  18

allegedly possibly wayland (xwayland?) does not behave like this causing a certain launcher to not die on wayland when they clearly messed something up in their XRRGetOutputInfo call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment