Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2018-05-30 18:31:33 +0000
committerEric Williams2018-06-06 20:05:49 +0000
commit820c46cbb7018b48aa8791ca34c8025246bda964 (patch)
treebfa0211d69d8f6e459047d13a329636acfd11643
parent05a9e389988d0135e5257c26f362880d3b1750af (diff)
downloadeclipse.platform.swt-820c46cbb7018b48aa8791ca34c8025246bda964.tar.gz
eclipse.platform.swt-820c46cbb7018b48aa8791ca34c8025246bda964.tar.xz
eclipse.platform.swt-820c46cbb7018b48aa8791ca34c8025246bda964.zip
Bug 319612: [Gtk] Shell.getSize() returns wrong value when created with
style SWT.RESIZE | SWT.ON_TOP Ignore hardcoded trim when calculating sizes for shells with SWT.ON_TOP and SWT.RESIZE set (i.e. "custom resize" shells). These shells already use border as set by gtk_container_set_border_width() -- subtracting the trimming in Shell.setBounds() is unnecessary. Tested on GTK3.22 on X11 and Wayland. A JUnit test case to reproduce the issue is attached. No AllNonBrowser JUnit tests fail. Change-Id: I81ebd319b623dfb3b98c533996a43e6435e80d2f Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java26
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java16
2 files changed, 35 insertions, 7 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 636f30cc7b..01d89b3dbf 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
@@ -489,8 +489,11 @@ void adjustTrim () {
* Bug in GTK. gdk_window_get_frame_extents() fails for various window
* managers, causing a large incorrect value to be returned as the trim.
* The fix is to ignore the returned trim values if they are too large.
+ *
+ * Additionally, ignore trim for Shells with SWT.RESIZE and SWT.ON_TOP set.
+ * See bug 319612.
*/
- if (trimWidth > MAXIMUM_TRIM || trimHeight > MAXIMUM_TRIM) {
+ if (trimWidth > MAXIMUM_TRIM || trimHeight > MAXIMUM_TRIM || isCustomResize()) {
display.ignoreTrim = true;
return;
}
@@ -686,10 +689,7 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) {
checkWidget();
Rectangle trim = super.computeTrimInPixels (x, y, width, height);
int border = 0;
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) {
- border = GTK.gtk_container_get_border_width (shellHandle);
- }
- if (isCustomResize ()) {
+ if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0 || isCustomResize()) {
border = GTK.gtk_container_get_border_width (shellHandle);
}
int trimWidth = trimWidth (), trimHeight = trimHeight ();
@@ -913,6 +913,12 @@ boolean isUndecorated () {
(style & (SWT.NO_TRIM | SWT.ON_TOP)) != 0;
}
+/**
+ * Determines whether a Shell has both SWT.RESIZE and SWT.ON_TOP set without SWT.NO_TRIM.
+ *
+ * @return true if this Shell has both SWT.RESIZE and SWT.ON_TOP set without
+ * SWT.NO_TRIM, false otherwise.
+ */
boolean isCustomResize () {
return (style & SWT.NO_TRIM) == 0 && (style & (SWT.RESIZE | SWT.ON_TOP)) == (SWT.RESIZE | SWT.ON_TOP);
}
@@ -1180,7 +1186,7 @@ Point getSizeInPixels () {
int width = allocation.width;
int height = allocation.height;
int border = 0;
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) {
+ if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0 || isCustomResize()) {
border = GTK.gtk_container_get_border_width (shellHandle);
}
return new Point (width + trimWidth () + 2*border, height + trimHeight () + 2*border);
@@ -2595,6 +2601,9 @@ boolean traverseEscape () {
int trimHeight () {
if ((style & SWT.NO_TRIM) != 0) return 0;
if (fullScreen) return 0;
+ // Shells with both ON_TOP and RESIZE set only use border, not trim.
+ // See bug 319612.
+ if (isCustomResize()) return 0;
boolean hasTitle = false, hasResize = false, hasBorder = false;
hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
hasResize = (style & SWT.RESIZE) != 0;
@@ -2612,6 +2621,9 @@ int trimHeight () {
int trimWidth () {
if ((style & SWT.NO_TRIM) != 0) return 0;
if (fullScreen) return 0;
+ // Shells with both ON_TOP and RESIZE set only use border, not trim.
+ // See bug 319612.
+ if (isCustomResize()) return 0;
boolean hasTitle = false, hasResize = false, hasBorder = false;
hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
hasResize = (style & SWT.RESIZE) != 0;
@@ -2780,7 +2792,7 @@ Rectangle getBoundsInPixels () {
int width = allocation.width;
int height = allocation.height;
int border = 0;
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) {
+ if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0 || isCustomResize()) {
border = GTK.gtk_container_get_border_width (shellHandle);
}
return new Rectangle (x [0], y [0], width + trimWidth () + 2*border, height + trimHeight () + 2*border);
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java
index 87a7c4fa4f..1d1cd096dc 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Shell.java
@@ -718,6 +718,22 @@ public void test_setSizeII() {
}
+@Test
+public void test_setSizeCustomResize() {
+ /*
+ * Bug 319612: test the case where Shells with SWT.RESIZE and SWT.ON_TOP
+ * were shrinking in size. Only applicable to GTK (both GTK2 and GTK3).
+ */
+ if (SwtTestUtil.isGTK) {
+ Shell testShell = new Shell (shell, SWT.RESIZE | SWT.ON_TOP);
+ Point size = new Point (200, 200);
+ testShell.setSize(size);
+ testShell.open();
+ assertEquals(size, testShell.getSize());
+ testShell.dispose();
+ }
+}
+
@Override
@Test
public void test_setSizeLorg_eclipse_swt_graphics_Point() {

Back to the top