dorkbox / SystemTray

Cross-platform SystemTray support for Swing/AWT, macOS, GtkStatusIcon, and AppIndicator on Java 8+
Other
446 stars 58 forks source link

NullPointerException when rght-click the tray icon #211

Open Zmax0 opened 7 months ago

Zmax0 commented 7 months ago

Hello,

resolution is 2880x1800 with 200% scaling

DEBUG [main] d.s.SystemTray - Version 4.4
DEBUG [main] d.s.SystemTray - OS: Windows 11
DEBUG [main] d.s.SystemTray - Arch: amd64
DEBUG [main] d.s.SystemTray - Oracle Corporation OpenJDK 64-Bit Server VM 21.0.2
DEBUG [main] d.s.SystemTray - JPMS enabled: true
DEBUG [main] d.s.SystemTray - Is Auto sizing tray/menu? true
DEBUG [main] d.s.SystemTray - Is JavaFX detected? false
DEBUG [main] d.s.SystemTray - Is SWT detected? false
DEBUG [main] d.s.SystemTray - Java Swing L&F: Metal
DEBUG [main] d.s.SystemTray - Auto-detecting tray type
DEBUG [main] d.s.SystemTray - Tray indicator image size: 24
DEBUG [main] d.s.SystemTray - Tray menu image size: 22
INFO [main] d.s.SystemTray - Successfully loaded type: _WindowsNativeTray
DEBUG [main] d.s.SystemTray - Resizing image-stream to 24
ERROR [WindowsEventDispatch_0] d.j.w.WindowsEventDispatch - Error during listener execution.
java.lang.NullPointerException: Cannot read field "y" because "bounds" is null
    at dorkbox.systemtray/dorkbox.systemTray.ui.swing.TrayPopup.doShow(TrayPopup.java:126)
    at dorkbox.systemtray/dorkbox.systemTray.ui.swing._WindowsNativeTray$4.run(_WindowsNativeTray.java:211)
    at dorkbox.jna/dorkbox.jna.windows.WindowsEventDispatch$1.callback(WindowsEventDispatch.java:166)
    at dorkbox.jna/dorkbox.jna.windows.User32_64.GetMessage(Native Method)
    at dorkbox.jna/dorkbox.jna.windows.WindowsEventDispatch.run(WindowsEventDispatch.java:190)
    at java.base/java.lang.Thread.run(Thread.java:1583)

mousePositionX = 2336; mousePositionY = 1754 xScalePtr.getValue() = 0, so result is infinity

    public static
    double dorkbox.systemTray.util.SizeAndScalingWindows#getDpiScaleForMouseClick(int mousePositionX, int mousePositionY) {
        WinDef.POINT.ByValue pointValue = new WinDef.POINT.ByValue(mousePositionX, mousePositionY);
        WinUser.HMONITOR monitorFromPoint = User32.User32.MonitorFromPoint(pointValue, WinUser.MONITOR_DEFAULTTONEAREST);

        // I don't know why this has 2 options, but the scale is always the same in both directions...
        IntByReference xScalePtr = new IntByReference();
        IntByReference yScalePtr = new IntByReference();
        ShCore.GetDpiForMonitor(monitorFromPoint, 0, xScalePtr, yScalePtr);

        // 96 is the default scale on windows
        return 96.0D / xScalePtr.getValue();
    }