diff --git a/src/dorkbox/systemTray/SystemTray.java b/src/dorkbox/systemTray/SystemTray.java index 298748a..178e2e8 100644 --- a/src/dorkbox/systemTray/SystemTray.java +++ b/src/dorkbox/systemTray/SystemTray.java @@ -756,7 +756,7 @@ class SystemTray { if (isJavaFxLoaded) { if (isTrayType(trayType, TrayType.GtkStatusIcon)) { // set a property so that GTK (if necessary) can set the name of the system tray icon - System.setProperty("SystemTray_GTK_SET_NAME", "true"); + System.setProperty("SystemTray_SET_NAME", "true"); } // This will initialize javaFX dispatch methods diff --git a/src/dorkbox/systemTray/gnomeShell/Extension.java b/src/dorkbox/systemTray/gnomeShell/Extension.java index c1ce926..ab0fc0a 100644 --- a/src/dorkbox/systemTray/gnomeShell/Extension.java +++ b/src/dorkbox/systemTray/gnomeShell/Extension.java @@ -237,7 +237,7 @@ class Extension { } // set a property so that GTK (if necessary) can set the name - System.setProperty("SystemTray_GTK_SET_NAME", "true"); + System.setProperty("SystemTray_SET_NAME", "true"); // have to copy the extension over and enable it. String userHome = System.getProperty("user.home"); diff --git a/src/dorkbox/systemTray/jna/linux/AppIndicator.java b/src/dorkbox/systemTray/jna/linux/AppIndicator.java index e95fc72..b7d72a3 100644 --- a/src/dorkbox/systemTray/jna/linux/AppIndicator.java +++ b/src/dorkbox/systemTray/jna/linux/AppIndicator.java @@ -239,6 +239,7 @@ class AppIndicator { public static native AppIndicatorInstanceStruct app_indicator_new(String id, String icon_name, int category); + public static native void app_indicator_set_title(AppIndicatorInstanceStruct self, String title); public static native void app_indicator_set_status(AppIndicatorInstanceStruct self, int status); public static native void app_indicator_set_menu(AppIndicatorInstanceStruct self, Pointer menu); public static native void app_indicator_set_icon(AppIndicatorInstanceStruct self, String icon_name); diff --git a/src/dorkbox/systemTray/jna/linux/Gtk.java b/src/dorkbox/systemTray/jna/linux/Gtk.java index 845945f..92ebcb5 100644 --- a/src/dorkbox/systemTray/jna/linux/Gtk.java +++ b/src/dorkbox/systemTray/jna/linux/Gtk.java @@ -246,6 +246,13 @@ class Gtk { if (SystemTray.isJavaFxLoaded) { if (!JavaFX.isEventThread()) { try { + if (!blockUntilStarted.await(10, TimeUnit.SECONDS)) { + if (SystemTray.DEBUG) { + SystemTray.logger.error("Something is very wrong. The waitForStartup took longer than expected.", + new Exception("")); + } + } + // we have to WAIT until all events are done processing, OTHERWISE we have initialization issues while (true) { Thread.sleep(100); @@ -256,13 +263,6 @@ class Gtk { } } } - - if (!blockUntilStarted.await(10, TimeUnit.SECONDS)) { - if (SystemTray.DEBUG) { - SystemTray.logger.error("Something is very wrong. The waitForStartup took longer than expected.", - new Exception("")); - } - } } catch (InterruptedException e) { e.printStackTrace(); } @@ -271,6 +271,13 @@ class Gtk { if (!Swt.isEventThread()) { // we have to WAIT until all events are done processing, OTHERWISE we have initialization issues try { + if (!blockUntilStarted.await(10, TimeUnit.SECONDS)) { + if (SystemTray.DEBUG) { + SystemTray.logger.error("Something is very wrong. The waitForStartup took longer than expected.", + new Exception("")); + } + } + while (true) { Thread.sleep(100); @@ -280,19 +287,19 @@ class Gtk { } } } - - if (!blockUntilStarted.await(10, TimeUnit.SECONDS)) { - if (SystemTray.DEBUG) { - SystemTray.logger.error("Something is very wrong. The waitForStartup took longer than expected.", - new Exception("")); - } - } } catch (InterruptedException e) { e.printStackTrace(); } } } else { try { + if (!blockUntilStarted.await(10, TimeUnit.SECONDS)) { + if (SystemTray.DEBUG) { + SystemTray.logger.error("Something is very wrong. The waitForStartup took longer than expected.", + new Exception("")); + } + } + // we have to WAIT until all events are done processing, OTHERWISE we have initialization issues while (true) { Thread.sleep(100); @@ -303,13 +310,6 @@ class Gtk { } } } - - if (!blockUntilStarted.await(10, TimeUnit.SECONDS)) { - if (SystemTray.DEBUG) { - SystemTray.logger.error("Something is very wrong. The waitForStartup took longer than expected.", - new Exception("")); - } - } } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/src/dorkbox/systemTray/nativeUI/_AppIndicatorNativeTray.java b/src/dorkbox/systemTray/nativeUI/_AppIndicatorNativeTray.java index 65c40ae..a5ed88a 100644 --- a/src/dorkbox/systemTray/nativeUI/_AppIndicatorNativeTray.java +++ b/src/dorkbox/systemTray/nativeUI/_AppIndicatorNativeTray.java @@ -209,6 +209,29 @@ class _AppIndicatorNativeTray extends Tray implements NativeUI { Gtk.waitForStartup(); + + if (System.getProperty("SystemTray_SET_NAME", "false").equals("true")) { + Gtk.dispatch(new Runnable() { + @Override + public + void run() { + // by default, the title/name of the tray icon is "java". We are the only java-based tray icon, so we just use that. + // If you change "SystemTray" to something else, make sure to change it in extension.js as well + + // default is to show the indicator + AppIndicator.app_indicator_set_status(appIndicator, AppIndicator.STATUS_ACTIVE); + + // can cause + // GLib-GIO-CRITICAL **: g_dbus_connection_emit_signal: assertion 'object_path != NULL && g_variant_is_object_path (object_path)' failed + // Gdk-CRITICAL **: IA__gdk_window_thaw_toplevel_updates_libgtk_only: assertion 'private->update_and_descendants_freeze_count > 0' failed + + // necessary for gnome icon detection/placement because we move tray icons around by title. This is hardcoded + // in extension.js, so don't change it + AppIndicator.app_indicator_set_title(appIndicator, "SystemTray"); + } + }); + } + bind(gtkMenu, null, systemTray); } diff --git a/src/dorkbox/systemTray/nativeUI/_GtkStatusIconNativeTray.java b/src/dorkbox/systemTray/nativeUI/_GtkStatusIconNativeTray.java index c72bdc6..c8ade47 100644 --- a/src/dorkbox/systemTray/nativeUI/_GtkStatusIconNativeTray.java +++ b/src/dorkbox/systemTray/nativeUI/_GtkStatusIconNativeTray.java @@ -196,7 +196,7 @@ class _GtkStatusIconNativeTray extends Tray implements NativeUI { // BUT this is REQUIRED when running JavaFX or Gnome For unknown reasons, the title isn't pushed to GTK, so our // gnome-shell extension cannot see our tray icon -- so naturally, it won't move it to the "top" area and // we appear broken. - if (System.getProperty("SystemTray_GTK_SET_NAME", "false").equals("true")) { + if (System.getProperty("SystemTray_SET_NAME", "false").equals("true")) { Gtk.gtk_status_icon_set_name(trayIcon, "SystemTray"); } } diff --git a/src/dorkbox/systemTray/swingUI/_AppIndicatorTray.java b/src/dorkbox/systemTray/swingUI/_AppIndicatorTray.java index 31e1408..cd8e7f3 100644 --- a/src/dorkbox/systemTray/swingUI/_AppIndicatorTray.java +++ b/src/dorkbox/systemTray/swingUI/_AppIndicatorTray.java @@ -272,6 +272,30 @@ class _AppIndicatorTray extends Tray implements SwingUI { bind(swingMenu, null, systemTray); } }); + + + if (System.getProperty("SystemTray_SET_NAME", "false").equals("true")) { + Gtk.dispatch(new Runnable() { + @Override + public + void run() { + // by default, the title/name of the tray icon is "java". We are the only java-based tray icon, so we just use that. + // If you change "SystemTray" to something else, make sure to change it in extension.js as well + + // default is to show the indicator + AppIndicator.app_indicator_set_status(appIndicator, AppIndicator.STATUS_ACTIVE); + + + // can cause + // GLib-GIO-CRITICAL **: g_dbus_connection_emit_signal: assertion 'object_path != NULL && g_variant_is_object_path (object_path)' failed + // Gdk-CRITICAL **: IA__gdk_window_thaw_toplevel_updates_libgtk_only: assertion 'private->update_and_descendants_freeze_count > 0' failed + + // necessary for gnome icon detection/placement because we move tray icons around by title. This is hardcoded + // in extension.js, so don't change it + AppIndicator.app_indicator_set_title(appIndicator, "SystemTray"); + } + }); + } } private diff --git a/src/dorkbox/systemTray/swingUI/_GtkStatusIconTray.java b/src/dorkbox/systemTray/swingUI/_GtkStatusIconTray.java index 89af4e2..d73b8a5 100644 --- a/src/dorkbox/systemTray/swingUI/_GtkStatusIconTray.java +++ b/src/dorkbox/systemTray/swingUI/_GtkStatusIconTray.java @@ -118,7 +118,7 @@ class _GtkStatusIconTray extends Tray implements SwingUI { // BUT this is REQUIRED when running JavaFX or Gnome For unknown reasons, the title isn't pushed to GTK, so our // gnome-shell extension cannot see our tray icon -- so naturally, it won't move it to the "top" area and // we appear broken. - if (System.getProperty("SystemTray_GTK_SET_NAME", "false").equals("true")) { + if (System.getProperty("SystemTray_SET_NAME", "false").equals("true")) { Gtk.gtk_status_icon_set_name(trayIcon, "SystemTray"); } }