# HG changeset patch
# User omajid
# Date 1281710168 14400
# Node ID ac23e40d3880c30085d7a76826145afbe73dd465
# Parent 636250081b3b27e4b9f536903aa2ddad135f24f2
6438179: XToolkit.isTraySupported() result has nothing to do with the system tray
Summary: Use System Tray Protocol Specification
Reviewed-by: prr, dcherepanov

--- openjdk.orig/jdk/src/share/classes/java/awt/SystemTray.java	Wed Aug 11 19:06:15 2010 +0100
+++ openjdk/jdk/src/share/classes/java/awt/SystemTray.java	Fri Aug 13 10:36:08 2010 -0400
@@ -164,16 +164,14 @@ public class SystemTray {
         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 class SystemTray {
      */
     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 @@ public class SystemTray {
             security.checkPermission(SecurityConstants.ACCESS_SYSTEM_TRAY_PERMISSION);
         }
     }
+
+    private static void initializeSystemTrayIfNeeded() {
+        synchronized (SystemTray.class) {
+            if (systemTray == null) {
+                systemTray = new SystemTray();
+            }
+        }
+    }
 }
--- openjdk.orig/jdk/src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java	Wed Aug 11 19:06:15 2010 +0100
+++ openjdk/jdk/src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java	Fri Aug 13 10:36:08 2010 -0400
@@ -55,6 +55,19 @@ public class XSystemTrayPeer implements 
         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;
+    }
+
     // ***********************************************************************
     // ***********************************************************************
 
--- openjdk.orig/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java	Wed Aug 11 19:06:15 2010 +0100
+++ openjdk/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java	Fri Aug 13 10:36:08 2010 -0400
@@ -1073,10 +1073,9 @@ public class XToolkit extends UNIXToolki
     }
 
     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;
     }

