eclipse.platform.swt
eclipse.platform.swt copied to clipboard
[GTK] `SWT.DIALOG_TRIM` calculates wrong size if `~/.swt/trims.prefs` is not cached
Describe the bug
If ~/.swt/trims.prefs is not cached yet (which more or less means that SWT runs for the first time on machine), dialogs calculate significantly wrong size.
To Reproduce
final Display display = new Display();
final Shell shell = new Shell(display, SWT.DIALOG_TRIM);
shell.setLayout (new GridLayout (1, true));
Label label = new Label(shell, 0);
label.setText(
"1. Run on Linux\n" +
"2. Delete file before running:\n" +
" ~/.swt/trims.prefs\n" +
"3. This shell's size will be incorrect\n"
);
Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
shell.setMinimumSize(size);
shell.setSize(size);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
Screenshots
Expected

Actual

Environment:
- Select the platform(s) on which the behavior is seen:
-
- [ ] All OS
-
- [ ] Windows
-
- [x] Linux
-
- [ ] macOS
When debugging the snippet, I observed the height of 325px (it can be seen on screenshots above that it's too tall).
I found that the value is composed the following way:
Important values
[1] 5 = SWT display.trimWidths [TRIM_TITLE_BORDER]
[2] 28 = SWT display.trimHeights[TRIM_TITLE_BORDER]
[3] 23 = GTK get_shadow_width().top
[4] 29 = GTK get_shadow_width().bottom
[5] 45 = GTK gtk_widget_get_preferred_height (priv->title_box).natural
[6] 200 = GTK NO_CONTENT_CHILD_NAT
[7] 297 = 200 + 23 + 29 + 45 // [6] + [3] + [4] + [5]
In 'gtk_window_realize()'
GTK sets 'gtk_widget_set_allocation()'
[8] 325 = 297 + 28 // [7] + [2]
In 'Shell.adjustTrim()' called from 'Shell.setVisible()'
SWT sets 'gtk_widget_set_size_request()'
297 = gtk_widget_get_allocation() seen by SWT snippet
297 = gdk_window_get_frame_extents() seen by SWT snippet
325 = screen client rect