Skip to content

x11: report a resolution per monitor and size the pointer for it - #253

Open
probonopd wants to merge 1 commit into
gnustep:masterfrom
probonopd:fix-per-screen-scale
Open

probonopd wants to merge 1 commit into
gnustep:masterfrom
probonopd:fix-per-screen-scale

Conversation

@probonopd

Copy link
Copy Markdown
Contributor

With two monitors of different pixel density, -resolutionForScreen: returns 72x72 for every monitor, so the gui cannot tell them apart and draws everything at one scale factor.

This PR belongs together with gnustep/libs-gui#1019, which gives each NSScreen and each window its own factor. Please merge the libs-gui one first; this one depends on it to lay windows out per monitor.

-resolutionForScreen: now returns the resolution of the monitor it is asked for (NSScreen already passes the monitor index), taken from the RandR output property "DPI" (INTEGER, 96 = 1.0x). XLibre creates that property on every output, and on other servers any client, such as a display configuration tool, can create it with XRRChangeOutputProperty. As an opt-in, the user default GSScreenScaleFromSize derives it from the output's physical size, rounded to GSScaleFactorStep (0.25). A change of "DPI" is handled like a screen change. When every monitor reports the same value, which includes every single-monitor setup, 72x72 is returned as before and GSScaleFactor stays in charge.

The rest makes windows behave when they cross monitors: styleoffsets:::::window: returns one window's own _NET_FRAME_EXTENTS, kept per window and refreshed on change, since a window manager that draws title bars per monitor gives windows of the same style different extents; that resize is delivered in order with the ConfigureNotify ones; and ConfigureNotify sizes older than the last resize request are ignored, which otherwise made a window lose width on every round trip between monitors. Cursors get the size of the monitor under the pointer (theme cursors at 24 px times its factor, image cursors resampled from points); with every monitor at 1.0 they are made exactly as before.

The size rule and the resampling are covered by a new test:

$ cd Tests && gnustep-tests x11/cursorscale.m
     14 Passed tests

The rest of Tests/x11 gives the same result with and without this branch here (4 failures in decorationfallback.m, frameextents.m and reparentoffsets.m on master too, because those tests load the installed backend). Live, on an Xorg with two dummy outputs whose "DPI" was set to 192 and 96, a window with a 300x200 content rect is 600x400 pixels on the first and 300x200 on the second, and setting "DPI" at run time converts open windows.

Known limits: the "DPI" property is only created automatically by XLibre; on Xorg something has to set it (the GSScreenScaleFromSize fallback is opt-in because the server's physical sizes are not always trustworthy); cursors without a theme come from the cursor font in one size.

cc @pkgdemon

resolutionForScreen: always returned 72x72, so the gui could not tell
monitors of different pixel density apart.

It now returns the resolution of the monitor it is asked for, from the
RandR output property "DPI" (96 = 1.0x, created by XLibre for every
output and settable by any client on other servers), or, when the user
default GSScreenScaleFromSize is set, from the output's physical size,
rounded to GSScaleFactorStep (0.25). A change of "DPI" is handled like
a screen change. When every monitor reports the same value, 72x72 is
returned as before, so GSScaleFactor stays in charge.

The new styleoffsets:::::window: returns the offsets of one window from
its own _NET_FRAME_EXTENTS, kept per window and refreshed when the
property changes, since a window manager that draws title bars per
monitor gives windows of the same style different extents. The resize
event for such a change is delivered in order with those of
ConfigureNotify, and ConfigureNotify sizes older than the last resize
request are ignored, so a window moving between monitors keeps the size
the gui gave it.

Cursors get the size of the monitor under the pointer: theme cursors
are loaded at 24 pixels times its factor and image cursors are
resampled from their size in points (Source/x11/cursorscale.c, tested
in Tests/x11/cursorscale.m). When every monitor runs at 1.0, cursors
are made exactly as before.
@probonopd
probonopd force-pushed the fix-per-screen-scale branch from aaeba43 to 4de42f2 Compare October 26, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant