Skip to content

[GTK] Use primary monitor for device zoom on multi-monitor setups#10

Open
vogella wants to merge 1 commit intomasterfrom
gtk-per-monitor-device-zoom
Open

[GTK] Use primary monitor for device zoom on multi-monitor setups#10
vogella wants to merge 1 commit intomasterfrom
gtk-per-monitor-device-zoom

Conversation

@vogella
Copy link
Copy Markdown
Owner

@vogella vogella commented Apr 29, 2026

On GTK, Display._getDeviceZoom(long) ignored its monitor argument and always queried the monitor at virtual coordinate (0,0); Device.getDeviceZoom() did the same on GTK3. On mixed-DPI multi-monitor setups this made every shell pick up the (0,0) monitor's scale factor, so a HiDPI laptop panel positioned at the top-left of the virtual screen would force shells on a standard-density secondary monitor to render at 2x.

This change honors the passed monitor handle in _getDeviceZoom and selects the GDK primary monitor for the initial Display zoom on GTK3, falling back to the (0,0) monitor only when no primary is available (e.g. on Wayland). Monitor.zoom values returned by getMonitors() on X11/Xwayland are now per-monitor instead of all reflecting the (0,0) monitor.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the monitor detection logic in Device.java and Display.java to prioritize the primary monitor and include a fallback to the monitor at coordinates (0,0). A review comment suggests refactoring this duplicated lookup logic into a shared helper method to improve code maintainability.

Comment on lines +6265 to +6271
if (monitor == 0) {
long display = GDK.gdk_display_get_default();
monitor = GDK.gdk_display_get_primary_monitor(display);
if (monitor == 0) {
monitor = GDK.gdk_display_get_monitor_at_point(display, 0, 0);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic for determining the default monitor is duplicated in Device.getDeviceZoom(). To improve maintainability, consider extracting this logic into a protected static helper method in the Device class and reusing it in both places.

For example, you could add the following method to Device.java:

protected static long getDefaultMonitor(long display) {
    long monitor = GDK.gdk_display_get_primary_monitor(display);
    if (monitor == 0) {
        monitor = GDK.gdk_display_get_monitor_at_point(display, 0, 0);
    }
    return monitor;
}

This new helper method could then be used here and in Device.getDeviceZoom() to simplify the code and remove the duplication.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 29, 2026

Test Results (linux)

   94 files  ±0     94 suites  ±0   14m 33s ⏱️ -29s
4 597 tests ±0  4 373 ✅ ±0  224 💤 ±0  0 ❌ ±0 
3 383 runs  ±0  3 308 ✅ ±0   75 💤 ±0  0 ❌ ±0 

Results for commit 6ea4c3f. ± Comparison against base commit 81a811a.

♻️ This comment has been updated with latest results.

@vogella vogella force-pushed the gtk-per-monitor-device-zoom branch 2 times, most recently from f2cc8d3 to 9477974 Compare April 29, 2026 10:06
Display._getDeviceZoom(long) ignored its monitor argument and always
queried the monitor at virtual coordinate (0,0), so every monitor
returned by getMonitors() reported the (0,0) monitor's scale factor on
X11/Xwayland. Device.getDeviceZoom() did the same on GTK3 for the
initial Display zoom.

On mixed-DPI multi-monitor setups this caused shells opened on a
non-(0,0) monitor to be sized for the wrong scale: e.g. a HiDPI laptop
panel sitting at the top-left of the virtual screen made shells on a
standard-density secondary monitor render at 2x.

Honor the passed monitor handle in _getDeviceZoom and pick the GDK
primary monitor for the initial zoom on GTK3, falling back to the
(0,0) monitor only when no primary is available (e.g. on Wayland).

Fixes eclipse-platform#3273
@vogella vogella force-pushed the gtk-per-monitor-device-zoom branch from 9477974 to 6ea4c3f Compare April 30, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant