From 4c24b9c6afa1a9e9d688d6efa52af525b63d936f Mon Sep 17 00:00:00 2001 From: Nick Ermakov Date: Mon, 5 Oct 2026 20:21:39 +0700 Subject: [PATCH 1/3] fix(x11): single-monitor frame from root geometry, not cached CRTC RRSetScreenSize (xrandr --fb -- and what streaming/remote-desktop servers use) does not bump the resources config timestamp that XRRGetScreenResources caches on, so crtc_info can serve stale geometry after a live resolution change. Xvfb additionally exposes several outputs with only one connected, so a check on the raw output count inside the loop does not fire. Normalize the frame after the RANDR loop, on the connected-output count, from DisplayWidth/DisplayHeight (already refreshed through XRRUpdateConfiguration when RRScreenChangeNotify arrives). Validated with a pixel-assertion harness (Xvfb+RandR, multi-hop 1280x800 <-> 1680x1050 at GSScaleFactor 2.0, GNUstep Workspace desktop): 13/13 assertions on baseline, after grow-resize and after back-resize, three consecutive runs. Before the fix the desktop window was clamped against the stale 1280-wide screen and ended up at origin.x = -400. --- Source/x11/XGServerWindow.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Source/x11/XGServerWindow.m b/Source/x11/XGServerWindow.m index 80ff8d58..7e89ccba 100644 --- a/Source/x11/XGServerWindow.m +++ b/Source/x11/XGServerWindow.m @@ -4873,6 +4873,18 @@ - (NSArray *)screenList } monitorsCount = mi; + /* A single monitor always spans the whole X screen. The CRTC + * data can be stale here because RRSetScreenSize (xrandr --fb, + * and what streaming servers use) does not bump the resources + * config timestamp that XRRGetScreenResources caches on, and + * Xvfb typically exposes several outputs with only one + * connected. The root geometry from DisplayWidth/DisplayHeight + * (refreshed above through XRRUpdateConfiguration) is the + * reliable source, so normalize after the loop, on the + * connected-output count. */ + if (monitorsCount == 1) + monitors[0].frame = + NSMakeRect(0, 0, xScreenSize.width, xScreenSize.height); if (monitorsCount != 0) { XRRFreeScreenResources(screen_res); From 873324f9d2e35e9983587660edc60861c00469f5 Mon Sep 17 00:00:00 2001 From: e4779 Date: Sat, 17 Oct 2026 10:40:30 +0700 Subject: [PATCH 2/3] tests(x11): screen frame versus fb-only resize and work area Runs its own Xvfb and re-executes itself for every reading, so each one is what a freshly launched application would see. Covers an fb-only resize (RRSetScreenSize without a mode change, what xrandr --fb and streaming servers issue), the same resize with _NET_WORKAREA published, and a mode change as the control case. --- Tests/x11/screenframe.m | 146 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 Tests/x11/screenframe.m diff --git a/Tests/x11/screenframe.m b/Tests/x11/screenframe.m new file mode 100644 index 00000000..14e79848 --- /dev/null +++ b/Tests/x11/screenframe.m @@ -0,0 +1,146 @@ +/* The frame of a screen has to track the X screen rather than the CRTC + * data: RRSetScreenSize (xrandr --fb, streaming servers) resizes the + * framebuffer without touching the CRTC. With a window manager the frame + * has to stay the _NET_WORKAREA it publishes. The test runs its own Xvfb + * and re-executes itself per reading, so each one is what a freshly + * launched application would see. */ +#import +#import "Testing.h" +#include "config.h" + +#if defined(BUILD_SERVER) && defined(SERVER_x11) && BUILD_SERVER == SERVER_x11 + +#import +#import +#import +#import +#import +#import + +static const char *display = ":9771"; +static const char *selfExe = "./screenframe"; + +static int +readFrame(float *w, float *h) +{ + char cmd[600]; + FILE *p; + + snprintf(cmd, sizeof(cmd), "%s --dump 2>/dev/null", selfExe); + p = popen(cmd, "r"); + if (p == NULL) + { + return -1; + } + *w = *h = -1; + fscanf(p, "%f %f", w, h); + pclose(p); + return (*w < 0) ? -1 : 0; +} + +int +main(int argc, const char **argv) +{ + float w = -1; + float h = -1; + + if (argc > 1 && strcmp(argv[1], "--dump") == 0) + { + extern void initialize_gnustep_backend(void); + GSDisplayServer *srv; + NSRect f; + + initialize_gnustep_backend(); + srv = [GSDisplayServer serverWithAttributes: nil]; + if (srv == nil) + { + return 1; + } + [GSDisplayServer setCurrentServer: srv]; + f = [[NSScreen mainScreen] frame]; + printf("%.0f %.0f\n", f.size.width, f.size.height); + return 0; + } + + START_SET("screen frame") + + if (argc > 0 && argv[0] != NULL) + { + selfExe = argv[0]; + } + + if (system("command -v Xvfb >/dev/null 2>&1" + " && command -v xrandr >/dev/null 2>&1" + " && command -v xprop >/dev/null 2>&1") != 0) + { + SKIP("needs Xvfb with RANDR, xrandr and xprop") + } + + setenv("DISPLAY", display, 1); + { + char cmd[600]; + + snprintf(cmd, sizeof(cmd), + "Xvfb %s -screen 0 1280x800x24 +extension RANDR" + " -nolisten tcp >/dev/null 2>&1 & sleep 1", display); + if (system(cmd) != 0 || readFrame(&w, &h) != 0) + { + SKIP("the Xvfb display did not come up") + } + } + + PASS(w == 1280 && h == 800, + "a fresh application sees the frame of the initial screen"); + + system("xrandr --fb 1680x1050"); + usleep(200000); + if (readFrame(&w, &h) != 0) + { + SKIP("reading the frame failed") + } + PASS(w == 1680 && h == 1050, + "the frame follows the framebuffer after an fb-only resize," + " which leaves the CRTC reporting the old mode"); + + system("xprop -root -f _NET_WORKAREA 32c" + " -set _NET_WORKAREA '0, 0, 1680, 1000'"); + usleep(200000); + if (readFrame(&w, &h) != 0) + { + SKIP("reading the frame failed") + } + PASS(!(w == 1680 && h == 1050), + "a published work area keeps the frame from following the framebuffer"); + + system("xprop -root -remove _NET_WORKAREA"); + system("xrandr --newmode t1024x768 65.0 1024 1048 1184 1344" + " 768 771 777 806 -hsync -vsync"); + system("xrandr --addmode screen t1024x768"); + system("xrandr --output screen --mode t1024x768"); + usleep(200000); + if (readFrame(&w, &h) != 0) + { + SKIP("reading the frame failed") + } + PASS(w == 1024 && h == 768, + "the frame follows a mode change"); + + system("pkill -x Xvfb"); + + END_SET("screen frame") + + return 0; +} + +#else + +int +main(int argc, const char **argv) +{ + START_SET("screen frame") + SKIP("back is not built with the x11 server") + END_SET("screen frame") + return 0; +} + +#endif From c7864913698e6e9a96ab0a3451eb6a44885c4cd6 Mon Sep 17 00:00:00 2001 From: e4779 Date: Sat, 17 Oct 2026 10:40:30 +0700 Subject: [PATCH 3/3] fix(x11): narrow the root-geometry frame to setups without a work area An fb-only resize leaves the CRTC reporting the mode it still drives rather than the X screen, and with no window manager there is no _NET_WORKAREA either: the root geometry is the only authority for the screen. Under a window manager the frame must stay the published work area, which the unconditional form overrode; the new test in Tests/x11 catches both directions. --- Source/x11/XGServerWindow.m | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Source/x11/XGServerWindow.m b/Source/x11/XGServerWindow.m index 7e89ccba..3de61c65 100644 --- a/Source/x11/XGServerWindow.m +++ b/Source/x11/XGServerWindow.m @@ -4873,16 +4873,10 @@ - (NSArray *)screenList } monitorsCount = mi; - /* A single monitor always spans the whole X screen. The CRTC - * data can be stale here because RRSetScreenSize (xrandr --fb, - * and what streaming servers use) does not bump the resources - * config timestamp that XRRGetScreenResources caches on, and - * Xvfb typically exposes several outputs with only one - * connected. The root geometry from DisplayWidth/DisplayHeight - * (refreshed above through XRRUpdateConfiguration) is the - * reliable source, so normalize after the loop, on the - * connected-output count. */ - if (monitorsCount == 1) + /* An fb-only resize (xrandr --fb, streaming servers) leaves + * the CRTC reporting the old mode; with no work area published + * the root geometry is the only authority for the screen. */ + if (monitorsCount == 1 && workAreas == nil) monitors[0].frame = NSMakeRect(0, 0, xScreenSize.width, xScreenSize.height); if (monitorsCount != 0)