changeset 414:ac23e40d3880

6438179: XToolkit.isTraySupported() result has nothing to do with the system tray Summary: Use System Tray Protocol Specification Reviewed-by: prr, dcherepanov
author omajid
date Fri, 13 Aug 2010 10:36:08 -0400
parents 636250081b3b
children 78235ae077a1
files src/share/classes/java/awt/SystemTray.java src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java src/solaris/classes/sun/awt/X11/XToolkit.java
diffstat 3 files changed, 28 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/SystemTray.java	Wed Aug 11 19:06:15 2010 +0100
+++ b/src/share/classes/java/awt/SystemTray.java	Fri Aug 13 10:36:08 2010 -0400
@@ -164,16 +164,14 @@
         if (GraphicsEnvironment.isHeadless()) {
             throw new HeadlessException();
         }
+
+        initializeSystemTrayIfNeeded();
+
         if (!isSupported()) {
             throw new UnsupportedOperationException(
                 "The system tray is not supported on the current platform.");
         }
 
-        synchronized (SystemTray.class) {
-            if (systemTray == null) {
-                systemTray = new SystemTray();
-            }
-        }
         return systemTray;
     }
 
@@ -204,7 +202,7 @@
      */
     public static boolean isSupported() {
         if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
-
+            initializeSystemTrayIfNeeded();
             return ((SunToolkit)Toolkit.getDefaultToolkit()).isTraySupported();
 
         } else if (Toolkit.getDefaultToolkit() instanceof HeadlessToolkit) {
@@ -472,4 +470,12 @@
             security.checkPermission(SecurityConstants.ACCESS_SYSTEM_TRAY_PERMISSION);
         }
     }
+
+    private static void initializeSystemTrayIfNeeded() {
+        synchronized (SystemTray.class) {
+            if (systemTray == null) {
+                systemTray = new SystemTray();
+            }
+        }
+    }
 }
--- a/src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java	Wed Aug 11 19:06:15 2010 +0100
+++ b/src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java	Fri Aug 13 10:36:08 2010 -0400
@@ -55,6 +55,19 @@
         return new Dimension(XTrayIconPeer.TRAY_ICON_HEIGHT, XTrayIconPeer.TRAY_ICON_WIDTH);
     }
 
+    boolean isAvailable() {
+        boolean available = false;
+        XToolkit.awtLock();
+        try {
+            long selection_owner = XlibWrapper.XGetSelectionOwner(XToolkit.getDisplay(),
+                _NET_SYSTEM_TRAY.getAtom());
+            available = (selection_owner != XConstants.None);
+        } finally {
+            XToolkit.awtUnlock();
+        }
+        return available;
+    }
+
     // ***********************************************************************
     // ***********************************************************************
 
--- a/src/solaris/classes/sun/awt/X11/XToolkit.java	Wed Aug 11 19:06:15 2010 +0100
+++ b/src/solaris/classes/sun/awt/X11/XToolkit.java	Fri Aug 13 10:36:08 2010 -0400
@@ -1073,10 +1073,9 @@
     }
 
     public boolean isTraySupported() {
-        int wm = XWM.getWMID();
-        if (wm == XWM.METACITY_WM || wm == XWM.KDE2_WM)
-        {
-            return true;
+        XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
+        if (peer != null) {
+            return peer.isAvailable();
         }
         return false;
     }