jdk/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java
author ssadetsky
Tue, 18 Oct 2016 12:43:07 +0300
changeset 41802 89f634379c0c
parent 41409 04b42eb73ee6
child 43081 66a49615076d
permissions -rw-r--r--
8166897: Some font overlap in the Optionpane dialog. Reviewed-by: azvegint
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
39856
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
     2
 * Copyright (c) 2002, 2016, 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: 4371
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: 4371
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: 4371
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
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.InvocationEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.WindowEvent;
39862
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
    32
import java.util.Collections;
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
    33
import java.util.HashMap;
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
    34
import java.util.Map;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 13648
diff changeset
    36
import sun.awt.IconInfo;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    37
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
    39
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
    42
abstract class XDecoratedPeer extends XWindowPeer {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    43
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XDecoratedPeer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    44
    private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XDecoratedPeer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    45
    private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XDecoratedPeer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    46
    private static final PlatformLogger iconLog = PlatformLogger.getLogger("sun.awt.X11.icon.XDecoratedPeer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    // Set to true when we get the first ConfigureNotify after being
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    // reparented - indicates that WM has adopted the top-level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    boolean configure_seen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    boolean insets_corrected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    XIconWindow iconWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    WindowDimensions dimensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    XContentWindow content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    Insets currentInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    XFocusProxyWindow focusProxy;
39862
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
    58
    static final Map<Class<?>,Insets> lastKnownInsets =
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
    59
                                   Collections.synchronizedMap(new HashMap<>());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    XDecoratedPeer(Window target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    XDecoratedPeer(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        super(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public long getShell() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public long getContentWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return (content == null) ? window : content.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        winAttr.initialFocus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
    81
        currentInsets = new Insets(0,0,0,0);
39862
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
    82
        if (XWM.getWMID() == XWM.UNITY_COMPIZ_WM) {
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
    83
            currentInsets = lastKnownInsets.get(getClass());
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
    84
        }
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
    85
        applyGuessedInsets();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        Rectangle bounds = (Rectangle)params.get(BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        dimensions = new WindowDimensions(bounds, getRealInsets(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        params.put(BOUNDS, dimensions.getClientRect());
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
    90
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
    91
            insLog.fine("Initial dimensions {0}", dimensions);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
    92
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        // Deny default processing of these events on the shell - proxy will take care of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // them instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        Long eventMask = (Long)params.get(EVENT_MASK);
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
    97
        params.add(EVENT_MASK, Long.valueOf(eventMask.longValue() & ~(XConstants.FocusChangeMask | XConstants.KeyPressMask | XConstants.KeyReleaseMask)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    void postInit(XCreateWindowParams params) {
6822
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents: 6637
diff changeset
   101
        // The size hints must be set BEFORE mapping the window (see 6895647)
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents: 6637
diff changeset
   102
        updateSizeHints(dimensions);
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents: 6637
diff changeset
   103
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents: 6637
diff changeset
   104
        // The super method maps the window if it's visible on the shared level
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        super.postInit(params);
6822
0a6eba317c96 6895647: Frame may jump to an unpredicted location upon entering the non-opaque mode on X11
anthony
parents: 6637
diff changeset
   106
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // The lines that follow need to be in a postInit, so they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // happen after the X window is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        initResizability();
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   110
        XWM.requestWMExtents(getWindow());
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   111
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
   112
        content = XContentWindow.createContent(this);
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   113
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if (warningWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            warningWindow.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        focusProxy = createFocusProxy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 13648
diff changeset
   120
    void setIconHints(java.util.List<IconInfo> icons) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (!XWM.getWM().setNetWMIcon(this, icons)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            if (icons.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                if (iconWindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    iconWindow = new XIconWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                iconWindow.setIconImages(icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public void updateMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        super.updateMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        updateMinSizeHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private void updateMinSizeHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            Dimension minimumSize = getTargetMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            if (minimumSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                Insets insets = getRealInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                int minWidth = minimumSize.width - insets.left - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                int minHeight = minimumSize.height - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                if (minWidth < 0) minWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                if (minHeight < 0) minHeight = 0;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   145
                setSizeHints(XUtilConstants.PMinSize | (isLocationByPlatform()?0:(XUtilConstants.PPosition | XUtilConstants.USPosition)),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                             getX(), getY(), minWidth, minHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                if (isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    Rectangle bounds = getShellBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    int nw = (bounds.width < minWidth) ? minWidth : bounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    int nh = (bounds.height < minHeight) ? minHeight : bounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    if (nw != bounds.width || nh != bounds.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                        setShellSize(new Rectangle(0, 0, nw, nh));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                boolean isMinSizeSet = isMinSizeSet();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   157
                XWM.removeSizeHints(this, XUtilConstants.PMinSize);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                /* Some WMs need remap to redecorate the window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                if (isMinSizeSet && isShowing() && XWM.needRemap(this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                     * Do the re/mapping at the Xlib level.  Since we essentially
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                     * work around a WM bug we don't want this hack to be exposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                     * to Intrinsics (i.e. don't mess with grabs, callbacks etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    xSetVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    xSetVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    XFocusProxyWindow createFocusProxy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return new XFocusProxyWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    protected XAtomList getWMProtocols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        XAtomList protocols = super.getWMProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        protocols.add(wm_delete_window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        protocols.add(wm_take_focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return protocols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public Graphics getGraphics() {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
   185
        AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return getGraphics(content.surfaceData,
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
   187
                           compAccessor.getForeground(target),
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
   188
                           compAccessor.getBackground(target),
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
   189
                           compAccessor.getFont(target));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public void setTitle(String title) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   193
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   194
            log.fine("Title is " + title);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   195
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        winAttr.title = title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        updateWMName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    protected String getWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (winAttr.title == null || winAttr.title.trim().equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return winAttr.title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    void updateWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        super.updateWMName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        String name = getWMName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            if (name == null || name.trim().equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                name = "Java";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            XAtom iconNameAtom = XAtom.get(XAtom.XA_WM_ICON_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            iconNameAtom.setProperty(getWindow(), name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            XAtom netIconNameAtom = XAtom.get("_NET_WM_ICON_NAME");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            netIconNameAtom.setPropertyUTF8(getWindow(), name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public void handleIconify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_ICONIFIED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public void handleDeiconify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_DEICONIFIED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public void handleFocusEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        super.handleFocusEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        XFocusChangeEvent xfe = xev.get_xfocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        // If we somehow received focus events forward it instead to proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        // FIXME: Shouldn't we instead check for inferrior?
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   243
        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   244
            focusLog.finer("Received focus event on shell: " + xfe);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   245
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
//         focusProxy.xRequestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
/***************************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 *                             I N S E T S   C O D E
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 **************************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    protected boolean isInitialReshape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   257
    private static Insets difference(Insets i1, Insets i2) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return new Insets(i1.top-i2.top, i1.left - i2.left, i1.bottom-i2.bottom, i1.right-i2.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   261
    private static boolean isNull(Insets i) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return (i == null) || ((i.left | i.top | i.right | i.bottom) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   264
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   265
    private static Insets copy(Insets i) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return new Insets(i.top, i.left, i.bottom, i.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
40161
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   269
    private Insets copyAndScaleDown(Insets i) {
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   270
        return new Insets(scaleDown(i.top), scaleDown(i.left),
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   271
                          scaleDown(i.bottom), scaleDown(i.right));
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   272
    }
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   273
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   274
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   275
    // insets which we get from WM (e.g from _NET_FRAME_EXTENTS)
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   276
    private Insets wm_set_insets;
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   277
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   278
    private Insets getWMSetInsets(XAtom changedAtom) {
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   279
        if (isEmbedded()) {
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   280
            return null;
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   281
        }
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   282
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   283
        if (wm_set_insets != null) {
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   284
            return wm_set_insets;
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   285
        }
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   286
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   287
        if (changedAtom == null) {
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   288
            wm_set_insets = XWM.getInsetsFromExtents(getWindow());
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   289
        } else {
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   290
            wm_set_insets = XWM.getInsetsFromProp(getWindow(), changedAtom);
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   291
        }
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   292
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   293
        if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   294
            insLog.finer("FRAME_EXTENTS: {0}", wm_set_insets);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   295
        }
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   296
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   297
        if (wm_set_insets != null) {
40161
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   298
            wm_set_insets = copyAndScaleDown(wm_set_insets);
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   299
        }
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   300
        return wm_set_insets;
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   301
    }
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   302
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   303
    private void resetWMSetInsets() {
41802
89f634379c0c 8166897: Some font overlap in the Optionpane dialog.
ssadetsky
parents: 41409
diff changeset
   304
        if (XWM.getWMID() != XWM.UNITY_COMPIZ_WM) {
89f634379c0c 8166897: Some font overlap in the Optionpane dialog.
ssadetsky
parents: 41409
diff changeset
   305
            currentInsets = new Insets(0, 0, 0, 0);
89f634379c0c 8166897: Some font overlap in the Optionpane dialog.
ssadetsky
parents: 41409
diff changeset
   306
            wm_set_insets = null;
89f634379c0c 8166897: Some font overlap in the Optionpane dialog.
ssadetsky
parents: 41409
diff changeset
   307
        }
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   308
    }
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   309
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   310
    public void handlePropertyNotify(XEvent xev) {
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   311
        super.handlePropertyNotify(xev);
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   312
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   313
        XPropertyEvent ev = xev.get_xproperty();
41409
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   314
        if( !insets_corrected && isReparented() &&
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   315
                                         XWM.getWMID() == XWM.UNITY_COMPIZ_WM) {
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   316
            int state = XWM.getWM().getState(this);
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   317
            if ((state & Frame.MAXIMIZED_BOTH) ==  Frame.MAXIMIZED_BOTH) {
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   318
                // Stop ignoring ConfigureNotify because no extents will be sent
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   319
                // by WM for initially maximized decorated window.
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   320
                // Re-request window bounds to ensure actual dimensions and
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   321
                // notify the target with the initial size.
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   322
                insets_corrected = true;
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   323
                XlibWrapper.XConfigureWindow(XToolkit.getDisplay(),
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   324
                                                             getWindow(), 0, 0);
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   325
            }
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   326
        }
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   327
        if (ev.get_atom() == XWM.XA_KDE_NET_WM_FRAME_STRUT.getAtom()
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   328
            || ev.get_atom() == XWM.XA_NET_FRAME_EXTENTS.getAtom())
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   329
        {
39862
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   330
            if (XWM.getWMID() != XWM.UNITY_COMPIZ_WM) {
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   331
                getWMSetInsets(XAtom.get(ev.get_atom()));
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   332
            } else {
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   333
                if(!isReparented()) {
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   334
                    return;
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   335
                }
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   336
                wm_set_insets = null;
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   337
                Insets in = getWMSetInsets(XAtom.get(ev.get_atom()));
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   338
                if (isNull(in)) {
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   339
                    return;
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   340
                }
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   341
                if (!isEmbedded() && !isTargetUndecorated()) {
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   342
                    lastKnownInsets.put(getClass(), in);
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   343
                }
41409
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   344
                if (!in.equals(dimensions.getInsets())) {
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   345
                    if (insets_corrected || isMaximized()) {
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   346
                        currentInsets = in;
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   347
                        insets_corrected = true;
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   348
                        // insets were changed by WM. To handle this situation
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   349
                        // re-request window bounds because the current
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   350
                        // dimensions may be not actual as well.
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   351
                        XlibWrapper.XConfigureWindow(XToolkit.getDisplay(),
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   352
                                                             getWindow(), 0, 0);
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   353
                    } else {
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   354
                        // recalculate dimensions when window is just created
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   355
                        // and the initially guessed insets were wrong
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   356
                        handleCorrectInsets(in);
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   357
                    }
41802
89f634379c0c 8166897: Some font overlap in the Optionpane dialog.
ssadetsky
parents: 41409
diff changeset
   358
                } else if (!insets_corrected || !dimensions.isClientSizeSet()) {
41409
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   359
                    insets_corrected = true;
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   360
                    // initial insets were guessed correctly. Re-request
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   361
                    // frame bounds because they may be changed by WM if the
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   362
                    // initial window position overlapped desktop's toolbars.
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   363
                    // This should initiate the final ConfigureNotify upon which
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   364
                    // the target will be notified with the final size.
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   365
                    XlibWrapper.XConfigureWindow(XToolkit.getDisplay(),
04b42eb73ee6 8165619: Frame is not repainted if created in state=MAXIMIZED_BOTH on Unity
ssadetsky
parents: 41393
diff changeset
   366
                                                             getWindow(), 0, 0);
39862
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   367
                }
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   368
            }
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   369
        }
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   370
    }
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   371
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    long reparent_serial = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public void handleReparentNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        XReparentEvent  xe = xev.get_xreparent();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   376
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   377
            insLog.fine(xe.toString());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   378
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        reparent_serial = xe.get_serial();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            long root = XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            if (isEmbedded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                setReparented(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                insets_corrected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            }
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
   389
            Component t = target;
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
   390
            if (getDecorations() == XWindowAttributesData.AWT_DECOR_NONE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                setReparented(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                insets_corrected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                reshape(dimensions, SET_SIZE, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            } else if (xe.get_parent() == root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                configure_seen = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                insets_corrected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                 * We can be repareted to root for two reasons:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                 *   . setVisible(false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                 *   . WM exited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                if (isVisible()) { /* WM exited */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    /* Work around 4775545 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    XWM.getWM().unshadeKludge(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    insLog.fine("- WM exited");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    insLog.fine(" - reparent due to hide");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            } else { /* reparented to WM frame, figure out our insets */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                setReparented(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                insets_corrected = false;
41393
ebc8d972cd3f 8161910: [PIT] regression: HW/LW mixing seems broken on Unity
ssadetsky
parents: 40161
diff changeset
   413
                if (XWM.getWMID() == XWM.UNITY_COMPIZ_WM) {
ebc8d972cd3f 8161910: [PIT] regression: HW/LW mixing seems broken on Unity
ssadetsky
parents: 40161
diff changeset
   414
                    return;
ebc8d972cd3f 8161910: [PIT] regression: HW/LW mixing seems broken on Unity
ssadetsky
parents: 40161
diff changeset
   415
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                // Check if we have insets provided by the WM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                Insets correctWM = getWMSetInsets(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                if (correctWM != null) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   420
                    if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   421
                        insLog.finer("wm-provided insets {0}", correctWM);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   422
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    // If these insets are equal to our current insets - no actions are necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    Insets dimInsets = dimensions.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    if (correctWM.equals(dimInsets)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                        insLog.finer("Insets are the same as estimated - no additional reshapes necessary");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                        no_reparent_artifacts = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                        insets_corrected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                        applyGuessedInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    correctWM = XWM.getWM().getInsets(this, xe.get_window(), xe.get_parent());
40161
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   434
                    if (correctWM != null) {
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   435
                        correctWM = copyAndScaleDown(correctWM);
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   436
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   438
                    if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   439
                        if (correctWM != null) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   440
                            insLog.finer("correctWM {0}", correctWM);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   441
                        } else {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   442
                            insLog.finer("correctWM insets are not available, waiting for configureNotify");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   443
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
41393
ebc8d972cd3f 8161910: [PIT] regression: HW/LW mixing seems broken on Unity
ssadetsky
parents: 40161
diff changeset
   447
                if (correctWM != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    handleCorrectInsets(correctWM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    protected void handleCorrectInsets(Insets correctWM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
             * Ok, now see if we need adjust window size because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
             * initial insets were wrong (most likely they were).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            Insets correction = difference(correctWM, currentInsets);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   464
            if (insLog.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   465
                insLog.finest("Corrention {0}", correction);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   466
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            if (!isNull(correction)) {
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   468
                currentInsets = copy(correctWM);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                applyGuessedInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                //Fix for 6318109: PIT: Min Size is not honored properly when a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                //smaller size is specified in setSize(), XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                //update minimum size hints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                updateMinSizeHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   476
            if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   477
                insLog.finer("Dimensions before reparent: " + dimensions);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   478
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            dimensions.setInsets(getRealInsets());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            insets_corrected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
2466
32f16bfa9608 6805897: Gap present between the choice and its drop down list in Jdk 7 build for a non resizable frame.
dcherepanov
parents: 1977
diff changeset
   483
            if (isMaximized()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   487
            /*
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   488
             * If this window has been sized by a pack() we need
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   489
             * to keep the interior geometry intact.  Since pack()
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   490
             * computed width and height with wrong insets, we
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   491
             * must adjust the target dimensions appropriately.
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   492
             */
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   493
            if ((getHints().get_flags() & (XUtilConstants.USPosition | XUtilConstants.PPosition)) != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                reshape(dimensions, SET_BOUNDS, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                reshape(dimensions, SET_SIZE, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    public void handleMoved(WindowDimensions dims) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        Point loc = dims.getLocation();
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
   505
        AWTAccessor.getComponentAccessor().setLocation(target, loc.x, loc.y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_MOVED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    protected Insets guessInsets() {
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   511
        if (isEmbedded() || isTargetUndecorated()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            return new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        } else {
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   514
            if (!isNull(currentInsets)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                /* insets were set on wdata by System Properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                return copy(currentInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                Insets res = getWMSetInsets(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                if (res == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                    res = XWM.getWM().guessInsets(this);
40161
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   521
                    if (res != null) {
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   522
                        res = copyAndScaleDown(res);
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   523
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    private void applyGuessedInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        Insets guessed = guessInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        currentInsets = copy(guessed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    public void revalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        XToolkit.executeOnEventHandlerThread(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    target.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    target.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    Insets getRealInsets() {
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   545
        if (isNull(currentInsets)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            applyGuessedInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        }
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   548
        return currentInsets;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        Insets in = copy(getRealInsets());
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2466
diff changeset
   553
        in.top += getMenuBarHeight();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   554
        if (insLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   555
            insLog.finest("Get insets returns {0}", in);
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   556
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        return in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    boolean gravityBug() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return XWM.configureGravityBuggy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    // The height of area used to display current active input method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    int getInputMethodHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    void updateSizeHints(WindowDimensions dims) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        Rectangle rec = dims.getClientRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        checkShellRect(rec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        updateSizeHints(rec.x, rec.y, rec.width, rec.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    void updateSizeHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        updateSizeHints(dimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    // Coordinates are that of the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    // Called only on Toolkit thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    public void reshape(WindowDimensions newDimensions, int op,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                        boolean userReshape)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   584
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            insLog.fine("Reshaping " + this + " to " + newDimensions + " op " + op + " user reshape " + userReshape);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   587
        if (userReshape) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   588
            // We handle only userReshape == true cases. It means that
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   589
            // if the window manager or any other part of the windowing
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   590
            // system sets inappropriate size for this window, we can
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   591
            // do nothing but accept it.
2643
ea218b1a2000 6821948: Consider removing the constraints for bounds of untrusted top-level windows
anthony
parents: 2472
diff changeset
   592
            Rectangle newBounds = newDimensions.getBounds();
1977
3a9980ccb120 6721088: Bad window size calculation after using pack()
art
parents: 449
diff changeset
   593
            Insets insets = newDimensions.getInsets();
3a9980ccb120 6721088: Bad window size calculation after using pack()
art
parents: 449
diff changeset
   594
            // Inherit isClientSizeSet from newDimensions
3a9980ccb120 6721088: Bad window size calculation after using pack()
art
parents: 449
diff changeset
   595
            if (newDimensions.isClientSizeSet()) {
3a9980ccb120 6721088: Bad window size calculation after using pack()
art
parents: 449
diff changeset
   596
                newBounds = new Rectangle(newBounds.x, newBounds.y,
3a9980ccb120 6721088: Bad window size calculation after using pack()
art
parents: 449
diff changeset
   597
                                          newBounds.width - insets.left - insets.right,
3a9980ccb120 6721088: Bad window size calculation after using pack()
art
parents: 449
diff changeset
   598
                                          newBounds.height - insets.top - insets.bottom);
3a9980ccb120 6721088: Bad window size calculation after using pack()
art
parents: 449
diff changeset
   599
            }
3a9980ccb120 6721088: Bad window size calculation after using pack()
art
parents: 449
diff changeset
   600
            newDimensions = new WindowDimensions(newBounds, insets, newDimensions.isClientSizeSet());
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   601
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            if (!isReparented() || !isVisible()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   605
                if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   606
                    insLog.fine("- not reparented({0}) or not visible({1}), default reshape",
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   607
                           Boolean.valueOf(isReparented()), Boolean.valueOf(visible));
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   608
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                // Fix for 6323293.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                // This actually is needed to preserve compatibility with previous releases -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                // some of licensees are expecting componentMoved event on invisible one while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                // its location changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                Point oldLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
   616
                Point newLocation = new Point(AWTAccessor.getComponentAccessor().getX(target),
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
   617
                                              AWTAccessor.getComponentAccessor().getY(target));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                if (!newLocation.equals(oldLocation)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    handleMoved(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                dimensions = new WindowDimensions(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                updateSizeHints(dimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                Rectangle client = dimensions.getClientRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                checkShellRect(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                setShellBounds(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                if (content != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                    !content.getSize().equals(newDimensions.getSize()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    reconfigureContentWindow(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            int wm = XWM.getWMID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            updateChildrenSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            applyGuessedInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            Rectangle shellRect = newDimensions.getClientRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            if (gravityBug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                Insets in = newDimensions.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                shellRect.translate(in.left, in.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            if ((op & NO_EMBEDDED_CHECK) == 0 && isEmbedded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                shellRect.setLocation(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            checkShellRectSize(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            if (!isEmbedded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                checkShellRectPos(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            op = op & ~NO_EMBEDDED_CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            if (op == SET_LOCATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                setShellPosition(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            } else if (isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                if (op == SET_BOUNDS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                    setShellBounds(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                    setShellSize(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                XWM.setShellNotResizable(this, newDimensions, shellRect, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                if (op == SET_BOUNDS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                    setShellPosition(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            reconfigureContentWindow(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * @param x, y, width, heith - dimensions of the window with insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    private void reshape(int x, int y, int width, int height, int operation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                         boolean userReshape)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        Rectangle newRec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        boolean setClient = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        WindowDimensions dims = new WindowDimensions(dimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        switch (operation & (~NO_EMBEDDED_CHECK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
          case SET_LOCATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
              // Set location always sets bounds location. However, until the window is mapped we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
              // should use client coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
              dims.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
          case SET_SIZE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
              // Set size sets bounds size. However, until the window is mapped we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
              // should use client coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
              dims.setSize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
          case SET_CLIENT_SIZE: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
              // Sets client rect size. Width and height contain insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
              Insets in = currentInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
              width -= in.left+in.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
              height -= in.top+in.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
              dims.setClientSize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
          case SET_BOUNDS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
              dims.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
              dims.setSize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   713
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   714
            insLog.fine("For the operation {0} new dimensions are {1}",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   715
                        operationToString(operation), dims);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   716
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        reshape(dims, operation, userReshape);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   721
    // This method gets overriden in XFramePeer & XDialogPeer.
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   722
    abstract boolean isTargetUndecorated();
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   723
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * @see java.awt.peer.ComponentPeer#setBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    public void setBounds(int x, int y, int width, int height, int op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        // TODO: Rewrite with WindowDimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        reshape(x, y, width, height, op, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        validateSurface();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    // Coordinates are that of the shell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    void reconfigureContentWindow(WindowDimensions dims) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        if (content == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            insLog.fine("WARNING: Content window is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        content.setContentBounds(dims);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    boolean no_reparent_artifacts = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    public void handleConfigureNotifyEvent(XEvent xev) {
39862
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   744
        if (XWM.getWMID() == XWM.UNITY_COMPIZ_WM && !insets_corrected) {
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   745
            return;
a3fc74a6c5a3 8036915: setLocationRelativeTo stopped working in Ubuntu 13.10 (Unity)
ssadetsky
parents: 39856
diff changeset
   746
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        assert (SunToolkit.isAWTLockHeldByCurrentThread());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        XConfigureEvent xe = xev.get_xconfigure();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   749
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   750
            insLog.fine("Configure notify {0}", xe);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   751
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        // XXX: should really only consider synthetic events, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        if (isReparented()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            configure_seen = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        if (!isMaximized()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            && (xe.get_serial() == reparent_serial || xe.get_window() != getShell())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            && !no_reparent_artifacts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            insLog.fine("- reparent artifact, skipping");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        no_reparent_artifacts = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
         * When there is a WM we receive some CN before being visible and after.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
         * We should skip all CN which are before being visible, because we assume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
         * the gravity is in action while it is not yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
         * When there is no WM we receive CN only _before_ being visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
         * We should process these CNs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        if (!isVisible() && XWM.getWMID() != XWM.NO_WM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            insLog.fine(" - not visible, skipping");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
         * Some window managers configure before we are reparented and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
         * the send event flag is set! ugh... (Enlighetenment for one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
         * possibly MWM as well).  If we haven't been reparented yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         * this is just the WM shuffling us into position.  Ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
         * it!!!! or we wind up in a bogus location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        int runningWM = XWM.getWMID();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   788
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   789
            insLog.fine("reparented={0}, visible={1}, WM={2}, decorations={3}",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   790
                        isReparented(), isVisible(), runningWM, getDecorations());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        if (!isReparented() && isVisible() && runningWM != XWM.NO_WM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                &&  !XWM.isNonReparentingWM()
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
   794
                && getDecorations() != XWindowAttributesData.AWT_DECOR_NONE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            insLog.fine("- visible but not reparented, skipping");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        //Last chance to correct insets
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
   799
        if (!insets_corrected && getDecorations() != XWindowAttributesData.AWT_DECOR_NONE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            long parent = XlibUtil.getParentWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            Insets correctWM = (parent != -1) ? XWM.getWM().getInsets(this, window, parent) : null;
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   802
            if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                if (correctWM != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                    insLog.finer("Configure notify - insets : " + correctWM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                    insLog.finer("Configure notify - insets are still not available");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            if (correctWM != null) {
40161
d1621c3f403c 8161273: [hidpi] The frame insets size is wrong on Linux HiDPI because it is not scaled.
ssadetsky
parents: 39862
diff changeset
   810
                handleCorrectInsets(copyAndScaleDown(correctWM));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                //Only one attempt to correct insets is made (to lower risk)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                //if insets are still not available we simply set the flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                insets_corrected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        updateChildrenSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
21786
2f3ad6aa2ac5 8027628: JWindow jumps to (0, 0) after mouse clicked
bagiras
parents: 21591
diff changeset
   820
        Point newLocation = getNewLocation(xe, currentInsets.left, currentInsets.top);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        WindowDimensions newDimensions =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                new WindowDimensions(newLocation,
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 33248
diff changeset
   823
                                     new Dimension(scaleDown(xe.get_width()),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 33248
diff changeset
   824
                                                   scaleDown(xe.get_height())),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 33248
diff changeset
   825
                                     copy(currentInsets), true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   827
        if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   828
            insLog.finer("Insets are {0}, new dimensions {1}",
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   829
                     currentInsets, newDimensions);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   830
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        checkIfOnNewScreen(newDimensions.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        Point oldLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        dimensions = newDimensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        if (!newLocation.equals(oldLocation)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            handleMoved(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        reconfigureContentWindow(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        updateChildrenSizes();
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2466
diff changeset
   841
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2466
diff changeset
   842
        repositionSecurityWarning();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    private void checkShellRectSize(Rectangle shellRect) {
6637
64ecd501905b 6987945: XDecoratedPeer shouldn't allow to resize a frame to zero size
omajid
parents: 5506
diff changeset
   846
        shellRect.width = Math.max(MIN_SIZE, shellRect.width);
64ecd501905b 6987945: XDecoratedPeer shouldn't allow to resize a frame to zero size
omajid
parents: 5506
diff changeset
   847
        shellRect.height = Math.max(MIN_SIZE, shellRect.height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    private void checkShellRectPos(Rectangle shellRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        int wm = XWM.getWMID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        if (wm == XWM.MOTIF_WM || wm == XWM.CDE_WM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            if (shellRect.x == 0 && shellRect.y == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                shellRect.x = shellRect.y = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    private void checkShellRect(Rectangle shellRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        checkShellRectSize(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        checkShellRectPos(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    public void setShellBounds(Rectangle rec) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   865
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   866
            insLog.fine("Setting shell bounds on " + this + " to " + rec);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   867
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            updateSizeHints(rec.x, rec.y, rec.width, rec.height);
33248
76e17c81ec4c 8058959: closed/java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically
ssadetsky
parents: 32865
diff changeset
   871
            XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), getShell(),
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 33248
diff changeset
   872
                                          scaleUp(rec.x), scaleUp(rec.y),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 33248
diff changeset
   873
                                          scaleUp(rec.width), scaleUp(rec.height));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    public void setShellSize(Rectangle rec) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   880
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   881
            insLog.fine("Setting shell size on " + this + " to " + rec);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   882
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            updateSizeHints(rec.x, rec.y, rec.width, rec.height);
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 33248
diff changeset
   886
            XlibWrapper.XResizeWindow(XToolkit.getDisplay(), getShell(),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 33248
diff changeset
   887
                                      scaleUp(rec.width), scaleUp(rec.height));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    public void setShellPosition(Rectangle rec) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   894
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   895
            insLog.fine("Setting shell position on " + this + " to " + rec);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   896
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            updateSizeHints(rec.x, rec.y, rec.width, rec.height);
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 33248
diff changeset
   900
            XlibWrapper.XMoveWindow(XToolkit.getDisplay(), getShell(),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 33248
diff changeset
   901
                                    scaleUp(rec.x), scaleUp(rec.y));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    void initResizability() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        setResizable(winAttr.initialResizability);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    public void setResizable(boolean resizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        int fs = winAttr.functions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        if (!isResizable() && resizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            resetWMSetInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            if (!isEmbedded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                setReparented(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            winAttr.isResizable = resizable;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   919
            if ((fs & MWMConstants.MWM_FUNC_ALL) != 0) {
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   920
                fs &= ~(MWMConstants.MWM_FUNC_RESIZE | MWMConstants.MWM_FUNC_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            } else {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   922
                fs |= (MWMConstants.MWM_FUNC_RESIZE | MWMConstants.MWM_FUNC_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            winAttr.functions = fs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            XWM.setShellResizable(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        } else if (isResizable() && !resizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            resetWMSetInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            if (!isEmbedded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                setReparented(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            winAttr.isResizable = resizable;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   932
            if ((fs & MWMConstants.MWM_FUNC_ALL) != 0) {
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   933
                fs |= (MWMConstants.MWM_FUNC_RESIZE | MWMConstants.MWM_FUNC_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            } else {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   935
                fs &= ~(MWMConstants.MWM_FUNC_RESIZE | MWMConstants.MWM_FUNC_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            winAttr.functions = fs;
118
35b334a806ab 6522731: Location of the frame changes,when the frame is resized & non-resized.
dcherepanov
parents: 115
diff changeset
   938
            XWM.setShellNotResizable(this, dimensions, dimensions.getBounds(), false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    Rectangle getShellBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        return dimensions.getClientRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        return dimensions.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        return dimensions.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    public int getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        return dimensions.getLocation().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    public int getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        return dimensions.getLocation().y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        return dimensions.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    public int getAbsoluteX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        // NOTE: returning this peer's location which is shell location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        return dimensions.getScreenBounds().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    public int getAbsoluteY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        // NOTE: returning this peer's location which is shell location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        return dimensions.getScreenBounds().y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    public int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        return getSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    public int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        return getSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30469
diff changeset
   984
    public final WindowDimensions getDimensions() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        return dimensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            if (configure_seen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                return toGlobal(0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                Point location = target.getLocation();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
   995
                if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   996
                    insLog.fine("getLocationOnScreen {0} not reparented: {1} ",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   997
                                this, location);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   998
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                return location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
/***************************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
 *              END            OF             I N S E T S   C O D E
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
 **************************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    protected boolean isEventDisabled(XEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        switch (e.get_type()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            // Do not generate MOVED/RESIZED events since we generate them by ourselves
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
  1014
          case XConstants.ConfigureNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
              return true;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
  1016
          case XConstants.EnterNotify:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
  1017
          case XConstants.LeaveNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
              // Disable crossing event on outer borders of Frame so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
              // we receive only one set of cross notifications(first set is from content window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
              return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
              return super.isEventDisabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    int getDecorations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        return winAttr.decorations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    int getFunctions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        return winAttr.functions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    public void setVisible(boolean vis) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
  1035
        if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1036
            log.finer("Setting {0} to visible {1}", this, Boolean.valueOf(vis));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1037
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        if (vis && !isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            XWM.setShellDecor(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            super.setVisible(vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            if (winAttr.isResizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                //Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                //We need to update frame's minimum size, not to reset it
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
  1044
                XWM.removeSizeHints(this, XUtilConstants.PMaxSize);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                updateMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            super.setVisible(vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    protected void suppressWmTakeFocus(boolean doSuppress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        XAtomList protocols = getWMProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        if (doSuppress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            protocols.remove(wm_take_focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            protocols.add(wm_take_focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        wm_protocols.setAtomListProperty(this, protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        if (content != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            content.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        focusProxy.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        if (iconWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            iconWindow.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    public void handleClientMessage(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        super.handleClientMessage(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        XClientMessageEvent cl = xev.get_xclient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        if ((wm_protocols != null) && (cl.get_message_type() == wm_protocols.getAtom())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            if (cl.get_data(0) == wm_delete_window.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                handleQuit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            } else if (cl.get_data(0) == wm_take_focus.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                handleWmTakeFocus(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    private void handleWmTakeFocus(XClientMessageEvent cl) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
  1088
        if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1089
            focusLog.fine("WM_TAKE_FOCUS on {0}", this);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1090
        }
39856
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1091
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1092
        if (XWM.getWMID() == XWM.UNITY_COMPIZ_WM) {
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1093
            // JDK-8159460
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1094
            Window focusedWindow = XKeyboardFocusManagerPeer.getInstance()
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1095
                    .getCurrentFocusedWindow();
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1096
            Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1097
            if (activeWindow != target) {
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1098
                requestWindowFocus(cl.get_data(1), true);
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1099
            } else {
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1100
                WindowEvent we = new WindowEvent(focusedWindow,
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1101
                        WindowEvent.WINDOW_GAINED_FOCUS);
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1102
                sendEvent(we);
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1103
            }
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1104
        } else {
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1105
            requestWindowFocus(cl.get_data(1), true);
96d7761b869a 8159460: On Ubuntu Unity, problem with java/awt/Window/FindOwner/FindOwnerTest
ssadetsky
parents: 34395
diff changeset
  1106
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * Requests focus to this decorated top-level by requesting X input focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * to the shell window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    protected void requestXFocus(long time, boolean timeProvided) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        // We have proxied focus mechanism - instead of shell the focus is held
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        // by "proxy" - invisible mapped window. When we want to set X input focus to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        // toplevel set it on proxy instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        if (focusProxy == null) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
  1118
            if (focusLog.isLoggable(PlatformLogger.Level.WARNING)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1119
                focusLog.warning("Focus proxy is null for " + this);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1120
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        } else {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
  1122
            if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1123
                focusLog.fine("Requesting focus to proxy: " + focusProxy);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1124
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            if (timeProvided) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                focusProxy.xRequestFocus(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                focusProxy.xRequestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    XFocusProxyWindow getFocusProxy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        return focusProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    public void handleQuit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_CLOSING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    final void dumpMe() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        System.err.println(">>> Peer: " + x + ", " + y + ", " + width + ", " + height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    final void dumpTarget() {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  1146
        AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
  1147
        int getWidth = compAccessor.getWidth(target);
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
  1148
        int getHeight = compAccessor.getHeight(target);
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
  1149
        int getTargetX = compAccessor.getX(target);
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21786
diff changeset
  1150
        int getTargetY = compAccessor.getY(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        System.err.println(">>> Target: " + getTargetX + ", " + getTargetY + ", " + getWidth + ", " + getHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    final void dumpShell() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        dumpWindow("Shell", getShell());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    final void dumpContent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        dumpWindow("Content", getContentWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    final void dumpParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        long parent = XlibUtil.getParentWindow(getShell());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        if (parent != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            dumpWindow("Parent", parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            System.err.println(">>> NO PARENT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    final void dumpWindow(String id, long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        XWindowAttributes pattr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                int status =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                    XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                                                     window, pattr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            System.err.println(">>>> " + id + ": " + pattr.get_x()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                               + ", " + pattr.get_y() + ", " + pattr.get_width()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                               + ", " + pattr.get_height());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            pattr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    final void dumpAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        dumpTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        dumpMe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        dumpParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        dumpShell();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        dumpContent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    boolean isMaximized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4214
diff changeset
  1204
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    boolean isOverrideRedirect() {
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4214
diff changeset
  1206
        return Window.Type.POPUP.equals(getWindowType());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    public boolean requestWindowFocus(long time, boolean timeProvided) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        focusLog.fine("Request for decorated window focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        // 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
  1212
        // If this is Window and its owner Frame is active we can be sure request succedded.
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 12829
diff changeset
  1213
        Window focusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
  1216
        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1217
            focusLog.finer("Current window is: active={0}, focused={1}",
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
  1218
                       Boolean.valueOf(target == activeWindow),
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
  1219
                       Boolean.valueOf(target == focusedWindow));
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1220
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        XWindowPeer toFocus = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        while (toFocus.nextTransientFor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            toFocus = toFocus.nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1226
        if (toFocus == null || !toFocus.focusAllowedFor()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            // This might change when WM will have property to determine focus policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            // Right now, because policy is unknown we can't be sure we succedded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        }
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1231
        if (this == toFocus) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1232
            if (isWMStateNetHidden()) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1233
                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
  1234
                return false;
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1235
            }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1236
            if (target == activeWindow && target != focusedWindow) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1237
                // Happens when an owned window is currently focused
21591
35320b590d9b 8026491: Typos in string literals
malenkov
parents: 18275
diff changeset
  1238
                focusLog.fine("Focus is on child window - transferring it back to the owner");
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1239
                handleWindowFocusInSync(-1);
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1240
                return true;
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1241
            }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1242
            Window realNativeFocusedWindow = XWindowPeer.getNativeFocusedWindow();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
  1243
            if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1244
                focusLog.finest("Real native focused window: " + realNativeFocusedWindow +
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1245
                            "\nKFM's focused window: " + focusedWindow);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1246
            }
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1247
16842
78641211dbbc 7147075: JTextField doesn't get focus or loses focus forever
ant
parents: 16839
diff changeset
  1248
            // A workaround for Metacity. See 6522725, 6613426, 7147075.
78641211dbbc 7147075: JTextField doesn't get focus or loses focus forever
ant
parents: 16839
diff changeset
  1249
            if (target == realNativeFocusedWindow && XWM.getWMID() == XWM.METACITY_WM) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
  1250
                if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1251
                    focusLog.fine("The window is already natively focused.");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1252
                }
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1253
                return true;
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1254
            }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1255
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16842
diff changeset
  1256
        if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1257
            focusLog.fine("Requesting focus to " + (this == toFocus ? "this window" : toFocus));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
  1258
        }
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1259
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1260
        if (timeProvided) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1261
            toFocus.requestXFocus(time);
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1262
        } else {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1263
            toFocus.requestXFocus();
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1264
        }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1265
        return (this == toFocus);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    XWindowPeer actualFocusedWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    void setActualFocusedWindow(XWindowPeer actualFocusedWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        synchronized(getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            this.actualFocusedWindow = actualFocusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    boolean requestWindowFocus(XWindowPeer actualFocusedWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                               long time, boolean timeProvided)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        setActualFocusedWindow(actualFocusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        return requestWindowFocus(time, timeProvided);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    public void handleWindowFocusIn(long serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        if (null == actualFocusedWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            super.handleWindowFocusIn(serial);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
             * Fix for 6314575.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
             * If this is a result of clicking on one of the Frame's component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
             * then 'actualFocusedWindow' shouldn't be focused. A decision of focusing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
             * it or not should be made after the appropriate Java mouse event (if any)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
             * is handled by the component where 'actualFocusedWindow' value may be reset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
             * The fix is based on the empiric fact consisting in that the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
             * receives native mouse event nearly at the same time the Frame receives
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
             * WM_TAKE_FOCUS (when FocusIn is generated via XSetInputFocus call) but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
             * definetely before the Frame gets FocusIn event (when this method is called).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            postEvent(new InvocationEvent(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                    XWindowPeer fw = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                    synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                        fw = actualFocusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                        actualFocusedWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                        if (null == fw || !fw.isVisible() || !fw.isFocusableWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                            fw = XDecoratedPeer.this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                    fw.handleWindowFocusIn_Dispatch();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    public void handleWindowFocusOut(Window oppositeWindow, long serial) {
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 12829
diff changeset
  1314
        Window actualFocusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        // If the actual focused window is not this decorated window then retain it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        if (actualFocusedWindow != null && actualFocusedWindow != target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            Window owner = XWindowPeer.getDecoratedOwner(actualFocusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            if (owner != null && owner == target) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 25859
diff changeset
  1321
                setActualFocusedWindow(AWTAccessor.getComponentAccessor().getPeer(actualFocusedWindow));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        super.handleWindowFocusOut(oppositeWindow, serial);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
}