< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  49 import java.awt.peer.WindowPeer;
  50 import java.io.UnsupportedEncodingException;
  51 import java.security.AccessController;
  52 import java.security.PrivilegedAction;
  53 import java.util.ArrayList;
  54 import java.util.HashSet;
  55 import java.util.Iterator;
  56 import java.util.Set;
  57 import java.util.Vector;
  58 import java.util.concurrent.atomic.AtomicBoolean;
  59 
  60 import sun.awt.AWTAccessor;
  61 import sun.awt.AWTAccessor.ComponentAccessor;
  62 import sun.awt.DisplayChangedListener;
  63 import sun.awt.IconInfo;
  64 import sun.awt.SunToolkit;
  65 import sun.awt.X11GraphicsDevice;
  66 import sun.awt.X11GraphicsEnvironment;
  67 import sun.java2d.pipe.Region;
  68 import sun.util.logging.PlatformLogger;

  69 
  70 class XWindowPeer extends XPanelPeer implements WindowPeer,
  71                                                 DisplayChangedListener {
  72 
  73     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWindowPeer");
  74     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XWindowPeer");
  75     private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XWindowPeer");
  76     private static final PlatformLogger grabLog = PlatformLogger.getLogger("sun.awt.X11.grab.XWindowPeer");
  77     private static final PlatformLogger iconLog = PlatformLogger.getLogger("sun.awt.X11.icon.XWindowPeer");
  78 
  79     // should be synchronized on awtLock
  80     private static Set<XWindowPeer> windows = new HashSet<XWindowPeer>();
  81 
  82 
  83     private boolean cachedFocusableWindow;
  84     XWarningWindow warningWindow;
  85 
  86     private boolean alwaysOnTop;
  87     private boolean locationByPlatform;
  88 


 103     private boolean mustControlStackPosition = false; // Am override-redirect not on top
 104     private XEventDispatcher rootPropertyEventDispatcher = null;
 105 
 106     private static final AtomicBoolean isStartupNotificationRemoved = new AtomicBoolean();
 107 
 108     /*
 109      * Focus related flags
 110      */
 111     private boolean isUnhiding = false;             // Is the window unhiding.
 112     private boolean isBeforeFirstMapNotify = false; // Is the window (being shown) between
 113                                                     //    setVisible(true) & handleMapNotify().
 114 
 115     /**
 116      * The type of the window.
 117      *
 118      * The type is supposed to be immutable while the peer object exists.
 119      * The value gets initialized in the preInit() method.
 120      */
 121     private Window.Type windowType = Window.Type.NORMAL;
 122 


 123     public final Window.Type getWindowType() {
 124         return windowType;
 125     }
 126 
 127     // It need to be accessed from XFramePeer.
 128     protected Vector <ToplevelStateListener> toplevelStateListeners = new Vector<ToplevelStateListener>();
 129     XWindowPeer(XCreateWindowParams params) {
 130         super(params.putIfNull(PARENT_WINDOW, Long.valueOf(0)));
 131     }
 132 
 133     XWindowPeer(Window target) {
 134         super(new XCreateWindowParams(new Object[] {
 135             TARGET, target,
 136             PARENT_WINDOW, Long.valueOf(0)}));
 137     }
 138 
 139     /*
 140      * This constant defines icon size recommended for using.
 141      * Apparently, we should use XGetIconSizes which should
 142      * return icon sizes would be most appreciated by the WM.


2007             XAtomList wtype = new XAtomList();
2008             wtype.add(typeAtom);
2009             protocol.XA_NET_WM_WINDOW_TYPE.
2010                 setAtomListProperty(getWindow(), wtype);
2011         } else {
2012             protocol.XA_NET_WM_WINDOW_TYPE.
2013                 DeleteProperty(getWindow());
2014         }
2015     }
2016 
2017     @Override
2018     public void xSetVisible(boolean visible) {
2019         if (log.isLoggable(PlatformLogger.Level.FINE)) {
2020             log.fine("Setting visible on " + this + " to " + visible);
2021         }
2022         XToolkit.awtLock();
2023         try {
2024             this.visible = visible;
2025             if (visible) {
2026                 applyWindowType();

















2027                 XlibWrapper.XMapRaised(XToolkit.getDisplay(), getWindow());
2028             } else {
2029                 XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), getWindow());
2030             }
2031             XlibWrapper.XFlush(XToolkit.getDisplay());
2032         }
2033         finally {
2034             XToolkit.awtUnlock();
2035         }
2036     }
2037 
2038     // should be synchronized on awtLock
2039     private int dropTargetCount = 0;
2040 
2041     public void addDropTarget() {
2042         XToolkit.awtLock();
2043         try {
2044             if (dropTargetCount == 0) {
2045                 long window = getWindow();
2046                 if (window != 0) {


   1 /*
   2  * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  49 import java.awt.peer.WindowPeer;
  50 import java.io.UnsupportedEncodingException;
  51 import java.security.AccessController;
  52 import java.security.PrivilegedAction;
  53 import java.util.ArrayList;
  54 import java.util.HashSet;
  55 import java.util.Iterator;
  56 import java.util.Set;
  57 import java.util.Vector;
  58 import java.util.concurrent.atomic.AtomicBoolean;
  59 
  60 import sun.awt.AWTAccessor;
  61 import sun.awt.AWTAccessor.ComponentAccessor;
  62 import sun.awt.DisplayChangedListener;
  63 import sun.awt.IconInfo;
  64 import sun.awt.SunToolkit;
  65 import sun.awt.X11GraphicsDevice;
  66 import sun.awt.X11GraphicsEnvironment;
  67 import sun.java2d.pipe.Region;
  68 import sun.util.logging.PlatformLogger;
  69 import sun.awt.OSInfo;
  70 
  71 class XWindowPeer extends XPanelPeer implements WindowPeer,
  72                                                 DisplayChangedListener {
  73 
  74     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWindowPeer");
  75     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XWindowPeer");
  76     private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XWindowPeer");
  77     private static final PlatformLogger grabLog = PlatformLogger.getLogger("sun.awt.X11.grab.XWindowPeer");
  78     private static final PlatformLogger iconLog = PlatformLogger.getLogger("sun.awt.X11.icon.XWindowPeer");
  79 
  80     // should be synchronized on awtLock
  81     private static Set<XWindowPeer> windows = new HashSet<XWindowPeer>();
  82 
  83 
  84     private boolean cachedFocusableWindow;
  85     XWarningWindow warningWindow;
  86 
  87     private boolean alwaysOnTop;
  88     private boolean locationByPlatform;
  89 


 104     private boolean mustControlStackPosition = false; // Am override-redirect not on top
 105     private XEventDispatcher rootPropertyEventDispatcher = null;
 106 
 107     private static final AtomicBoolean isStartupNotificationRemoved = new AtomicBoolean();
 108 
 109     /*
 110      * Focus related flags
 111      */
 112     private boolean isUnhiding = false;             // Is the window unhiding.
 113     private boolean isBeforeFirstMapNotify = false; // Is the window (being shown) between
 114                                                     //    setVisible(true) & handleMapNotify().
 115 
 116     /**
 117      * The type of the window.
 118      *
 119      * The type is supposed to be immutable while the peer object exists.
 120      * The value gets initialized in the preInit() method.
 121      */
 122     private Window.Type windowType = Window.Type.NORMAL;
 123 
 124     private static final boolean isAIX = OSInfo.getOSType() == OSInfo.OSType.AIX;
 125 
 126     public final Window.Type getWindowType() {
 127         return windowType;
 128     }
 129 
 130     // It need to be accessed from XFramePeer.
 131     protected Vector <ToplevelStateListener> toplevelStateListeners = new Vector<ToplevelStateListener>();
 132     XWindowPeer(XCreateWindowParams params) {
 133         super(params.putIfNull(PARENT_WINDOW, Long.valueOf(0)));
 134     }
 135 
 136     XWindowPeer(Window target) {
 137         super(new XCreateWindowParams(new Object[] {
 138             TARGET, target,
 139             PARENT_WINDOW, Long.valueOf(0)}));
 140     }
 141 
 142     /*
 143      * This constant defines icon size recommended for using.
 144      * Apparently, we should use XGetIconSizes which should
 145      * return icon sizes would be most appreciated by the WM.


2010             XAtomList wtype = new XAtomList();
2011             wtype.add(typeAtom);
2012             protocol.XA_NET_WM_WINDOW_TYPE.
2013                 setAtomListProperty(getWindow(), wtype);
2014         } else {
2015             protocol.XA_NET_WM_WINDOW_TYPE.
2016                 DeleteProperty(getWindow());
2017         }
2018     }
2019 
2020     @Override
2021     public void xSetVisible(boolean visible) {
2022         if (log.isLoggable(PlatformLogger.Level.FINE)) {
2023             log.fine("Setting visible on " + this + " to " + visible);
2024         }
2025         XToolkit.awtLock();
2026         try {
2027             this.visible = visible;
2028             if (visible) {
2029                 applyWindowType();
2030                 if (isAIX) {
2031                     /* On Motif Window Manager, non-focusable window should not set WM_TAKE_FOCUS */
2032                     XAtomList currentWMProtocols = wm_protocols.getAtomListPropertyList(this);
2033                     if (isFocusableWindow()) {
2034                         if (!currentWMProtocols.contains(wm_take_focus)) {
2035                             currentWMProtocols.add(wm_take_focus);
2036                             wm_protocols.setAtomListProperty(this, currentWMProtocols);
2037                         }
2038                     } else {
2039                         if (XWM.isMotif()) {
2040                             if (currentWMProtocols.contains(wm_take_focus)) {
2041                                 currentWMProtocols.remove(wm_take_focus);
2042                                 wm_protocols.setAtomListProperty(this, currentWMProtocols);
2043                             }
2044                         }
2045                     }
2046                 }
2047                 XlibWrapper.XMapRaised(XToolkit.getDisplay(), getWindow());
2048             } else {
2049                 XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), getWindow());
2050             }
2051             XlibWrapper.XFlush(XToolkit.getDisplay());
2052         }
2053         finally {
2054             XToolkit.awtUnlock();
2055         }
2056     }
2057 
2058     // should be synchronized on awtLock
2059     private int dropTargetCount = 0;
2060 
2061     public void addDropTarget() {
2062         XToolkit.awtLock();
2063         try {
2064             if (dropTargetCount == 0) {
2065                 long window = getWindow();
2066                 if (window != 0) {


< prev index next >