Skip to content

Cursors not correctly sized when using swt.autoScale on a HighDPI screen. #2308

@ptziegler

Description

@ptziegler

I'm using a monitor with 150% zoom. Now consider the following snippet:

package test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

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

                Shell shell = new Shell(SWT.NO_TRIM);
                shell.setSize(100, 100);
                shell.setCursor(cursor);
                shell.setBackground(new Color(0, 255, 0));
                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();
                }
        }
}

Expectation: The cursor should always take up 25% of the shell.

SWT 3.128.0 (2024-12), exactly right:
Image

SWT 3.129.0 (2025-03), way too big:
Image

SWT 3.130.0 (2025-06), too big:
Image

SWT 3.131.0 (2025-09), too small:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    HiDPIIssues related to High resolution monitorsWindowsHappens on Windows OS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions