Fixed image scaling query for Ubuntu 16.06, changed all debug logs to

'debug'. Added a separate menu entry size (independent of tray size)
This commit is contained in:
nathan 2016-09-26 20:56:42 +02:00
parent 49b0ec0ff2
commit 6a9b606e51
9 changed files with 73 additions and 45 deletions

View File

@ -97,6 +97,14 @@ class SystemTray {
*/
public static int DEFAULT_LINUX_SIZE = 16;
@Property
/**
* Size of the menu entries, so that the icon can be properly scaled based on OS.
* <p>
* You will experience WEIRD graphical glitches if this is NOT a power of 2.
*/
public static int DEFAULT_MENU_SIZE = 16;
@Property
/** Forces the system tray to always choose GTK2 (even when GTK3 might be available). */
public static boolean FORCE_GTK2 = false;
@ -120,7 +128,7 @@ class SystemTray {
/**
* This property is provided for debugging any errors in the logic used to determine the system-tray type.
*/
public static boolean DEBUG = false;
public static boolean DEBUG = true;
private static volatile SystemTray systemTray = null;
@ -477,7 +485,7 @@ class SystemTray {
if (!output.isEmpty()) {
if (DEBUG) {
logger.info("Installing gnome-shell extension");
logger.debug("Installing gnome-shell extension");
}
GnomeShellExtension.install(output);
@ -732,7 +740,7 @@ class SystemTray {
*/
public
void setIcon(String imagePath) {
setIcon_(ImageUtils.resizeAndCache(ImageUtils.SIZE, imagePath));
setIcon_(ImageUtils.resizeAndCache(ImageUtils.TRAY_SIZE, imagePath));
}
/**
@ -745,7 +753,7 @@ class SystemTray {
*/
public
void setIcon(URL imageUrl) {
setIcon_(ImageUtils.resizeAndCache(ImageUtils.SIZE, imageUrl));
setIcon_(ImageUtils.resizeAndCache(ImageUtils.TRAY_SIZE, imageUrl));
}
/**
@ -759,7 +767,7 @@ class SystemTray {
*/
public
void setIcon(String cacheName, InputStream imageStream) {
setIcon_(ImageUtils.resizeAndCache(ImageUtils.SIZE, cacheName, imageStream));
setIcon_(ImageUtils.resizeAndCache(ImageUtils.TRAY_SIZE, cacheName, imageStream));
}
/**
@ -772,7 +780,7 @@ class SystemTray {
*/
public
void setIcon(InputStream imageStream) {
setIcon_(ImageUtils.resizeAndCache(ImageUtils.SIZE, imageStream));
setIcon_(ImageUtils.resizeAndCache(ImageUtils.TRAY_SIZE, imageStream));
}

View File

@ -200,7 +200,9 @@ class GnomeShellExtension {
// should be ['background-logo@fedorahosted.org', 'zyx', 'abs'
// or will be [ (if there is nothing)
logger.info("Installed extensions (should have leading '[') are: {}", stringBuilder.toString());
if (SystemTray.DEBUG) {
logger.debug("Installed extensions (should have leading '[') are: {}", stringBuilder.toString());
}
// add our extension to the list
if (stringBuilder.length() > 2) {
@ -230,8 +232,9 @@ class GnomeShellExtension {
return;
}
logger.info("Restarting gnome-shell so tray notification changes can be applied.");
if (SystemTray.DEBUG) {
logger.debug("Restarting gnome-shell so tray notification changes can be applied.");
}
// now we have to restart the gnome shell via bash
final ShellProcessBuilder restartShell = new ShellProcessBuilder();

View File

@ -142,7 +142,7 @@ class GtkMenuEntry implements MenuEntry, GCallback {
setImage_(null);
}
else {
setImage_(ImageUtils.resizeAndCache(ImageUtils.SIZE, imagePath));
setImage_(ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imagePath));
}
}
@ -153,7 +153,7 @@ class GtkMenuEntry implements MenuEntry, GCallback {
setImage_(null);
}
else {
setImage_(ImageUtils.resizeAndCache(ImageUtils.SIZE, imageUrl));
setImage_(ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imageUrl));
}
}
@ -164,7 +164,7 @@ class GtkMenuEntry implements MenuEntry, GCallback {
setImage_(null);
}
else {
setImage_(ImageUtils.resizeAndCache(ImageUtils.SIZE, cacheName, imageStream));
setImage_(ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, cacheName, imageStream));
}
}
@ -176,7 +176,7 @@ class GtkMenuEntry implements MenuEntry, GCallback {
setImage_(null);
}
else {
setImage_(ImageUtils.resizeAndCache(ImageUtils.SIZE, imageStream));
setImage_(ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imageStream));
}
}

View File

