Skip to content

[GTK] Pick largest monitor as device-zoom base when no primary is set#11

Open
vogella wants to merge 1 commit into
masterfrom
gtk-wayland-zoom-largest-monitor
Open

[GTK] Pick largest monitor as device-zoom base when no primary is set#11
vogella wants to merge 1 commit into
masterfrom
gtk-wayland-zoom-largest-monitor

Conversation

@vogella
Copy link
Copy Markdown
Owner

@vogella vogella commented May 19, 2026

Follow-up to b98f360.
On Wayland, gdk_display_get_primary_monitor() always returns NULL because the protocol has no concept of a primary monitor, so the fallback in Device.getPrimaryMonitor(long) was just gdk_display_get_monitor_at_point(display, 0, 0), which arbitrarily picks whichever output the compositor anchors at the virtual origin. That is exactly the behaviour issue eclipse-platform#3273 was meant to fix.

This adds a Wayland-friendly middle step: when no primary is reported, pick the monitor with the largest geometry, which is a stable compositor-independent heuristic for the user's main work display and matches the X11 answer in the common case. The (0,0) fallback stays as a defensive last resort for single-monitor setups.

Scope is intentionally narrow.
SWT's GTK port still uses a single global device zoom, so this only improves the startup pick on mixed-DPI Wayland layouts; per-monitor rescaling at runtime (as Win32 already does) is the real fix and is tracked separately.
No JNI changes, no native rebuild required.

Follow-up to b98f360. On Wayland, gdk_display_get_primary_monitor()
always returns NULL because the protocol has no notion of a primary
monitor, so Device.getPrimaryMonitor(long) fell back to
gdk_display_get_monitor_at_point(display, 0, 0). That returns whichever
output the compositor happens to anchor at the virtual origin, which is
exactly the arbitrary choice issue eclipse-platform#3273 was trying to get rid of: it
may pick the HiDPI laptop panel or the standard-density external
depending on layout, leaving the initial device zoom dependent on
compositor placement.

Insert a Wayland-friendly middle step: when no primary is reported, pick
the monitor with the largest geometry. This is a stable, compositor-
independent heuristic for the user's main work display and matches the
answer gdk_display_get_primary_monitor() gives on X11 in the common
case. The (0,0) fallback is preserved for single-monitor setups and as
a final defensive path.

This only improves the startup pick. A single global device zoom still
cannot represent a mixed-DPI layout correctly when shells move between
monitors; per-monitor rescaling at runtime (as on Win32) is the real
fix and is tracked separately.

No JNI changes; uses already-bound gdk_display_get_n_monitors and
gdk_monitor_get_geometry.
@vogella vogella force-pushed the gtk-wayland-zoom-largest-monitor branch from 5191641 to 6300294 Compare May 19, 2026 10:30
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 improves monitor selection in Device.java by introducing a heuristic to pick the largest monitor when no primary monitor is detected, specifically addressing issues on Wayland. The changes include a new pickLargestMonitor method. Feedback was provided to optimize this method by moving the GdkRectangle instantiation outside the loop to avoid redundant object allocations.

I am having trouble creating individual review comments. Click here to see my feedback.

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java (1164-1167)

medium

The GdkRectangle object is instantiated inside the loop. Since it is only used to receive geometry data from the native call, it can be instantiated once outside the loop and reused to avoid unnecessary object allocations.

	GdkRectangle r = new GdkRectangle();
	for (int i = 0; i < n; i++) {
		long m = GDK.gdk_display_get_monitor(display, i);
		if (m == 0) continue;

@github-actions
Copy link
Copy Markdown

Test Results (linux)

   94 files  ±0     94 suites  ±0   14m 22s ⏱️ ±0s
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 6300294. ± Comparison against base commit 7f9089e.

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