Skip to content

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

Merged
vogella merged 1 commit intoeclipse-platform:masterfrom
vogella:gtk-per-monitor-device-zoom
Apr 30, 2026
Merged

[GTK] Use primary monitor for device zoom on multi-monitor setups#3274
vogella merged 1 commit intoeclipse-platform:masterfrom
vogella:gtk-per-monitor-device-zoom

Conversation

@vogella
Copy link
Copy Markdown
Contributor

@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.

Fixes #3273

@vogella vogella requested a review from akurtakov April 29, 2026 06:11
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 29, 2026

Test Results (linux)

   94 files  ±0     94 suites  ±0   14m 36s ⏱️ -7s
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 b40fe94.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 passed GdkMonitor handle 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.

Copy link
Copy Markdown
Member

@akurtakov akurtakov left a comment

Choose a reason for hiding this comment

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

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 .

Copy link
Copy Markdown
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

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

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@vogella vogella force-pushed the gtk-per-monitor-device-zoom branch from f2cc8d3 to 9477974 Compare April 29, 2026 10:06
Comment thread bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java Outdated
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
@vogella vogella merged commit b98f360 into eclipse-platform:master Apr 30, 2026
20 checks passed
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.

Eclipse looks broken in Ubuntu 2026-04

4 participants