src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java

Print this page




  29 import java.awt.event.ComponentEvent;
  30 import java.awt.event.FocusEvent;
  31 import java.awt.event.WindowEvent;
  32 
  33 import java.awt.peer.ComponentPeer;
  34 import java.awt.peer.WindowPeer;
  35 
  36 import java.io.UnsupportedEncodingException;
  37 
  38 import java.security.AccessController;
  39 import java.security.PrivilegedAction;
  40 
  41 import java.util.ArrayList;
  42 import java.util.HashSet;
  43 import java.util.Iterator;
  44 import java.util.Set;
  45 import java.util.Vector;
  46 
  47 import java.util.concurrent.atomic.AtomicBoolean;
  48 

  49 import sun.util.logging.PlatformLogger;
  50 
  51 import sun.awt.AWTAccessor;
  52 import sun.awt.DisplayChangedListener;
  53 import sun.awt.SunToolkit;
  54 import sun.awt.X11GraphicsDevice;
  55 import sun.awt.X11GraphicsEnvironment;
  56 import sun.awt.IconInfo;
  57 
  58 import sun.java2d.pipe.Region;
  59 
  60 class XWindowPeer extends XPanelPeer implements WindowPeer,
  61                                                 DisplayChangedListener {
  62 
  63     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWindowPeer");
  64     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XWindowPeer");
  65     private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XWindowPeer");
  66     private static final PlatformLogger grabLog = PlatformLogger.getLogger("sun.awt.X11.grab.XWindowPeer");
  67     private static final PlatformLogger iconLog = PlatformLogger.getLogger("sun.awt.X11.icon.XWindowPeer");
  68 


 208     }
 209 
 210     private static native String getLocalHostname();
 211     private static native int getJvmPID();
 212 
 213     @SuppressWarnings("deprecation")
 214     void postInit(XCreateWindowParams params) {
 215         super.postInit(params);
 216 
 217         // Init WM_PROTOCOLS atom
 218         initWMProtocols();
 219 
 220         // Set _NET_WM_PID and WM_CLIENT_MACHINE using this JVM
 221         XAtom.get("WM_CLIENT_MACHINE").setProperty(getWindow(), getLocalHostname());
 222         XAtom.get("_NET_WM_PID").setCard32Property(getWindow(), getJvmPID());
 223 
 224         // Set WM_TRANSIENT_FOR and group_leader
 225         Window t_window = (Window)target;
 226         Window owner = t_window.getOwner();
 227         if (owner != null) {
 228             ownerPeer = (XWindowPeer)owner.getPeer();
 229             if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
 230                 focusLog.finer("Owner is " + owner);
 231                 focusLog.finer("Owner peer is " + ownerPeer);
 232                 focusLog.finer("Owner X window " + Long.toHexString(ownerPeer.getWindow()));
 233                 focusLog.finer("Owner content X window " + Long.toHexString(ownerPeer.getContentWindow()));
 234             }
 235             // as owner window may be an embedded window, we must get a toplevel window
 236             // to set as TRANSIENT_FOR hint
 237             long ownerWindow = ownerPeer.getWindow();
 238             if (ownerWindow != 0) {
 239                 XToolkit.awtLock();
 240                 try {
 241                     // Set WM_TRANSIENT_FOR
 242                     if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
 243                         focusLog.fine("Setting transient on " + Long.toHexString(getWindow())
 244                                       + " for " + Long.toHexString(ownerWindow));
 245                     }
 246                     setToplevelTransientFor(this, ownerPeer, false, true);
 247 
 248                     // Set group leader


 384         if (iconLog.isLoggable(PlatformLogger.Level.FINEST)) {
 385             iconLog.finest(">>> Length_ of buffer of icons data: " + totalLength +
 386                            ", maximum length: " + MAXIMUM_BUFFER_LENGTH_NET_WM_ICON);
 387         }
 388 
 389         return result;
 390     }
 391 
 392     /*
 393      * Dumps each icon from the list
 394      */
 395     static void dumpIcons(java.util.List<IconInfo> icons) {
 396         if (iconLog.isLoggable(PlatformLogger.Level.FINEST)) {
 397             iconLog.finest(">>> Sizes of icon images:");
 398             for (Iterator<IconInfo> i = icons.iterator(); i.hasNext(); ) {
 399                 iconLog.finest("    {0}", i.next());
 400             }
 401         }
 402     }
 403 
 404     @SuppressWarnings("deprecation")
 405     public void recursivelySetIcon(java.util.List<IconInfo> icons) {
 406         dumpIcons(winAttr.icons);
 407         setIconHints(icons);
 408         Window target = (Window)this.target;
 409         Window[] children = target.getOwnedWindows();
 410         int cnt = children.length;

 411         for (int i = 0; i < cnt; i++) {
 412             ComponentPeer childPeer = children[i].getPeer();
 413             if (childPeer != null && childPeer instanceof XWindowPeer) {
 414                 if (((XWindowPeer)childPeer).winAttr.iconsInherited) {
 415                     ((XWindowPeer)childPeer).winAttr.icons = icons;
 416                     ((XWindowPeer)childPeer).recursivelySetIcon(icons);
 417                 }
 418             }
 419         }
 420     }
 421 
 422     java.util.List<IconInfo> getIconInfo() {
 423         return winAttr.icons;
 424     }
 425     void setIconHints(java.util.List<IconInfo> icons) {
 426         //This does nothing for XWindowPeer,
 427         //It's overriden in XDecoratedPeer
 428     }
 429 
 430     private static ArrayList<IconInfo> defaultIconInfo;
 431     protected synchronized static java.util.List<IconInfo> getDefaultIconInfo() {
 432         if (defaultIconInfo == null) {


1144     // The height of menu bar window
1145     int getMenuBarHeight() {
1146         return 0;
1147     }
1148 
1149     // Called when shell changes its size and requires children windows
1150     // to update their sizes appropriately
1151     void updateChildrenSizes() {
1152     }
1153 
1154     public void repositionSecurityWarning() {
1155         // NOTE: On KWin if the window/border snapping option is enabled,
1156         // the Java window may be swinging while it's being moved.
1157         // This doesn't make the application unusable though looks quite ugly.
1158         // Probobly we need to find some hint to assign to our Security
1159         // Warning window in order to exclude it from the snapping option.
1160         // We are not currently aware of existance of such a property.
1161         if (warningWindow != null) {
1162             // We can't use the coordinates stored in the XBaseWindow since
1163             // they are zeros for decorated frames.
1164             AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
1165             int x = compAccessor.getX(target);
1166             int y = compAccessor.getY(target);
1167             int width = compAccessor.getWidth(target);
1168             int height = compAccessor.getHeight(target);
1169             warningWindow.reposition(x, y, width, height);
1170         }
1171     }
1172 
1173     @Override
1174     protected void setMouseAbove(boolean above) {
1175         super.setMouseAbove(above);
1176         updateSecurityWarningVisibility();
1177     }
1178 
1179     @Override
1180     public void setFullScreenExclusiveModeState(boolean state) {
1181         super.setFullScreenExclusiveModeState(state);
1182         updateSecurityWarningVisibility();
1183     }
1184 


1469 
1470     boolean hasDecorations(int decor) {
1471         if (!winAttr.nativeDecor) {
1472             return false;
1473         }
1474         else {
1475             int myDecor = winAttr.decorations;
1476             boolean hasBits = ((myDecor & decor) == decor);
1477             if ((myDecor & XWindowAttributesData.AWT_DECOR_ALL) != 0)
1478                 return !hasBits;
1479             else
1480                 return hasBits;
1481         }
1482     }
1483 
1484     void setReparented(boolean newValue) {
1485         super.setReparented(newValue);
1486         XToolkit.awtLock();
1487         try {
1488             if (isReparented() && delayedModalBlocking) {
1489                 addToTransientFors((XDialogPeer) AWTAccessor.getComponentAccessor().getPeer(modalBlocker));
1490                 delayedModalBlocking = false;
1491             }
1492         } finally {
1493             XToolkit.awtUnlock();
1494         }
1495     }
1496 
1497     /*
1498      * Returns a Vector of all Java top-level windows,
1499      * sorted by their current Z-order
1500      */
1501     static Vector<XWindowPeer> collectJavaToplevels() {
1502         Vector<XWindowPeer> javaToplevels = new Vector<XWindowPeer>();
1503         Vector<Long> v = new Vector<Long>();
1504         X11GraphicsEnvironment ge =
1505             (X11GraphicsEnvironment)GraphicsEnvironment.getLocalGraphicsEnvironment();
1506         GraphicsDevice[] gds = ge.getScreenDevices();
1507         if (!ge.runningXinerama() && (gds.length > 1)) {
1508             for (GraphicsDevice gd : gds) {
1509                 int screen = ((X11GraphicsDevice)gd).getScreen();


1553                         }
1554                     }
1555                 }
1556             } finally {
1557                 qt.dispose();
1558             }
1559         }
1560         return javaToplevels;
1561     }
1562 
1563     public void setModalBlocked(Dialog d, boolean blocked) {
1564         setModalBlocked(d, blocked, null);
1565     }
1566     public void setModalBlocked(Dialog d, boolean blocked,
1567                                 Vector<XWindowPeer> javaToplevels)
1568     {
1569         XToolkit.awtLock();
1570         try {
1571             // State lock should always be after awtLock
1572             synchronized(getStateLock()) {
1573                 XDialogPeer blockerPeer = (XDialogPeer) AWTAccessor.getComponentAccessor().getPeer(d);
1574                 if (blocked) {
1575                     if (log.isLoggable(PlatformLogger.Level.FINE)) {
1576                         log.fine("{0} is blocked by {1}", this, blockerPeer);
1577                     }
1578                     modalBlocker = d;
1579 
1580                     if (isReparented() || XWM.isNonReparentingWM()) {
1581                         addToTransientFors(blockerPeer, javaToplevels);
1582                     } else {
1583                         delayedModalBlocking = true;
1584                     }
1585                 } else {
1586                     if (d != modalBlocker) {
1587                         throw new IllegalStateException("Trying to unblock window blocked by another dialog");
1588                     }
1589                     modalBlocker = null;
1590 
1591                     if (isReparented() || XWM.isNonReparentingWM()) {
1592                         removeFromTransientFors();
1593                     } else {


1835      *   W2-B2-B3 (window W2 is blocked by B2 and B2 is blocked by B3)
1836      *
1837      * This method should be called under the AWT lock.
1838      *
1839      * @see #addToTransientFors
1840      * @see #setModalBlocked
1841      */
1842     private void removeFromTransientFors() {
1843         // the head of the chain of this window
1844         XWindowPeer thisChain = this;
1845         // the head of the current chain
1846         // nextTransientFor is always not null as this window is in the chain
1847         XWindowPeer otherChain = nextTransientFor;
1848         // the set of blockers in this chain: if this dialog blocks some other
1849         // modal dialogs, their blocked windows should stay in this dialog's chain
1850         Set<XWindowPeer> thisChainBlockers = new HashSet<XWindowPeer>();
1851         thisChainBlockers.add(this);
1852         // current chain iterator in the order from next to prev
1853         XWindowPeer chainToSplit = prevTransientFor;
1854         while (chainToSplit != null) {
1855             XWindowPeer blocker = (XWindowPeer) AWTAccessor.getComponentAccessor().getPeer(chainToSplit.modalBlocker);
1856             if (thisChainBlockers.contains(blocker)) {
1857                 // add to this dialog's chain
1858                 setToplevelTransientFor(thisChain, chainToSplit, true, false);
1859                 thisChain = chainToSplit;
1860                 thisChainBlockers.add(chainToSplit);
1861             } else {
1862                 // leave in the current chain
1863                 setToplevelTransientFor(otherChain, chainToSplit, true, false);
1864                 otherChain = chainToSplit;
1865             }
1866             chainToSplit = chainToSplit.prevTransientFor;
1867         }
1868         restoreTransientFor(thisChain);
1869         thisChain.prevTransientFor = null;
1870         restoreTransientFor(otherChain);
1871         otherChain.prevTransientFor = null;
1872         nextTransientFor = null;
1873 
1874         XToolkit.XSync();
1875     }


1896 
1897     public boolean requestWindowFocus(long time, boolean timeProvided) {
1898         focusLog.fine("Request for window focus");
1899         // If this is Frame or Dialog we can't assure focus request success - but we still can try
1900         // If this is Window and its owner Frame is active we can be sure request succedded.
1901         Window ownerWindow  = XWindowPeer.getDecoratedOwner((Window)target);
1902         Window focusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
1903         Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
1904 
1905         if (isWMStateNetHidden()) {
1906             focusLog.fine("The window is unmapped, so rejecting the request");
1907             return false;
1908         }
1909         if (activeWindow == ownerWindow) {
1910             focusLog.fine("Parent window is active - generating focus for this window");
1911             handleWindowFocusInSync(-1);
1912             return true;
1913         }
1914         focusLog.fine("Parent window is not active");
1915 
1916         XDecoratedPeer wpeer = (XDecoratedPeer)AWTAccessor.getComponentAccessor().getPeer(ownerWindow);
1917         if (wpeer != null && wpeer.requestWindowFocus(this, time, timeProvided)) {
1918             focusLog.fine("Parent window accepted focus request - generating focus for this window");
1919             return true;
1920         }
1921         focusLog.fine("Denied - parent window is not active and didn't accept focus request");
1922         return false;
1923     }
1924 
1925     // This method is to be overriden in XDecoratedPeer.
1926     void setActualFocusedWindow(XWindowPeer actualFocusedWindow) {
1927     }
1928 
1929     /**
1930      * Applies the current window type.
1931      */
1932     private void applyWindowType() {
1933         XNETProtocol protocol = XWM.getWM().getNETProtocol();
1934         if (protocol == null) {
1935             return;
1936         }


2242                     // shell will mean that this will also filter out press on title
2243                     if ((target == this || target == getContentXWindow()) && !containsGlobal(xbe.get_x_root(), xbe.get_y_root())) {
2244                         // Outside this toplevel hierarchy
2245                         // According to the specification of UngrabEvent, post it
2246                         // when press occurs outside of the window and not on its owned windows
2247                         if (xbe.get_type() == XConstants.ButtonPress) {
2248                             if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
2249                                 grabLog.fine("Generating UngrabEvent on {0} because not inside of shell", this);
2250                             }
2251                             postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
2252                             return;
2253                         }
2254                     }
2255                     // First, get the toplevel
2256                     XWindowPeer toplevel = target.getToplevelXWindow();
2257                     if (toplevel != null) {
2258                         Window w = (Window)toplevel.target;
2259                         while (w != null && toplevel != this && !(toplevel instanceof XDialogPeer)) {
2260                             w = (Window) AWTAccessor.getComponentAccessor().getParent(w);
2261                             if (w != null) {
2262                                 toplevel = (XWindowPeer) AWTAccessor.getComponentAccessor().getPeer(w);
2263                             }
2264                         }
2265                         if (w == null || (w != this.target && w instanceof Dialog)) {
2266                             // toplevel == null - outside of
2267                             // hierarchy, toplevel is Dialog - should
2268                             // send ungrab (but shouldn't for Window)
2269                             if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
2270                                 grabLog.fine("Generating UngrabEvent on {0} because hierarchy ended", this);
2271                             }
2272                             postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
2273                         }
2274                     } else {
2275                         // toplevel is null - outside of hierarchy
2276                         if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
2277                             grabLog.fine("Generating UngrabEvent on {0} because toplevel is null", this);
2278                         }
2279                         postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
2280                         return;
2281                     }
2282                 } else {




  29 import java.awt.event.ComponentEvent;
  30 import java.awt.event.FocusEvent;
  31 import java.awt.event.WindowEvent;
  32 
  33 import java.awt.peer.ComponentPeer;
  34 import java.awt.peer.WindowPeer;
  35 
  36 import java.io.UnsupportedEncodingException;
  37 
  38 import java.security.AccessController;
  39 import java.security.PrivilegedAction;
  40 
  41 import java.util.ArrayList;
  42 import java.util.HashSet;
  43 import java.util.Iterator;
  44 import java.util.Set;
  45 import java.util.Vector;
  46 
  47 import java.util.concurrent.atomic.AtomicBoolean;
  48 
  49 import sun.awt.AWTAccessor.ComponentAccessor;
  50 import sun.util.logging.PlatformLogger;
  51 
  52 import sun.awt.AWTAccessor;
  53 import sun.awt.DisplayChangedListener;
  54 import sun.awt.SunToolkit;
  55 import sun.awt.X11GraphicsDevice;
  56 import sun.awt.X11GraphicsEnvironment;
  57 import sun.awt.IconInfo;
  58 
  59 import sun.java2d.pipe.Region;
  60 
  61 class XWindowPeer extends XPanelPeer implements WindowPeer,
  62                                                 DisplayChangedListener {
  63 
  64     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWindowPeer");
  65     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XWindowPeer");
  66     private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XWindowPeer");
  67     private static final PlatformLogger grabLog = PlatformLogger.getLogger("sun.awt.X11.grab.XWindowPeer");
  68     private static final PlatformLogger iconLog = PlatformLogger.getLogger("sun.awt.X11.icon.XWindowPeer");
  69 


 209     }
 210 
 211     private static native String getLocalHostname();
 212     private static native int getJvmPID();
 213 
 214     @SuppressWarnings("deprecation")
 215     void postInit(XCreateWindowParams params) {
 216         super.postInit(params);
 217 
 218         // Init WM_PROTOCOLS atom
 219         initWMProtocols();
 220 
 221         // Set _NET_WM_PID and WM_CLIENT_MACHINE using this JVM
 222         XAtom.get("WM_CLIENT_MACHINE").setProperty(getWindow(), getLocalHostname());
 223         XAtom.get("_NET_WM_PID").setCard32Property(getWindow(), getJvmPID());
 224 
 225         // Set WM_TRANSIENT_FOR and group_leader
 226         Window t_window = (Window)target;
 227         Window owner = t_window.getOwner();
 228         if (owner != null) {
 229             ownerPeer = AWTAccessor.getComponentAccessor().getPeer(owner);
 230             if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
 231                 focusLog.finer("Owner is " + owner);
 232                 focusLog.finer("Owner peer is " + ownerPeer);
 233                 focusLog.finer("Owner X window " + Long.toHexString(ownerPeer.getWindow()));
 234                 focusLog.finer("Owner content X window " + Long.toHexString(ownerPeer.getContentWindow()));
 235             }
 236             // as owner window may be an embedded window, we must get a toplevel window
 237             // to set as TRANSIENT_FOR hint
 238             long ownerWindow = ownerPeer.getWindow();
 239             if (ownerWindow != 0) {
 240                 XToolkit.awtLock();
 241                 try {
 242                     // Set WM_TRANSIENT_FOR
 243                     if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
 244                         focusLog.fine("Setting transient on " + Long.toHexString(getWindow())
 245                                       + " for " + Long.toHexString(ownerWindow));
 246                     }
 247                     setToplevelTransientFor(this, ownerPeer, false, true);
 248 
 249                     // Set group leader


 385         if (iconLog.isLoggable(PlatformLogger.Level.FINEST)) {
 386             iconLog.finest(">>> Length_ of buffer of icons data: " + totalLength +
 387                            ", maximum length: " + MAXIMUM_BUFFER_LENGTH_NET_WM_ICON);
 388         }
 389 
 390         return result;
 391     }
 392 
 393     /*
 394      * Dumps each icon from the list
 395      */
 396     static void dumpIcons(java.util.List<IconInfo> icons) {
 397         if (iconLog.isLoggable(PlatformLogger.Level.FINEST)) {
 398             iconLog.finest(">>> Sizes of icon images:");
 399             for (Iterator<IconInfo> i = icons.iterator(); i.hasNext(); ) {
 400                 iconLog.finest("    {0}", i.next());
 401             }
 402         }
 403     }
 404 

 405     public void recursivelySetIcon(java.util.List<IconInfo> icons) {
 406         dumpIcons(winAttr.icons);
 407         setIconHints(icons);
 408         Window target = (Window)this.target;
 409         Window[] children = target.getOwnedWindows();
 410         int cnt = children.length;
 411         final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
 412         for (int i = 0; i < cnt; i++) {
 413             final ComponentPeer childPeer = acc.getPeer(children[i]);
 414             if (childPeer != null && childPeer instanceof XWindowPeer) {
 415                 if (((XWindowPeer)childPeer).winAttr.iconsInherited) {
 416                     ((XWindowPeer)childPeer).winAttr.icons = icons;
 417                     ((XWindowPeer)childPeer).recursivelySetIcon(icons);
 418                 }
 419             }
 420         }
 421     }
 422 
 423     java.util.List<IconInfo> getIconInfo() {
 424         return winAttr.icons;
 425     }
 426     void setIconHints(java.util.List<IconInfo> icons) {
 427         //This does nothing for XWindowPeer,
 428         //It's overriden in XDecoratedPeer
 429     }
 430 
 431     private static ArrayList<IconInfo> defaultIconInfo;
 432     protected synchronized static java.util.List<IconInfo> getDefaultIconInfo() {
 433         if (defaultIconInfo == null) {


1145     // The height of menu bar window
1146     int getMenuBarHeight() {
1147         return 0;
1148     }
1149 
1150     // Called when shell changes its size and requires children windows
1151     // to update their sizes appropriately
1152     void updateChildrenSizes() {
1153     }
1154 
1155     public void repositionSecurityWarning() {
1156         // NOTE: On KWin if the window/border snapping option is enabled,
1157         // the Java window may be swinging while it's being moved.
1158         // This doesn't make the application unusable though looks quite ugly.
1159         // Probobly we need to find some hint to assign to our Security
1160         // Warning window in order to exclude it from the snapping option.
1161         // We are not currently aware of existance of such a property.
1162         if (warningWindow != null) {
1163             // We can't use the coordinates stored in the XBaseWindow since
1164             // they are zeros for decorated frames.
1165             ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
1166             int x = compAccessor.getX(target);
1167             int y = compAccessor.getY(target);
1168             int width = compAccessor.getWidth(target);
1169             int height = compAccessor.getHeight(target);
1170             warningWindow.reposition(x, y, width, height);
1171         }
1172     }
1173 
1174     @Override
1175     protected void setMouseAbove(boolean above) {
1176         super.setMouseAbove(above);
1177         updateSecurityWarningVisibility();
1178     }
1179 
1180     @Override
1181     public void setFullScreenExclusiveModeState(boolean state) {
1182         super.setFullScreenExclusiveModeState(state);
1183         updateSecurityWarningVisibility();
1184     }
1185 


1470 
1471     boolean hasDecorations(int decor) {
1472         if (!winAttr.nativeDecor) {
1473             return false;
1474         }
1475         else {
1476             int myDecor = winAttr.decorations;
1477             boolean hasBits = ((myDecor & decor) == decor);
1478             if ((myDecor & XWindowAttributesData.AWT_DECOR_ALL) != 0)
1479                 return !hasBits;
1480             else
1481                 return hasBits;
1482         }
1483     }
1484 
1485     void setReparented(boolean newValue) {
1486         super.setReparented(newValue);
1487         XToolkit.awtLock();
1488         try {
1489             if (isReparented() && delayedModalBlocking) {
1490                 addToTransientFors(AWTAccessor.getComponentAccessor().getPeer(modalBlocker));
1491                 delayedModalBlocking = false;
1492             }
1493         } finally {
1494             XToolkit.awtUnlock();
1495         }
1496     }
1497 
1498     /*
1499      * Returns a Vector of all Java top-level windows,
1500      * sorted by their current Z-order
1501      */
1502     static Vector<XWindowPeer> collectJavaToplevels() {
1503         Vector<XWindowPeer> javaToplevels = new Vector<XWindowPeer>();
1504         Vector<Long> v = new Vector<Long>();
1505         X11GraphicsEnvironment ge =
1506             (X11GraphicsEnvironment)GraphicsEnvironment.getLocalGraphicsEnvironment();
1507         GraphicsDevice[] gds = ge.getScreenDevices();
1508         if (!ge.runningXinerama() && (gds.length > 1)) {
1509             for (GraphicsDevice gd : gds) {
1510                 int screen = ((X11GraphicsDevice)gd).getScreen();


1554                         }
1555                     }
1556                 }
1557             } finally {
1558                 qt.dispose();
1559             }
1560         }
1561         return javaToplevels;
1562     }
1563 
1564     public void setModalBlocked(Dialog d, boolean blocked) {
1565         setModalBlocked(d, blocked, null);
1566     }
1567     public void setModalBlocked(Dialog d, boolean blocked,
1568                                 Vector<XWindowPeer> javaToplevels)
1569     {
1570         XToolkit.awtLock();
1571         try {
1572             // State lock should always be after awtLock
1573             synchronized(getStateLock()) {
1574                 XDialogPeer blockerPeer = AWTAccessor.getComponentAccessor().getPeer(d);
1575                 if (blocked) {
1576                     if (log.isLoggable(PlatformLogger.Level.FINE)) {
1577                         log.fine("{0} is blocked by {1}", this, blockerPeer);
1578                     }
1579                     modalBlocker = d;
1580 
1581                     if (isReparented() || XWM.isNonReparentingWM()) {
1582                         addToTransientFors(blockerPeer, javaToplevels);
1583                     } else {
1584                         delayedModalBlocking = true;
1585                     }
1586                 } else {
1587                     if (d != modalBlocker) {
1588                         throw new IllegalStateException("Trying to unblock window blocked by another dialog");
1589                     }
1590                     modalBlocker = null;
1591 
1592                     if (isReparented() || XWM.isNonReparentingWM()) {
1593                         removeFromTransientFors();
1594                     } else {


1836      *   W2-B2-B3 (window W2 is blocked by B2 and B2 is blocked by B3)
1837      *
1838      * This method should be called under the AWT lock.
1839      *
1840      * @see #addToTransientFors
1841      * @see #setModalBlocked
1842      */
1843     private void removeFromTransientFors() {
1844         // the head of the chain of this window
1845         XWindowPeer thisChain = this;
1846         // the head of the current chain
1847         // nextTransientFor is always not null as this window is in the chain
1848         XWindowPeer otherChain = nextTransientFor;
1849         // the set of blockers in this chain: if this dialog blocks some other
1850         // modal dialogs, their blocked windows should stay in this dialog's chain
1851         Set<XWindowPeer> thisChainBlockers = new HashSet<XWindowPeer>();
1852         thisChainBlockers.add(this);
1853         // current chain iterator in the order from next to prev
1854         XWindowPeer chainToSplit = prevTransientFor;
1855         while (chainToSplit != null) {
1856             XWindowPeer blocker = AWTAccessor.getComponentAccessor().getPeer(chainToSplit.modalBlocker);
1857             if (thisChainBlockers.contains(blocker)) {
1858                 // add to this dialog's chain
1859                 setToplevelTransientFor(thisChain, chainToSplit, true, false);
1860                 thisChain = chainToSplit;
1861                 thisChainBlockers.add(chainToSplit);
1862             } else {
1863                 // leave in the current chain
1864                 setToplevelTransientFor(otherChain, chainToSplit, true, false);
1865                 otherChain = chainToSplit;
1866             }
1867             chainToSplit = chainToSplit.prevTransientFor;
1868         }
1869         restoreTransientFor(thisChain);
1870         thisChain.prevTransientFor = null;
1871         restoreTransientFor(otherChain);
1872         otherChain.prevTransientFor = null;
1873         nextTransientFor = null;
1874 
1875         XToolkit.XSync();
1876     }


1897 
1898     public boolean requestWindowFocus(long time, boolean timeProvided) {
1899         focusLog.fine("Request for window focus");
1900         // If this is Frame or Dialog we can't assure focus request success - but we still can try
1901         // If this is Window and its owner Frame is active we can be sure request succedded.
1902         Window ownerWindow  = XWindowPeer.getDecoratedOwner((Window)target);
1903         Window focusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
1904         Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
1905 
1906         if (isWMStateNetHidden()) {
1907             focusLog.fine("The window is unmapped, so rejecting the request");
1908             return false;
1909         }
1910         if (activeWindow == ownerWindow) {
1911             focusLog.fine("Parent window is active - generating focus for this window");
1912             handleWindowFocusInSync(-1);
1913             return true;
1914         }
1915         focusLog.fine("Parent window is not active");
1916 
1917         XDecoratedPeer wpeer = AWTAccessor.getComponentAccessor().getPeer(ownerWindow);
1918         if (wpeer != null && wpeer.requestWindowFocus(this, time, timeProvided)) {
1919             focusLog.fine("Parent window accepted focus request - generating focus for this window");
1920             return true;
1921         }
1922         focusLog.fine("Denied - parent window is not active and didn't accept focus request");
1923         return false;
1924     }
1925 
1926     // This method is to be overriden in XDecoratedPeer.
1927     void setActualFocusedWindow(XWindowPeer actualFocusedWindow) {
1928     }
1929 
1930     /**
1931      * Applies the current window type.
1932      */
1933     private void applyWindowType() {
1934         XNETProtocol protocol = XWM.getWM().getNETProtocol();
1935         if (protocol == null) {
1936             return;
1937         }


2243                     // shell will mean that this will also filter out press on title
2244                     if ((target == this || target == getContentXWindow()) && !containsGlobal(xbe.get_x_root(), xbe.get_y_root())) {
2245                         // Outside this toplevel hierarchy
2246                         // According to the specification of UngrabEvent, post it
2247                         // when press occurs outside of the window and not on its owned windows
2248                         if (xbe.get_type() == XConstants.ButtonPress) {
2249                             if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
2250                                 grabLog.fine("Generating UngrabEvent on {0} because not inside of shell", this);
2251                             }
2252                             postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
2253                             return;
2254                         }
2255                     }
2256                     // First, get the toplevel
2257                     XWindowPeer toplevel = target.getToplevelXWindow();
2258                     if (toplevel != null) {
2259                         Window w = (Window)toplevel.target;
2260                         while (w != null && toplevel != this && !(toplevel instanceof XDialogPeer)) {
2261                             w = (Window) AWTAccessor.getComponentAccessor().getParent(w);
2262                             if (w != null) {
2263                                 toplevel = AWTAccessor.getComponentAccessor().getPeer(w);
2264                             }
2265                         }
2266                         if (w == null || (w != this.target && w instanceof Dialog)) {
2267                             // toplevel == null - outside of
2268                             // hierarchy, toplevel is Dialog - should
2269                             // send ungrab (but shouldn't for Window)
2270                             if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
2271                                 grabLog.fine("Generating UngrabEvent on {0} because hierarchy ended", this);
2272                             }
2273                             postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
2274                         }
2275                     } else {
2276                         // toplevel is null - outside of hierarchy
2277                         if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
2278                             grabLog.fine("Generating UngrabEvent on {0} because toplevel is null", this);
2279                         }
2280                         postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
2281                         return;
2282                     }
2283                 } else {