[packages/icedtea7: 77/103] - added patch fixing system tray support in most window managers - Release: 1
jajcus
jajcus at pld-linux.org
Fri Apr 19 13:14:17 CEST 2013
commit 0676719a320b119a796744ac979ae9291bc61e2b
Author: Jacek Konieczny <jajcus at pld-linux.org>
Date: Sat Nov 27 19:32:23 2010 +0000
- added patch fixing system tray support in most window managers
- Release: 1
Changed files:
icedtea6-system_tray.patch -> 1.1
icedtea6.spec -> 1.69
icedtea6-system_tray.patch | 364 +++++++++++++++++++++++++++++++++++++++++++++
icedtea6.spec | 12 +-
2 files changed, 374 insertions(+), 2 deletions(-)
---
diff --git a/icedtea6.spec b/icedtea6.spec
index f787f16..2437edb 100644
--- a/icedtea6.spec
+++ b/icedtea6.spec
@@ -21,7 +21,7 @@ Summary: OpenJDK and GNU Classpath code
Summary(pl.UTF-8): Kod OpenJDK i GNU Classpath
Name: icedtea6
Version: 1.8.3
-Release: 0.1
+Release: 1
License: GPL v2
Group: Development/Languages/Java
Source0: http://icedtea.classpath.org/download/source/%{name}-%{version}.tar.gz
@@ -40,6 +40,7 @@ Patch1: %{name}-ecj_single_thread.patch
Patch2: %{name}-no_dtdtype_patch.patch
Patch3: %{name}-rpath.patch
Patch4: %{name}-libpath.patch
+Patch5: %{name}-system_tray.patch
URL: http://icedtea.classpath.org/wiki/Main_Page
BuildRequires: alsa-lib-devel
%{!?with_bootstrap:BuildRequires: ant-nodeps}
@@ -394,6 +395,7 @@ Wtyczka z obsługą Javy dla przeglądarek WWW.
%prep
%setup -q
+
%patch0 -p1
# workaround for an ECJ bug
@@ -406,6 +408,10 @@ Wtyczka z obsługą Javy dla przeglądarek WWW.
%patch4 -p1
+# patches to applied to the extracted sources
+mkdir -p pld-patches
+cp "%{PATCH5}" pld-patches
+
# let the build system extract the sources where it wants them
mkdir drops
ln -s %{SOURCE1} .
@@ -445,7 +451,8 @@ export PATH="$JAVA_HOME/bin:$PATH"
--with-xalan2-serializer-jar=%{_javadir}/serializer.jar \
--with-rhino=%{_javadir}/js.jar
-%{__make} extract extract-ecj
+%{__make} extract extract-ecj \
+ DISTRIBUTION_PATCHES="$(echo pld-patches/*.patch)"
%if %{with bootstrap}
# Cannot do that as patch, as the sources are prepared by make
@@ -456,6 +463,7 @@ export PATH="$JAVA_HOME/bin:$PATH"
sed -i -e's/dpkg-architecture/dpkg-architecture__/' openjdk*/*/make/common/shared/Platform.gmk
%{__make} -j1 \
+ DISTRIBUTION_PATCHES="$(echo pld-patches/*.patch)" \
PRINTF=/bin/printf
%install
diff --git a/icedtea6-system_tray.patch b/icedtea6-system_tray.patch
new file mode 100644
index 0000000..4a0cb00
--- /dev/null
+++ b/icedtea6-system_tray.patch
@@ -0,0 +1,364 @@
+diff -durN -x '*~' -x '*.orig' -x '*.rej' openjdk.orig/jdk/src/share/classes/java/awt/SystemTray.java openjdk/jdk/src/share/classes/java/awt/SystemTray.java
+--- openjdk.orig/jdk/src/share/classes/java/awt/SystemTray.java 2010-02-17 04:14:21.000000000 +0100
++++ openjdk/jdk/src/share/classes/java/awt/SystemTray.java 2010-11-27 19:29:43.661160073 +0100
+@@ -125,6 +125,8 @@
+
+ transient private SystemTrayPeer peer;
+
++ private static final TrayIcon[] EMPTY_TRAY_ARRAY = new TrayIcon[0];
++
+ /**
+ * Private <code>SystemTray</code> constructor.
+ *
+@@ -164,16 +166,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;
+ }
+
+@@ -203,15 +203,18 @@
+ * functionality is supported for the current platform
+ */
+ public static boolean isSupported() {
+- if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
+-
+- return ((SunToolkit)Toolkit.getDefaultToolkit()).isTraySupported();
+-
+- } else if (Toolkit.getDefaultToolkit() instanceof HeadlessToolkit) {
+-
+- return ((HeadlessToolkit)Toolkit.getDefaultToolkit()).isTraySupported();
++ Toolkit toolkit = Toolkit.getDefaultToolkit();
++ if (toolkit instanceof SunToolkit) {
++ // connecting tray to native resource
++ initializeSystemTrayIfNeeded();
++ return ((SunToolkit)toolkit).isTraySupported();
++ } else if (toolkit instanceof HeadlessToolkit) {
++ // skip initialization as the init routine
++ // throws HeadlessException
++ return ((HeadlessToolkit)toolkit).isTraySupported();
++ } else {
++ return false;
+ }
+- return false;
+ }
+
+ /**
+@@ -323,7 +326,7 @@
+ if (icons != null) {
+ return (TrayIcon[])icons.toArray(new TrayIcon[icons.size()]);
+ }
+- return new TrayIcon[0];
++ return EMPTY_TRAY_ARRAY;
+ }
+
+ /**
+@@ -343,19 +346,32 @@
+ }
+
+ /**
+- * Adds a {@code PropertyChangeListener} to the listener list for a
+- * specific property. Currently supported property:
+- * <ul>
+- * <li>{@code trayIcons}<p>
+- * <p>
+- * This {@code SystemTray}'s array of {@code TrayIcon}s.
+- * The array is accessed via {@link SystemTray#getTrayIcons}.<br>
+- * This property is changed when a {@code TrayIcon} is added to
+- * (or removed from) the {@code SystemTray}.<br> For example, this property
+- * is changed when the native {@code SystemTray} becomes unavailable on the
+- * desktop<br> and the {@code TrayIcon}s are automatically removed.</li>
+- * </ul>
+- * <p>
++ * Adds a {@code PropertyChangeListener} to the list of listeners for the
++ * specific property. The following properties are currently supported:
++ * <p> </p>
++ * <table border=1 summary="SystemTray properties">
++ * <tr>
++ * <th>Property</th>
++ * <th>Description</th>
++ * </tr>
++ * <tr>
++ * <td>{@code trayIcons}</td>
++ * <td>The {@code SystemTray}'s array of {@code TrayIcon} objects.
++ * The array is accessed via the {@link #getTrayIcons} method.<br>
++ * This property is changed when a tray icon is added to (or removed
++ * from) the system tray.<br> For example, this property is changed
++ * when the system tray becomes unavailable on the desktop<br>
++ * and the tray icons are automatically removed.</td>
++ * </tr>
++ * <tr>
++ * <td>{@code systemTray}</td>
++ * <td>This property contains {@code SystemTray} instance when the system tray
++ * is available or <code>null</code> otherwise.<br> This property is changed
++ * when the system tray becomes available or unavailable on the desktop.<br>
++ * The property is accessed by the {@link #getSystemTray} method.</td>
++ * </tr>
++ * </table>
++ * <p> </p>
+ * The {@code listener} listens to property changes only in this context.
+ * <p>
+ * If {@code listener} is {@code null}, no exception is thrown
+@@ -462,7 +478,12 @@
+
+ synchronized void addNotify() {
+ if (peer == null) {
+- peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createSystemTray(this);
++ Toolkit toolkit = Toolkit.getDefaultToolkit();
++ if (toolkit instanceof SunToolkit) {
++ peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createSystemTray(this);
++ } else if (toolkit instanceof HeadlessToolkit) {
++ peer = ((HeadlessToolkit)Toolkit.getDefaultToolkit()).createSystemTray(this);
++ }
+ }
+ }
+
+@@ -472,4 +493,12 @@
+ security.checkPermission(SecurityConstants.ACCESS_SYSTEM_TRAY_PERMISSION);
+ }
+ }
++
++ private static void initializeSystemTrayIfNeeded() {
++ synchronized (SystemTray.class) {
++ if (systemTray == null) {
++ systemTray = new SystemTray();
++ }
++ }
++ }
+ }
+diff -durN -x '*~' -x '*.orig' -x '*.rej' openjdk.orig/jdk/src/solaris/classes/sun/awt/X11/XMSelection.java openjdk/jdk/src/solaris/classes/sun/awt/X11/XMSelection.java
+--- openjdk.orig/jdk/src/solaris/classes/sun/awt/X11/XMSelection.java 2010-02-17 04:14:46.000000000 +0100
++++ openjdk/jdk/src/solaris/classes/sun/awt/X11/XMSelection.java 2010-11-27 19:29:43.661160073 +0100
+@@ -254,7 +254,7 @@
+ }
+
+ public synchronized void removeSelectionListener(XMSelectionListener listener) {
+- if (listeners == null) {
++ if (listeners != null) {
+ listeners.remove(listener);
+ }
+ }
+diff -durN -x '*~' -x '*.orig' -x '*.rej' openjdk.orig/jdk/src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java openjdk/jdk/src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java
+--- openjdk.orig/jdk/src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java 2010-02-17 04:14:46.000000000 +0100
++++ openjdk/jdk/src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java 2010-11-27 19:29:43.661160073 +0100
+@@ -27,47 +27,94 @@
+
+ import java.awt.*;
+ import java.awt.peer.SystemTrayPeer;
++import java.lang.reflect.Method;
++import java.lang.reflect.InvocationTargetException;
++import java.util.logging.Logger;
++import sun.awt.SunToolkit;
++import sun.awt.AppContext;
++
++public class XSystemTrayPeer implements SystemTrayPeer, XMSelectionListener {
++ private static final Logger log = Logger.getLogger("sun.awt.X11.XSystemTrayPeer");
+
+-public class XSystemTrayPeer implements SystemTrayPeer {
+ SystemTray target;
+- long tray_owner;
+ static XSystemTrayPeer peerInstance; // there is only one SystemTray peer per application
+
+- final static XAtom _NET_SYSTEM_TRAY = XAtom.get("_NET_SYSTEM_TRAY_S0");
+- final static XAtom _XEMBED_INFO = XAtom.get("_XEMBED_INFO");
+- final static XAtom _NET_SYSTEM_TRAY_OPCODE = XAtom.get("_NET_SYSTEM_TRAY_OPCODE");
+- final static XAtom _NET_WM_ICON = XAtom.get("_NET_WM_ICON");
+- final static long SYSTEM_TRAY_REQUEST_DOCK = 0;
++ private volatile boolean available;
++ private final XMSelection selection = new XMSelection("_NET_SYSTEM_TRAY");
++
++ private static final Method firePropertyChangeMethod =
++ XToolkit.getMethod(SystemTray.class, "firePropertyChange", new Class[] {String.class, Object.class, Object.class});
++ private static final Method addNotifyMethod = XToolkit.getMethod(TrayIcon.class, "addNotify", null);
++ private static final Method removeNotifyMethod = XToolkit.getMethod(TrayIcon.class, "removeNotify", null);
++
++ private static final int SCREEN = 0;
++ private static final String SYSTEM_TRAY_PROPERTY_NAME = "systemTray";
++ private static final XAtom _NET_SYSTEM_TRAY = XAtom.get("_NET_SYSTEM_TRAY_S" + SCREEN);
++ private static final XAtom _XEMBED_INFO = XAtom.get("_XEMBED_INFO");
++ private static final XAtom _NET_SYSTEM_TRAY_OPCODE = XAtom.get("_NET_SYSTEM_TRAY_OPCODE");
++ private static final XAtom _NET_WM_ICON = XAtom.get("_NET_WM_ICON");
++ private static final long SYSTEM_TRAY_REQUEST_DOCK = 0;
+
+ XSystemTrayPeer(SystemTray target) {
+ this.target = target;
+ peerInstance = this;
+
+- XToolkit.awtLock();
+- try {
+- tray_owner = XlibWrapper.XGetSelectionOwner(XToolkit.getDisplay(), _NET_SYSTEM_TRAY.getAtom());
+- } finally {
+- XToolkit.awtUnlock();
++ selection.addSelectionListener(this);
++
++ long selection_owner = selection.getOwner(SCREEN);
++ available = (selection_owner != XConstants.None);
++
++ log.fine(" check if system tray is available. selection owner: " + selection_owner);
++ }
++
++ public void ownerChanged(int screen, XMSelection sel, long newOwner, long data, long timestamp) {
++ if (screen != SCREEN) {
++ return;
++ }
++ if (!available) {
++ available = true;
++ firePropertyChange(SYSTEM_TRAY_PROPERTY_NAME, null, target);
++ } else {
++ removeTrayPeers();
+ }
++ createTrayPeers();
++ }
++
++ public void ownerDeath(int screen, XMSelection sel, long deadOwner) {
++ if (screen != SCREEN) {
++ return;
++ }
++ if (available) {
++ available = false;
++ firePropertyChange(SYSTEM_TRAY_PROPERTY_NAME, target, null);
++ removeTrayPeers();
++ }
++ }
++
++ public void selectionChanged(int screen, XMSelection sel, long owner, XPropertyEvent event) {
+ }
+
+ public Dimension getTrayIconSize() {
+ return new Dimension(XTrayIconPeer.TRAY_ICON_HEIGHT, XTrayIconPeer.TRAY_ICON_WIDTH);
+ }
+
++ boolean isAvailable() {
++ return available;
++ }
++
++ void dispose() {
++ selection.removeSelectionListener(this);
++ }
++
+ // ***********************************************************************
+ // ***********************************************************************
+
+ void addTrayIcon(XTrayIconPeer tiPeer) throws AWTException {
+- tray_owner = 0;
+- XToolkit.awtLock();
+- try {
+- tray_owner = XlibWrapper.XGetSelectionOwner(XToolkit.getDisplay(), _NET_SYSTEM_TRAY.getAtom());
+- } finally {
+- XToolkit.awtUnlock();
+- }
++ long selection_owner = selection.getOwner(SCREEN);
+
+- if (tray_owner == 0) {
++ log.fine(" send SYSTEM_TRAY_REQUEST_DOCK message to owner: " + selection_owner);
++
++ if (selection_owner == XConstants.None) {
+ throw new AWTException("TrayIcon couldn't be displayed.");
+ }
+
+@@ -77,7 +124,7 @@
+
+ _XEMBED_INFO.setAtomData(tray_window, data_ptr, data.length);
+
+- sendMessage(tray_owner, SYSTEM_TRAY_REQUEST_DOCK, tray_window, 0, 0);
++ sendMessage(selection_owner, SYSTEM_TRAY_REQUEST_DOCK, tray_window, 0, 0);
+ }
+
+ void sendMessage(long win, long msg, long data1, long data2, long data3) {
+@@ -109,4 +156,51 @@
+ static XSystemTrayPeer getPeerInstance() {
+ return peerInstance;
+ }
++
++ private void firePropertyChange(final String propertyName, final Object oldValue, final Object newValue) {
++ Runnable runnable = new Runnable() {
++ public void run() {
++ Object[] args = new Object[] {propertyName, oldValue, newValue};
++ invokeMethod(firePropertyChangeMethod, target, args);
++ }
++ };
++ invokeOnEachAppContext(runnable);
++ }
++
++ private void createTrayPeers() {
++ invokeOnEachTrayIcon(addNotifyMethod);
++ }
++
++ private void removeTrayPeers() {
++ invokeOnEachTrayIcon(removeNotifyMethod);
++ }
++
++ private void invokeOnEachTrayIcon(final Method method) {
++ Runnable runnable = new Runnable() {
++ public void run() {
++ TrayIcon[] icons = target.getTrayIcons();
++ for (TrayIcon ti : icons) {
++ invokeMethod(method, ti, (Object[]) null);
++ }
++ }
++ };
++ invokeOnEachAppContext(runnable);
++ }
++
++ private void invokeMethod(Method method, Object obj, Object[] args) {
++ try{
++ method.invoke(obj, args);
++ } catch (InvocationTargetException e){
++ e.printStackTrace();
++ } catch (IllegalAccessException e) {
++ e.printStackTrace();
++ }
++ }
++
++ private void invokeOnEachAppContext(Runnable runnable) {
++ for (AppContext appContext : AppContext.getAppContexts()) {
++ SunToolkit.invokeLaterOnAppContext(appContext, runnable);
++ }
++ }
++
+ }
+diff -durN -x '*~' -x '*.orig' -x '*.rej' openjdk.orig/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java openjdk/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java
+--- openjdk.orig/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java 2010-11-27 18:09:50.051823664 +0100
++++ openjdk/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java 2010-11-27 19:30:50.372032878 +0100
+@@ -300,6 +300,14 @@
+ }
+ }
+ });
++ Runtime.getRuntime().addShutdownHook(new Thread() {
++ public void run() {
++ XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
++ if (peer != null) {
++ peer.dispose();
++ }
++ }
++ });
+ }
+
+ static String getCorrectXIDString(String val) {
+@@ -1066,10 +1074,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;
+ }
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/icedtea7.git/commitdiff/f360048b2271851d733c2fc755b8e7cae2f337cf
More information about the pld-cvs-commit
mailing list