src/solaris/classes/sun/awt/X11/XWindowPeer.java

Print this page




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 package sun.awt.X11;
  26 
  27 import java.awt.*;
  28 
  29 import java.awt.event.ComponentEvent;
  30 import java.awt.event.FocusEvent;
  31 import java.awt.event.WindowEvent;
  32 
  33 import java.awt.image.BufferedImage;
  34 
  35 import java.awt.peer.ComponentPeer;
  36 import java.awt.peer.WindowPeer;
  37 





  38 import java.util.ArrayList;
  39 import java.util.HashSet;
  40 import java.util.Iterator;
  41 import java.util.Set;
  42 import java.util.Vector;
  43 


  44 import sun.util.logging.PlatformLogger;
  45 
  46 import sun.awt.AWTAccessor;
  47 import sun.awt.ComponentAccessor;
  48 import sun.awt.WindowAccessor;
  49 import sun.awt.AWTAccessor;
  50 import sun.awt.DisplayChangedListener;
  51 import sun.awt.SunToolkit;
  52 import sun.awt.X11GraphicsDevice;
  53 import sun.awt.X11GraphicsEnvironment;
  54 
  55 import sun.java2d.pipe.Region;
  56 
  57 class XWindowPeer extends XPanelPeer implements WindowPeer,
  58                                                 DisplayChangedListener {
  59 
  60     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWindowPeer");
  61     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XWindowPeer");
  62     private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XWindowPeer");
  63     private static final PlatformLogger grabLog = PlatformLogger.getLogger("sun.awt.X11.grab.XWindowPeer");


  73     private boolean alwaysOnTop;
  74     private boolean locationByPlatform;
  75 
  76     Dialog modalBlocker;
  77     boolean delayedModalBlocking = false;
  78     Dimension targetMinimumSize = null;
  79 
  80     private XWindowPeer ownerPeer;
  81 
  82     // used for modal blocking to keep existing z-order
  83     protected XWindowPeer prevTransientFor, nextTransientFor;
  84     // value of WM_TRANSIENT_FOR hint set on this window
  85     private XWindowPeer curRealTransientFor;
  86 
  87     private boolean grab = false; // Whether to do a grab during showing
  88 
  89     private boolean isMapped = false; // Is this window mapped or not
  90     private boolean mustControlStackPosition = false; // Am override-redirect not on top
  91     private XEventDispatcher rootPropertyEventDispatcher = null;
  92 


  93     /*
  94      * Focus related flags
  95      */
  96     private boolean isUnhiding = false;             // Is the window unhiding.
  97     private boolean isBeforeFirstMapNotify = false; // Is the window (being shown) between
  98                                                     //    setVisible(true) & handleMapNotify().
  99 
 100     // It need to be accessed from XFramePeer.
 101     protected Vector <ToplevelStateListener> toplevelStateListeners = new Vector<ToplevelStateListener>();
 102     XWindowPeer(XCreateWindowParams params) {
 103         super(params.putIfNull(PARENT_WINDOW, Long.valueOf(0)));
 104     }
 105 
 106     XWindowPeer(Window target) {
 107         super(new XCreateWindowParams(new Object[] {
 108             TARGET, target,
 109             PARENT_WINDOW, Long.valueOf(0)}));
 110     }
 111 
 112     /*


1166         winAttr.visibilityState = ve.get_state();
1167 //         if (ve.get_state() == XlibWrapper.VisibilityUnobscured) {
1168 //             // raiseInputMethodWindow
1169 //         }
1170         repositionSecurityWarning();
1171     }
1172 
1173     void handleRootPropertyNotify(XEvent xev) {
1174         XPropertyEvent ev = xev.get_xproperty();
1175         if( mustControlStackPosition &&
1176             ev.get_atom() == XAtom.get("_NET_CLIENT_LIST_STACKING").getAtom()){
1177             // Restore stack order unhadled/spoiled by WM or some app (nautilus).
1178             // As of now, don't use any generic machinery: just
1179             // do toBack() again.
1180             if(isOverrideRedirect()) {
1181                 toBack();
1182             }
1183         }
1184     }
1185 




































































1186     public void handleMapNotifyEvent(XEvent xev) {


1187         // See 6480534.
1188         isUnhiding |= isWMStateNetHidden();
1189 
1190         super.handleMapNotifyEvent(xev);
1191         if (!winAttr.initialFocus) {
1192             suppressWmTakeFocus(false); // restore the protocol.
1193             /*
1194              * For some reason, on Metacity, a frame/dialog being shown
1195              * without WM_TAKE_FOCUS protocol doesn't get moved to the front.
1196              * So, we do it evidently.
1197              */
1198             XToolkit.awtLock();
1199             try {
1200                 XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
1201             } finally {
1202                 XToolkit.awtUnlock();
1203             }
1204         }
1205         if (shouldFocusOnMapNotify()) {
1206             focusLog.fine("Automatically request focus on window");




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 package sun.awt.X11;
  26 
  27 import java.awt.*;
  28 
  29 import java.awt.event.ComponentEvent;
  30 import java.awt.event.FocusEvent;
  31 import java.awt.event.WindowEvent;
  32 
  33 import java.awt.image.BufferedImage;
  34 
  35 import java.awt.peer.ComponentPeer;
  36 import java.awt.peer.WindowPeer;
  37 
  38 import java.io.UnsupportedEncodingException;
  39 
  40 import java.security.AccessController;
  41 import java.security.PrivilegedAction;
  42 
  43 import java.util.ArrayList;
  44 import java.util.HashSet;
  45 import java.util.Iterator;
  46 import java.util.Set;
  47 import java.util.Vector;
  48 
  49 import java.util.concurrent.atomic.AtomicBoolean;
  50 
  51 import sun.util.logging.PlatformLogger;
  52 
  53 import sun.awt.AWTAccessor;
  54 import sun.awt.ComponentAccessor;
  55 import sun.awt.WindowAccessor;
  56 import sun.awt.AWTAccessor;
  57 import sun.awt.DisplayChangedListener;
  58 import sun.awt.SunToolkit;
  59 import sun.awt.X11GraphicsDevice;
  60 import sun.awt.X11GraphicsEnvironment;
  61 
  62 import sun.java2d.pipe.Region;
  63 
  64 class XWindowPeer extends XPanelPeer implements WindowPeer,
  65                                                 DisplayChangedListener {
  66 
  67     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWindowPeer");
  68     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XWindowPeer");
  69     private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XWindowPeer");
  70     private static final PlatformLogger grabLog = PlatformLogger.getLogger("sun.awt.X11.grab.XWindowPeer");


  80     private boolean alwaysOnTop;
  81     private boolean locationByPlatform;
  82 
  83     Dialog modalBlocker;
  84     boolean delayedModalBlocking = false;
  85     Dimension targetMinimumSize = null;
  86 
  87     private XWindowPeer ownerPeer;
  88 
  89     // used for modal blocking to keep existing z-order
  90     protected XWindowPeer prevTransientFor, nextTransientFor;
  91     // value of WM_TRANSIENT_FOR hint set on this window
  92     private XWindowPeer curRealTransientFor;
  93 
  94     private boolean grab = false; // Whether to do a grab during showing
  95 
  96     private boolean isMapped = false; // Is this window mapped or not
  97     private boolean mustControlStackPosition = false; // Am override-redirect not on top
  98     private XEventDispatcher rootPropertyEventDispatcher = null;
  99 
 100     private static final AtomicBoolean isStartupNotificationRemoved = new AtomicBoolean();
 101 
 102     /*
 103      * Focus related flags
 104      */
 105     private boolean isUnhiding = false;             // Is the window unhiding.
 106     private boolean isBeforeFirstMapNotify = false; // Is the window (being shown) between
 107                                                     //    setVisible(true) & handleMapNotify().
 108 
 109     // It need to be accessed from XFramePeer.
 110     protected Vector <ToplevelStateListener> toplevelStateListeners = new Vector<ToplevelStateListener>();
 111     XWindowPeer(XCreateWindowParams params) {
 112         super(params.putIfNull(PARENT_WINDOW, Long.valueOf(0)));
 113     }
 114 
 115     XWindowPeer(Window target) {
 116         super(new XCreateWindowParams(new Object[] {
 117             TARGET, target,
 118             PARENT_WINDOW, Long.valueOf(0)}));
 119     }
 120 
 121     /*


1175         winAttr.visibilityState = ve.get_state();
1176 //         if (ve.get_state() == XlibWrapper.VisibilityUnobscured) {
1177 //             // raiseInputMethodWindow
1178 //         }
1179         repositionSecurityWarning();
1180     }
1181 
1182     void handleRootPropertyNotify(XEvent xev) {
1183         XPropertyEvent ev = xev.get_xproperty();
1184         if( mustControlStackPosition &&
1185             ev.get_atom() == XAtom.get("_NET_CLIENT_LIST_STACKING").getAtom()){
1186             // Restore stack order unhadled/spoiled by WM or some app (nautilus).
1187             // As of now, don't use any generic machinery: just
1188             // do toBack() again.
1189             if(isOverrideRedirect()) {
1190                 toBack();
1191             }
1192         }
1193     }
1194 
1195     private void removeStartupNotification() {
1196         if (isStartupNotificationRemoved.getAndSet(true)) {
1197             return;
1198         }
1199 
1200         final String desktopStartupId = AccessController.doPrivileged(new PrivilegedAction<String>() {
1201             public String run() {
1202                 return XToolkit.getEnv("DESKTOP_STARTUP_ID");
1203             }
1204         });
1205         if (desktopStartupId == null) {
1206             return;
1207         }
1208 
1209         final StringBuilder messageBuilder = new StringBuilder("remove: ID=");
1210         messageBuilder.append('"');
1211         for (int i = 0; i < desktopStartupId.length(); i++) {
1212             if (desktopStartupId.charAt(i) == '"' || desktopStartupId.charAt(i) == '\\') {
1213                 messageBuilder.append('\\');
1214             }
1215             messageBuilder.append(desktopStartupId.charAt(i));
1216         }
1217         messageBuilder.append('"');
1218         messageBuilder.append('\0');
1219         final byte[] message;
1220         try {
1221             message = messageBuilder.toString().getBytes("UTF-8");
1222         } catch (UnsupportedEncodingException cannotHappen) {
1223             return;
1224         }
1225 
1226         XClientMessageEvent req = null;
1227 
1228         XToolkit.awtLock();
1229         try {
1230             final XAtom netStartupInfoBeginAtom = XAtom.get("_NET_STARTUP_INFO_BEGIN");
1231             final XAtom netStartupInfoAtom = XAtom.get("_NET_STARTUP_INFO");
1232 
1233             req = new XClientMessageEvent();
1234             req.set_type(XConstants.ClientMessage);
1235             req.set_window(getWindow());
1236             req.set_message_type(netStartupInfoBeginAtom.getAtom());
1237             req.set_format(8);
1238 
1239             for (int pos = 0; pos < message.length; pos += 20) {
1240                 final int msglen = Math.min(message.length - pos, 20);
1241                 int i = 0;
1242                 for (; i < msglen; i++) {
1243                     XlibWrapper.unsafe.putByte(req.get_data() + i, message[pos + i]);
1244                 }
1245                 for (; i < 20; i++) {
1246                     XlibWrapper.unsafe.putByte(req.get_data() + i, (byte)0);
1247                 }
1248                 XlibWrapper.XSendEvent(XToolkit.getDisplay(),
1249                     XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()),
1250                     false,
1251                     XConstants.PropertyChangeMask,
1252                     req.pData);
1253                 req.set_message_type(netStartupInfoAtom.getAtom());
1254             }
1255         } finally {
1256             XToolkit.awtUnlock();
1257             if (req != null) {
1258                 req.dispose();
1259             }
1260         }
1261     }
1262 
1263     public void handleMapNotifyEvent(XEvent xev) {
1264         removeStartupNotification();
1265 
1266         // See 6480534.
1267         isUnhiding |= isWMStateNetHidden();
1268 
1269         super.handleMapNotifyEvent(xev);
1270         if (!winAttr.initialFocus) {
1271             suppressWmTakeFocus(false); // restore the protocol.
1272             /*
1273              * For some reason, on Metacity, a frame/dialog being shown
1274              * without WM_TAKE_FOCUS protocol doesn't get moved to the front.
1275              * So, we do it evidently.
1276              */
1277             XToolkit.awtLock();
1278             try {
1279                 XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
1280             } finally {
1281                 XToolkit.awtUnlock();
1282             }
1283         }
1284         if (shouldFocusOnMapNotify()) {
1285             focusLog.fine("Automatically request focus on window");