Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXi Yan2018-07-20 21:03:08 +0000
committerAlexander Kurtakov2018-08-04 07:42:28 +0000
commit9d77cdae8ede54cd29d86993fdb4c85b4d7229aa (patch)
tree0f4946f86a246ade65ed112e3f11a6c31919c1e4
parent39c1d77a97d9228bcc48581f54842a54e717418b (diff)
downloadeclipse.platform.swt-9d77cdae8ede54cd29d86993fdb4c85b4d7229aa.tar.gz
eclipse.platform.swt-9d77cdae8ede54cd29d86993fdb4c85b4d7229aa.tar.xz
eclipse.platform.swt-9d77cdae8ede54cd29d86993fdb4c85b4d7229aa.zip
Bug 336238 - Shell.setBounds sometimes fails to set the right location
Calling gtk_widget_show for the first time before gtk_widget_resize assumes the initial default size for any subsequent calls to gtk_widget_move. This causes issue with shell.setBounds where the location can only be moved to a limited bound on the screen corresponding to the default size by the window manager, even when the new resized shell is smaller and is able to move to further x, y position without being cutoff by the screen. The fix is to set the default size to the smallest possible (1, 1) before gtk_widget_show. Tested with attached JUnit test. Change-Id: I3f20a6aaed5972bfda3775816aab96202bae7e5d Signed-off-by: Xi Yan <xixiyan@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java21
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug336238_ShellSetBoundFailTest.java46
2 files changed, 66 insertions, 1 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
index 39c0c8a7d9..d2710b6031 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
@@ -2443,11 +2443,30 @@ public void setVisible (boolean visible) {
* unminimized or shown on the desktop.
*/
mapped = false;
+ /*
+ * Bug/Feature in GTK: calling gtk_widget_show for the first time before
+ * gtk_widget_resize assumes the initial default size for any subsequent calls
+ * to gtk_widget_move. This causes issue with shell.setBounds where the
+ * location can only be moved to a limited bound on the screen corresponding
+ * to the default size by the window manager, even when the new resized shell
+ * is smaller and is able to move to further x, y position without being cutoff by
+ * the screen. The fix is to set the default size to the smallest possible (1, 1)
+ * before gtk_widget_show.
+ */
+ if (oldWidth == 0 && oldHeight == 0) {
+ int [] init_width = new int[1], init_height = new int[1];
+ GTK.gtk_window_get_size(shellHandle, init_width, init_height);
+ GTK.gtk_window_resize(shellHandle, 1, 1);
+ GTK.gtk_widget_show (shellHandle);
+ GTK.gtk_window_resize(shellHandle, init_width[0], init_height[0]);
+ resizeBounds (init_width[0], init_height[0], false);
+ } else {
+ GTK.gtk_widget_show (shellHandle);
+ }
/**
* Feature in GTK: This handles grabbing the keyboard focus from a SWT.ON_TOP window
* if it has editable fields and is running Wayland. Refer to bug 515773.
*/
- GTK.gtk_widget_show (shellHandle);
if (enableWindow != 0) GDK.gdk_window_raise (enableWindow);
if (isDisposed ()) return;
if (!(OS.isX11() && GTK.GTK_IS_PLUG (shellHandle))) {
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug336238_ShellSetBoundFailTest.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug336238_ShellSetBoundFailTest.java
new file mode 100644
index 0000000000..12f501d398
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug336238_ShellSetBoundFailTest.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Red Hat and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.swt.widgets.Shell;
+import org.junit.Test;
+
+public class Bug336238_ShellSetBoundFailTest {
+
+ static int cycles = 100;
+
+ @Test
+ public void testSetBounds() {
+
+ int x;
+ int y;
+ int width = 100;
+ int height = 100;
+
+ for (int i = 0; i < cycles; i++) {
+
+ x = (new Double(Math.random() * 1000)).intValue();
+ y = (new Double(Math.random() * 1000)).intValue() + 27;
+
+ Shell testShell = new Shell();
+ testShell.open();
+
+ testShell.setBounds(x, y, width, height);
+
+ assertEquals(x, testShell.getLocation().x);
+ assertEquals(y, testShell.getLocation().y);
+ testShell.close();
+ }
+ }
+
+}

Back to the top