Description of the Bug Report
On X11, Fl_X11_Screen_Driver::init() calls XRRSizes() to compute
the screen DPI. XRRSizes() sends a RandR 1.0 GetScreenInfo request,
and the X server handles that by re-probing every output
(ProcRRGetScreenInfo() calls RRGetInfo(pScreen, TRUE) in randr/rrscreen.c), which re-reads all monitor EDIDs.
This happens when an FLTK app starts, and again after every RRScreenChangeNotify, because XRRUpdateConfiguration() frees
libXrandr's cached GetScreenInfo reply and react_to_screen_reconfiguration() calls Fl::init_screens().
On a multi-monitor system this re-probe is slow, and monitors on
marginal links can briefly report "disconnected". Here, a monitor
connected through a passive DP->HDMI cable dropped out when an
application that bundles FLTK was started, and the desktop (KDE
Plasma, X11) re-arranged all monitors. I have not confirmed with a
minimal FLTK program that it was this request that caused the drop;
the analysis above is from reading the FLTK, libXrandr and Xorg
server sources.
To Reproduce
The code path, on current master:
Fl_X11_Screen_Driver::init() calls XRRSizes().
libXrandr XRRSizes() -> _XRRValidateCache() -> _XRRGetScreenInfo() sends RRGetScreenInfo when the cache is
empty (at startup, and after XRRUpdateConfiguration() handles
an RRScreenChangeNotify).
Xorg ProcRRGetScreenInfo() calls RRGetInfo(pScreen, TRUE),
i.e. a forced probe of all outputs.
Expected behavior
Getting the DPI should not make the X server probe the hardware.
RandR 1.5 XRRGetMonitors() returns the current monitor sizes in
pixels and mm without probing (ProcRRGetMonitors() uses RRGetInfo(pScreen, FALSE)).
Proposed fix
Use XRRGetMonitors() to get the primary (or first) monitor's size
and keep XRRSizes() as the fallback for servers without RandR 1.5.
Patch below. With it, a small test program calling Fl::screen_dpi() in an X11 session added no probe lines to the
Xorg log (NVIDIA driver). I'm happy to open a PR if this approach
is acceptable.
patch
diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx
index d7507a0..e6f24c2 100644
--- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx+++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx@@ -283,6 +283,53 @@ typedef struct {
int mwidth, mheight;
} XRRScreenSize;
typedef XRRScreenSize* (*XRRSizes_type)(Display *dpy, int screen, int *nsizes);
+typedef struct {+ Atom name;+ Bool primary, automatic;+ int noutput;+ int x, y, width, height;+ int mwidth, mheight;+ XID *outputs;+} XRRMonitorInfo;+typedef Status (*XRRQueryVersion_type)(Display*, int*, int*);+typedef XRRMonitorInfo* (*XRRGetMonitors_type)(Display*, Window, Bool, int*);+typedef void (*XRRFreeMonitors_type)(XRRMonitorInfo*);++// Get size in pixels and mm of the primary (or first) monitor.+// Unlike XRRSizes(), XRRGetMonitors() does not make the X server+// re-probe all outputs. Returns 0 if RandR 1.5 is not available.+static int primary_monitor_size(int &w, int &h, int &mmw, int &mmh) {+ static XRRGetMonitors_type XRRGetMonitors_f = NULL;+ static XRRFreeMonitors_type XRRFreeMonitors_f = NULL;+ static int tried = 0;+ if (!tried) {+ tried = 1;+ void *lib = Fl_Posix_System_Driver::dlopen_or_dlsym("libXrandr");+ XRRQueryVersion_type XRRQueryVersion_f = lib ?+ (XRRQueryVersion_type)dlsym(lib, "XRRQueryVersion") : NULL;+ int major = 0, minor = 0;+ if (XRRQueryVersion_f && XRRQueryVersion_f(fl_display, &major, &minor) &&+ (major > 1 || (major == 1 && minor >= 5))) {+ XRRGetMonitors_f = (XRRGetMonitors_type)dlsym(lib, "XRRGetMonitors");+ XRRFreeMonitors_f = (XRRFreeMonitors_type)dlsym(lib, "XRRFreeMonitors");+ }+ }+ if (!XRRGetMonitors_f || !XRRFreeMonitors_f) return 0;+ int n = 0;+ Window root = RootWindow(fl_display, fl_screen);+ XRRMonitorInfo *m = XRRGetMonitors_f(fl_display, root, True, &n);+ if (!m) return 0;+ int p = 0;+ for (int i = 0; i < n; i++) {+ if (m[i].primary) { p = i; break; }+ }+ if (n > 0) {+ w = m[p].width; h = m[p].height;+ mmw = m[p].mwidth; mmh = m[p].mheight;+ }+ XRRFreeMonitors_f(m);+ return n > 0;+}
#endif // USE_XRANDR
void Fl_X11_Screen_Driver::init() {
@@ -293,11 +340,18 @@ void Fl_X11_Screen_Driver::init() {
#if USE_XRANDR
+ int w = 0, h = 0, mmw = 0, mmh = 0;+ if (primary_monitor_size(w, h, mmw, mmh) && mmw > 0 && mmh > 0) {+ dpih = w*25.4f/mmw;+ dpiv = h*25.4f/mmh;+ dpi_by_randr = 1;+ }+
static XRRSizes_type XRRSizes_f = NULL;
- if (!XRRSizes_f) {+ if (!dpi_by_randr && !XRRSizes_f) {
XRRSizes_f = (XRRSizes_type)Fl_Posix_System_Driver::dlopen_or_dlsym("libXrandr", "XRRSizes");
}
- if (XRRSizes_f) {+ if (!dpi_by_randr && XRRSizes_f) { // RandR < 1.5
int nscreens;
XRRScreenSize *ssize = XRRSizes_f(fl_display, fl_screen, &nscreens);
Xorg server with NVIDIA proprietary driver + Intel iGPU (modesetting),
5 monitors, KDE Plasma 6 X11 session
Linux/Unix Runtime, if applicable:
X11
Additional context
This analysis and patch were prepared with the help of an AI assistant
(Claude) and reviewed by me.
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <fltk/fltk/issues/1623@github.com>
Comments are owned by the poster. All other content is copyright 1998-2026 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.