Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GTK] Disabled toolbar icons and button images are double size on hi-res screen #315

Closed
Phillipus opened this issue Aug 14, 2022 · 6 comments · Fixed by #327
Closed

[GTK] Disabled toolbar icons and button images are double size on hi-res screen #315

Phillipus opened this issue Aug 14, 2022 · 6 comments · Fixed by #327
Labels
Linux/GTK Happens on Linux

Comments

@Phillipus
Copy link
Contributor

Phillipus commented Aug 14, 2022

Describe the bug
I'm bringing this over from https://bugs.eclipse.org/bugs/show_bug.cgi?id=575492 as the problem still exists.

Disabled images in buttons and toolbar items are the wrong size when DPI scaling is at 200%

To Reproduce
Run Snippet at 200% scaling to see that the disabled button image is scaled incorrectly and is too big and off-centred.

Expected behavior
The disabled button image should be scaled correctly when DPI is at 200% scale.

Screenshots
Disabled button at 100% scale:

100-scale

Disabled button at 200% scale:

200-scale

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)
    Linux Mint Cinnamon X11. Didn't test on Wayland.

  2. JRE/JDK version
    AdoptOpeJDK 11.0.15

Version since
Worked OK in Eclipse 4.15, but not since

@Phillipus
Copy link
Contributor Author

Snippet to reproduce:

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class DisabledButtonImageTest {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new GridLayout());
        shell.setText("Button Image");

        Image image = display.getSystemImage(SWT.ICON_WARNING);

        Button button = new Button(shell, SWT.FLAT);
        button.setImage(image);
        button.setEnabled(false);

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

To test this at 200% scaling either use a Hi-DPI monitor or set an Environment Variable GDK_SCALE=2 in the launch configuration.

@lshanmug lshanmug added the Linux/GTK Happens on Linux label Aug 16, 2022
@joel-majano
Copy link
Contributor

joel-majano commented Aug 18, 2022

Reproduced the bug in XWayland (Wayland using GDK_BACKEND=x11). This bug does not affect Wayland itself.

EDIT: This bug does affect Wayland. The issue is that GDK_SCALE=2 does not change the device zoom in Wayland, but it does in X11. To test this bug in Wayland I had to change my display scale directly from Fedora 36's settings.

@AlexisDrogoul
Copy link

Affects Ubuntu with Eclipse 2022-03 (4.23) (see https://github.com/gama-platform/gama/issues/3460). Disabled icons for buttons in the Coolbar (contributed by plugin.xml) and regular buttons are doubled in size with a 2x scale/HiDPI setting. The same happens to ToolItems unless a disabled icon is passed to them.

@joel-majano
Copy link
Contributor

joel-majano commented Aug 21, 2022

Looking at this some more, to create the disabled image we copy from the image we get using getSystemImage. In this case, the icon is already scaled when it is first created. When creating the copy in the Image constructor, it copies the currentDeviceZoom and performs another scale up using cairo_surface_set_device_scale. This is why the image scaled 4x.

The fix is to check if DPIUtil.getDeviceZoom() is equal to the copied currentDeviceZoom, and if it is, skip the scaling. I have a patch ready which I will upload in the morning eastern time.

EDIT: ToolItem has this issue too. Testing on the same patch causes the ToolItem image to be correctly "sized" i.e not cut off. However it is much too large compared to the regular image. I suspect this is due to the image setting working differently but I'm not sure at the moment. Will try to find out before pushing the patch.

@Phillipus
Copy link
Contributor Author

Might be a clue in this bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=568407

Maybe the fix for that bug wasn't applied to disabled images?

@joel-majano
Copy link
Contributor

joel-majano commented Aug 22, 2022

I was able to find the issue on the toolbar icon size; it was due to a bug in ImageList. Pushed the fix.

EDIT: Please test and let me know if there are any regressions that are caused by this patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linux/GTK Happens on Linux
Projects
None yet
4 participants