diff --git a/src/dorkbox/systemTray/SystemTray.java b/src/dorkbox/systemTray/SystemTray.java index 12218f0b..7b2930da 100644 --- a/src/dorkbox/systemTray/SystemTray.java +++ b/src/dorkbox/systemTray/SystemTray.java @@ -89,18 +89,12 @@ class SystemTray { } @Property - /** Enables auto-detection for the system tray. This should be mostly successful. - *
- * Auto-detection will use DEFAULT_TRAY_SIZE as a 'base-line' for determining what size to use. - *
- * If auto-detection fails and the incorrect size is detected or used, disable this and specify the correct DEFAULT_TRAY_SIZE or - * DEFAULT_MENU_SIZE instead - */ + /** Enables auto-detection for the system tray. This should be mostly successful. */ public static boolean AUTO_SIZE = true; @Property /** Forces the system tray to always choose GTK2 (even when GTK3 might be available). */ - public static boolean FORCE_GTK2 = false; + public static boolean FORCE_GTK2 = true; @Property /** @@ -108,7 +102,7 @@ class SystemTray { *
* This is an advanced feature, and it is recommended to leave at AutoDetect.
*/
- public static TrayType FORCE_TRAY_TYPE = TrayType.Swing;
+ public static TrayType FORCE_TRAY_TYPE = TrayType.AutoDetect;
@Property
/**
@@ -264,9 +258,9 @@ class SystemTray {
return;
}
- // Windows can ONLY use Swing (non-native) - AWT/native looks absolutely horrid
+ // Windows can ONLY use Swing (non-native) - AWT/native looks absolutely horrid and is not an option
// OSx can use Swing (non-native) or AWT (native) .
- // Linux can use Swing (non-native) menus + (native Icon via GTK or AppIndicator), GtkStatusIcon (native), or AppIndicator (native)
+ // Linux can use Swing (non-native), AWT (native), GtkStatusIcon (native), or AppIndicator (native)
if (OS.isWindows()) {
if (FORCE_TRAY_TYPE != TrayType.AutoDetect && FORCE_TRAY_TYPE != TrayType.Swing) {
// windows MUST use swing only!
@@ -282,102 +276,96 @@ class SystemTray {
}
}
else if (OS.isLinux() || OS.isUnix()) {
- // kablooie if SWT/JavaFX or Swing is not configured in a way that works with us.
- if (FORCE_TRAY_TYPE != TrayType.Swing) {
- // NOTE: if the UI uses the 'getSystemLookAndFeelClassName' and is on Linux, this will cause GTK2 to get loaded first,
- // which will cause conflicts if one tries to use GTK3
- if (!FORCE_GTK2 && !isJavaFxLoaded && !isSwtLoaded) {
+ // NOTE: if the UI uses the 'getSystemLookAndFeelClassName' and is on Linux, this will cause GTK2 to get loaded first,
+ // which will cause conflicts if one tries to use GTK3
+ if (!FORCE_GTK2 && !isJavaFxLoaded && !isSwtLoaded) {
- String currentUI = UIManager.getLookAndFeel()
- .getClass()
- .getName();
+ String currentUI = UIManager.getLookAndFeel()
+ .getClass()
+ .getName();
- boolean mustForceGtk2 = false;
+ boolean mustForceGtk2 = false;
- if (currentUI.equals(GTKLookAndFeel.class.getCanonicalName())) {
- // this means our look and feel is the GTK look and feel... THIS CREATES PROBLEMS!
+ if (currentUI.equals(GTKLookAndFeel.class.getCanonicalName())) {
+ // this means our look and feel is the GTK look and feel... THIS CREATES PROBLEMS!
- // THIS IS NOT DOCUMENTED ANYWHERE...
- String swingGtkVersion = java.security.AccessController.doPrivileged(new GetPropertyAction("swing.gtk.version"));
- mustForceGtk2 = swingGtkVersion == null || swingGtkVersion.startsWith("2");
- }
-
- if (mustForceGtk2) {
- // we are NOT using javaFX/SWT and our UI is GTK2 and we want GTK3
- // JavaFX/SWT can be GTK3, but Swing can not be GTK3.
-
- if (AUTO_FIX_INCONSISTENCIES) {
- // we must use GTK2 because Swing is configured to use GTK2
- logger.warn("Forcing GTK2 because the Swing UIManager is GTK2");
- FORCE_GTK2 = true;
- } else {
- logger.error("Unable to use the SystemTray when the Swing UIManager is configured to use the native L&F, which " +
- "uses GTK2. This is incompatible with GTK3. " +
- "Please set `SystemTray.AUTO_FIX_INCONSISTENCIES=true;` to automatically fix this problem.");
-
- systemTrayMenu = null;
- systemTray = null;
- return;
- }
- }
+ // THIS IS NOT DOCUMENTED ANYWHERE...
+ String swingGtkVersion = java.security.AccessController.doPrivileged(new GetPropertyAction("swing.gtk.version"));
+ mustForceGtk2 = swingGtkVersion == null || swingGtkVersion.startsWith("2");
}
+ if (mustForceGtk2) {
+ // we are NOT using javaFX/SWT and our UI is GTK2 and we want GTK3
+ // JavaFX/SWT can be GTK3, but Swing can not be GTK3.
- if (isSwtLoaded) {
- // Necessary for us to work with SWT based on version info. We can try to set us to be compatible with whatever it is set to
- // System.setProperty("SWT_GTK3", "0");
+ if (AUTO_FIX_INCONSISTENCIES) {
+ // we must use GTK2 because Swing is configured to use GTK2
+ logger.warn("Forcing GTK2 because the Swing UIManager is GTK2");
+ FORCE_GTK2 = true;
+ } else {
+ logger.error("Unable to use the SystemTray when the Swing UIManager is configured to use the native L&F, which " +
+ "uses GTK2. This is incompatible with GTK3. " +
+ "Please set `SystemTray.AUTO_FIX_INCONSISTENCIES=true;` to automatically fix this problem.");
- // was SWT forced?
- String swt_gtk3 = System.getProperty("SWT_GTK3");
- boolean isSwt_GTK3 = swt_gtk3 != null && !swt_gtk3.equals("0");
- if (!isSwt_GTK3) {
- // check a different property
- String property = System.getProperty("org.eclipse.swt.internal.gtk.version");
- isSwt_GTK3 = property != null && !property.startsWith("2.");
+ systemTrayMenu = null;
+ systemTray = null;
}
+ }
+ }
+ else if (isSwtLoaded) {
+ // Necessary for us to work with SWT based on version info. We can try to set us to be compatible with whatever it is set to
+ // System.setProperty("SWT_GTK3", "0");
- if (isSwt_GTK3 && FORCE_GTK2) {
- logger.error("Unable to use the SystemTray when SWT is configured to use GTK3 and the SystemTray is configured to use " +
- "GTK2. Please configure SWT to use GTK2, via `System.setProperty(\"SWT_GTK3\", \"0\");` before SWT is " +
- "initialized, or set `SystemTray.FORCE_GTK2=false;`");
+ // was SWT forced?
+ String swt_gtk3 = System.getProperty("SWT_GTK3");
+ boolean isSwt_GTK3 = swt_gtk3 != null && !swt_gtk3.equals("0");
+ if (!isSwt_GTK3) {
+ // check a different property
+ String property = System.getProperty("org.eclipse.swt.internal.gtk.version");
+ isSwt_GTK3 = property != null && !property.startsWith("2.");
+ }
+
+ if (isSwt_GTK3 && FORCE_GTK2) {
+ logger.error("Unable to use the SystemTray when SWT is configured to use GTK3 and the SystemTray is configured to use " +
+ "GTK2. Please configure SWT to use GTK2, via `System.setProperty(\"SWT_GTK3\", \"0\");` before SWT is " +
+ "initialized, or set `SystemTray.FORCE_GTK2=false;`");
+
+ systemTrayMenu = null;
+ systemTray = null;
+ return;
+ } else if (!isSwt_GTK3 && !FORCE_GTK2 && AUTO_FIX_INCONSISTENCIES) {
+ // we must use GTK2, because SWT is GTK2
+ logger.warn("Forcing GTK2 because SWT is GTK2");
+ FORCE_GTK2 = true;
+ }
+ }
+ else if (isJavaFxLoaded) {
+ // JavaFX Java7,8 is GTK2 only. Java9 can MAYBE have it be GTK3 if `-Djdk.gtk.version=3` is specified
+ // see
+ // http://mail.openjdk.java.net/pipermail/openjfx-dev/2016-May/019100.html
+ // https://docs.oracle.com/javafx/2/system_requirements_2-2-3/jfxpub-system_requirements_2-2-3.htm
+ // from the page: JavaFX 2.2.3 for Linux requires gtk2 2.18+.
+ boolean isJava_GTK3_Possible = OS.javaVersion >= 9 && System.getProperty("jdk.gtk.version", "2").equals("3");
+ if (isJava_GTK3_Possible && FORCE_GTK2) {
+ // if we are java9, then we can change it -- otherwise we cannot.
+ if (OS.javaVersion == 9 && AUTO_FIX_INCONSISTENCIES) {
+ logger.warn("Unable to use the SystemTray when JavaFX is configured to use GTK3 and the SystemTray is " +
+ "configured to use GTK2. Please configure JavaFX to use GTK2 (via `System.setProperty(\"jdk.gtk.version\", \"3\");`) " +
+ "before JavaFX is initialized, or set `SystemTray.FORCE_GTK2=false;` Undoing `FORCE_GTK2`.");
+
+ FORCE_GTK2 = false;
+ } else {
+ logger.error("Unable to use the SystemTray when JavaFX is configured to use GTK3 and the SystemTray is configured to use " +
+ "GTK2. Please set `SystemTray.FORCE_GTK2=false;` if that is not possible then it will not work.");
systemTrayMenu = null;
systemTray = null;
return;
- } else if (!isSwt_GTK3 && !FORCE_GTK2 && AUTO_FIX_INCONSISTENCIES) {
- // we must use GTK2, because SWT is GTK2
- logger.warn("Forcing GTK2 because SWT is GTK2");
- FORCE_GTK2 = true;
- }
- }
- else if (isJavaFxLoaded) {
- // JavaFX Java7,8 is GTK2 only. Java9 can MAYBE have it be GTK3 if `-Djdk.gtk.version=3` is specified
- // see
- // http://mail.openjdk.java.net/pipermail/openjfx-dev/2016-May/019100.html
- // https://docs.oracle.com/javafx/2/system_requirements_2-2-3/jfxpub-system_requirements_2-2-3.htm
- // from the page: JavaFX 2.2.3 for Linux requires gtk2 2.18+.
- boolean isJava_GTK3_Possible = OS.javaVersion >= 9 && System.getProperty("jdk.gtk.version", "2").equals("3");
- if (isJava_GTK3_Possible && FORCE_GTK2) {
- // if we are java9, then we can change it -- otherwise we cannot.
- if (OS.javaVersion == 9 && AUTO_FIX_INCONSISTENCIES) {
- logger.warn("Unable to use the SystemTray when JavaFX is configured to use GTK3 and the SystemTray is " +
- "configured to use GTK2. Please configure JavaFX to use GTK2 (via `System.setProperty(\"jdk.gtk.version\", \"3\");`) " +
- "before JavaFX is initialized, or set `SystemTray.FORCE_GTK2=false;` Undoing `FORCE_GTK2`.");
-
- FORCE_GTK2 = false;
- } else {
- logger.error("Unable to use the SystemTray when JavaFX is configured to use GTK3 and the SystemTray is configured to use " +
- "GTK2. Please set `SystemTray.FORCE_GTK2=false;` if that is not possible then it will not work.");
-
- systemTrayMenu = null;
- systemTray = null;
- return;
- }
- } else if (!isJava_GTK3_Possible && !FORCE_GTK2 && AUTO_FIX_INCONSISTENCIES) {
- // we must use GTK2, because JavaFX is GTK2
- logger.warn("Forcing GTK2 because JavaFX is GTK2");
- FORCE_GTK2 = true;
}
+ } else if (!isJava_GTK3_Possible && !FORCE_GTK2 && AUTO_FIX_INCONSISTENCIES) {
+ // we must use GTK2, because JavaFX is GTK2
+ logger.warn("Forcing GTK2 because JavaFX is GTK2");
+ FORCE_GTK2 = true;
}
}
}
@@ -420,13 +408,14 @@ class SystemTray {
}
}
else if (OS.isMacOsX()) {
- // macosx doesn't respond to all buttons (but should)
- SystemTrayFixes.fixMacOS();
-
- try {
- trayType = selectType(TrayType.AWT);
- } catch (Throwable e) {
- logger.error("You might need to grant the AWTPermission `accessSystemTray` to the SecurityManager.");
+ if (SystemTray.FORCE_TRAY_TYPE != TrayType.AutoDetect) {
+ // macos can ONLY use the AWT tray indicator, if you want it to follow the L&F of the OS. If we force a specific type,
+ // then allow that.
+ try {
+ trayType = selectType(TrayType.AWT);
+ } catch (Throwable e) {
+ logger.error("You might need to grant the AWTPermission `accessSystemTray` to the SecurityManager.");
+ }
}
}
else if ((OS.isLinux() || OS.isUnix())) {
@@ -635,36 +624,34 @@ class SystemTray {
// fallback...
if (trayType == null) {
- trayType = selectTypeQuietly(TrayType.GtkStatusIcon);
- logger.warn("Unable to determine the system window manager type. Falling back to GtkStatusIcon.");
+ logger.warn("Unable to determine the system window manager type. Using the Swing Tray type instead.");
+
+ trayType = selectTypeQuietly(TrayType.Swing);
}
// this is bad...
if (trayType == null) {
- logger.error("SystemTray initialization failed. Unable to load the system tray native libraries. Please write an issue " +
- "and include your OS type and configuration");
+ logger.error("SystemTray initialization failed. Unable to load the system tray native libraries. " +
+ "Using the Swing Tray type instead. Please write an issue and include your OS type and configuration");
- systemTrayMenu = null;
- systemTray = null;
- return;
+ trayType = selectTypeQuietly(TrayType.Swing);
}
if (isTrayType(trayType, TrayType.AppIndicator) && OSUtil.Linux.isRoot()) {
// if are we running as ROOT, there can be issues (definitely on Ubuntu 16.04, maybe others)!
-
logger.error("Attempting to load the SystemTray as the 'root/sudo' user. This will likely not work because of dbus " +
- "restrictions.");
+ "restrictions. Using the Swing Tray type instead.");
+
+ trayType = selectTypeQuietly(TrayType.Swing);
}
}
if (trayType == null) {
- // unsupported tray, or unknown type
- logger.error("SystemTray initialization failed. (Unable to discover which implementation to use). Something is seriously wrong.");
+ trayType = selectTypeQuietly(TrayType.Swing);
- systemTrayMenu = null;
- systemTray = null;
- return;
+ // unsupported tray, or unknown type
+ logger.error("SystemTray initialization failed. (Unable to discover which implementation to use). Falling back to the Swing Tray.");
}
final AtomicReference