Skip to content

[GTK] Minimum size of shell is partly ignored #3332

@tmssngr

Description

@tmssngr

Describe the bug
When setting the minimum size of a "normal" (SWT.SHELL_TRIM) shell, the size is not respected correctly. With GTK4, at least the width is respected.

To Reproduce

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class GTK4MinSizeTest {

	public static void main(String[] args) {
		final Display display = new Display();

		final Shell shell = new Shell(display);
		shell.addListener(SWT.Resize, event -> System.out.println(shell.getSize()));
		final Composite ourControl = new Composite(shell, SWT.NONE);
		ourControl.addListener(SWT.Paint, event -> {
			final Rectangle bounds = ourControl.getBounds();
			event.gc.drawRectangle(1, 1, bounds.width - 3, bounds.height - 3);
			event.gc.drawString(bounds.toString(), 2, 2, true);
		});
		shell.setLayout(new Layout() {
			@Override
			protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
				return getPreferredControlSize();
			}

			@Override
			protected void layout(Composite composite, boolean flushCache) {
				final Rectangle clientArea = composite.getClientArea();
				final Point size = getPreferredControlSize();
				ourControl.setBounds(clientArea.x, clientArea.y, size.x, size.y);
			}

			private Point getPreferredControlSize() {
				return new Point(300, 200);
			}
		});

		final Point minSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
		System.out.println("min size: " + minSize);
		shell.setMinimumSize(minSize);
		shell.setSize(minSize);
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}

		display.dispose();
	}
}
  • run this snippet with SWT_GTK4=1 -> the shell has the correct initial size
  • try to make it smaller -> on my stock Ubuntu 26.04 machine I can reduce the size down to 300, 153
  • run this snippet with SWT_GTK4=0 -> the shell has the correct initial size
  • try to make it smaller -> on my stock Ubuntu 26.04 machine I can reduce the size down to 248, 103

Expected behavior
The shell must not be made smaller than the configured minimum size.

Screenshots
Image

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)
    Ubuntu 26.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions