jdk/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java
author ssadetsky
Tue, 15 Mar 2016 09:18:29 +0300
changeset 36882 9347af61016c
parent 36881 3a22af76f434
child 38992 5e8d53377c10
permissions -rw-r--r--
8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios Reviewed-by: serb, azvegint
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36881
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4829
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4829
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4829
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4829
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4829
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.ComponentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.FocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.WindowEvent;
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
    32
import java.awt.geom.AffineTransform;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.peer.WindowPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
4361
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
    37
import java.io.UnsupportedEncodingException;
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
    38
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
    39
import java.security.AccessController;
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
    40
import java.security.PrivilegedAction;
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
    41
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
4361
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
    48
import java.util.concurrent.atomic.AtomicBoolean;
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
    49
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
    50
import sun.awt.AWTAccessor.ComponentAccessor;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
    51
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
    53
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.awt.DisplayChangedListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.awt.X11GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.awt.X11GraphicsEnvironment;
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
    58
import sun.awt.IconInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
    60
import sun.java2d.pipe.Region;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
    61
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
class XWindowPeer extends XPanelPeer implements WindowPeer,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
    63
                                                DisplayChangedListener {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
    65
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWindowPeer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
    66
    private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XWindowPeer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
    67
    private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XWindowPeer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
    68
    private static final PlatformLogger grabLog = PlatformLogger.getLogger("sun.awt.X11.grab.XWindowPeer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
    69
    private static final PlatformLogger iconLog = PlatformLogger.getLogger("sun.awt.X11.icon.XWindowPeer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // should be synchronized on awtLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static Set<XWindowPeer> windows = new HashSet<XWindowPeer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private boolean cachedFocusableWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    XWarningWindow warningWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private boolean alwaysOnTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private boolean locationByPlatform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    Dialog modalBlocker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    boolean delayedModalBlocking = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    Dimension targetMinimumSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private XWindowPeer ownerPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // used for modal blocking to keep existing z-order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    protected XWindowPeer prevTransientFor, nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // value of WM_TRANSIENT_FOR hint set on this window
36882
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
    90
    private XBaseWindow curRealTransientFor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private boolean grab = false; // Whether to do a grab during showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private boolean isMapped = false; // Is this window mapped or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private boolean mustControlStackPosition = false; // Am override-redirect not on top
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private XEventDispatcher rootPropertyEventDispatcher = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
4361
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
    98
    private static final AtomicBoolean isStartupNotificationRemoved = new AtomicBoolean();
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
    99
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Focus related flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private boolean isUnhiding = false;             // Is the window unhiding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private boolean isBeforeFirstMapNotify = false; // Is the window (being shown) between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                                    //    setVisible(true) & handleMapNotify().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   107
    /**
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   108
     * The type of the window.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   109
     *
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   110
     * The type is supposed to be immutable while the peer object exists.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   111
     * The value gets initialized in the preInit() method.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   112
     */
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   113
    private Window.Type windowType = Window.Type.NORMAL;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   114
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   115
    public final Window.Type getWindowType() {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   116
        return windowType;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   117
    }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   118
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    // It need to be accessed from XFramePeer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    protected Vector <ToplevelStateListener> toplevelStateListeners = new Vector<ToplevelStateListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    XWindowPeer(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        super(params.putIfNull(PARENT_WINDOW, Long.valueOf(0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    XWindowPeer(Window target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        super(new XCreateWindowParams(new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            TARGET, target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            PARENT_WINDOW, Long.valueOf(0)}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * This constant defines icon size recommended for using.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Apparently, we should use XGetIconSizes which should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * return icon sizes would be most appreciated by the WM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * However, XGetIconSizes always returns 0 for some reason.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * So the constant has been introduced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static final int PREFERRED_SIZE_FOR_ICON = 128;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Sometimes XChangeProperty(_NET_WM_ICON) doesn't work if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * image buffer is too large. This constant holds maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * length of buffer which can be used with _NET_WM_ICON hint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * It holds int's value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private static final int MAXIMUM_BUFFER_LENGTH_NET_WM_ICON = (2<<15) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    void preInit(XCreateWindowParams params) {
1190
f27065d0d9f0 6708392: Provide internal API to create OverrideRedirect windows, XToolkit
art
parents: 449
diff changeset
   149
        target = (Component)params.get(TARGET);
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
   150
        windowType = ((Window)target).getType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        params.put(REPARENTED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                   Boolean.valueOf(isOverrideRedirect() || isSimpleWindow()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        super.preInit(params);
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   154
        params.putIfNull(BIT_GRAVITY, Integer.valueOf(XConstants.NorthWestGravity));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   156
        long eventMask = 0;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   157
        if (params.containsKey(EVENT_MASK)) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   158
            eventMask = ((Long)params.get(EVENT_MASK));
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   159
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   160
        eventMask |= XConstants.VisibilityChangeMask;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   161
        params.put(EVENT_MASK, eventMask);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   162
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        XA_NET_WM_STATE = XAtom.get("_NET_WM_STATE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        params.put(OVERRIDE_REDIRECT, Boolean.valueOf(isOverrideRedirect()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
2642
d08c8f125592 6826104: Getting a NullPointer exception when clicked on Application & Toolkit Modal dialog
anthony
parents: 2472
diff changeset
   168
        SunToolkit.awtLock();
d08c8f125592 6826104: Getting a NullPointer exception when clicked on Application & Toolkit Modal dialog
anthony
parents: 2472
diff changeset
   169
        try {
d08c8f125592 6826104: Getting a NullPointer exception when clicked on Application & Toolkit Modal dialog
anthony
parents: 2472
diff changeset
   170
            windows.add(this);
d08c8f125592 6826104: Getting a NullPointer exception when clicked on Application & Toolkit Modal dialog
anthony
parents: 2472
diff changeset
   171
        } finally {
d08c8f125592 6826104: Getting a NullPointer exception when clicked on Application & Toolkit Modal dialog
anthony
parents: 2472
diff changeset
   172
            SunToolkit.awtUnlock();
d08c8f125592 6826104: Getting a NullPointer exception when clicked on Application & Toolkit Modal dialog
anthony
parents: 2472
diff changeset
   173
        }
d08c8f125592 6826104: Getting a NullPointer exception when clicked on Application & Toolkit Modal dialog
anthony
parents: 2472
diff changeset
   174
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        cachedFocusableWindow = isFocusableWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        Font f = target.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (f == null) {
116
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   179
            f = XWindow.getDefaultFont();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            target.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            // we should not call setFont because it will call a repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            // which the peer may not be ready to do yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        Color c = target.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            Color background = SystemColor.window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            target.setBackground(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            // we should not call setBackGround because it will call a repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            // which the peer may not be ready to do yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        c = target.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            target.setForeground(SystemColor.windowText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            // we should not call setForeGround because it will call a repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            // which the peer may not be ready to do yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        alwaysOnTop = ((Window)target).isAlwaysOnTop() && ((Window)target).isAlwaysOnTopSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        GraphicsConfiguration gc = getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        ((X11GraphicsDevice)gc.getDevice()).addDisplayChangedListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    protected String getWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        String name = target.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (name == null || name.trim().equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            name = " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
11090
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 7668
diff changeset
   212
    private static native String getLocalHostname();
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 7668
diff changeset
   213
    private static native int getJvmPID();
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 7668
diff changeset
   214
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
   215
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // Init WM_PROTOCOLS atom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        initWMProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
11090
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 7668
diff changeset
   222
        // Set _NET_WM_PID and WM_CLIENT_MACHINE using this JVM
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 7668
diff changeset
   223
        XAtom.get("WM_CLIENT_MACHINE").setProperty(getWindow(), getLocalHostname());
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 7668
diff changeset
   224
        XAtom.get("_NET_WM_PID").setCard32Property(getWindow(), getJvmPID());
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 7668
diff changeset
   225
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        // Set WM_TRANSIENT_FOR and group_leader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        Window t_window = (Window)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        Window owner = t_window.getOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (owner != null) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
   230
            ownerPeer = AWTAccessor.getComponentAccessor().getPeer(owner);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
   231
            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   232
                focusLog.finer("Owner is " + owner);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   233
                focusLog.finer("Owner peer is " + ownerPeer);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   234
                focusLog.finer("Owner X window " + Long.toHexString(ownerPeer.getWindow()));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   235
                focusLog.finer("Owner content X window " + Long.toHexString(ownerPeer.getContentWindow()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            // as owner window may be an embedded window, we must get a toplevel window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            // to set as TRANSIENT_FOR hint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            long ownerWindow = ownerPeer.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            if (ownerWindow != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    // Set WM_TRANSIENT_FOR
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
   244
                    if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   245
                        focusLog.fine("Setting transient on " + Long.toHexString(getWindow())
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   246
                                      + " for " + Long.toHexString(ownerWindow));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   247
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    setToplevelTransientFor(this, ownerPeer, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    // Set group leader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    XWMHints hints = getWMHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   252
                    hints.set_flags(hints.get_flags() | (int)XUtilConstants.WindowGroupHint);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    hints.set_window_group(ownerWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                    XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
11659
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   262
        if (owner != null || isSimpleWindow()) {
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   263
            XNETProtocol protocol = XWM.getWM().getNETProtocol();
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   264
            if (protocol != null && protocol.active()) {
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   265
                XToolkit.awtLock();
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   266
                try {
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   267
                    XAtomList net_wm_state = getNETWMState();
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   268
                    net_wm_state.add(protocol.XA_NET_WM_STATE_SKIP_TASKBAR);
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   269
                    setNETWMState(net_wm_state);
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   270
                } finally {
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   271
                    XToolkit.awtUnlock();
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   272
                }
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   273
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   274
            }
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   275
        }
2cc8db870a68 7078460: JDialog is shown as separate icon on the taskbar
denis
parents: 11090
diff changeset
   276
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
         // Init warning window(for applets)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (((Window)target).getWarningString() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            // and TrayIcon balloon windows without a warning window.
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
   281
            if (!AWTAccessor.getWindowAccessor().isTrayIconWindow((Window)target)) {
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   282
                warningWindow = new XWarningWindow((Window)target, getWindow(), this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        setSaveUnder(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        updateIconImages();
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   289
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   290
        updateShape();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   291
        updateOpacity();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   292
        // no need in updateOpaque() as it is no-op
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public void updateIconImages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        Window target = (Window)this.target;
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
   297
        java.util.List<Image> iconImages = target.getIconImages();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        XWindowPeer ownerPeer = getOwnerPeer();
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   299
        winAttr.icons = new ArrayList<IconInfo>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (iconImages.size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            //read icon images from target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            winAttr.iconsInherited = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            for (Iterator<Image> i = iconImages.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                Image image = i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                if (image == null) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
   306
                    if (log.isLoggable(PlatformLogger.Level.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                        log.finest("XWindowPeer.updateIconImages: Skipping the image passed into Java because it's null.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                }
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   311
                IconInfo iconInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                try {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   313
                    iconInfo = new IconInfo(image);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                } catch (Exception e){
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
   315
                    if (log.isLoggable(PlatformLogger.Level.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                        log.finest("XWindowPeer.updateIconImages: Perhaps the image passed into Java is broken. Skipping this icon.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                if (iconInfo.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    winAttr.icons.add(iconInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // Fix for CR#6425089
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        winAttr.icons = normalizeIconImages(winAttr.icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (winAttr.icons.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            //target.icons is empty or all icon images are broken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            if (ownerPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                //icon is inherited from parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                winAttr.iconsInherited = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                winAttr.icons = ownerPeer.getIconInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                //default icon is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                winAttr.iconsInherited = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                winAttr.icons = getDefaultIconInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        recursivelySetIcon(winAttr.icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Sometimes XChangeProperty(_NET_WM_ICON) doesn't work if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * image buffer is too large. This function help us accommodate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * initial list of the icon images to certainly-acceptable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * It does scale some of these icons to appropriate size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * if it's necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   351
    static java.util.List<IconInfo> normalizeIconImages(java.util.List<IconInfo> icons) {
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   352
        java.util.List<IconInfo> result = new ArrayList<IconInfo>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        int totalLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        boolean haveLargeIcon = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   356
        for (IconInfo icon : icons) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            int width = icon.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            int height = icon.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            int length = icon.getRawLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            if (width > PREFERRED_SIZE_FOR_ICON || height > PREFERRED_SIZE_FOR_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                if (haveLargeIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                int scaledWidth = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                int scaledHeight = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                while (scaledWidth > PREFERRED_SIZE_FOR_ICON ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                       scaledHeight > PREFERRED_SIZE_FOR_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    scaledWidth = scaledWidth / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    scaledHeight = scaledHeight / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                icon.setScaledSize(scaledWidth, scaledHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                length = icon.getRawLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            if (totalLength + length <= MAXIMUM_BUFFER_LENGTH_NET_WM_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                totalLength += length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                result.add(icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                if (width > PREFERRED_SIZE_FOR_ICON || height > PREFERRED_SIZE_FOR_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    haveLargeIcon = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
   386
        if (iconLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
   387
            iconLog.finest(">>> Length_ of buffer of icons data: " + totalLength +
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
   388
                           ", maximum length: " + MAXIMUM_BUFFER_LENGTH_NET_WM_ICON);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * Dumps each icon from the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   397
    static void dumpIcons(java.util.List<IconInfo> icons) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
   398
        if (iconLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
   399
            iconLog.finest(">>> Sizes of icon images:");
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   400
            for (Iterator<IconInfo> i = icons.iterator(); i.hasNext(); ) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
   401
                iconLog.finest("    {0}", i.next());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   406
    public void recursivelySetIcon(java.util.List<IconInfo> icons) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        dumpIcons(winAttr.icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        setIconHints(icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        Window target = (Window)this.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        Window[] children = target.getOwnedWindows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        int cnt = children.length;
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
   412
        final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        for (int i = 0; i < cnt; i++) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
   414
            final ComponentPeer childPeer = acc.getPeer(children[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            if (childPeer != null && childPeer instanceof XWindowPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                if (((XWindowPeer)childPeer).winAttr.iconsInherited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    ((XWindowPeer)childPeer).winAttr.icons = icons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    ((XWindowPeer)childPeer).recursivelySetIcon(icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   424
    java.util.List<IconInfo> getIconInfo() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return winAttr.icons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   427
    void setIconHints(java.util.List<IconInfo> icons) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        //This does nothing for XWindowPeer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        //It's overriden in XDecoratedPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   432
    private static ArrayList<IconInfo> defaultIconInfo;
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31649
diff changeset
   433
    protected static synchronized java.util.List<IconInfo> getDefaultIconInfo() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (defaultIconInfo == null) {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   435
            defaultIconInfo = new ArrayList<IconInfo>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            if (XlibWrapper.dataModel == 32) {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   437
                defaultIconInfo.add(new IconInfo(sun.awt.AWTIcon32_java_icon16_png.java_icon16_png));
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   438
                defaultIconInfo.add(new IconInfo(sun.awt.AWTIcon32_java_icon24_png.java_icon24_png));
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   439
                defaultIconInfo.add(new IconInfo(sun.awt.AWTIcon32_java_icon32_png.java_icon32_png));
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   440
                defaultIconInfo.add(new IconInfo(sun.awt.AWTIcon32_java_icon48_png.java_icon48_png));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            } else {
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   442
                defaultIconInfo.add(new IconInfo(sun.awt.AWTIcon64_java_icon16_png.java_icon16_png));
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   443
                defaultIconInfo.add(new IconInfo(sun.awt.AWTIcon64_java_icon24_png.java_icon24_png));
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   444
                defaultIconInfo.add(new IconInfo(sun.awt.AWTIcon64_java_icon32_png.java_icon32_png));
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 14888
diff changeset
   445
                defaultIconInfo.add(new IconInfo(sun.awt.AWTIcon64_java_icon48_png.java_icon48_png));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return defaultIconInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   451
    private void updateShape() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   452
        // Shape shape = ((Window)target).getShape();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   453
        Shape shape = AWTAccessor.getWindowAccessor().getShape((Window)target);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   454
        if (shape != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   455
            applyShape(Region.getInstance(shape, null));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   456
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   457
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   458
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   459
    private void updateOpacity() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   460
        // float opacity = ((Window)target).getOpacity();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   461
        float opacity = AWTAccessor.getWindowAccessor().getOpacity((Window)target);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   462
        if (opacity < 1.0f) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   463
            setOpacity(opacity);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   464
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   465
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   466
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public void updateMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        //This function only saves minimumSize value in XWindowPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        //Setting WMSizeHints is implemented in XDecoratedPeer
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
   470
        targetMinimumSize = (target.isMinimumSizeSet()) ?
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
   471
            target.getMinimumSize() : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public Dimension getTargetMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return (targetMinimumSize == null) ? null : new Dimension(targetMinimumSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    public XWindowPeer getOwnerPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        return ownerPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    //Fix for 6318144: PIT:Setting Min Size bigger than current size enlarges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    //the window but fails to revalidate, Sol-CDE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    //This bug is regression for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    //5025858: Resizing a decorated frame triggers componentResized event twice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    //Since events are not posted from Component.setBounds we need to send them here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    //Note that this function is overriden in XDecoratedPeer so event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    //posting is not changing for decorated peers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    public void setBounds(int x, int y, int width, int height, int op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            Rectangle oldBounds = getBounds();
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   493
2643
ea218b1a2000 6821948: Consider removing the constraints for bounds of untrusted top-level windows
anthony
parents: 2642
diff changeset
   494
            super.setBounds(x, y, width, height, op);
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   495
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            Rectangle bounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            XSizeHints hints = getHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   499
            setSizeHints(hints.get_flags() | XUtilConstants.PPosition | XUtilConstants.PSize,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                             bounds.x, bounds.y, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            XWM.setMotifDecor(this, false, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   503
            boolean isResized = !bounds.getSize().equals(oldBounds.getSize());
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   504
            boolean isMoved = !bounds.getLocation().equals(oldBounds.getLocation());
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   505
            if (isMoved || isResized) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   506
                repositionSecurityWarning();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   507
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   508
            if (isResized) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_RESIZED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            }
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   511
            if (isMoved) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_MOVED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    void updateFocusability() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        updateFocusableWindowState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            XWMHints hints = getWMHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   524
            hints.set_flags(hints.get_flags() | (int)XUtilConstants.InputHint);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            hints.set_input(false/*isNativelyNonFocusableWindow() ? (0):(1)*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    public Insets getInsets() {
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   534
        return new Insets(0, 0, 0, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    public void handleIconify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_ICONIFIED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public void handleDeiconify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_DEICONIFIED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    public void handleStateChange(int oldState, int newState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        postEvent(new WindowEvent((Window)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                                  WindowEvent.WINDOW_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                                  oldState, newState));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * DEPRECATED:  Replaced by getInsets().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    public Insets insets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    boolean isAutoRequestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if (XToolkit.isToolkitThread()) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
   566
            return AWTAccessor.getWindowAccessor().isAutoRequestFocus((Window)target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            return ((Window)target).isAutoRequestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    /*
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   573
     * Retrives real native focused window and converts it into Java peer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    static XWindowPeer getNativeFocusedWindowPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        XBaseWindow baseWindow = XToolkit.windowToXWindow(xGetInputFocus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        return (baseWindow instanceof XWindowPeer) ? (XWindowPeer)baseWindow :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
               (baseWindow instanceof XFocusProxyWindow) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
               ((XFocusProxyWindow)baseWindow).getOwner() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   582
    /*
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   583
     * Retrives real native focused window and converts it into Java window.
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   584
     */
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   585
    static Window getNativeFocusedWindow() {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   586
        XWindowPeer peer = getNativeFocusedWindowPeer();
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   587
        return peer != null ? (Window)peer.target : null;
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   588
    }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   589
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    boolean isFocusableWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        if (XToolkit.isToolkitThread() || SunToolkit.isAWTLockHeldByCurrentThread())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            return cachedFocusableWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            return ((Window)target).isFocusableWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    /* WARNING: don't call client code in this method! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    boolean isFocusedWindowModalBlocker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    long getFocusTargetWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        return getContentWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * Returns whether or not this window peer has native X window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * configured as non-focusable window. It might happen if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * - Java window is non-focusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * - Java window is simple Window(not Frame or Dialog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    boolean isNativelyNonFocusableWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        if (XToolkit.isToolkitThread() || SunToolkit.isAWTLockHeldByCurrentThread())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            return isSimpleWindow() || !cachedFocusableWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            return isSimpleWindow() || !(((Window)target).isFocusableWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    public void handleWindowFocusIn_Dispatch() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (EventQueue.isDispatchThread()) {
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11659
diff changeset
   625
            XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
6826
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   626
            WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   627
            SunToolkit.setSystemGenerated(we);
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   628
            target.dispatchEvent(we);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    public void handleWindowFocusInSync(long serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11659
diff changeset
   634
        XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        sendEvent(we);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    public void handleWindowFocusIn(long serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        /* wrap in Sequenced, then post*/
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11659
diff changeset
   642
        XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        postEvent(wrapInSequenced((AWTEvent) we));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    public void handleWindowFocusOut(Window oppositeWindow, long serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11659
diff changeset
   650
        XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11659
diff changeset
   651
        XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        /* wrap in Sequenced, then post*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        postEvent(wrapInSequenced((AWTEvent) we));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    public void handleWindowFocusOutSync(Window oppositeWindow, long serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11659
diff changeset
   657
        XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11659
diff changeset
   658
        XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        sendEvent(we);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
/* --- DisplayChangedListener Stuff --- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /* Xinerama
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * called to check if we've been moved onto a different screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * Based on checkNewXineramaScreen() in awt_GraphicsEnv.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    public void checkIfOnNewScreen(Rectangle newBounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        if (!XToolkit.localEnv.runningXinerama()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
   673
        if (log.isLoggable(PlatformLogger.Level.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            log.finest("XWindowPeer: Check if we've been moved to a new screen since we're running in Xinerama mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        int area = newBounds.width * newBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        int intAmt, vertAmt, horizAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        int largestAmt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        int curScreenNum = ((X11GraphicsDevice)getGraphicsConfiguration().getDevice()).getScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        int newScreenNum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        GraphicsDevice gds[] = XToolkit.localEnv.getScreenDevices();
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   683
        GraphicsConfiguration newGC = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        Rectangle screenBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
31649
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   686
        XToolkit.awtUnlock();
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   687
        try {
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   688
            for (int i = 0; i < gds.length; i++) {
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   689
                screenBounds = gds[i].getDefaultConfiguration().getBounds();
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   690
                if (newBounds.intersects(screenBounds)) {
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   691
                    horizAmt = Math.min(newBounds.x + newBounds.width,
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   692
                                        screenBounds.x + screenBounds.width) -
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   693
                               Math.max(newBounds.x, screenBounds.x);
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   694
                    vertAmt = Math.min(newBounds.y + newBounds.height,
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   695
                                       screenBounds.y + screenBounds.height)-
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   696
                              Math.max(newBounds.y, screenBounds.y);
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   697
                    intAmt = horizAmt * vertAmt;
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   698
                    if (intAmt == area) {
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   699
                        // Completely on this screen - done!
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   700
                        newScreenNum = i;
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   701
                        newGC = gds[i].getDefaultConfiguration();
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   702
                        break;
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   703
                    }
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   704
                    if (intAmt > largestAmt) {
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   705
                        largestAmt = intAmt;
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   706
                        newScreenNum = i;
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   707
                        newGC = gds[i].getDefaultConfiguration();
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   708
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            }
31649
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   711
        } finally {
738dd49e1689 8129116: Deadlock with multimonitor fullscreen windows.
azvegint
parents: 30469
diff changeset
   712
            XToolkit.awtLock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        if (newScreenNum != curScreenNum) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
   715
            if (log.isLoggable(PlatformLogger.Level.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                log.finest("XWindowPeer: Moved to a new screen");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            }
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   718
            executeDisplayChangedOnEDT(newGC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * Helper method that executes the displayChanged(screen) method on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * the event dispatch thread.  This method is used in the Xinerama case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * and after display mode change events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     */
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   727
    private void executeDisplayChangedOnEDT(final GraphicsConfiguration gc) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        Runnable dc = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            public void run() {
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   730
                AWTAccessor.getComponentAccessor().
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
   731
                    setGraphicsConfiguration(target, gc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        };
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
   734
        SunToolkit.executeOnEventHandlerThread(target, dc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * From the DisplayChangedListener interface; called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * X11GraphicsDevice when the display mode has been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    public void displayChanged() {
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   742
        executeDisplayChangedOnEDT(getGraphicsConfiguration());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * From the DisplayChangedListener interface; top-levels do not need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * to react to this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public void paletteChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
21786
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   752
    private Point queryXLocation()
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   753
    {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   754
        return XlibUtil.translateCoordinates(getContentWindow(), XlibWrapper
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   755
                                             .RootWindow(XToolkit.getDisplay(),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   756
                                             getScreenNumber()),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   757
                                             new Point(0, 0), getScale());
21786
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   758
    }
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   759
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   760
    protected Point getNewLocation(XConfigureEvent xe, int leftInset, int topInset) {
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   761
        // Bounds of the window
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
   762
        Rectangle targetBounds = AWTAccessor.getComponentAccessor().getBounds(target);
21786
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   763
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   764
        int runningWM = XWM.getWMID();
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   765
        Point newLocation = targetBounds.getLocation();
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   766
        if (xe.get_send_event() || runningWM == XWM.NO_WM || XWM.isNonReparentingWM()) {
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   767
            // Location, Client size + insets
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   768
            newLocation = new Point(scaleDown(xe.get_x()) - leftInset,
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   769
                                    scaleDown(xe.get_y()) - topInset);
21786
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   770
        } else {
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   771
            // ICCCM 4.1.5 states that a real ConfigureNotify will be sent when
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   772
            // a window is resized but the client can not tell if the window was
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   773
            // moved or not. The client should consider the position as unkown
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   774
            // and use TranslateCoordinates to find the actual position.
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   775
            //
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   776
            // TODO this should be the default for every case.
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   777
            switch (runningWM) {
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   778
                case XWM.CDE_WM:
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   779
                case XWM.MOTIF_WM:
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   780
                case XWM.METACITY_WM:
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   781
                case XWM.MUTTER_WM:
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   782
                case XWM.SAWFISH_WM:
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   783
                {
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   784
                    Point xlocation = queryXLocation();
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   785
                    if (log.isLoggable(PlatformLogger.Level.FINE)) {
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   786
                        log.fine("New X location: {0}", xlocation);
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   787
                    }
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   788
                    if (xlocation != null) {
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   789
                        newLocation = xlocation;
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   790
                    }
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   791
                    break;
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   792
                }
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   793
                default:
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   794
                    break;
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   795
            }
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   796
        }
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   797
        return newLocation;
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   798
    }
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 18275
diff changeset
   799
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * Overridden to check if we need to update our GraphicsDevice/Config
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * Added for 4934052.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     */
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   804
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    public void handleConfigureNotifyEvent(XEvent xev) {
36881
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   806
        assert (SunToolkit.isAWTLockHeldByCurrentThread());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        XConfigureEvent xe = xev.get_xconfigure();
36881
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   808
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   809
            insLog.fine(xe.toString());
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   810
        }
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   811
        checkIfOnNewScreen(toGlobal(new Rectangle(scaleDown(xe.get_x()),
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   812
                scaleDown(xe.get_y()),
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   813
                scaleDown(xe.get_width()),
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   814
                scaleDown(xe.get_height()))));
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   815
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   816
        Rectangle oldBounds = getBounds();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
36881
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   818
        x = scaleDown(xe.get_x());
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   819
        y = scaleDown(xe.get_y());
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   820
        width = scaleDown(xe.get_width());
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   821
        height = scaleDown(xe.get_height());
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   822
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   823
        if (!getBounds().getSize().equals(oldBounds.getSize())) {
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   824
            AWTAccessor.getComponentAccessor().setSize(target, width, height);
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   825
            postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_RESIZED));
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   826
        }
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   827
        if (!getBounds().getLocation().equals(oldBounds.getLocation())) {
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   828
            AWTAccessor.getComponentAccessor().setLocation(target, x, y);
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   829
            postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_MOVED));
3a22af76f434 8143295: Validating issue in AWT
ssadetsky
parents: 35667
diff changeset
   830
        }
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   831
        repositionSecurityWarning();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    final void requestXFocus(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        requestXFocus(time, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    final void requestXFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        requestXFocus(0, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * Requests focus to this top-level. Descendants should override to provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * implementations based on a class of top-level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    protected void requestXFocus(long time, boolean timeProvided) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        // Since in XAWT focus is synthetic and all basic Windows are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        // override_redirect all we can do is check whether our parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        // is active. If it is - we can freely synthesize focus transfer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        // Luckily, this logic is already implemented in requestWindowFocus.
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
   851
        if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   852
            focusLog.fine("Requesting window focus");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   853
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        requestWindowFocus(time, timeProvided);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    public final boolean focusAllowedFor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        if (isNativelyNonFocusableWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        Window target = (Window)this.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        if (!target.isVisible() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            !target.isEnabled() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            !target.isFocusable())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        if (isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    public void handleFocusEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        XFocusChangeEvent xfe = xev.get_xfocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        FocusEvent fe;
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
   879
        if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   880
            focusLog.fine("{0}", xfe);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   881
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   885
        if (xev.get_type() == XConstants.FocusIn)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            // If this window is non-focusable don't post any java focus event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            if (focusAllowedFor()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   889
                if (xfe.get_mode() == XConstants.NotifyNormal // Normal notify
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   890
                    || xfe.get_mode() == XConstants.NotifyWhileGrabbed) // Alt-Tab notify
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                    handleWindowFocusIn(xfe.get_serial());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   898
            if (xfe.get_mode() == XConstants.NotifyNormal // Normal notify
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   899
                || xfe.get_mode() == XConstants.NotifyWhileGrabbed) // Alt-Tab notify
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                // If this window is non-focusable don't post any java focus event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                if (!isNativelyNonFocusableWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                    XWindowPeer oppositeXWindow = getNativeFocusedWindowPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                    Object oppositeTarget = (oppositeXWindow!=null)? oppositeXWindow.getTarget() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                    Window oppositeWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                    if (oppositeTarget instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                        oppositeWindow = (Window) oppositeTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                    // Check if opposite window is non-focusable. In that case we don't want to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                    // post any event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                    if (oppositeXWindow != null && oppositeXWindow.isNativelyNonFocusableWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                    if (this == oppositeXWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                        oppositeWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                    } else if (oppositeXWindow instanceof XDecoratedPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                        if (((XDecoratedPeer) oppositeXWindow).actualFocusedWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                            oppositeXWindow = ((XDecoratedPeer) oppositeXWindow).actualFocusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                            oppositeTarget = oppositeXWindow.getTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                            if (oppositeTarget instanceof Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                                && oppositeXWindow.isVisible()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                                && oppositeXWindow.isNativelyNonFocusableWindow())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                                oppositeWindow = ((Window) oppositeTarget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                    handleWindowFocusOut(oppositeWindow, xfe.get_serial());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    void setSaveUnder(boolean state) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    public void toFront() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        if (isOverrideRedirect() && mustControlStackPosition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            mustControlStackPosition = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            removeRootPropertyEventDispatcher();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        if (isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            super.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            if (isFocusableWindow() && isAutoRequestFocus() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                !isModalBlocked() && !isWithdrawn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                requestInitialFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    public void toBack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            if(!isOverrideRedirect()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                XlibWrapper.XLowerWindow(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            }else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                lowerOverrideRedirect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    private void lowerOverrideRedirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        // make new hash of toplevels of all windows from 'windows' hash.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        // FIXME: do not call them "toplevel" as it is misleading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        //
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   971
        HashSet<Long> toplevels = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        long topl = 0, mytopl = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        for (XWindowPeer xp : windows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            topl = getToplevelWindow( xp.getWindow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            if( xp.equals( this ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                mytopl = topl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            if( topl > 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                toplevels.add( Long.valueOf( topl ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        // find in the root's tree:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        // (1) my toplevel, (2) lowest java toplevel, (3) desktop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        // We must enforce (3), (1), (2) order, upward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        // note that nautilus on the next restacking will do (1),(3),(2).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        long laux,     wDesktop = -1, wBottom = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        int  iMy = -1, iDesktop = -1, iBottom = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        XQueryTree xqt = new XQueryTree(XToolkit.getDefaultRootWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            if( xqt.execute() > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                int nchildren = xqt.get_nchildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                long children = xqt.get_children();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                for(i = 0; i < nchildren; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                    laux = Native.getWindow(children, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                    if( laux == mytopl ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                        iMy = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                    }else if( isDesktopWindow( laux ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                        // we need topmost desktop of them all.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                        iDesktop = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                        wDesktop = laux;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                    }else if(iBottom < 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                             toplevels.contains( Long.valueOf(laux) ) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                             laux != mytopl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                        iBottom = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                        wBottom = laux;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            if( (iMy < iBottom || iBottom < 0 )&& iDesktop < iMy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                return; // no action necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            long to_restack = Native.allocateLongArray(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            Native.putLong(to_restack, 0, wBottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            Native.putLong(to_restack, 1,  mytopl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            XlibWrapper.XRestackWindows(XToolkit.getDisplay(), to_restack, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            XlibWrapper.unsafe.freeMemory(to_restack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            if( !mustControlStackPosition ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                mustControlStackPosition = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                // add root window property listener:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                // somebody (eg nautilus desktop) may obscure us
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                addRootPropertyEventDispatcher();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            xqt.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        Get XID of closest to root window in a given window hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        FIXME: do not call it "toplevel" as it is misleading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        On error return 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    private long getToplevelWindow( long w ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        long wi = w, ret, root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            ret = wi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            XQueryTree qt = new XQueryTree(wi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                if (qt.execute() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                root = qt.get_root();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                wi = qt.get_parent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                qt.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        } while (wi != root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    }
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
  1058
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
  1059
    private static boolean isDesktopWindow( long wi ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        return XWM.getWM().isDesktopWindow( wi );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    private void updateAlwaysOnTop() {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  1064
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  1065
            log.fine("Promoting always-on-top state {0}", Boolean.valueOf(alwaysOnTop));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  1066
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        XWM.getWM().setLayer(this,
36882
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1068
                alwaysOnTop ?
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1069
                        XLayerProtocol.LAYER_ALWAYS_ON_TOP :
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1070
                        XLayerProtocol.LAYER_NORMAL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
16892
24a521782b42 8006790: Improve checking for windows
malenkov
parents: 14888
diff changeset
  1073
    public void updateAlwaysOnTopState() {
24a521782b42 8006790: Improve checking for windows
malenkov
parents: 14888
diff changeset
  1074
        this.alwaysOnTop = ((Window) this.target).isAlwaysOnTop();
36882
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1075
        if (ownerPeer != null) {
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1076
            XToolkit.awtLock();
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1077
            try {
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1078
                restoreTransientFor(this);
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1079
                applyWindowType();
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1080
            }
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1081
            finally {
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1082
                XToolkit.awtUnlock();
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1083
            }
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1084
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        updateAlwaysOnTop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    boolean isLocationByPlatform() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        return locationByPlatform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    private void promoteDefaultPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        this.locationByPlatform = ((Window)target).isLocationByPlatform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        if (locationByPlatform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                Rectangle bounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                XSizeHints hints = getHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1099
                setSizeHints(hints.get_flags() & ~(XUtilConstants.USPosition | XUtilConstants.PPosition),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                             bounds.x, bounds.y, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    public void setVisible(boolean vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        if (!isVisible() && vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            isBeforeFirstMapNotify = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            winAttr.initialFocus = isAutoRequestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            if (!winAttr.initialFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                 * It's easier and safer to temporary suppress WM_TAKE_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                 * protocol itself than to ignore WM_TAKE_FOCUS client message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                 * Because we will have to make the difference between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                 * the message come after showing and the message come after
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                 * activation. Also, on Metacity, for some reason, we have _two_
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                 * WM_TAKE_FOCUS client messages when showing a frame/dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                suppressWmTakeFocus(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        updateFocusability();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        promoteDefaultPosition();
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1125
        if (!vis && warningWindow != null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1126
            warningWindow.setSecurityWarningVisible(false, false);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1127
        }
36882
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1128
        boolean refreshChildsTransientFor = isVisible() != vis;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        super.setVisible(vis);
36882
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1130
        if (refreshChildsTransientFor) {
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1131
            for (Window child : ((Window) target).getOwnedWindows()) {
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1132
                XToolkit.awtLock();
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1133
                try {
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1134
                    if(!child.isLightweight() && child.isVisible()) {
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1135
                        ComponentPeer childPeer = AWTAccessor.
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1136
                                getComponentAccessor().getPeer(child);
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1137
                        if(childPeer instanceof XWindowPeer) {
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1138
                            XWindowPeer windowPeer = (XWindowPeer) childPeer;
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1139
                            restoreTransientFor(windowPeer);
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1140
                            windowPeer.applyWindowType();
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1141
                        }
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1142
                    }
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1143
                }
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1144
                finally {
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1145
                    XToolkit.awtUnlock();
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1146
                }
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1147
            }
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1148
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        if (!vis && !isWithdrawn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            // ICCCM, 4.1.4. Changing Window State:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            // "Iconic -> Withdrawn - The client should unmap the window and follow it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            // with a synthetic UnmapNotify event as described later in this section."
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            // The same is true for Normal -> Withdrawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                XUnmapEvent unmap = new XUnmapEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                unmap.set_window(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                unmap.set_event(XToolkit.getDefaultRootWindow());
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
  1159
                unmap.set_type(XConstants.UnmapNotify);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                unmap.set_from_configure(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                XlibWrapper.XSendEvent(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1162
                        false, XConstants.SubstructureNotifyMask | XConstants.SubstructureRedirectMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                        unmap.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                unmap.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        // method called somewhere in parent does not generate configure-notify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        // event for override-redirect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        // Ergo, no reshape and bugs like 5085647 in case setBounds was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        // called before setVisible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        if (isOverrideRedirect() && vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            updateChildrenSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        }
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1177
        repositionSecurityWarning();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    protected void suppressWmTakeFocus(boolean doSuppress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    final boolean isSimpleWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        return !(target instanceof Frame || target instanceof Dialog);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    boolean hasWarningWindow() {
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
  1187
        return ((Window)target).getWarningString() != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    // The height of menu bar window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    int getMenuBarHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1195
    // Called when shell changes its size and requires children windows
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1196
    // to update their sizes appropriately
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1197
    void updateChildrenSizes() {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1198
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1199
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1200
    public void repositionSecurityWarning() {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1201
        // NOTE: On KWin if the window/border snapping option is enabled,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1202
        // the Java window may be swinging while it's being moved.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1203
        // This doesn't make the application unusable though looks quite ugly.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1204
        // Probobly we need to find some hint to assign to our Security
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1205
        // Warning window in order to exclude it from the snapping option.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1206
        // We are not currently aware of existance of such a property.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        if (warningWindow != null) {
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1208
            // We can't use the coordinates stored in the XBaseWindow since
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1209
            // they are zeros for decorated frames.
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
  1210
            ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  1211
            int x = compAccessor.getX(target);
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  1212
            int y = compAccessor.getY(target);
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  1213
            int width = compAccessor.getWidth(target);
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  1214
            int height = compAccessor.getHeight(target);
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1215
            warningWindow.reposition(x, y, width, height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1219
    @Override
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1220
    protected void setMouseAbove(boolean above) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1221
        super.setMouseAbove(above);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1222
        updateSecurityWarningVisibility();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1223
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1224
4256
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1225
    @Override
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1226
    public void setFullScreenExclusiveModeState(boolean state) {
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1227
        super.setFullScreenExclusiveModeState(state);
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1228
        updateSecurityWarningVisibility();
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1229
    }
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1230
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1231
    public void updateSecurityWarningVisibility() {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1232
        if (warningWindow == null) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1233
            return;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1234
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1235
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1236
        if (!isVisible()) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1237
            return; // The warning window should already be hidden.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        }
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1239
4256
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1240
        boolean show = false;
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1241
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1242
        if (!isFullScreenExclusiveMode()) {
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1243
            int state = getWMState();
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1244
4256
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1245
            // getWMState() always returns 0 (Withdrawn) for simple windows. Hence
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1246
            // we ignore the state for such windows.
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1247
            if (isVisible() && (state == XUtilConstants.NormalState || isSimpleWindow())) {
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11659
diff changeset
  1248
                if (XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() ==
4256
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1249
                        getTarget())
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1250
                {
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1251
                    show = true;
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1252
                }
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1253
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1254
                if (isMouseAbove() || warningWindow.isMouseAbove())
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1255
                {
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1256
                    show = true;
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 4254
diff changeset
  1257
                }
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1258
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1259
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1260
2804
a947dcefc8cb 6811219: Deadlock java AWT in XWarningWindow
anthony
parents: 2643
diff changeset
  1261
        warningWindow.setSecurityWarningVisible(show, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    boolean isOverrideRedirect() {
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1265
        return XWM.getWMID() == XWM.OPENLOOK_WM ||
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1266
            Window.Type.POPUP.equals(getWindowType());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    final boolean isOLWMDecorBug() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        return XWM.getWMID() == XWM.OPENLOOK_WM &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            winAttr.nativeDecor == false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    public void dispose() {
13649
ac4f162d1f35 7192887: java/awt/Window/Grab/GrabTest.java still failed (fix failed for CR 7149068)
denis
parents: 13648
diff changeset
  1275
        if (isGrabbed()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  1276
            if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
13649
ac4f162d1f35 7192887: java/awt/Window/Grab/GrabTest.java still failed (fix failed for CR 7149068)
denis
parents: 13648
diff changeset
  1277
                grabLog.fine("Generating UngrabEvent on {0} because of the window disposal", this);
ac4f162d1f35 7192887: java/awt/Window/Grab/GrabTest.java still failed (fix failed for CR 7149068)
denis
parents: 13648
diff changeset
  1278
            }
ac4f162d1f35 7192887: java/awt/Window/Grab/GrabTest.java still failed (fix failed for CR 7149068)
denis
parents: 13648
diff changeset
  1279
            postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
ac4f162d1f35 7192887: java/awt/Window/Grab/GrabTest.java still failed (fix failed for CR 7149068)
denis
parents: 13648
diff changeset
  1280
        }
ac4f162d1f35 7192887: java/awt/Window/Grab/GrabTest.java still failed (fix failed for CR 7149068)
denis
parents: 13648
diff changeset
  1281
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        SunToolkit.awtLock();
13649
ac4f162d1f35 7192887: java/awt/Window/Grab/GrabTest.java still failed (fix failed for CR 7149068)
denis
parents: 13648
diff changeset
  1283
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            windows.remove(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            SunToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        }
13649
ac4f162d1f35 7192887: java/awt/Window/Grab/GrabTest.java still failed (fix failed for CR 7149068)
denis
parents: 13648
diff changeset
  1289
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        if (warningWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            warningWindow.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        }
13649
ac4f162d1f35 7192887: java/awt/Window/Grab/GrabTest.java still failed (fix failed for CR 7149068)
denis
parents: 13648
diff changeset
  1293
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        removeRootPropertyEventDispatcher();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        mustControlStackPosition = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
         * Fix for 6457980.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
         * When disposing an owned Window we should implicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
         * return focus to its decorated owner because it won't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
         * receive WM_TAKE_FOCUS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        if (isSimpleWindow()) {
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11659
diff changeset
  1305
            if (target == XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                Window owner = getDecoratedOwner((Window)target);
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  1307
                ((XWindowPeer)AWTAccessor.getComponentAccessor().getPeer(owner)).requestWindowFocus();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    }
13649
ac4f162d1f35 7192887: java/awt/Window/Grab/GrabTest.java still failed (fix failed for CR 7149068)
denis
parents: 13648
diff changeset
  1311
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    boolean isResizable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        return winAttr.isResizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    public void handleVisibilityEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        super.handleVisibilityEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        XVisibilityEvent ve = xev.get_xvisibility();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        winAttr.visibilityState = ve.get_state();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
//         if (ve.get_state() == XlibWrapper.VisibilityUnobscured) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
//             // raiseInputMethodWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
//         }
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1323
        repositionSecurityWarning();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    void handleRootPropertyNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        XPropertyEvent ev = xev.get_xproperty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        if( mustControlStackPosition &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            ev.get_atom() == XAtom.get("_NET_CLIENT_LIST_STACKING").getAtom()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            // Restore stack order unhadled/spoiled by WM or some app (nautilus).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            // As of now, don't use any generic machinery: just
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            // do toBack() again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            if(isOverrideRedirect()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                toBack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
4361
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1339
    private void removeStartupNotification() {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1340
        if (isStartupNotificationRemoved.getAndSet(true)) {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1341
            return;
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1342
        }
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1343
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1344
        final String desktopStartupId = AccessController.doPrivileged(new PrivilegedAction<String>() {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1345
            public String run() {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1346
                return XToolkit.getEnv("DESKTOP_STARTUP_ID");
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1347
            }
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1348
        });
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1349
        if (desktopStartupId == null) {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1350
            return;
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1351
        }
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1352
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1353
        final StringBuilder messageBuilder = new StringBuilder("remove: ID=");
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1354
        messageBuilder.append('"');
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1355
        for (int i = 0; i < desktopStartupId.length(); i++) {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1356
            if (desktopStartupId.charAt(i) == '"' || desktopStartupId.charAt(i) == '\\') {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1357
                messageBuilder.append('\\');
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1358
            }
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1359
            messageBuilder.append(desktopStartupId.charAt(i));
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1360
        }
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1361
        messageBuilder.append('"');
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1362
        messageBuilder.append('\0');
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1363
        final byte[] message;
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1364
        try {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1365
            message = messageBuilder.toString().getBytes("UTF-8");
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1366
        } catch (UnsupportedEncodingException cannotHappen) {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1367
            return;
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1368
        }
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1369
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1370
        XClientMessageEvent req = null;
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1371
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1372
        XToolkit.awtLock();
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1373
        try {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1374
            final XAtom netStartupInfoBeginAtom = XAtom.get("_NET_STARTUP_INFO_BEGIN");
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1375
            final XAtom netStartupInfoAtom = XAtom.get("_NET_STARTUP_INFO");
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1376
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1377
            req = new XClientMessageEvent();
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1378
            req.set_type(XConstants.ClientMessage);
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1379
            req.set_window(getWindow());
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1380
            req.set_message_type(netStartupInfoBeginAtom.getAtom());
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1381
            req.set_format(8);
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1382
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1383
            for (int pos = 0; pos < message.length; pos += 20) {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1384
                final int msglen = Math.min(message.length - pos, 20);
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1385
                int i = 0;
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1386
                for (; i < msglen; i++) {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1387
                    XlibWrapper.unsafe.putByte(req.get_data() + i, message[pos + i]);
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1388
                }
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1389
                for (; i < 20; i++) {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1390
                    XlibWrapper.unsafe.putByte(req.get_data() + i, (byte)0);
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1391
                }
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1392
                XlibWrapper.XSendEvent(XToolkit.getDisplay(),
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1393
                    XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()),
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1394
                    false,
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1395
                    XConstants.PropertyChangeMask,
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1396
                    req.pData);
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1397
                req.set_message_type(netStartupInfoAtom.getAtom());
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1398
            }
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1399
        } finally {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1400
            XToolkit.awtUnlock();
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1401
            if (req != null) {
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1402
                req.dispose();
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1403
            }
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1404
        }
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1405
    }
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1406
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
    public void handleMapNotifyEvent(XEvent xev) {
4361
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1408
        removeStartupNotification();
66c14524f39c 6863566: Java should support the freedesktop.org startup notification specification
anthony
parents: 4259
diff changeset
  1409
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        // See 6480534.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        isUnhiding |= isWMStateNetHidden();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        super.handleMapNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        if (!winAttr.initialFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            suppressWmTakeFocus(false); // restore the protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
             * For some reason, on Metacity, a frame/dialog being shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
             * without WM_TAKE_FOCUS protocol doesn't get moved to the front.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
             * So, we do it evidently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        if (shouldFocusOnMapNotify()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            focusLog.fine("Automatically request focus on window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            requestInitialFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        isUnhiding = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        isBeforeFirstMapNotify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        updateAlwaysOnTop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            if (!isMapped) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                isMapped = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
    public void handleUnmapNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        super.handleUnmapNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        // On Metacity UnmapNotify comes before PropertyNotify (for _NET_WM_STATE_HIDDEN).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
        // So we also check for the property later in MapNotify. See 6480534.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        isUnhiding |= isWMStateNetHidden();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
            if (isMapped) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                isMapped = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    private boolean shouldFocusOnMapNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        boolean res = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        if (isBeforeFirstMapNotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            res = (winAttr.initialFocus ||          // Window.autoRequestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                   isFocusedWindowModalBlocker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            res = isUnhiding;                       // Unhiding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        res = res &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            isFocusableWindow() &&                  // General focusability
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            !isModalBlocked();                      // Modality
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1473
    protected boolean isWMStateNetHidden() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        XNETProtocol protocol = XWM.getWM().getNETProtocol();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        return (protocol != null && protocol.isWMStateNetHidden(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    protected void requestInitialFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        requestXFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
    public void addToplevelStateListener(ToplevelStateListener l){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        toplevelStateListeners.add(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
    public void removeToplevelStateListener(ToplevelStateListener l){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        toplevelStateListeners.remove(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
     * Override this methods to get notifications when top-level window state changes. The state is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
     * meant in terms of ICCCM: WithdrawnState, IconicState, NormalState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
     */
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1494
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
    protected void stateChanged(long time, int oldState, int newState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        // Fix for 6401700, 6412803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        // If this window is modal blocked, it is put into the transient_for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        // chain using prevTransientFor and nextTransientFor hints. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        // the real WM_TRANSIENT_FOR hint shouldn't be set for windows in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        // different WM states (except for owner-window relationship), so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        // if the window changes its state, its real WM_TRANSIENT_FOR hint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        // should be updated accordingly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        updateTransientFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        for (ToplevelStateListener topLevelListenerTmp : toplevelStateListeners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            topLevelListenerTmp.stateChangedICCCM(oldState, newState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  1509
        updateSecurityWarningVisibility();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
    boolean isWithdrawn() {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1513
        return getWMState() == XUtilConstants.WithdrawnState;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    boolean hasDecorations(int decor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        if (!winAttr.nativeDecor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
            int myDecor = winAttr.decorations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            boolean hasBits = ((myDecor & decor) == decor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
            if ((myDecor & XWindowAttributesData.AWT_DECOR_ALL) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                return !hasBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                return hasBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    void setReparented(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        super.setReparented(newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
            if (isReparented() && delayedModalBlocking) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
  1535
                addToTransientFors(AWTAccessor.getComponentAccessor().getPeer(modalBlocker));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                delayedModalBlocking = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     * Returns a Vector of all Java top-level windows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
     * sorted by their current Z-order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
    static Vector<XWindowPeer> collectJavaToplevels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        Vector<XWindowPeer> javaToplevels = new Vector<XWindowPeer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        Vector<Long> v = new Vector<Long>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        X11GraphicsEnvironment ge =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            (X11GraphicsEnvironment)GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        GraphicsDevice[] gds = ge.getScreenDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        if (!ge.runningXinerama() && (gds.length > 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
            for (GraphicsDevice gd : gds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                int screen = ((X11GraphicsDevice)gd).getScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                long rootWindow = XlibWrapper.RootWindow(XToolkit.getDisplay(), screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                v.add(rootWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
            v.add(XToolkit.getDefaultRootWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        final int windowsCount = windows.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        while ((v.size() > 0) && (javaToplevels.size() < windowsCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            long win = v.remove(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
            XQueryTree qt = new XQueryTree(win);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                if (qt.execute() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                    int nchildren = qt.get_nchildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                    long children = qt.get_children();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                    // XQueryTree returns window children ordered by z-order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                    for (int i = 0; i < nchildren; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                        long child = Native.getWindow(children, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                        XBaseWindow childWindow = XToolkit.windowToXWindow(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                        // filter out Java non-toplevels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                        if ((childWindow != null) && !(childWindow instanceof XWindowPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                            v.add(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                        if (childWindow instanceof XWindowPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                            XWindowPeer np = (XWindowPeer)childWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                            javaToplevels.add(np);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                            // XQueryTree returns windows sorted by their z-order. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                            // if WM has not handled transient for hint for a child window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                            // it may appear in javaToplevels before its owner. Move such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                            // children after their owners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                            int k = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                            XWindowPeer toCheck = javaToplevels.get(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                            while (toCheck != np) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                                XWindowPeer toCheckOwnerPeer = toCheck.getOwnerPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                                if (toCheckOwnerPeer == np) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                                    javaToplevels.remove(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                                    javaToplevels.add(toCheck);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                                    k++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                                toCheck = javaToplevels.get(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                qt.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
        return javaToplevels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    public void setModalBlocked(Dialog d, boolean blocked) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        setModalBlocked(d, blocked, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
    public void setModalBlocked(Dialog d, boolean blocked,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                                Vector<XWindowPeer> javaToplevels)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
            // State lock should always be after awtLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
            synchronized(getStateLock()) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
  1619
                XDialogPeer blockerPeer = AWTAccessor.getComponentAccessor().getPeer(d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                if (blocked) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  1621
                    if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  1622
                        log.fine("{0} is blocked by {1}", this, blockerPeer);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  1623
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                    modalBlocker = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                    if (isReparented() || XWM.isNonReparentingWM()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                        addToTransientFors(blockerPeer, javaToplevels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                        delayedModalBlocking = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                    if (d != modalBlocker) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                        throw new IllegalStateException("Trying to unblock window blocked by another dialog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                    modalBlocker = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                    if (isReparented() || XWM.isNonReparentingWM()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                        removeFromTransientFors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                        delayedModalBlocking = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                updateTransientFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
     * Sets the TRANSIENT_FOR hint to the given top-level window. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
     *  method is used when a window is modal blocked/unblocked or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
     *  changed its state from/to NormalState to/from other states.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
     * If window or transientForWindow are embedded frames, the containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
     *  top-level windows are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     * @param window specifies the top-level window that the hint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     *  is to be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
     * @param transientForWindow the top-level window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     * @param updateChain specifies if next/prevTransientFor fields are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     *  to be updated
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 34395
diff changeset
  1663
     * @param allStates if set to {@code true} then TRANSIENT_FOR hint
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
     *  is set regardless of the state of window and transientForWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
     *  otherwise it is set only if both are in the same state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
    static void setToplevelTransientFor(XWindowPeer window, XWindowPeer transientForWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                                                boolean updateChain, boolean allStates)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
        if ((window == null) || (transientForWindow == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
        if (updateChain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
            window.prevTransientFor = transientForWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
            transientForWindow.nextTransientFor = window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        if (!allStates && (window.getWMState() != transientForWindow.getWMState())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
        if (window.getScreenNumber() != transientForWindow.getScreenNumber()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        long bpw = window.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
        while (!XlibUtil.isToplevelWindow(bpw) && !XlibUtil.isXAWTToplevelWindow(bpw)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
            bpw = XlibUtil.getParentWindow(bpw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        long tpw = transientForWindow.getWindow();
36882
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1688
        XBaseWindow parent = transientForWindow;
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1689
        while (tpw != 0 && ((!XlibUtil.isToplevelWindow(tpw) &&
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1690
                !XlibUtil.isXAWTToplevelWindow(tpw)) || !parent.isVisible())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            tpw = XlibUtil.getParentWindow(tpw);
36882
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1692
            parent = XToolkit.windowToXWindow(tpw);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
        XlibWrapper.XSetTransientFor(XToolkit.getDisplay(), bpw, tpw);
36882
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1695
        window.curRealTransientFor = parent;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * This method does nothing if this window is not blocked by any modal dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * For modal blocked windows this method looks up for the nearest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     *  prevTransiendFor window that is in the same state (Normal/Iconified/Withdrawn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
     *  as this one and makes this window transient for it. The same operation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     *  performed for nextTransientFor window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     * Values of prevTransientFor and nextTransientFor fields are not changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
    void updateTransientFor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        int state = getWMState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        XWindowPeer p = prevTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        while ((p != null) && ((p.getWMState() != state) || (p.getScreenNumber() != getScreenNumber()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
            p = p.prevTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
            setToplevelTransientFor(this, p, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            restoreTransientFor(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
        XWindowPeer n = nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
        while ((n != null) && ((n.getWMState() != state) || (n.getScreenNumber() != getScreenNumber()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
            n = n.nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
        if (n != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
            setToplevelTransientFor(n, this, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     * Removes the TRANSIENT_FOR hint from the given top-level window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     * If window or transientForWindow are embedded frames, the containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     *  top-level windows are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     * @param window specifies the top-level window that the hint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     *  is to be removed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
    private static void removeTransientForHint(XWindowPeer window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        XAtom XA_WM_TRANSIENT_FOR = XAtom.get(XAtom.XA_WM_TRANSIENT_FOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        long bpw = window.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        while (!XlibUtil.isToplevelWindow(bpw) && !XlibUtil.isXAWTToplevelWindow(bpw)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            bpw = XlibUtil.getParentWindow(bpw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        XlibWrapper.XDeleteProperty(XToolkit.getDisplay(), bpw, XA_WM_TRANSIENT_FOR.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        window.curRealTransientFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
     * When a modal dialog is shown, all its blocked windows are lined up into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     *  a chain in such a way that each window is a transient_for window for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     *  the next one. That allows us to keep the modal dialog above all its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     *  blocked windows (even if there are some another modal dialogs between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     *  them).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     * This method adds this top-level window to the chain of the given modal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     *  dialog. To keep the current relative z-order, we should use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     *  XQueryTree to find the place to insert this window to. As each window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     *  can be blocked by only one modal dialog (such checks are performed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     *  shared code), both this and blockerPeer are on the top of their chains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     *  (chains may be empty).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
     * If this window is a modal dialog and has its own chain, these chains are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
     *  merged according to the current z-order (XQueryTree is used again).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
     *  Below are some simple examples (z-order is from left to right, -- is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
     *  modal blocking).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     * Example 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
     *     T (current chain of this, no windows are blocked by this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     *  W1---B (current chain of blockerPeer, W2 is blocked by blockerPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     *  Result is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     *  W1-T-B (merged chain, all the windows are blocked by blockerPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * Example 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     *  W1-T (current chain of this, W1 is blocked by this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     *       W2-B (current chain of blockerPeer, W2 is blocked by blockerPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     *  Result is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     *  W1-T-W2-B (merged chain, all the windows are blocked by blockerPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     * Example 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     *  W1----T (current chain of this, W1 is blocked by this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     *     W2---B (current chain of blockerPeer, W2 is blocked by blockerPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     *  Result is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     *  W1-W2-T-B (merged chain, all the windows are blocked by blockerPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     * This method should be called under the AWT lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     * @see #removeFromTransientFors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     * @see #setModalBlocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
    private void addToTransientFors(XDialogPeer blockerPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        addToTransientFors(blockerPeer, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
    private void addToTransientFors(XDialogPeer blockerPeer, Vector<XWindowPeer> javaToplevels)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
        // blockerPeer chain iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        XWindowPeer blockerChain = blockerPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
        while (blockerChain.prevTransientFor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
            blockerChain = blockerChain.prevTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        // this window chain iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
        // each window can be blocked no more than once, so this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
        //   is on top of its chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        XWindowPeer thisChain = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
        while (thisChain.prevTransientFor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
            thisChain = thisChain.prevTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
        // if there are no windows blocked by modalBlocker, simply add this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
        //  and its chain to blocker's chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
        if (blockerChain == blockerPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
            setToplevelTransientFor(blockerPeer, this, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
            // Collect all the Java top-levels, if required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            if (javaToplevels == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                javaToplevels = collectJavaToplevels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
            // merged chain tail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
            XWindowPeer mergedChain = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
            for (XWindowPeer w : javaToplevels) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
                XWindowPeer prevMergedChain = mergedChain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                if (w == thisChain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                    if (thisChain == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                        if (prevMergedChain != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                            setToplevelTransientFor(this, prevMergedChain, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                        setToplevelTransientFor(blockerChain, this, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                        mergedChain = thisChain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                        thisChain = thisChain.nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                } else if (w == blockerChain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                    mergedChain = blockerChain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                    blockerChain = blockerChain.nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                if (prevMergedChain == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                    mergedChain.prevTransientFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                    setToplevelTransientFor(mergedChain, prevMergedChain, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                    mergedChain.updateTransientFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                if (blockerChain == blockerPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                    setToplevelTransientFor(thisChain, mergedChain, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                    setToplevelTransientFor(blockerChain, this, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
        XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    static void restoreTransientFor(XWindowPeer window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        XWindowPeer ownerPeer = window.getOwnerPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
        if (ownerPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
            setToplevelTransientFor(window, ownerPeer, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
            removeTransientForHint(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * When a window is modally unblocked, it should be removed from its blocker
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     *  chain, see {@link #addToTransientFor addToTransientFors} method for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     *  chain definition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * The problem is that we cannot simply restore window's original
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     *  TRANSIENT_FOR hint (if any) and link prevTransientFor and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     *  nextTransientFor together as the whole chain could be created as a merge
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     *  of two other chains in addToTransientFors. In that case, if this window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     *  a modal dialog, it would lost all its own chain, if we simply exclude it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     *  from the chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     * The correct behaviour of this method should be to split the chain, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     *  window is currently in, into two chains. First chain is this window own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     *  chain (i. e. all the windows blocked by this one, directly or indirectly),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     *  if any, and the rest windows from the current chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     * Example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
     *  Original state:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
     *   W1-B1 (window W1 is blocked by B1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
     *   W2-B2 (window W2 is blocked by B2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
     *  B3 is shown and blocks B1 and B2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
     *   W1-W2-B1-B2-B3 (a single chain after B1.addToTransientFors() and B2.addToTransientFors())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
     *  If we then unblock B1, the state should be:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
     *   W1-B1 (window W1 is blocked by B1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
     *   W2-B2-B3 (window W2 is blocked by B2 and B2 is blocked by B3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
     * This method should be called under the AWT lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
     * @see #addToTransientFors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
     * @see #setModalBlocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
    private void removeFromTransientFors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
        // the head of the chain of this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
        XWindowPeer thisChain = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        // the head of the current chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
        // nextTransientFor is always not null as this window is in the chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
        XWindowPeer otherChain = nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
        // the set of blockers in this chain: if this dialog blocks some other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        // modal dialogs, their blocked windows should stay in this dialog's chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
        Set<XWindowPeer> thisChainBlockers = new HashSet<XWindowPeer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
        thisChainBlockers.add(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
        // current chain iterator in the order from next to prev
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
        XWindowPeer chainToSplit = prevTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
        while (chainToSplit != null) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
  1901
            XWindowPeer blocker = AWTAccessor.getComponentAccessor().getPeer(chainToSplit.modalBlocker);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
            if (thisChainBlockers.contains(blocker)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                // add to this dialog's chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                setToplevelTransientFor(thisChain, chainToSplit, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                thisChain = chainToSplit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                thisChainBlockers.add(chainToSplit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                // leave in the current chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                setToplevelTransientFor(otherChain, chainToSplit, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                otherChain = chainToSplit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
            chainToSplit = chainToSplit.prevTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        restoreTransientFor(thisChain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        thisChain.prevTransientFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
        restoreTransientFor(otherChain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
        otherChain.prevTransientFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
        nextTransientFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
        XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
    boolean isModalBlocked() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        return modalBlocker != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
    static Window getDecoratedOwner(Window window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
        while ((null != window) && !(window instanceof Frame || window instanceof Dialog)) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  1929
            window = (Window) AWTAccessor.getComponentAccessor().getParent(window);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
        return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1934
    public boolean requestWindowFocus(XWindowPeer actualFocusedWindow) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1935
        setActualFocusedWindow(actualFocusedWindow);
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1936
        return requestWindowFocus();
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1937
    }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1938
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
    public boolean requestWindowFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
        return requestWindowFocus(0, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
    public boolean requestWindowFocus(long time, boolean timeProvided) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
        focusLog.fine("Request for window focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        // If this is Frame or Dialog we can't assure focus request success - but we still can try
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
        // If this is Window and its owner Frame is active we can be sure request succedded.
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1947
        Window ownerWindow  = XWindowPeer.getDecoratedOwner((Window)target);
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11659
diff changeset
  1948
        Window focusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1949
        Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1951
        if (isWMStateNetHidden()) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1952
            focusLog.fine("The window is unmapped, so rejecting the request");
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1953
            return false;
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1954
        }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1955
        if (activeWindow == ownerWindow) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
            focusLog.fine("Parent window is active - generating focus for this window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
            handleWindowFocusInSync(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
        }
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1960
        focusLog.fine("Parent window is not active");
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1961
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
  1962
        XDecoratedPeer wpeer = AWTAccessor.getComponentAccessor().getPeer(ownerWindow);
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1963
        if (wpeer != null && wpeer.requestWindowFocus(this, time, timeProvided)) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1964
            focusLog.fine("Parent window accepted focus request - generating focus for this window");
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1965
            return true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
        focusLog.fine("Denied - parent window is not active and didn't accept focus request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
    // This method is to be overriden in XDecoratedPeer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
    void setActualFocusedWindow(XWindowPeer actualFocusedWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1975
    /**
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1976
     * Applies the current window type.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1977
     */
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1978
    private void applyWindowType() {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1979
        XNETProtocol protocol = XWM.getWM().getNETProtocol();
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1980
        if (protocol == null) {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1981
            return;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1982
        }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1983
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1984
        XAtom typeAtom = null;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1985
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1986
        switch (getWindowType())
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1987
        {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1988
            case NORMAL:
36882
9347af61016c 8021961: setAlwaysOnTop doesn't behave correctly in Linux/Solaris under certain scenarios
ssadetsky
parents: 36881
diff changeset
  1989
                typeAtom = curRealTransientFor == null ?
17147
e1cd5c92e81c 8012586: [x11] Modal dialogs for fullscreen window may show behind its owner
anthony
parents: 16930
diff changeset
  1990
                               protocol.XA_NET_WM_WINDOW_TYPE_NORMAL :
e1cd5c92e81c 8012586: [x11] Modal dialogs for fullscreen window may show behind its owner
anthony
parents: 16930
diff changeset
  1991
                               protocol.XA_NET_WM_WINDOW_TYPE_DIALOG;
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1992
                break;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1993
            case UTILITY:
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1994
                typeAtom = protocol.XA_NET_WM_WINDOW_TYPE_UTILITY;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1995
                break;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1996
            case POPUP:
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1997
                typeAtom = protocol.XA_NET_WM_WINDOW_TYPE_POPUP_MENU;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1998
                break;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  1999
        }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2000
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2001
        if (typeAtom != null) {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2002
            XAtomList wtype = new XAtomList();
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2003
            wtype.add(typeAtom);
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2004
            protocol.XA_NET_WM_WINDOW_TYPE.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2005
                setAtomListProperty(getWindow(), wtype);
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2006
        } else {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2007
            protocol.XA_NET_WM_WINDOW_TYPE.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2008
                DeleteProperty(getWindow());
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2009
        }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2010
    }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2011
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2012
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
    public void xSetVisible(boolean visible) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  2014
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2015
            log.fine("Setting visible on " + this + " to " + visible);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2016
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
            this.visible = visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            if (visible) {
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4364
diff changeset
  2021
                applyWindowType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
                XlibWrapper.XMapRaised(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
                XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
            XlibWrapper.XFlush(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2033
    // should be synchronized on awtLock
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
    private int dropTargetCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2036
    public void addDropTarget() {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2037
        XToolkit.awtLock();
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2038
        try {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2039
            if (dropTargetCount == 0) {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2040
                long window = getWindow();
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2041
                if (window != 0) {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2042
                    XDropTargetRegistry.getRegistry().registerDropSite(window);
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2043
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
            }
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2045
            dropTargetCount++;
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2046
        } finally {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2047
            XToolkit.awtUnlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2051
    public void removeDropTarget() {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2052
        XToolkit.awtLock();
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2053
        try {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2054
            dropTargetCount--;
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2055
            if (dropTargetCount == 0) {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2056
                long window = getWindow();
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2057
                if (window != 0) {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2058
                    XDropTargetRegistry.getRegistry().unregisterDropSite(window);
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2059
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
            }
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2061
        } finally {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2062
            XToolkit.awtUnlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
    void addRootPropertyEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
        if( rootPropertyEventDispatcher == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
            rootPropertyEventDispatcher = new XEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                public void dispatchEvent(XEvent ev) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  2069
                    if( ev.get_type() == XConstants.PropertyNotify ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                        handleRootPropertyNotify( ev );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
            XlibWrapper.XSelectInput( XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
                                      XToolkit.getDefaultRootWindow(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  2076
                                      XConstants.PropertyChangeMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
            XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
                                                rootPropertyEventDispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
    void removeRootPropertyEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
        if( rootPropertyEventDispatcher != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
            XToolkit.removeEventDispatcher(XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
                                                rootPropertyEventDispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
            rootPropertyEventDispatcher = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
    public void updateFocusableWindowState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
        cachedFocusableWindow = isFocusableWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
    XAtom XA_NET_WM_STATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
    XAtomList net_wm_state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
    public XAtomList getNETWMState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
        if (net_wm_state == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            net_wm_state = XA_NET_WM_STATE.getAtomListPropertyList(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
        return net_wm_state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
    public void setNETWMState(XAtomList state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
        net_wm_state = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        if (state != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
            XA_NET_WM_STATE.setAtomListProperty(this, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
    public PropMwmHints getMWMHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
        if (mwm_hints == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
            mwm_hints = new PropMwmHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  2111
            if (!XWM.XA_MWM_HINTS.getAtomData(getWindow(), mwm_hints.pData, MWMConstants.PROP_MWM_HINTS_ELEMENTS)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
                mwm_hints.zero();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
        return mwm_hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
    public void setMWMHints(PropMwmHints hints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
        mwm_hints = hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
        if (hints != null) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  2121
            XWM.XA_MWM_HINTS.setAtomData(getWindow(), mwm_hints.pData, MWMConstants.PROP_MWM_HINTS_ELEMENTS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2125
    protected void updateDropTarget() {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2126
        XToolkit.awtLock();
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2127
        try {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2128
            if (dropTargetCount > 0) {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2129
                long window = getWindow();
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2130
                if (window != 0) {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2131
                    XDropTargetRegistry.getRegistry().unregisterDropSite(window);
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2132
                    XDropTargetRegistry.getRegistry().registerDropSite(window);
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2133
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
            }
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2135
        } finally {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2810
diff changeset
  2136
            XToolkit.awtUnlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
    public void setGrab(boolean grab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
        this.grab = grab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
        if (grab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
            pressTarget = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
            grabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
            ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
    public boolean isGrabbed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
        return grab && XAwtState.getGrabWindow() == this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
    public void handleXCrossingEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
        XCrossingEvent xce = xev.get_xcrossing();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  2156
        if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
  2157
            grabLog.fine("{0}, when grabbed {1}, contains {2}",
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2158
                         xce, isGrabbed(),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2159
                         containsGlobal(scaleDown(xce.get_x_root()),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2160
                                        scaleDown(xce.get_y_root())));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
        if (isGrabbed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
            // When window is grabbed, all events are dispatched to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
            // it.  Retarget them to the corresponding windows (notice
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
            // that XBaseWindow.dispatchEvent does the opposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
            // translation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
            // Note that we need to retarget XCrossingEvents to content window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
            // since it generates MOUSE_ENTERED/MOUSE_EXITED for frame and dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
            // (fix for 6390326)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
            XBaseWindow target = XToolkit.windowToXWindow(xce.get_window());
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  2171
            if (grabLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2172
                grabLog.finer("  -  Grab event target {0}", target);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2173
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
            if (target != null && target != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
                target.dispatchEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
        super.handleXCrossingEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
    public void handleMotionNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
        XMotionEvent xme = xev.get_xmotion();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  2184
        if (grabLog.isLoggable(PlatformLogger.Level.FINER)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
  2185
            grabLog.finer("{0}, when grabbed {1}, contains {2}",
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2186
                          xme, isGrabbed(),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2187
                          containsGlobal(scaleDown(xme.get_x_root()),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2188
                                         scaleDown(xme.get_y_root())));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
        if (isGrabbed()) {
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  2191
            boolean dragging = false;
14888
7ad1550e7050 8005018: X11: focus problems with openjdk 1.7.0 under gnome3 when selected keyboard is not the first in keyboard list
neugens
parents: 13649
diff changeset
  2192
            final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2808
diff changeset
  2193
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2808
diff changeset
  2194
            for (int i = 0; i < buttonsNumber; i++){
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  2195
                // here is the bug in WM: extra buttons doesn't have state!=0 as they should.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  2196
                if ((i != 4) && (i != 5)){
14888
7ad1550e7050 8005018: X11: focus problems with openjdk 1.7.0 under gnome3 when selected keyboard is not the first in keyboard list
neugens
parents: 13649
diff changeset
  2197
                    dragging = dragging || ((xme.get_state() & XlibUtil.getButtonMask(i + 1)) != 0);
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  2198
                }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  2199
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
            // When window is grabbed, all events are dispatched to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
            // it.  Retarget them to the corresponding windows (notice
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
            // that XBaseWindow.dispatchEvent does the opposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
            // translation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
            XBaseWindow target = XToolkit.windowToXWindow(xme.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
            if (dragging && pressTarget != target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
                // for some reasons if we grab input MotionNotify for drag is reported with target
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
                // to underlying window, not to window on which we have initiated drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
                // so we need to retarget them.  Here I use simplified logic which retarget all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
                // such events to source of mouse press (or the grabber).  It helps with fix for 6390326.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
                // So, I do not want to implement complicated logic for better retargeting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
                target = pressTarget.isVisible() ? pressTarget : this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
                xme.set_window(target.getWindow());
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2213
                Point localCoord = target.toLocal(scaleDown(xme.get_x_root()),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2214
                                                  scaleDown(xme.get_y_root()));
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2215
                xme.set_x(scaleUp(localCoord.x));
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2216
                xme.set_y(scaleUp(localCoord.y));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
            }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  2218
            if (grabLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2219
                grabLog.finer("  -  Grab event target {0}", target);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2220
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
                if (target != getContentXWindow() && target != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
                    target.dispatchEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
            // note that we need to pass dragging events to the grabber (6390326)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
            // see comment above for more inforamtion.
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2230
            if (!containsGlobal(scaleDown(xme.get_x_root()),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2231
                                scaleDown(xme.get_y_root()))
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2232
                    && !dragging) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
                // Outside of Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
        super.handleMotionNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
    // we use it to retarget mouse drag and mouse release during grab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
    private XBaseWindow pressTarget = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
    public void handleButtonPressRelease(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
        XButtonEvent xbe = xev.get_xbutton();
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2808
diff changeset
  2245
        /*
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2808
diff changeset
  2246
         * Ignore the buttons above 20 due to the bit limit for
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2808
diff changeset
  2247
         * InputEvent.BUTTON_DOWN_MASK.
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2808
diff changeset
  2248
         * One more bit is reserved for FIRST_HIGH_BIT.
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2808
diff changeset
  2249
         */
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2808
diff changeset
  2250
        if (xbe.get_button() > SunToolkit.MAX_BUTTONS_SUPPORTED) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2808
diff changeset
  2251
            return;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2808
diff changeset
  2252
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  2253
        if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
  2254
            grabLog.fine("{0}, when grabbed {1}, contains {2} ({3}, {4}, {5}x{6})",
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2255
                         xbe, isGrabbed(),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2256
                         containsGlobal(scaleDown(xbe.get_x_root()),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2257
                                        scaleDown(xbe.get_y_root())),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2258
                         getAbsoluteX(), getAbsoluteY(),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2259
                         getWidth(), getHeight());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
        if (isGrabbed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
            // When window is grabbed, all events are dispatched to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
            // it.  Retarget them to the corresponding windows (notice
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
            // that XBaseWindow.dispatchEvent does the opposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
            // translation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
            XBaseWindow target = XToolkit.windowToXWindow(xbe.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
            try {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  2268
                if (grabLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2269
                    grabLog.finer("  -  Grab event target {0} (press target {1})", target, pressTarget);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2270
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
                if (xbe.get_type() == XConstants.ButtonPress
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  2272
                    && xbe.get_button() == XConstants.buttons[0])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
                    // need to keep it to retarget mouse release
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
                    pressTarget = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
                } else if (xbe.get_type() == XConstants.ButtonRelease
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  2277
                           && xbe.get_button() == XConstants.buttons[0]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
                           && pressTarget != target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
                    // during grab we do receive mouse release on different component (not on the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
                    // of mouse press).  So we need to retarget it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
                    // see 6390326 for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
                    target = pressTarget.isVisible() ? pressTarget : this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
                    xbe.set_window(target.getWindow());
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2285
                    Point localCoord = target.toLocal(scaleDown(xbe.get_x_root()),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2286
                                                      scaleDown(xbe.get_y_root()));
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2287
                    xbe.set_x(scaleUp(localCoord.x));
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2288
                    xbe.set_y(scaleUp(localCoord.y));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
                    pressTarget = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
                if (target != null && target != getContentXWindow() && target != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
                    target.dispatchEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
                if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
                    // Target is either us or our content window -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
                    // check that event is inside.  'Us' in case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
                    // shell will mean that this will also filter out press on title
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2300
                    if ((target == this || target == getContentXWindow())
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2301
                            && !containsGlobal(scaleDown(xbe.get_x_root()),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2302
                                               scaleDown(xbe.get_y_root())))
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  2303
                    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
                        // Outside this toplevel hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
                        // According to the specification of UngrabEvent, post it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
                        // when press occurs outside of the window and not on its owned windows
4829
21778cfb4353 6893325: JComboBox and dragging to an item outside the bounds of the containing JFrame is not selecting that
dav
parents: 4371
diff changeset
  2307
                        if (xbe.get_type() == XConstants.ButtonPress) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  2308
                            if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2309
                                grabLog.fine("Generating UngrabEvent on {0} because not inside of shell", this);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2310
                            }
4829
21778cfb4353 6893325: JComboBox and dragging to an item outside the bounds of the containing JFrame is not selecting that
dav
parents: 4371
diff changeset
  2311
                            postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
21778cfb4353 6893325: JComboBox and dragging to an item outside the bounds of the containing JFrame is not selecting that
dav
parents: 4371
diff changeset
  2312
                            return;
21778cfb4353 6893325: JComboBox and dragging to an item outside the bounds of the containing JFrame is not selecting that
dav
parents: 4371
diff changeset
  2313
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
                    // First, get the toplevel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
                    XWindowPeer toplevel = target.getToplevelXWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
                    if (toplevel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
                        Window w = (Window)toplevel.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
                        while (w != null && toplevel != this && !(toplevel instanceof XDialogPeer)) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  2320
                            w = (Window) AWTAccessor.getComponentAccessor().getParent(w);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
                            if (w != null) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
  2322
                                toplevel = AWTAccessor.getComponentAccessor().getPeer(w);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
                        if (w == null || (w != this.target && w instanceof Dialog)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
                            // toplevel == null - outside of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
                            // hierarchy, toplevel is Dialog - should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
                            // send ungrab (but shouldn't for Window)
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  2329
                            if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2330
                                grabLog.fine("Generating UngrabEvent on {0} because hierarchy ended", this);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2331
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
                            postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
                        // toplevel is null - outside of hierarchy
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  2336
                        if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2337
                            grabLog.fine("Generating UngrabEvent on {0} because toplevel is null", this);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2338
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
                        postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
                    // target doesn't map to XAWT window - outside of hierarchy
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17147
diff changeset
  2344
                    if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2345
                        grabLog.fine("Generating UngrabEvent on because target is null {0}", this);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  2346
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
                    postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
        super.handleButtonPressRelease(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
    }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2354
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2355
    public void print(Graphics g) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2356
        // We assume we print the whole frame,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2357
        // so we expect no clip was set previously
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2358
        Shape shape = AWTAccessor.getWindowAccessor().getShape((Window)target);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2359
        if (shape != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2360
            g.setClip(shape);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2361
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2362
        super.print(g);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2363
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2364
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2365
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2366
    public void setOpacity(float opacity) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2367
        final long maxOpacity = 0xffffffffl;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2368
        long iOpacity = (long)(opacity * maxOpacity);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2369
        if (iOpacity < 0) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2370
            iOpacity = 0;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2371
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2372
        if (iOpacity > maxOpacity) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2373
            iOpacity = maxOpacity;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2374
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2375
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2376
        XAtom netWmWindowOpacityAtom = XAtom.get("_NET_WM_WINDOW_OPACITY");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2377
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2378
        if (iOpacity == maxOpacity) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2379
            netWmWindowOpacityAtom.DeleteProperty(getWindow());
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2380
        } else {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2381
            netWmWindowOpacityAtom.setCard32Property(getWindow(), iOpacity);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2382
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2383
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2384
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2385
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2386
    public void setOpaque(boolean isOpaque) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2387
        // no-op
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2388
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2389
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2390
    @Override
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2804
diff changeset
  2391
    public void updateWindow() {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2392
        // no-op
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  2393
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
}