Skip to content

Commit

Permalink
Remove Linux System tray support (#997)
Browse files Browse the repository at this point in the history
Remove Linux System tray support
Closes #996
  • Loading branch information
tresf authored Aug 4, 2022
1 parent 2cc8898 commit edcfa39
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 144 deletions.
7 changes: 0 additions & 7 deletions src/qz/ui/component/IconCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import org.apache.logging.log4j.Logger;
import qz.utils.ColorUtilities;
import qz.utils.SystemUtilities;
import qz.utils.UbuntuUtilities;
import qz.utils.UnixUtilities;

import javax.imageio.ImageIO;
import javax.swing.*;
Expand Down Expand Up @@ -258,11 +256,6 @@ public void setBgColor(Icon i, Color bgColor) {
* - macOS 10.14+ dark mode support
*/
public void fixTrayIcons(boolean darkTaskbar) {
// Fix the tray icon to look proper on Ubuntu
if (UnixUtilities.isUbuntu()) {
UbuntuUtilities.fixTrayIcons(this);
}

// Handle mask-style tray icons
if (SystemUtilities.prefersMaskTrayIcon()) {
// Clone the mask icon
Expand Down
7 changes: 0 additions & 7 deletions src/qz/ui/tray/TaskbarTrayIcon.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package qz.ui.tray;

import qz.common.Constants;
import qz.utils.UbuntuUtilities;
import qz.utils.UnixUtilities;

import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
Expand All @@ -27,11 +25,6 @@ private void initializeComponents(Image trayImage, final ActionListener exitList
setTaskBarTitle(getTitle());
setSize(0, 0);
getContentPane().setBackground(Color.BLACK);
if (UnixUtilities.isUbuntu()) {
// attempt to camouflage the single pixel left behind
getContentPane().setBackground(UbuntuUtilities.getTrayColor());
}

iconSize = new Dimension(40, 40);

setIconImage(trayImage);
Expand Down
18 changes: 18 additions & 0 deletions src/qz/utils/LinuxUtilities.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package qz.utils;

import com.github.zafarkhaja.semver.Version;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import qz.common.Constants;

import java.awt.*;
import java.io.IOException;
import java.nio.file.Path;

Expand Down Expand Up @@ -34,4 +37,19 @@ public static boolean elevatedFileCopy(Path source, Path destination) {
String[] command = {foundElevator, "cp", source.toString(), destination.toString()};
return ShellUtilities.execute(command);
}

/**
* Runs a shell command to determine if "Dark" desktop theme is enabled
* @return true if enabled, false if not
*/
public static boolean isDarkMode() {
return !ShellUtilities.execute(new String[] { "gsettings", "get", "org.gnome.desktop.interface", "gtk-theme" }, new String[] { "dark" }, true, true).isEmpty();
}

public static double getScaleFactor() {
if (Constants.JAVA_VERSION.lessThan(Version.valueOf("11.0.0"))) {
return Toolkit.getDefaultToolkit().getScreenResolution() / 96.0;
}
return GtkUtilities.getScaleFactor();
}
}
11 changes: 6 additions & 5 deletions src/qz/utils/SystemUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public static boolean isDarkDesktop(boolean recheck) {
} else if (isWindows()) {
darkDesktop = WindowsUtilities.isDarkDesktop();
} else {
darkDesktop = UbuntuUtilities.isDarkMode();
darkDesktop = LinuxUtilities.isDarkMode();
}
}
return darkDesktop.booleanValue();
Expand All @@ -444,7 +444,7 @@ public static boolean setSystemLookAndFeel() {
try {
UIManager.getDefaults().put("Button.showMnemonics", Boolean.TRUE);
boolean darculaThemeNeeded = true;
if(!isMac() && (isUnix() && UbuntuUtilities.isDarkMode())) {
if(!isMac() && (isUnix() && LinuxUtilities.isDarkMode())) {
darculaThemeNeeded = false;
}
if(isDarkDesktop() && darculaThemeNeeded) {
Expand Down Expand Up @@ -509,7 +509,7 @@ public static double getWindowScaleFactor() {
return 1;
}
// Linux on JDK11 requires JNA calls to Gdk
return UbuntuUtilities.getScaleFactor();
return LinuxUtilities.getScaleFactor();
}

/**
Expand All @@ -528,7 +528,7 @@ public static boolean isHiDPI() {
return WindowsUtilities.getScaleFactor() > 1;
}
// Fallback to a JNA Gdk technique
return UbuntuUtilities.getScaleFactor() > 1;
return LinuxUtilities.getScaleFactor() > 1;
}

/**
Expand Down Expand Up @@ -744,7 +744,8 @@ public static boolean isSystemTraySupported(boolean headless) {
case MAC:
break;
default:
// TODO: Default to false for Linux?
// Linux System Tray support is abysmal, always use TaskbarTrayIcon
return false;
}
return SystemTray.isSupported();
}
Expand Down
125 changes: 0 additions & 125 deletions src/qz/utils/UbuntuUtilities.java

This file was deleted.

0 comments on commit edcfa39

Please sign in to comment.