@ -295,7 +295,7 @@ class GtkTypeSystemTray extends SystemTray {
addMenuEntry_(menuText, null, callback);
}
else {
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.SIZE, imagePath), callback);
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imagePath), callback);
}
}
@ -306,7 +306,7 @@ class GtkTypeSystemTray extends SystemTray {
addMenuEntry_(menuText, null, callback);
}
else {
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.SIZE, imageUrl), callback);
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imageUrl), callback);
}
}
@ -317,7 +317,7 @@ class GtkTypeSystemTray extends SystemTray {
addMenuEntry_(menuText, null, callback);
}
else {
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.SIZE, cacheName, imageStream), callback);
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, cacheName, imageStream), callback);
}
}
@ -329,7 +329,7 @@ class GtkTypeSystemTray extends SystemTray {
addMenuEntry_(menuText, null, callback);
}
else {
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.SIZE, imageStream), callback);
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imageStream), callback);
}
}
}

View File

@ -85,7 +85,7 @@ class Gtk {
isLoaded = true;
if (SystemTray.DEBUG) {
logger.info("GTK: {}", gtk2LibName);
logger.debug("GTK: {}", gtk2LibName);
}
} catch (Throwable e) {
if (SystemTray.DEBUG) {
@ -107,7 +107,7 @@ class Gtk {
isLoaded = true;
if (SystemTray.DEBUG) {
logger.info("GTK: {}", gtk3LibName);
logger.debug("GTK: {}", gtk3LibName);
}
} catch (Throwable e) {
if (SystemTray.DEBUG) {
@ -129,7 +129,7 @@ class Gtk {
isLoaded = true;
if (SystemTray.DEBUG) {
logger.info("GTK: {}", gtk2LibName);
logger.debug("GTK: {}", gtk2LibName);
}
} catch (Throwable e) {
if (SystemTray.DEBUG) {
@ -143,7 +143,7 @@ class Gtk {
alreadyRunningGTK |= SystemTray.isSwtLoaded;
if (SystemTray.DEBUG) {
logger.info("Is the system already running GTK? {}", alreadyRunningGTK);
logger.debug("Is the system already running GTK? {}", alreadyRunningGTK);
}
if (!isLoaded) {

View File

@ -125,7 +125,7 @@ class SwingMenuEntry implements MenuEntry {
setImage_(null);
}
else {
setImage_(ImageUtils.resizeAndCache(ImageUtils.SIZE, imagePath));
setImage_(ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imagePath));
}
}
@ -136,7 +136,7 @@ class SwingMenuEntry implements MenuEntry {
setImage_(null);
}
else {
setImage_(ImageUtils.resizeAndCache(ImageUtils.SIZE, imageUrl));
setImage_(ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imageUrl));
}
}
@ -147,7 +147,7 @@ class SwingMenuEntry implements MenuEntry {
setImage_(null);
}
else {
setImage_(ImageUtils.resizeAndCache(ImageUtils.SIZE, cacheName, imageStream));
setImage_(ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, cacheName, imageStream));
}
}
@ -159,7 +159,7 @@ class SwingMenuEntry implements MenuEntry {
setImage_(null);
}
else {
setImage_(ImageUtils.resizeAndCache(ImageUtils.SIZE, imageStream));
setImage_(ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imageStream));
}
}

View File

@ -259,7 +259,7 @@ class SwingSystemTray extends dorkbox.systemTray.SystemTray {
addMenuEntry_(menuText, null, callback);
}
else {
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.SIZE, imagePath), callback);
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imagePath), callback);
}
}
@ -270,7 +270,7 @@ class SwingSystemTray extends dorkbox.systemTray.SystemTray {
addMenuEntry_(menuText, null, callback);
}
else {
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.SIZE, imageUrl), callback);
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imageUrl), callback);
}
}
@ -281,7 +281,7 @@ class SwingSystemTray extends dorkbox.systemTray.SystemTray {
addMenuEntry_(menuText, null, callback);
}
else {
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.SIZE, cacheName, imageStream), callback);
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, cacheName, imageStream), callback);
}
}
@ -293,7 +293,7 @@ class SwingSystemTray extends dorkbox.systemTray.SystemTray {
addMenuEntry_(menuText, null, callback);
}
else {
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.SIZE, imageStream), callback);
addMenuEntry_(menuText, ImageUtils.resizeAndCache(ImageUtils.ENTRY_SIZE, imageStream), callback);
}
}
}

View File

