Fixed issues with windows/mac

This commit is contained in:
nathan 2016-10-04 16:59:22 +02:00
parent 62c73e8f32
commit 42d053398f
7 changed files with 25 additions and 27 deletions

View File

@ -66,7 +66,7 @@ class AppIndicatorTray extends GtkTypeSystemTray {
throw new IllegalArgumentException("Unable to start AppIndicator if 'SystemTray.FORCE_TRAY_TYPE' is set to GtkStatusIcon"); throw new IllegalArgumentException("Unable to start AppIndicator if 'SystemTray.FORCE_TRAY_TYPE' is set to GtkStatusIcon");
} }
ImageUtils.determineIconSize(SystemTray.TYPE_APP_INDICATOR); ImageUtils.determineIconSize();
Gtk.startGui(); Gtk.startGui();
dispatch(new Runnable() { dispatch(new Runnable() {

View File

@ -58,7 +58,7 @@ class GtkSystemTray extends GtkTypeSystemTray {
throw new IllegalArgumentException("Unable to start GtkStatusIcon if 'SystemTray.FORCE_TRAY_TYPE' is set to AppIndicator"); throw new IllegalArgumentException("Unable to start GtkStatusIcon if 'SystemTray.FORCE_TRAY_TYPE' is set to AppIndicator");
} }
ImageUtils.determineIconSize(SystemTray.TYPE_GTK_STATUSICON); ImageUtils.determineIconSize();
Gtk.startGui(); Gtk.startGui();
dispatch(new Runnable() { dispatch(new Runnable() {

View File

@ -24,9 +24,9 @@ import javax.swing.border.EmptyBorder;
class AdjustedJMenu extends JMenu { class AdjustedJMenu extends JMenu {
// only necessary in linux // only necessary in linux
private final SwingSystemTrayLinuxMenuPopup mainPopup; private final SwingSystemTrayMenuPopup mainPopup;
AdjustedJMenu(final SwingSystemTrayLinuxMenuPopup mainPopup) { AdjustedJMenu(final SwingSystemTrayMenuPopup mainPopup) {
this.mainPopup = mainPopup; this.mainPopup = mainPopup;
} }

View File

@ -59,20 +59,20 @@ class SwingMenu extends Menu implements MenuEntry {
public public
void run() { void run() {
if (parent != null) { if (parent != null) {
if (OS.isLinux()) { if (OS.isWindows()) {
_native = new AdjustedJMenu((SwingSystemTrayLinuxMenuPopup)((SwingMenu) systemTray.getMenu())._native); _native = new AdjustedJMenu(null);
} }
else { else {
_native = new AdjustedJMenu(null); _native = new AdjustedJMenu((SwingSystemTrayMenuPopup)((SwingMenu) systemTray.getMenu())._native);
} }
((SwingMenu) parent)._native.add(_native); ((SwingMenu) parent)._native.add(_native);
} else { } else {
// when we are the system tray // when we are the system tray
if (OS.isLinux()) { if (OS.isWindows()) {
_native = new SwingSystemTrayLinuxMenuPopup();
} else {
_native = new SwingSystemTrayMenuWindowsPopup(); _native = new SwingSystemTrayMenuWindowsPopup();
} else {
_native = new SwingSystemTrayMenuPopup();
} }
} }
} }
@ -324,8 +324,8 @@ class SwingMenu extends Menu implements MenuEntry {
if (_native instanceof SwingSystemTrayMenuWindowsPopup) { if (_native instanceof SwingSystemTrayMenuWindowsPopup) {
((SwingSystemTrayMenuWindowsPopup) _native).close(); ((SwingSystemTrayMenuWindowsPopup) _native).close();
} }
else if (_native instanceof SwingSystemTrayLinuxMenuPopup) { else if (_native instanceof SwingSystemTrayMenuPopup) {
((SwingSystemTrayLinuxMenuPopup) _native).close(); ((SwingSystemTrayMenuPopup) _native).close();
} }
SwingMenu parent = (SwingMenu) getParent(); SwingMenu parent = (SwingMenu) getParent();

View File

@ -54,7 +54,7 @@ class SwingSystemTray extends SwingMenu {
SwingSystemTray(final dorkbox.systemTray.SystemTray systemTray) { SwingSystemTray(final dorkbox.systemTray.SystemTray systemTray) {
super(systemTray, null); super(systemTray, null);
ImageUtils.determineIconSize(dorkbox.systemTray.SystemTray.TYPE_SWING); ImageUtils.determineIconSize();
dispatchAndWait(new Runnable() { dispatchAndWait(new Runnable() {
@Override @Override

View File

@ -35,7 +35,7 @@ import dorkbox.util.SwingUtil;
* work, so we must implement an "auto-hide" feature that checks if our mouse is still inside a menu every POPUP_HIDE_DELAY seconds * work, so we must implement an "auto-hide" feature that checks if our mouse is still inside a menu every POPUP_HIDE_DELAY seconds
*/ */
public public
class SwingSystemTrayLinuxMenuPopup extends JPopupMenu { class SwingSystemTrayMenuPopup extends JPopupMenu {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Property @Property
@ -56,7 +56,7 @@ class SwingSystemTrayLinuxMenuPopup extends JPopupMenu {
// NOTE: we can use the "hidden dialog" focus window trick... only on windows and mac // NOTE: we can use the "hidden dialog" focus window trick... only on windows and mac
// private JDialog hiddenDialog; // private JDialog hiddenDialog;
SwingSystemTrayLinuxMenuPopup() { SwingSystemTrayMenuPopup() {
super(); super();
setFocusable(true); setFocusable(true);
// setBorder(new BorderUIResource.EmptyBorderUIResource(0, 0, 0, 0)); // borderUI resource border type will get changed! // setBorder(new BorderUIResource.EmptyBorderUIResource(0, 0, 0, 0)); // borderUI resource border type will get changed!
@ -89,7 +89,7 @@ class SwingSystemTrayLinuxMenuPopup extends JPopupMenu {
) { ) {
// restart the timer // restart the timer
SwingSystemTrayLinuxMenuPopup.this.timer.delay(POPUP_HIDE_DELAY); SwingSystemTrayMenuPopup.this.timer.delay(POPUP_HIDE_DELAY);
return; return;
} }
} }
@ -103,7 +103,7 @@ class SwingSystemTrayLinuxMenuPopup extends JPopupMenu {
) { ) {
// restart the timer // restart the timer
SwingSystemTrayLinuxMenuPopup.this.timer.delay(POPUP_HIDE_DELAY); SwingSystemTrayMenuPopup.this.timer.delay(POPUP_HIDE_DELAY);
return; return;
} }
@ -119,7 +119,7 @@ class SwingSystemTrayLinuxMenuPopup extends JPopupMenu {
public public
void mouseExited(MouseEvent event) { void mouseExited(MouseEvent event) {
// wait before checking if mouse is still on the menu // wait before checking if mouse is still on the menu
SwingSystemTrayLinuxMenuPopup.this.timer.delay(SwingSystemTrayLinuxMenuPopup.this.timer.getDelay()); SwingSystemTrayMenuPopup.this.timer.delay(SwingSystemTrayMenuPopup.this.timer.getDelay());
} }
}); });
} }
@ -154,7 +154,7 @@ class SwingSystemTrayLinuxMenuPopup extends JPopupMenu {
} }
// restart the timer // restart the timer
SwingSystemTrayLinuxMenuPopup.this.timer.delay(POPUP_HIDE_DELAY); SwingSystemTrayMenuPopup.this.timer.delay(POPUP_HIDE_DELAY);
} }
public public

View File

@ -51,14 +51,8 @@ class ImageUtils {
public static volatile int TRAY_SIZE = 0; public static volatile int TRAY_SIZE = 0;
public static volatile int ENTRY_SIZE = 0; public static volatile int ENTRY_SIZE = 0;
/**
* @param trayType
* LINUX_GTK = 1;
* LINUX_APP_INDICATOR = 2;
* SWING_INDICATOR = 3;
*/
public static public static
void determineIconSize(int trayType) { void determineIconSize() {
int scalingFactor = 0; int scalingFactor = 0;
if (SystemTray.AUTO_TRAY_SIZE) { if (SystemTray.AUTO_TRAY_SIZE) {
@ -142,7 +136,7 @@ class ImageUtils {
if (SystemTray.DEBUG) { if (SystemTray.DEBUG) {
SystemTray.logger.error("Windows version (partial): '{}'", windowsVersion); SystemTray.logger.error("Windows version (partial): '{}'", windowsVersion);
} }
} else { } else if (OS.isLinux()) {
// GtkStatusIcon will USUALLY automatically scale the icon // GtkStatusIcon will USUALLY automatically scale the icon
// AppIndicator MIGHT scale the icon (depends on the OS) // AppIndicator MIGHT scale the icon (depends on the OS)
try { try {
@ -187,6 +181,10 @@ class ImageUtils {
SystemTray.logger.error("Cannot check scaling factor", e); SystemTray.logger.error("Cannot check scaling factor", e);
} }
} }
} else if (OS.isMacOsX()) {
// don't know how exactly to determine this, but we are going to assume HiDPI for this...
// the OS should go up/down as needed.
scalingFactor = 8;
} }
} }