forked from dorkbox/SystemTray
Code polish
This commit is contained in:
parent
736b098e86
commit
ca56dc9215
@ -22,12 +22,12 @@ import com.sun.jna.Pointer;
|
|||||||
import dorkbox.systemTray.jna.linux.Gobject;
|
import dorkbox.systemTray.jna.linux.Gobject;
|
||||||
import dorkbox.systemTray.jna.linux.Gtk;
|
import dorkbox.systemTray.jna.linux.Gtk;
|
||||||
import dorkbox.systemTray.peer.EntryPeer;
|
import dorkbox.systemTray.peer.EntryPeer;
|
||||||
import dorkbox.systemTray.util.ImageUtils;
|
import dorkbox.systemTray.util.ImageResizeUtil;
|
||||||
|
|
||||||
abstract
|
abstract
|
||||||
class GtkBaseMenuItem implements EntryPeer {
|
class GtkBaseMenuItem implements EntryPeer {
|
||||||
// these are necessary BECAUSE GTK menus look funky as hell when there are some menu entries WITH icons and some WITHOUT
|
// these are necessary BECAUSE GTK menus look funky as hell when there are some menu entries WITH icons and some WITHOUT
|
||||||
private static File transparentIcon = null;
|
private static final File transparentIcon = ImageResizeUtil.getTransparentImage();
|
||||||
private volatile boolean hasLegitImage = true;
|
private volatile boolean hasLegitImage = true;
|
||||||
|
|
||||||
// these have to be volatile, because they can be changed from any thread
|
// these have to be volatile, because they can be changed from any thread
|
||||||
@ -38,11 +38,6 @@ class GtkBaseMenuItem implements EntryPeer {
|
|||||||
|
|
||||||
GtkBaseMenuItem(final Pointer _native) {
|
GtkBaseMenuItem(final Pointer _native) {
|
||||||
this._native = _native;
|
this._native = _native;
|
||||||
|
|
||||||
// cannot be done in a static initializer, because the tray icon size might not yet have been determined
|
|
||||||
if (transparentIcon == null) {
|
|
||||||
transparentIcon = ImageUtils.getTransparentImage(ImageUtils.ENTRY_SIZE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public
|
public
|
||||||
|
@ -28,7 +28,7 @@ import dorkbox.systemTray.jna.linux.AppIndicator;
|
|||||||
import dorkbox.systemTray.jna.linux.AppIndicatorInstanceStruct;
|
import dorkbox.systemTray.jna.linux.AppIndicatorInstanceStruct;
|
||||||
import dorkbox.systemTray.jna.linux.Gobject;
|
import dorkbox.systemTray.jna.linux.Gobject;
|
||||||
import dorkbox.systemTray.jna.linux.Gtk;
|
import dorkbox.systemTray.jna.linux.Gtk;
|
||||||
import dorkbox.systemTray.util.ImageUtils;
|
import dorkbox.systemTray.util.ImageResizeUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for handling all system tray interactions.
|
* Class for handling all system tray interactions.
|
||||||
@ -169,7 +169,6 @@ class _AppIndicatorNativeTray extends Tray implements NativeUI {
|
|||||||
|
|
||||||
if (!isActive) {
|
if (!isActive) {
|
||||||
isActive = true;
|
isActive = true;
|
||||||
|
|
||||||
AppIndicator.app_indicator_set_status(appIndicator, AppIndicator.STATUS_ACTIVE);
|
AppIndicator.app_indicator_set_status(appIndicator, AppIndicator.STATUS_ACTIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,9 +219,10 @@ class _AppIndicatorNativeTray extends Tray implements NativeUI {
|
|||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void run() {
|
void run() {
|
||||||
// we initialize with a blank image
|
|
||||||
File image = ImageUtils.getTransparentImage(ImageUtils.ENTRY_SIZE);
|
|
||||||
String id = System.nanoTime() + "DBST";
|
String id = System.nanoTime() + "DBST";
|
||||||
|
|
||||||
|
// we initialize with a blank image. Throws RuntimeException if not possible (this should never happen!)
|
||||||
|
File image = ImageResizeUtil.getTransparentImage(); // tiny size is OK because we will be replacing this image.
|
||||||
appIndicator = AppIndicator.app_indicator_new(id, image.getAbsolutePath(), AppIndicator.CATEGORY_APPLICATION_STATUS);
|
appIndicator = AppIndicator.app_indicator_new(id, image.getAbsolutePath(), AppIndicator.CATEGORY_APPLICATION_STATUS);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -232,10 +232,10 @@ class _AppIndicatorNativeTray extends Tray implements NativeUI {
|
|||||||
bind(gtkMenu, null, systemTray);
|
bind(gtkMenu, null, systemTray);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://bugs.launchpad.net/indicator-application/+bug/527458/comments/12
|
|
||||||
@Override
|
@Override
|
||||||
protected
|
protected
|
||||||
void setTooltip_(final String tooltipText) {
|
void setTooltip_(final String tooltipText) {
|
||||||
|
// https://bugs.launchpad.net/indicator-application/+bug/527458/comments/12
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,8 +64,6 @@ class _AwtTray extends Tray implements NativeUI {
|
|||||||
"type and configuration");
|
"type and configuration");
|
||||||
}
|
}
|
||||||
|
|
||||||
_AwtTray.this.tray = SystemTray.getSystemTray();
|
|
||||||
|
|
||||||
// we override various methods, because each tray implementation is SLIGHTLY different. This allows us customization.
|
// we override various methods, because each tray implementation is SLIGHTLY different. This allows us customization.
|
||||||
final AwtMenu awtMenu = new AwtMenu(null) {
|
final AwtMenu awtMenu = new AwtMenu(null) {
|
||||||
@Override
|
@Override
|
||||||
@ -75,6 +73,10 @@ class _AwtTray extends Tray implements NativeUI {
|
|||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void run() {
|
void run() {
|
||||||
|
if (tray == null) {
|
||||||
|
tray = SystemTray.getSystemTray();
|
||||||
|
}
|
||||||
|
|
||||||
boolean enabled = menuItem.getEnabled();
|
boolean enabled = menuItem.getEnabled();
|
||||||
|
|
||||||
if (OS.isMacOsX()) {
|
if (OS.isMacOsX()) {
|
||||||
@ -138,6 +140,10 @@ class _AwtTray extends Tray implements NativeUI {
|
|||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void run() {
|
void run() {
|
||||||
|
if (tray == null) {
|
||||||
|
tray = SystemTray.getSystemTray();
|
||||||
|
}
|
||||||
|
|
||||||
// stupid java won't scale it right away, so we have to do this twice to get the correct size
|
// stupid java won't scale it right away, so we have to do this twice to get the correct size
|
||||||
final Image trayImage = new ImageIcon(imageFile.getAbsolutePath()).getImage();
|
final Image trayImage = new ImageIcon(imageFile.getAbsolutePath()).getImage();
|
||||||
trayImage.flush();
|
trayImage.flush();
|
||||||
@ -185,7 +191,10 @@ class _AwtTray extends Tray implements NativeUI {
|
|||||||
void run() {
|
void run() {
|
||||||
if (trayIcon != null) {
|
if (trayIcon != null) {
|
||||||
trayIcon.setPopupMenu(null);
|
trayIcon.setPopupMenu(null);
|
||||||
tray.remove(trayIcon);
|
if (tray != null) {
|
||||||
|
tray.remove(trayIcon);
|
||||||
|
}
|
||||||
|
|
||||||
trayIcon = null;
|
trayIcon = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,6 +218,10 @@ class _AwtTray extends Tray implements NativeUI {
|
|||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void run() {
|
void run() {
|
||||||
|
if (tray == null) {
|
||||||
|
tray = SystemTray.getSystemTray();
|
||||||
|
}
|
||||||
|
|
||||||
// don't want to matter which (setImage/setTooltip/setEnabled) is done first, and if the image/enabled is changed, we
|
// don't want to matter which (setImage/setTooltip/setEnabled) is done first, and if the image/enabled is changed, we
|
||||||
// want to make sure keep the tooltip text the same as before.
|
// want to make sure keep the tooltip text the same as before.
|
||||||
if (trayIcon != null) {
|
if (trayIcon != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user