Fixed XFCE systray panel size detection, general code polish

This commit is contained in:
Robinson 2021-03-20 22:57:00 +01:00
parent 0410a83a62
commit 3b36203df7

View File

@ -38,7 +38,6 @@ import dorkbox.jna.linux.structs.GtkStyle;
import dorkbox.jna.linux.structs.PangoRectangle;
import dorkbox.os.OS;
import dorkbox.os.OSUtil;
import dorkbox.swt.Swt;
import dorkbox.util.FileUtil;
import dorkbox.util.MathUtil;
@ -242,12 +241,13 @@ class GtkTheme {
OSUtil.DesktopEnv.Env env = OSUtil.DesktopEnv.get();
// sometimes the scaling-factor is set. If we have gsettings, great! otherwise try KDE
try {
// gsettings get org.gnome.desktop.interface scaling-factor
String output = Executor.Companion.run("gsettings", "get", "org.gnome.desktop.interface", "scaling-factor");
if (!output.isEmpty()) {
if (!output.isEmpty() && !output.endsWith("not found")) {
// DEFAULT icon size is 16. HiDpi changes this scale, so we should use it as well.
// should be: uint32 0 or something
if (output.contains("uint32")) {
@ -379,7 +379,7 @@ class GtkTheme {
}
}
}
else {
if (OSUtil.Linux.isUbuntu() && OSUtil.DesktopEnv.isUnity(env)) {
// if we measure on ubuntu unity using a screen shot (using swing, so....) , the max size was 24, HOWEVER this goes from
// the top->bottom of the indicator bar -- and since it was swing, it uses a different rendering method and it (honestly)
@ -388,16 +388,22 @@ class GtkTheme {
return 22;
}
else {
// xfce is easy, because it's not a GTK setting for the size (xfce notification area maximum icon size)
if (env == OSUtil.DesktopEnv.Env.XFCE) {
// xfce is easy, because it's not a GTK setting for the size (xfce notification area maximum icon size)
String properties = OSUtil.DesktopEnv.queryXfce("xfce4-panel", null);
String[] propertiesAsList = properties.split(OS.LINE_SEPARATOR);
for (String prop : propertiesAsList) {
if (prop.startsWith("/plugins/") && prop.endsWith("/size-max")) {
// this is the property we are looking for (we just don't know which panel it's on)
// note: trim() is required because it will strip new-line
String size = OSUtil.DesktopEnv.queryXfce("xfce4-panel", prop);
// xfconf-query -c xfce4-panel -p /plugins/plugin-14 (this will say 'systray' or 'tasklist' or whatever)
// find the 'systray' plugin
String panelString = prop.substring(0, prop.indexOf("/size-max"));
String panelName = OSUtil.DesktopEnv.queryXfce("xfce4-panel", panelString).trim();
if (panelName.equals("systray")) {
String size = OSUtil.DesktopEnv.queryXfce("xfce4-panel", prop).trim();
try {
return Integer.parseInt(size);
} catch (Exception e) {
@ -407,18 +413,11 @@ class GtkTheme {
}
}
}
// default...
return 22;
}
}
// try to use GTK to get the tray icon size
final AtomicInteger traySize = new AtomicInteger();
if (Swt.isLoaded) {
} else {
GtkEventDispatch.dispatchAndWait(new Runnable() {
@Override
public
@ -462,14 +461,11 @@ class GtkTheme {
}
}
});
}
int i = traySize.get();
if (i != 0) {
return i;
}
}
}
// sane default
LoggerFactory.getLogger(GtkTheme.class).warn("Unable to get tray image size. Using default.");