@ -47,7 +47,8 @@ class ImageUtils {
private static final File TEMP_DIR = new File(CacheUtil.TEMP_DIR, "ResizedImages");
// tray/menu-entry size.
public static volatile int SIZE = 0;
public static volatile int TRAY_SIZE = 0;
public static volatile int ENTRY_SIZE = 0;
/**
* @param trayType
@ -57,16 +58,21 @@ class ImageUtils {
*/
public static
void determineIconSize(int trayType) {
int trayScale = 0;
int menuScale = 0;
if (SystemTray.AUTO_TRAY_SIZE) {
if (OS.isWindows()) {
// windows will automatically scale the tray size
SIZE = SystemTray.DEFAULT_WINDOWS_SIZE;
// windows will automatically scale the tray size BUT NOT the menu entry icon size
trayScale = SystemTray.DEFAULT_WINDOWS_SIZE;
menuScale = SystemTray.DEFAULT_MENU_SIZE;
} else {
// GtkStatusIcon will USUALLY automatically scale the icon
// AppIndicator will NOT scale the icon
if (trayType == SystemTray.TYPE_SWING || trayType == SystemTray.TYPE_GTK_STATUSICON) {
// swing or GtkStatusIcon on linux/mac? use the default settings
SIZE = SystemTray.DEFAULT_LINUX_SIZE;
trayScale = SystemTray.DEFAULT_LINUX_SIZE;
menuScale = SystemTray.DEFAULT_MENU_SIZE;
} else {
int uiScalingFactor = 0;
@ -86,13 +92,13 @@ class ImageUtils {
if (!output.isEmpty()) {
if (SystemTray.DEBUG) {
SystemTray.logger.info("Checking scaling factor for GTK environment, should start with 'uint32', value: '{}'", output);
SystemTray.logger.debug("Checking scaling factor for GTK environment, should start with 'uint32', value: '{}'", output);
}
// DEFAULT icon size is 16. HiDpi changes this scale, so we should use it as well.
// should be: uint32 0 or something
if (output.startsWith("uint32")) {
String value = output.substring(output.indexOf(" ")+1, output.length()-1);
if (output.contains("uint32")) {
String value = output.substring(output.indexOf("uint")+7, output.length()-1);
uiScalingFactor = Integer.parseInt(value);
// 0 is disabled (no scaling)
@ -115,23 +121,30 @@ class ImageUtils {
// the DEFAULT scale is 16
if (uiScalingFactor > 1) {
SIZE = SystemTray.DEFAULT_LINUX_SIZE * uiScalingFactor;
trayScale = SystemTray.DEFAULT_LINUX_SIZE * uiScalingFactor;
menuScale = SystemTray.DEFAULT_MENU_SIZE * uiScalingFactor;
} else {
SIZE = SystemTray.DEFAULT_LINUX_SIZE;
trayScale = SystemTray.DEFAULT_LINUX_SIZE;
menuScale = SystemTray.DEFAULT_MENU_SIZE;
}
if (SystemTray.DEBUG) {
SystemTray.logger.info("uiScaling factor is '{}', auto tray size is '{}'.", uiScalingFactor, SIZE);
SystemTray.logger.debug("uiScaling factor is '{}', auto tray size is '{}'.", uiScalingFactor, trayScale);
}
}
}
} else {
if (OS.isWindows()) {
SIZE = SystemTray.DEFAULT_WINDOWS_SIZE;
trayScale = SystemTray.DEFAULT_WINDOWS_SIZE;
menuScale = SystemTray.DEFAULT_MENU_SIZE;
} else {
SIZE = SystemTray.DEFAULT_LINUX_SIZE;
trayScale = SystemTray.DEFAULT_LINUX_SIZE;
menuScale = SystemTray.DEFAULT_MENU_SIZE;
}
}
TRAY_SIZE = trayScale;
ENTRY_SIZE = menuScale;
}
@ -328,6 +341,10 @@ class ImageUtils {
@SuppressWarnings("ResultOfMethodCallIgnored")
private static
File resizeFileNoCheck(final int size, final URL fileUrl) throws IOException {
if (SystemTray.DEBUG) {
SystemTray.logger.debug("Resizing URL to {}. '{}'", size, fileUrl.getPath());
}
InputStream inputStream = fileUrl.openStream();
// have to resize the file (and return the new path)

View File

@ -114,7 +114,7 @@ class WindowsSystemTraySwing {
trayClass.getConstructors()[0].setModifiers(trayClass.getConstructors()[0].getModifiers() & javassist.Modifier.PUBLIC);
CtMethod ctMethodGet = trayClass.getDeclaredMethod("getTrayIconSize");
ctMethodGet.setBody("{" +
"return new java.awt.Dimension(" + ImageUtils.SIZE + ", " + ImageUtils.SIZE + ");" +
"return new java.awt.Dimension(" + ImageUtils.TRAY_SIZE + ", " + ImageUtils.TRAY_SIZE + ");" +
"}");
trayBytes = trayClass.toBytecode();
@ -125,7 +125,7 @@ class WindowsSystemTraySwing {
CtMethod ctMethodCreate = trayIconClass.getDeclaredMethod("createNativeImage");
CtMethod ctMethodUpdate = trayIconClass.getDeclaredMethod("updateNativeImage");
int TRAY_MASK = (ImageUtils.SIZE * ImageUtils.SIZE) / 8;
int TRAY_MASK = (ImageUtils.TRAY_SIZE * ImageUtils.TRAY_SIZE) / 8;
ctMethodCreate.setBody("{" +
"java.awt.image.BufferedImage bufferedImage = $1;\n" +
@ -194,10 +194,10 @@ class WindowsSystemTraySwing {
BootStrapClassLoader.defineClass(trayIconBytes);
if (SystemTray.DEBUG) {
logger.info("Successfully changed tray icon size to: {}", ImageUtils.SIZE);
logger.debug("Successfully changed tray icon size to: {}", ImageUtils.TRAY_SIZE);
}
} catch (Exception e) {
logger.error("Error setting tray icon size to: {}", ImageUtils.SIZE, e);
logger.error("Error setting tray icon size to: {}", ImageUtils.TRAY_SIZE, e);
}
}
}