|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
33 | 33 | import static java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR;
|
34 | 34 | import static java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB;
|
35 | 35 | import static java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
|
| 36 | +import static java.util.concurrent.TimeUnit.SECONDS; |
36 | 37 |
|
37 | 38 | import java.awt.color.ColorSpace;
|
38 | 39 |
|
|
47 | 48 | import java.awt.image.DataBufferByte;
|
48 | 49 | import java.awt.image.Raster;
|
49 | 50 | import java.awt.image.WritableRaster;
|
| 51 | +import java.io.BufferedReader; |
| 52 | +import java.io.IOException; |
| 53 | +import java.io.InputStreamReader; |
50 | 54 | import java.security.AccessController;
|
51 | 55 | import java.security.PrivilegedAction;
|
52 | 56 | import java.util.Arrays;
|
@@ -240,6 +244,72 @@ protected Object lazilyLoadGTKIcon(String longname) {
|
240 | 244 | return img;
|
241 | 245 | }
|
242 | 246 |
|
| 247 | + private static volatile Boolean shouldDisableSystemTray = null; |
| 248 | + |
| 249 | + /** |
| 250 | + * There is an issue displaying the xembed icons in appIndicators |
| 251 | + * area with certain Gnome Shell versions. |
| 252 | + * To avoid any loss of quality of service, we are disabling |
| 253 | + * SystemTray support in such cases. |
| 254 | + * |
| 255 | + * @return true if system tray should be disabled |
| 256 | + */ |
| 257 | + public boolean shouldDisableSystemTray() { |
| 258 | + Boolean result = shouldDisableSystemTray; |
| 259 | + if (result == null) { |
| 260 | + synchronized (GTK_LOCK) { |
| 261 | + result = shouldDisableSystemTray; |
| 262 | + if (result == null) { |
| 263 | + if ("gnome".equals(getDesktop())) { |
| 264 | + @SuppressWarnings("removal") |
| 265 | + Integer gnomeShellMajorVersion = |
| 266 | + AccessController |
| 267 | + .doPrivileged((PrivilegedAction<Integer>) |
| 268 | + this::getGnomeShellMajorVersion); |
| 269 | + |
| 270 | + if (gnomeShellMajorVersion == null |
| 271 | + || gnomeShellMajorVersion < 45) { |
| 272 | + |
| 273 | + return shouldDisableSystemTray = true; |
| 274 | + } |
| 275 | + } |
| 276 | + shouldDisableSystemTray = result = false; |
| 277 | + } |
| 278 | + } |
| 279 | + } |
| 280 | + return result; |
| 281 | + } |
| 282 | + |
| 283 | + private Integer getGnomeShellMajorVersion() { |
| 284 | + try { |
| 285 | + Process process = |
| 286 | + new ProcessBuilder("/usr/bin/gnome-shell", "--version") |
| 287 | + .start(); |
| 288 | + try (InputStreamReader isr = new InputStreamReader(process.getInputStream()); |
| 289 | + BufferedReader reader = new BufferedReader(isr)) { |
| 290 | + |
| 291 | + if (process.waitFor(2, SECONDS) && process.exitValue() == 0) { |
| 292 | + String line = reader.readLine(); |
| 293 | + if (line != null) { |
| 294 | + String[] versionComponents = line |
| 295 | + .replaceAll("[^\\d.]", "") |
| 296 | + .split("\\."); |
| 297 | + |
| 298 | + if (versionComponents.length >= 1) { |
| 299 | + return Integer.parseInt(versionComponents[0]); |
| 300 | + } |
| 301 | + } |
| 302 | + } |
| 303 | + } |
| 304 | + } catch (IOException |
| 305 | + | InterruptedException |
| 306 | + | IllegalThreadStateException |
| 307 | + | NumberFormatException ignored) { |
| 308 | + } |
| 309 | + |
| 310 | + return null; |
| 311 | + } |
| 312 | + |
243 | 313 | /**
|
244 | 314 | * Returns a BufferedImage which contains the Gtk icon requested. If no
|
245 | 315 | * such icon exists or an error occurs loading the icon the result will
|
|
0 commit comments