dustinkredmond / FXTrayIcon

Tray Icon implementation for JavaFX applications. Say goodbye to using AWT's SystemTray icon, instead use a JavaFX Tray Icon.
MIT License
324 stars 25 forks source link

Tray icon is non-transparent on some Linux desktop environments #82

Open crschnick opened 11 months ago

crschnick commented 11 months ago

I have tested my application xpipe on various Linux distros and noticed that the tray icon it looks off on some of them. Here is for example how it looks on manjaro with Plasma and KWin (the default Manjaro ones):

image

On any other operating system or DEs like gnome it looks fine.

For reference, this is the code I use to call FXTrayIcon: https://github.com/xpipe-io/xpipex/blob/d2ac3383ac0b6202f567f42b963819f10b0c98c8/app/src/main/java/io/xpipe/app/core/AppTray.java

EasyG0ing1 commented 11 months ago

@crschnick I'm curious as to how you got a TrayIcon to work in Linux at all. The last time I looked into it, Gnome didn't even have a system tray which necessitated adding a third-party system tray and that's as far as I got.

Could you share how you got FXTrayIcon working on the various Linux desktops?

Also, FXTrayIcon is a wrapper for AWT (JavaFX doesn't support system tray icons). The rendering of the icon image itself happens outside of FXTrayIcon's control. We have noticed that different desktops like different image sizes for the icon. For example, Windows likes a 16x16 icon image while MacOS likes a 22x22 icon image. Going larger than 22x22 in MacOS (for example) changes nothing while going larger in Windows distorts the icon. You might try playing with different icon sizes in the various desktop environments to see if you can find their "sweet spot" icon size so that your icon doesn't look like the odd man out.

crschnick commented 11 months ago

It works out of the box for me on Manjaro and EndeavourOS but not on something like Ubuntu. I didn't do anything special here, it just worked.

I guess the issue lies with a bad AWT implementation: https://stackoverflow.com/questions/331407/java-trayicon-using-image-with-transparent-background?rq=4 . Judging from the age of that issue, it's probably not going to get fixed.

crschnick commented 11 months ago

I managed to fix the issue with an ugly reflection hack: https://github.com/xpipe-io/xpipex/blob/a716708f45353fb610b8a32ebea79ce3abc6315d/app/src/main/java/io/xpipe/app/core/AppTray.java#L82

EasyG0ing1 commented 10 months ago

@crschnick There has been an open issue with implementing Tray Icons in the official JavaFX developers issue tracker for close to 8 years now. It looked like it was gaining some traction, and then stopped dead in its tracks. They apparently were looking for someone who could basically back-engineer the AWT code and adapt it to total native FX ... but no one had taken it on the last time I checked.

Glad you found a fix for this.