Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2019-06-12 16:26:37 -0400
committerEric Williams2019-06-14 09:35:39 -0400
commit92a04bd1ad8bb54084f77a21b000a8224e3d7e7b (patch)
tree201f1c7577e448a9703fc6e3d03997a48b3ec5c9
parent13fb2739bfa6ffe9f8b07a725be5b55157c720c3 (diff)
downloadeclipse.platform.swt-92a04bd1ad8bb54084f77a21b000a8224e3d7e7b.tar.gz
eclipse.platform.swt-92a04bd1ad8bb54084f77a21b000a8224e3d7e7b.tar.xz
eclipse.platform.swt-92a04bd1ad8bb54084f77a21b000a8224e3d7e7b.zip
Bug 547375: [GTK] Display.getBounds() returns wrong values for most
multi monitor setups Re-work the Display.getBounds() functionality to account for different monitor layouts, resolutions, and more. Tested on GTK3.24 with Wayland and various screen layouts. No AllNonBrowser JUnit tests fail. Change-Id: I7b7c8493e26d386031b67a889588d3ea88e95cf3 Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java27
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug547375_DisplayBounds.java35
2 files changed, 46 insertions, 16 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
index 7b6f1a4323..757369b3a3 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
@@ -1646,39 +1646,34 @@ Rectangle getBoundsInPixels () {
checkDevice ();
int monitorCount;
Rectangle bounds = new Rectangle(0, 0, 0, 0);
+ int maxWidth = 0, maxHeight = 0;
if (GTK.GTK_VERSION >= OS.VERSION(3, 22, 0)) {
long display = GDK.gdk_display_get_default ();
monitorCount = GDK.gdk_display_get_n_monitors (display);
if (monitorCount > 0) {
- GdkRectangle dest = new GdkRectangle ();
for (int i = 0; i < monitorCount; i++) {
long monitor = GDK.gdk_display_get_monitor(display, i);
+ GdkRectangle dest = new GdkRectangle ();
GDK.gdk_monitor_get_geometry (monitor, dest);
- if (i == 0) {
- bounds.width = dest.width;
- bounds.height = dest.height;
- } else {
- bounds.width += dest.x;
- bounds.height += dest.y;
- }
+ if ((dest.x + dest.width) > maxWidth) maxWidth = dest.x + dest.width;
+ if ((dest.y + dest.height) > maxHeight) maxHeight = dest.y + dest.height;
}
+ bounds.width = maxWidth;
+ bounds.height = maxHeight;
return bounds;
}
} else {
long screen = GDK.gdk_screen_get_default();
monitorCount = GDK.gdk_screen_get_n_monitors(screen);
if (monitorCount > 0) {
- GdkRectangle dest = new GdkRectangle ();
for (int i = 0; i < monitorCount; i++) {
+ GdkRectangle dest = new GdkRectangle ();
GDK.gdk_screen_get_monitor_geometry (screen, i, dest);
- if (i == 0) {
- bounds.width = dest.width;
- bounds.height = dest.height;
- } else {
- bounds.width += dest.x;
- bounds.height += dest.y;
- }
+ if ((dest.x + dest.width) > maxWidth) maxWidth = dest.x + dest.width;
+ if ((dest.y + dest.height) > maxHeight) maxHeight = dest.y + dest.height;
}
+ bounds.width = maxWidth;
+ bounds.height = maxHeight;
return bounds;
}
}
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug547375_DisplayBounds.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug547375_DisplayBounds.java
new file mode 100644
index 0000000000..bce7681379
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug547375_DisplayBounds.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Red Hat and others. All rights reserved.
+ * The contents of this file are made available under the terms
+ * of the GNU Lesser General Public License (LGPL) Version 2.1 that
+ * accompanies this distribution (lgpl-v21.txt). The LGPL is also
+ * available at http://www.gnu.org/licenses/lgpl.html. If the version
+ * of the LGPL at http://www.gnu.org is different to the version of
+ * the LGPL accompanying this distribution and there is any conflict
+ * between the two license versions, the terms of the LGPL accompanying
+ * this distribution shall govern.
+ *
+ * Contributors:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class Bug547375_DisplayBounds {
+
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ shell.setSize(500, 200);
+ System.out.println("Display bounds are " + display.getBounds());
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ }
+}

Back to the top