-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linux (GNOME): rework system tray support detection
- In addition to the previously cheked extensions also show tray icon if any of the TopIcons extensions is enabled - Show tray icon for older GNOME releases < 3.26, that come with out-of-the-box support for tray icons
- Loading branch information
Showing
1 changed file
with
35 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,7 @@ | |
import java.security.SecureRandom; | ||
import java.text.MessageFormat; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.EnumMap; | ||
import java.util.EnumSet; | ||
|
@@ -135,6 +136,7 @@ | |
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import java.util.prefs.Preferences; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import javax.swing.AbstractAction; | ||
|
@@ -298,6 +300,9 @@ public final class Main { | |
private static final String SINGLE_INSTANCE_INIT = "INIT"; | ||
private static final String SINGLE_INSTANCE_ACK = "ACK"; | ||
private static final String SINGLE_INSTANCE_EOF = "EOF"; | ||
private static final String[] GNOME_SYSTEM_TRAY_EXTENSIONS = { "[email protected]", | ||
"[email protected]", "[email protected]@gmail.com", "topiconsfix@[email protected]", | ||
"[email protected]", "[email protected]" }; | ||
static volatile Main main; | ||
static boolean skipMessageDialogs; | ||
private static volatile boolean terminated; | ||
|
@@ -1066,6 +1071,18 @@ private static void deleteSingleInstanceLockFile() { | |
} | ||
} | ||
|
||
private static String execCommandForOutput(final String[] cmdarray) { | ||
String output = null; | ||
try (final var inputStream = Runtime.getRuntime().exec(cmdarray).getInputStream(); | ||
final var scanner = new Scanner(inputStream, StandardCharsets.UTF_8).useDelimiter("\\A")) { | ||
output = scanner.hasNext() ? scanner.next() : null; | ||
} catch (final IOException e) { | ||
log.log(Level.WARNING, e.getMessage(), e); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
private static int getExtendedKeyCodeForMenu(final AbstractButton button, | ||
final Set<Integer> alreadyAssignedKeyCodes) { | ||
var keyCode = KeyEvent.VK_UNDEFINED; | ||
|
@@ -2071,17 +2088,25 @@ private void onControllersChanged(final List<ControllerInfo> presentControllers, | |
if (systemTraySupported && isLinux) { | ||
switch (System.getenv("XDG_SESSION_DESKTOP")) { | ||
case "gnome" -> { | ||
String output = null; | ||
try (final var inputStream = Runtime.getRuntime() | ||
.exec(new String[] { "/usr/bin/gnome-extensions", "list", "--enabled" }).getInputStream(); | ||
final var scanner = new Scanner(inputStream, StandardCharsets.UTF_8).useDelimiter("\\A")) { | ||
output = scanner.hasNext() ? scanner.next() : null; | ||
} catch (final IOException e) { | ||
log.log(Level.WARNING, e.getMessage(), e); | ||
} | ||
final var gnomeExtensions = execCommandForOutput( | ||
new String[] { "/usr/bin/gnome-extensions", "list", "--enabled" }); | ||
if (gnomeExtensions == null | ||
|| Arrays.stream(GNOME_SYSTEM_TRAY_EXTENSIONS).noneMatch(gnomeExtensions::contains)) { | ||
systemTraySupported = false; | ||
|
||
final var gnomeVersion = execCommandForOutput(new String[] { "/usr/bin/gnome-shell", "--version" }); | ||
if (gnomeVersion == null) { | ||
break; | ||
} | ||
|
||
systemTraySupported = (output != null && (output.contains("[email protected]") | ||
|| output.contains("[email protected]"))); | ||
final var matcher = Pattern.compile("^GNOME Shell (\\d+)\\.(\\d+).*").matcher(gnomeVersion); | ||
if (matcher.matches()) { | ||
final var majorVersion = Integer.parseInt(matcher.group(1)); | ||
final var minorVersion = Integer.parseInt(matcher.group(2)); | ||
|
||
systemTraySupported = majorVersion < 3 || (majorVersion == 3 && minorVersion < 26); | ||
} | ||
} | ||
} | ||
case "KDE" -> { | ||
final var kdeSessionVersion = System.getenv("KDE_SESSION_VERSION"); | ||
|