forked from dorkbox/SystemTray
Code polish
This commit is contained in:
parent
bb03e870c7
commit
9fdee240f8
@ -59,8 +59,7 @@ class ImageUtils {
|
|||||||
*/
|
*/
|
||||||
public static
|
public static
|
||||||
void determineIconSize(int trayType) {
|
void determineIconSize(int trayType) {
|
||||||
int trayScale;
|
int scalingFactor = 0;
|
||||||
int menuScale;
|
|
||||||
|
|
||||||
if (SystemTray.AUTO_TRAY_SIZE) {
|
if (SystemTray.AUTO_TRAY_SIZE) {
|
||||||
if (OS.isWindows()) {
|
if (OS.isWindows()) {
|
||||||
@ -96,7 +95,6 @@ class ImageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int scalingFactor;
|
|
||||||
if (windowsVersion.startsWith("5.1")) {
|
if (windowsVersion.startsWith("5.1")) {
|
||||||
// Windows XP 5.1.2600
|
// Windows XP 5.1.2600
|
||||||
scalingFactor = 1;
|
scalingFactor = 1;
|
||||||
@ -144,25 +142,9 @@ class ImageUtils {
|
|||||||
if (SystemTray.DEBUG) {
|
if (SystemTray.DEBUG) {
|
||||||
SystemTray.logger.error("Windows version (partial): '{}'", windowsVersion);
|
SystemTray.logger.error("Windows version (partial): '{}'", windowsVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
// windows will automatically scale the tray size BUT NOT the menu entry icon size
|
|
||||||
// we want to make sure our "scaled" size is appropriate for the OS.
|
|
||||||
trayScale = SystemTray.DEFAULT_TRAY_SIZE * scalingFactor;
|
|
||||||
menuScale = SystemTray.DEFAULT_MENU_SIZE;
|
|
||||||
} else {
|
} else {
|
||||||
// GtkStatusIcon will USUALLY automatically scale the icon
|
// GtkStatusIcon will USUALLY automatically scale the icon
|
||||||
// AppIndicator will NOT scale the icon
|
// AppIndicator MIGHT scale the icon (depends on the OS)
|
||||||
if (trayType == SystemTray.TYPE_SWING || trayType == SystemTray.TYPE_GTK_STATUSICON) {
|
|
||||||
// swing or GtkStatusIcon on linux/mac? use the default settings
|
|
||||||
trayScale = SystemTray.DEFAULT_TRAY_SIZE;
|
|
||||||
menuScale = SystemTray.DEFAULT_MENU_SIZE;
|
|
||||||
} else {
|
|
||||||
if (SystemTray.DEBUG) {
|
|
||||||
SystemTray.logger.error("Auto detecting UI scale");
|
|
||||||
}
|
|
||||||
|
|
||||||
int uiScalingFactor = 0;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
|
||||||
PrintStream outputStream = new PrintStream(byteArrayOutputStream);
|
PrintStream outputStream = new PrintStream(byteArrayOutputStream);
|
||||||
@ -186,7 +168,7 @@ class ImageUtils {
|
|||||||
// should be: uint32 0 or something
|
// should be: uint32 0 or something
|
||||||
if (output.contains("uint32")) {
|
if (output.contains("uint32")) {
|
||||||
String value = output.substring(output.indexOf("uint")+7, output.length()-1);
|
String value = output.substring(output.indexOf("uint")+7, output.length()-1);
|
||||||
uiScalingFactor = Integer.parseInt(value);
|
scalingFactor = Integer.parseInt(value);
|
||||||
|
|
||||||
// 0 is disabled (no scaling)
|
// 0 is disabled (no scaling)
|
||||||
// 1 is enabled (default scale)
|
// 1 is enabled (default scale)
|
||||||
@ -205,35 +187,27 @@ class ImageUtils {
|
|||||||
SystemTray.logger.error("Cannot check scaling factor", e);
|
SystemTray.logger.error("Cannot check scaling factor", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// windows, mac, linux(GtkStatusIcon) will automatically scale the tray size
|
||||||
|
// the menu entry icon size will NOT get scaled (it will show whatever we specify)
|
||||||
|
// we want to make sure our "scaled" size is appropriate for the OS.
|
||||||
|
|
||||||
// the DEFAULT scale is 16
|
// the DEFAULT scale is 16
|
||||||
if (uiScalingFactor > 1) {
|
if (scalingFactor > 1) {
|
||||||
trayScale = SystemTray.DEFAULT_TRAY_SIZE * uiScalingFactor;
|
TRAY_SIZE = SystemTray.DEFAULT_TRAY_SIZE * scalingFactor;
|
||||||
menuScale = SystemTray.DEFAULT_MENU_SIZE * uiScalingFactor;
|
ENTRY_SIZE = SystemTray.DEFAULT_MENU_SIZE;
|
||||||
} else {
|
|
||||||
trayScale = SystemTray.DEFAULT_TRAY_SIZE;
|
|
||||||
menuScale = SystemTray.DEFAULT_MENU_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SystemTray.DEBUG) {
|
if (SystemTray.DEBUG) {
|
||||||
SystemTray.logger.debug("uiScaling factor is '{}', auto tray size is '{}'.", uiScalingFactor, trayScale);
|
SystemTray.logger.debug("Scaling Factor factor is '{}', tray size is '{}'.", scalingFactor, TRAY_SIZE);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (OS.isWindows()) {
|
TRAY_SIZE = SystemTray.DEFAULT_TRAY_SIZE;
|
||||||
trayScale = SystemTray.DEFAULT_TRAY_SIZE;
|
ENTRY_SIZE = SystemTray.DEFAULT_MENU_SIZE;
|
||||||
menuScale = SystemTray.DEFAULT_MENU_SIZE;
|
|
||||||
} else {
|
|
||||||
trayScale = SystemTray.DEFAULT_TRAY_SIZE;
|
|
||||||
menuScale = SystemTray.DEFAULT_MENU_SIZE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TRAY_SIZE = trayScale;
|
|
||||||
ENTRY_SIZE = menuScale;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static
|
public static
|
||||||
File getTransparentImage(final int size) {
|
File getTransparentImage(final int size) {
|
||||||
|
Loading…
Reference in New Issue
Block a user