[GTK] Use primary monitor for device zoom on multi-monitor setups#3274
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes incorrect zoom/DPI selection on GTK multi-monitor setups by ensuring SWT queries the intended monitor (or a sensible default) rather than always using the monitor at virtual (0,0). This aligns shell rendering scale with the monitor the shell is actually on and fixes per-monitor Monitor.zoom reporting on X11/Xwayland.
Changes:
- Update
Display._getDeviceZoom(long)to honor the passedGdkMonitorhandle and only fall back to primary / (0,0) when no monitor is provided. - Update GTK3
Device.getDeviceZoom()initialization logic to prefer the GDK primary monitor, falling back to (0,0) when needed.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java |
Uses the provided monitor handle when computing zoom, fixing per-monitor zoom reporting on GTK3 X11. |
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java |
Sets initial GTK3 device zoom from the primary monitor (with fallback), improving default scaling on multi-monitor setups. |
akurtakov
left a comment
There was a problem hiding this comment.
This looks good. Unfortunately, I don't have a multimonitor setup to test right now.
FWIW, on X11 monitor at 0,0 was the primary monitor but with Wayland this is no longer mandatory .
HeikoKlare
left a comment
There was a problem hiding this comment.
Conceptually, the change looks sound. I have currently no chance to test it. But from how I understand the control flows, one of the changes seems obsolete and maybe there is further potential for simplification/DRY, see the specific comment.
| } | ||
|
|
||
| static int _getDeviceZoom (long monitor_num) { | ||
| static int _getDeviceZoom (long monitor) { |
There was a problem hiding this comment.
I find this method and the change to it a bit confusing. It only seems to be called from a code branch is is specific to X11 + GTK3. According to @akurtakov, in that combination the monitor at 0,0 and the primary monitor are the same anyway, so this change should be obsolete (see #3274 (review)). Since the method originally did not use the passed monitor anyway, should there rather be a getPrimaryMonitor() method used at both placed changed in this PR?
There was a problem hiding this comment.
The change isn't obsolete: the primary-monitor fallback only runs when monitor == 0 (and yes, that's a no-op on X11+GTK3).
The fix is honoring the non-zero handle, since getMonitors() (Display.java:2715) passes monitor.handle per monitor and the old code ignored it, making every Monitor.zoom identical.
getPrimaryMonitor() helper sounds ok to me, it is just three lines but I can adjust the change accordingly.
There was a problem hiding this comment.
If that's true, it's a bug completely independent of this PR. Are you sure the assessment is correct? To me it sounds as if the zoom set to a monitor on X11 / GTK3 should effectively be the one of the primary monitor to make SWT work correctly (which is why the method argument is ignored). If that is not the case, then your change is probably correct but, as said, independent of the purpose of this PR.
There was a problem hiding this comment.
I fail to understand your response. Without this patch my primary monitor is not used, it always uses the monitor in the fixed coordinates. So Eclipse starts completely broken on my primary device. If I start it on my laptop it starts fine, as this fits to the hard code coordinates
There was a problem hiding this comment.
Are you using Wayland or X11? I understood this comment #3274 (review) as if the change should effectively be a no-op on X11 because primary monitor zoom and zoom at (0,0) should be equal. And when using Wayland, this method is not called anyway.
f2cc8d3 to
9477974
Compare
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
9477974 to
6ea4c3f
Compare
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
_getDeviceZoomand 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.zoomvalues returned bygetMonitors()on X11/Xwayland are now per-monitor instead of all reflecting the (0,0) monitor.Fixes #3273