[GTK] Use primary monitor for device zoom on multi-monitor setups#10
[GTK] Use primary monitor for device zoom on multi-monitor setups#10
Conversation
There was a problem hiding this comment.
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.
| 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
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.