jdk/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java
changeset 3938 ef327bd847c0
parent 2472 b7aba00cabb6
child 4214 0fa32d38146b
equal deleted inserted replaced
3934:487e1aa949c4 3938:ef327bd847c0
    29 import java.awt.event.*;
    29 import java.awt.event.*;
    30 import java.awt.peer.TrayIconPeer;
    30 import java.awt.peer.TrayIconPeer;
    31 import sun.awt.*;
    31 import sun.awt.*;
    32 import java.awt.image.*;
    32 import java.awt.image.*;
    33 import java.text.BreakIterator;
    33 import java.text.BreakIterator;
    34 import java.util.logging.Logger;
       
    35 import java.util.logging.Level;
       
    36 import java.util.concurrent.ArrayBlockingQueue;
    34 import java.util.concurrent.ArrayBlockingQueue;
    37 import java.security.AccessController;
    35 import java.security.AccessController;
    38 import java.security.PrivilegedAction;
    36 import java.security.PrivilegedAction;
    39 import java.lang.reflect.InvocationTargetException;
    37 import java.lang.reflect.InvocationTargetException;
       
    38 import sun.util.logging.PlatformLogger;
    40 
    39 
    41 public class XTrayIconPeer implements TrayIconPeer,
    40 public class XTrayIconPeer implements TrayIconPeer,
    42        InfoWindow.Balloon.LiveArguments,
    41        InfoWindow.Balloon.LiveArguments,
    43        InfoWindow.Tooltip.LiveArguments
    42        InfoWindow.Tooltip.LiveArguments
    44 {
    43 {
    45     private static final Logger ctrLog = Logger.getLogger("sun.awt.X11.XTrayIconPeer.centering");
    44     private static final PlatformLogger ctrLog = PlatformLogger.getLogger("sun.awt.X11.XTrayIconPeer.centering");
    46 
    45 
    47     TrayIcon target;
    46     TrayIcon target;
    48     TrayIconEventProxy eventProxy;
    47     TrayIconEventProxy eventProxy;
    49     XTrayIconEmbeddedFrame eframe;
    48     XTrayIconEmbeddedFrame eframe;
    50     TrayIconCanvas canvas;
    49     TrayIconCanvas canvas;
   105                         return;
   104                         return;
   106                     }
   105                     }
   107 
   106 
   108                     XConfigureEvent ce = ev.get_xconfigure();
   107                     XConfigureEvent ce = ev.get_xconfigure();
   109 
   108 
   110                     ctrLog.log(Level.FINE, "ConfigureNotify on parent of {0}: {1}x{2}+{3}+{4} (old: {5}+{6})",
   109                     ctrLog.fine("ConfigureNotify on parent of {0}: {1}x{2}+{3}+{4} (old: {5}+{6})",
   111                                new Object[] { XTrayIconPeer.this, ce.get_width(), ce.get_height(),
   110                                 XTrayIconPeer.this, ce.get_width(), ce.get_height(),
   112                                               ce.get_x(), ce.get_y(), old_x, old_y });
   111                                 ce.get_x(), ce.get_y(), old_x, old_y);
   113 
   112 
   114                     // A workaround for Gnome/Metacity (it doesn't affect the behaviour on KDE).
   113                     // A workaround for Gnome/Metacity (it doesn't affect the behaviour on KDE).
   115                     // On Metacity the EmbeddedFrame's parent window bounds are larger
   114                     // On Metacity the EmbeddedFrame's parent window bounds are larger
   116                     // than TrayIcon size required (that is we need a square but a rectangle
   115                     // than TrayIcon size required (that is we need a square but a rectangle
   117                     // is provided by the Panel Notification Area). The parent's background color
   116                     // is provided by the Panel Notification Area). The parent's background color
   127                     if (ce.get_height() != TRAY_ICON_HEIGHT && ce.get_width() != TRAY_ICON_WIDTH) {
   126                     if (ce.get_height() != TRAY_ICON_HEIGHT && ce.get_width() != TRAY_ICON_WIDTH) {
   128 
   127 
   129                         // If both the height and the width differ from the fixed size then WM
   128                         // If both the height and the width differ from the fixed size then WM
   130                         // must level at least one side to the fixed size. For some reason it may take
   129                         // must level at least one side to the fixed size. For some reason it may take
   131                         // a few hops (even after reparenting) and we have to skip the intermediate ones.
   130                         // a few hops (even after reparenting) and we have to skip the intermediate ones.
   132                         ctrLog.log(Level.FINE, "ConfigureNotify on parent of {0}. Skipping as intermediate resizing.",
   131                         ctrLog.fine("ConfigureNotify on parent of {0}. Skipping as intermediate resizing.",
   133                                    XTrayIconPeer.this);
   132                                     XTrayIconPeer.this);
   134                         return;
   133                         return;
   135 
   134 
   136                     } else if (ce.get_height() > TRAY_ICON_HEIGHT) {
   135                     } else if (ce.get_height() > TRAY_ICON_HEIGHT) {
   137 
   136 
   138                         ctrLog.log(Level.FINE, "ConfigureNotify on parent of {0}. Centering by \"Y\".",
   137                         ctrLog.fine("ConfigureNotify on parent of {0}. Centering by \"Y\".",
   139                                    XTrayIconPeer.this);
   138                                     XTrayIconPeer.this);
   140 
   139 
   141                         XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), eframeParentID,
   140                         XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), eframeParentID,
   142                                                       ce.get_x(),
   141                                                       ce.get_x(),
   143                                                       ce.get_y()+ce.get_height()/2-TRAY_ICON_HEIGHT/2,
   142                                                       ce.get_y()+ce.get_height()/2-TRAY_ICON_HEIGHT/2,
   144                                                       TRAY_ICON_WIDTH,
   143                                                       TRAY_ICON_WIDTH,
   146                         ex_height = ce.get_height();
   145                         ex_height = ce.get_height();
   147                         ex_width = 0;
   146                         ex_width = 0;
   148 
   147 
   149                     } else if (ce.get_width() > TRAY_ICON_WIDTH) {
   148                     } else if (ce.get_width() > TRAY_ICON_WIDTH) {
   150 
   149 
   151                         ctrLog.log(Level.FINE, "ConfigureNotify on parent of {0}. Centering by \"X\".",
   150                         ctrLog.fine("ConfigureNotify on parent of {0}. Centering by \"X\".",
   152                                    XTrayIconPeer.this);
   151                                     XTrayIconPeer.this);
   153 
   152 
   154                         XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), eframeParentID,
   153                         XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), eframeParentID,
   155                                                       ce.get_x()+ce.get_width()/2 - TRAY_ICON_WIDTH/2,
   154                                                       ce.get_x()+ce.get_width()/2 - TRAY_ICON_WIDTH/2,
   156                                                       ce.get_y(),
   155                                                       ce.get_y(),
   157                                                       TRAY_ICON_WIDTH,
   156                                                       TRAY_ICON_WIDTH,
   164                         // When some tray icon gets removed from the tray, a Java icon may be repositioned.
   163                         // When some tray icon gets removed from the tray, a Java icon may be repositioned.
   165                         // In this case the parent window also lose centering. We have to restore it.
   164                         // In this case the parent window also lose centering. We have to restore it.
   166 
   165 
   167                         if (ex_height != 0) {
   166                         if (ex_height != 0) {
   168 
   167 
   169                             ctrLog.log(Level.FINE, "ConfigureNotify on parent of {0}. Move detected. Centering by \"Y\".",
   168                             ctrLog.fine("ConfigureNotify on parent of {0}. Move detected. Centering by \"Y\".",
   170                                        XTrayIconPeer.this);
   169                                         XTrayIconPeer.this);
   171 
   170 
   172                             XlibWrapper.XMoveWindow(XToolkit.getDisplay(), eframeParentID,
   171                             XlibWrapper.XMoveWindow(XToolkit.getDisplay(), eframeParentID,
   173                                                     ce.get_x(),
   172                                                     ce.get_x(),
   174                                                     ce.get_y() + ex_height/2 - TRAY_ICON_HEIGHT/2);
   173                                                     ce.get_y() + ex_height/2 - TRAY_ICON_HEIGHT/2);
   175 
   174 
   176                         } else if (ex_width != 0) {
   175                         } else if (ex_width != 0) {
   177 
   176 
   178                             ctrLog.log(Level.FINE, "ConfigureNotify on parent of {0}. Move detected. Centering by \"X\".",
   177                             ctrLog.fine("ConfigureNotify on parent of {0}. Move detected. Centering by \"X\".",
   179                                        XTrayIconPeer.this);
   178                                         XTrayIconPeer.this);
   180 
   179 
   181                             XlibWrapper.XMoveWindow(XToolkit.getDisplay(), eframeParentID,
   180                             XlibWrapper.XMoveWindow(XToolkit.getDisplay(), eframeParentID,
   182                                                     ce.get_x() + ex_width/2 - TRAY_ICON_WIDTH/2,
   181                                                     ce.get_x() + ex_width/2 - TRAY_ICON_WIDTH/2,
   183                                                     ce.get_y());
   182                                                     ce.get_y());
   184                         } else {
   183                         } else {
   185                             ctrLog.log(Level.FINE, "ConfigureNotify on parent of {0}. Move detected. Skipping.",
   184                             ctrLog.fine("ConfigureNotify on parent of {0}. Move detected. Skipping.",
   186                                        XTrayIconPeer.this);
   185                                         XTrayIconPeer.this);
   187                         }
   186                         }
   188                     }
   187                     }
   189                     old_x = ce.get_x();
   188                     old_x = ce.get_x();
   190                     old_y = ce.get_y();
   189                     old_y = ce.get_y();
   191                     isParentWindowLocated = true;
   190                     isParentWindowLocated = true;