compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

System tray icon not showing (correctly) with Gnome (Xorg/Wayland)

Open Jeansen opened this issue 3 years ago • 6 comments

Currently I am on Debian with Gnome 41.3.

When I run the https://github.com/JetBrains/compose-jb/tree/master/tutorials/Tray_Notifications_MenuBar_new I get two things:

  • With Gnome on Wayland I get an icon, but the circle is double the size it should, be, therefore clipped and the background is white (instead of transparent)
  • With Gnome on Xorg, I have a black icon.

Context menu works in both scenarios.

Note: Tray only works when this extension is installed: https://extensions.gnome.org/extension/615/appindicator-support/ .

On Windows, it works fine. On both systems I can invoke the tray menu, increase the counter and close the application. It's simply that the tray icon itself has issues with Gnome.

Jeansen avatar Feb 14 '22 22:02 Jeansen

One addition: dorkbox.systemTray.SystemTray works perfectly fine with an older app I'd like to transition from JavaFX + Kotlin to Compose. That is, I have an tray icon with transparent background, the right icon size in Windows and Gnome (either Xorg or Wayland).

Jeansen avatar Feb 14 '22 22:02 Jeansen

Fwiw: When using the Tray functionality, I get a JavaEmbeddedFrame task in my task switcher, which does display the requested tray icon.

Also when using multiple monitors, the resultant menu that opens when tapping on the tray icon, may appear on the incorrect display.

(On Gnome 40.4.0 and using X11 windowing system)

ChrisAJS avatar Feb 17 '22 21:02 ChrisAJS

I tried again with OpenJDK 17, Compose 1.0.1 and Kotlin 1.6.10. Same issues. 1.2.0-alpha01-dev620 does not reveal any changes, either

Jeansen avatar Feb 18 '22 13:02 Jeansen

I ended up using Dorkbox as @Jeansen recommended. Here's a little snippet on how to get up and running with it:

h3. Gradle dependency

implementation("com.dorkbox:SystemTray:4.1")

h3. Sample use

@Composable
fun DorkTray() {
    val tray by remember { mutableStateOf(SystemTray.get()!!) }

    LaunchedEffect(true) {
        tray.installShutdownHook() // Auto-remove icon when application is killed
        tray.setImage(javaClass.getResourceAsStream("/icon.png")) // Use icon in src/main/resources/icon.png
        tray.menu.add(MenuItem("Click me!").apply {
            setCallback { println("Handled click!") }
        })
    }
}

This should be enough to get someone going if they find themselves here.

ChrisAJS avatar Sep 23 '22 14:09 ChrisAJS

Didn't you get this error @ChrisAJS loader 'bootstrap' attempted duplicate class definition for java.awt.TrayIcon. (java.awt.TrayIcon is in module java.desktop of loader 'bootstrap')

Giuliopime avatar Oct 18 '23 16:10 Giuliopime

Didn't you get this error @ChrisAJS loader 'bootstrap' attempted duplicate class definition for java.awt.TrayIcon. (java.awt.TrayIcon is in module java.desktop of loader 'bootstrap')

Did you solve this? Getting the same issue. : )

Nohus avatar Dec 17 '23 07:12 Nohus

Didn't you get this error @ChrisAJS loader 'bootstrap' attempted duplicate class definition for java.awt.TrayIcon. (java.awt.TrayIcon is in module java.desktop of loader 'bootstrap')

Just managed to run the cod of ChrisAJS by setting SystemTray.FORCE_TRAY_TYPE manually before the SystemTray.get() call to Swing on macOS (14.5):

fun DorkTray() {
    SystemTray.FORCE_TRAY_TYPE = SystemTray.TrayType.Swing
    val tray by remember { mutableStateOf(SystemTray.get()!!) }
...

realrubbish avatar Jul 26 '24 10:07 realrubbish

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

okushnikov avatar Aug 26 '24 15:08 okushnikov