Skip to content

Conversation

HeikoKlare
Copy link
Contributor

@HeikoKlare HeikoKlare commented Oct 17, 2025

Cursors are initialized with the zoom of the control on which they are set. However, cursors are usually expected to scale according to the autoscaled UI around those controls for which autoscaling was disabled.

This change adapts the cursor initializations to use the autoscale zoom of the containing shell instead of the zoom of the control itself. In consequence, cursors will have the same size in the whole shell, no matter on which control they are set.

Contributes to eclipse-gef/gef-classic#821

How to test

Best possibility to productively test is with Draw2d/GEF and according examples.

For simple testing, the following snippet can be used (adapted from #2308). The lines for different properties AUTOSCALE_DISABLED, swt.autoScale and swt.autoScale.updateOnRuntime can be changed to test different combinations. The combination that is activated by default shows the bug in the existing implementation. The others allow to test that we do not have possible regressions regarding previous issue reports, such as #2308.

In any case, a primary monitor with zoom != 100% should be used.

public class Snippet1 {

	public static void main(String[] args) {
//		System.setProperty("swt.autoScale", "200");
//		System.setProperty("swt.autoScale", "false");
		System.setProperty("swt.autoScale.updateOnRuntime", "true");
		Cursor cursor = new Cursor(null, getImageData(100), 0, 0);

		Shell shell = new Shell(SWT.NO_TRIM);
		shell.setSize(100, 100);
		shell.setLayout(new FillLayout());
		Composite c = new Composite(shell, SWT.NONE);
		c.setBackground(new Color(0, 255, 0));
		c.setData("AUTOSCALE_DISABLED", true);
		c.setCursor(cursor);
		shell.open();

		Display display = shell.getDisplay();
		while (!display.isDisposed()) {
			display.readAndDispatch();
		}
		cursor.dispose();
	}

	private static ImageData getImageData(int zoom) {
		Image image = new Image(null, 50, 50);
		try {
			GC gc = new GC(image);
			gc.setBackground(new Color(255, 0, 0));
			gc.fillRectangle(0, 0, 50, 50);
			return image.getImageData(zoom);
		} finally {
			image.dispose();
		}
	}
}

The red cursor is expected to always have half the width and height of the green shell.

With the default configuration is looks like this without the change:
cursor_old

And this is how it looks with the change:
cursor_new

Cursors are initialized with the zoom of the control on which they are
set. However, cursors are usually expected to scale according to the
autoscaled UI around those controls for which autoscaling was disabled.

This change adapts the cursor initializations to use the autoscale zoom
of the containing shell instead of the zoom of the control itself. In
consequence, cursors will have the same size in the whole shell, no
matter on which control they are set.
Copy link
Contributor

Test Results

  115 files  ±0    115 suites  ±0   13m 7s ⏱️ + 1m 12s
4 554 tests ±0  4 538 ✅ ±0  16 💤 ±0  0 ❌ ±0 
  311 runs  ±0    308 ✅ ±0   3 💤 ±0  0 ❌ ±0 

Results for commit 56d74b2. ± Comparison against base commit 3122344.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrectly sized cursors for controls with disabled autoscaling

1 participant