Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
azvegint committed Feb 14, 2024
1 parent b823fa4 commit e001b46
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 6 deletions.
71 changes: 70 additions & 1 deletion src/java.desktop/unix/classes/sun/awt/UNIXToolkit.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -33,6 +33,7 @@
import static java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR;
import static java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB;
import static java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
import static java.util.concurrent.TimeUnit.SECONDS;

import java.awt.color.ColorSpace;

Expand All @@ -47,6 +48,9 @@
import java.awt.image.DataBufferByte;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
Expand Down Expand Up @@ -240,6 +244,71 @@ protected Object lazilyLoadGTKIcon(String longname) {
return img;
}

private static volatile Boolean shouldDisableSystemTray = null;

/**
* There is an issue displaying the xembed icons in appIndicators
* area with certain Gnome Shell versions.
* To avoid any loss of quality of service, we are disabling
* SystemTray support in such cases.
*
* @return true if system tray should be disabled
*/
public boolean shouldDisableSystemTray() {
Boolean result = shouldDisableSystemTray;
if (result == null) {
synchronized (GTK_LOCK) {
result = shouldDisableSystemTray;
if (result == null) {
if ("gnome".equals(getDesktop())) {
@SuppressWarnings("removal")
Integer gnomeShellMajorVersion =
AccessController
.doPrivileged((PrivilegedAction<Integer>)
this::getGnomeShellMajorVersion);

if (gnomeShellMajorVersion == null
|| gnomeShellMajorVersion < 45) {

return shouldDisableSystemTray = true;
}
}
shouldDisableSystemTray = result = false;
}
}
}
return result;
}

private Integer getGnomeShellMajorVersion() {
try {
Process process =
new ProcessBuilder("/usr/bin/gnome-shell", "--version")
.start();
try (InputStreamReader isr = new InputStreamReader(process.getInputStream());
BufferedReader reader = new BufferedReader(isr)) {

if (process.waitFor(2, SECONDS) && process.exitValue() == 0) {
String line = reader.readLine();
if (line != null) {
String[] versionComponents = line
.replaceAll("[^\\d.]", "")
.split("\\.");

if (versionComponents.length >= 1) {
return Integer.parseInt(versionComponents[0]);
}
}
}
}
} catch (IOException
| InterruptedException
| NumberFormatException ignored) {
}

return null;
}

/**
* Returns a BufferedImage which contains the Gtk icon requested. If no
* such icon exists or an error occurs loading the icon the result will
Expand Down
14 changes: 9 additions & 5 deletions src/java.desktop/unix/classes/sun/awt/X11/XSystemTrayPeer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,6 +30,7 @@
import sun.awt.SunToolkit;
import sun.awt.AppContext;
import sun.awt.AWTAccessor;
import sun.awt.UNIXToolkit;
import sun.util.logging.PlatformLogger;

public class XSystemTrayPeer implements SystemTrayPeer, XMSelectionListener {
Expand All @@ -55,11 +56,14 @@ public class XSystemTrayPeer implements SystemTrayPeer, XMSelectionListener {

selection.addSelectionListener(this);

long selection_owner = selection.getOwner(SCREEN);
available = (selection_owner != XConstants.None);
UNIXToolkit tk = (UNIXToolkit)Toolkit.getDefaultToolkit();
if (!tk.shouldDisableSystemTray()) {
long selection_owner = selection.getOwner(SCREEN);
available = (selection_owner != XConstants.None);

if (log.isLoggable(PlatformLogger.Level.FINE)) {
log.fine(" check if system tray is available. selection owner: " + selection_owner);
if (log.isLoggable(PlatformLogger.Level.FINE)) {
log.fine(" check if system tray is available. selection owner: " + selection_owner);
}
}
}

Expand Down

0 comments on commit e001b46

Please sign in to comment.