src/java.desktop/unix/classes/sun/awt/X11/XBaseWindow.java
author neugens
Tue, 12 Nov 2019 15:54:24 +0100
changeset 59186 d5af26ef7b95
parent 52248 2e330da7cbf4
child 59190 88ddd6943a06
permissions -rw-r--r--
8231991: Mouse wheel change focus on awt/swing windows Summary: Avoid focus logic when only mouse wheel is moved up/down. Reviewed-by: serb, dmarkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47971
diff changeset
     2
 * Copyright (c) 2003, 2018, 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: 4214
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: 4214
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: 4214
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4214
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4214
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3288
diff changeset
    31
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
    33
public class XBaseWindow {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3288
diff changeset
    34
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XBaseWindow");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3288
diff changeset
    35
    private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XBaseWindow");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3288
diff changeset
    36
    private static final PlatformLogger eventLog = PlatformLogger.getLogger("sun.awt.X11.event.XBaseWindow");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3288
diff changeset
    37
    private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XBaseWindow");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3288
diff changeset
    38
    private static final PlatformLogger grabLog = PlatformLogger.getLogger("sun.awt.X11.grab.XBaseWindow");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        PARENT_WINDOW = "parent window", // parent window, Long
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        BOUNDS = "bounds", // bounds of the window, Rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        OVERRIDE_REDIRECT = "overrideRedirect", // override_redirect setting, Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        EVENT_MASK = "event mask", // event mask, Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        VALUE_MASK = "value mask", // value mask, Long
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        BORDER_PIXEL = "border pixel", // border pixel value, Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        COLORMAP = "color map", // color map, Long
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        DEPTH = "visual depth", // depth, Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        VISUAL_CLASS = "visual class", // visual class, Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        VISUAL = "visual", // visual, Long
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        EMBEDDED = "embedded", // is embedded?, Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        DELAYED = "delayed", // is creation delayed?, Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        PARENT = "parent", // parent peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        BACKGROUND_PIXMAP = "pixmap", // background pixmap
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        VISIBLE = "visible", // whether it is visible by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        SAVE_UNDER = "save under", // save content under this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        BACKING_STORE = "backing store", // enables double buffering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        BIT_GRAVITY = "bit gravity"; // copy old content on geometry change
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private XCreateWindowParams delayedParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    Set<Long> children = new HashSet<Long>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    long window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    boolean visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    boolean mapped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    boolean embedded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    Rectangle maxBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    volatile XBaseWindow parentWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private boolean disposed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private long screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private XSizeHints hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private XWMHints wmHints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    75
    static final int MIN_SIZE = 1;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    76
    static final int DEF_LOCATION = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static XAtom wm_client_leader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static enum InitialiseState {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        INITIALISING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        INITIALISED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        FAILED_INITIALISATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private InitialiseState initialising;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    int y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    int height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    void awtLock() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    void awtUnlock() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    void awtLockNotifyAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        XToolkit.awtLockNotifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    void awtLockWait() throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        XToolkit.awtLockWait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // To prevent errors from overriding obsolete methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    protected final void init(long parentWindow, Rectangle bounds) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    protected final void preInit() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    protected final void postInit() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    // internal lock for synchronizing state changes and paint calls, initialized in preInit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // the order with other locks: AWTLock -> stateLock
47971
75686e8da573 8190228: Remove redundant modifiers in java.desktop module.
ssadetsky
parents: 47216
diff changeset
   116
    static class StateLock { }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    protected StateLock state_lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Called for delayed inits during construction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    void instantPreInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        state_lock = new StateLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Called before window creation, descendants should override to initialize the data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * initialize params.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        state_lock = new StateLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        embedded = Boolean.TRUE.equals(params.get(EMBEDDED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        visible = Boolean.TRUE.equals(params.get(VISIBLE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        Object parent = params.get(PARENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (parent instanceof XBaseWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            parentWindow = (XBaseWindow)parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            Long parentWindowID = (Long)params.get(PARENT_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            if (parentWindowID != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                parentWindow = XToolkit.windowToXWindow(parentWindowID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        Long eventMask = (Long)params.get(EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (eventMask != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            long mask = eventMask.longValue();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   148
            mask |= XConstants.SubstructureNotifyMask;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            params.put(EVENT_MASK, mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        screen = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Called after window creation, descendants should override to initialize Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * with class-specific values and perform post-initialization actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    void postInit(XCreateWindowParams params) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   160
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   161
            log.fine("WM name is " + getWMName());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   162
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        updateWMName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        // Set WM_CLIENT_LEADER property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        initClientLeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 35658
diff changeset
   170
     * Creates window using parameters {@code params}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * If params contain flag DELAYED doesn't do anything.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Note: Descendants can call this method to create the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * at the time different to instance construction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    protected final void init(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        initialising = InitialiseState.INITIALISING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            if (!Boolean.TRUE.equals(params.get(DELAYED))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                create(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                instantPreInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                delayedParams = params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            initialising = InitialiseState.INITIALISED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            awtLockNotifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        } catch (RuntimeException re) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            initialising = InitialiseState.FAILED_INITIALISATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            awtLockNotifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            throw re;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        } catch (Throwable t) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3288
diff changeset
   200
            log.warning("Exception during peer initialization", t);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            initialising = InitialiseState.FAILED_INITIALISATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            awtLockNotifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            awtUnlock();
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
    public boolean checkInitialised() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            switch (initialising) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
              case INITIALISED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
              case INITIALISING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                  try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                      while (initialising != InitialiseState.INITIALISED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                          awtLockWait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                  } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                      return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
              case FAILED_INITIALISATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                  return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                  return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Creates an invisible InputOnly window without an associated Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    XBaseWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        this(new XCreateWindowParams());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Creates normal child window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    XBaseWindow(long parentWindow, Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        this(new XCreateWindowParams(new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            BOUNDS, bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            PARENT_WINDOW, Long.valueOf(parentWindow)}));
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
     * Creates top-level window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    XBaseWindow(Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        this(new XCreateWindowParams(new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            BOUNDS, bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public XBaseWindow (XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        init(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /* This create is used by the XEmbeddedFramePeer since it has to create the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
       as a child of the netscape window. This netscape window is passed in as wid */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    XBaseWindow(long parentWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        this(new XCreateWindowParams(new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            PARENT_WINDOW, Long.valueOf(parentWindow),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            EMBEDDED, Boolean.TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Verifies that all required parameters are set. If not, sets them to default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Verifies values of critical parameters, adjust their values when needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @throws IllegalArgumentException if params is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    protected void checkParams(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (params == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            throw new IllegalArgumentException("Window creation parameters are null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        params.putIfNull(PARENT_WINDOW, Long.valueOf(XToolkit.getDefaultRootWindow()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        params.putIfNull(BOUNDS, new Rectangle(DEF_LOCATION, DEF_LOCATION, MIN_SIZE, MIN_SIZE));
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   282
        params.putIfNull(DEPTH, Integer.valueOf((int)XConstants.CopyFromParent));
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   283
        params.putIfNull(VISUAL, Long.valueOf(XConstants.CopyFromParent));
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 18178
diff changeset
   284
        params.putIfNull(VISUAL_CLASS, Integer.valueOf(XConstants.InputOnly));
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   285
        params.putIfNull(VALUE_MASK, Long.valueOf(XConstants.CWEventMask));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        Rectangle bounds = (Rectangle)params.get(BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        bounds.width = Math.max(MIN_SIZE, bounds.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        bounds.height = Math.max(MIN_SIZE, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        Long eventMaskObj = (Long)params.get(EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        long eventMask = eventMaskObj != null ? eventMaskObj.longValue() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        // We use our own synthetic grab see XAwtState.getGrabWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // (see X vol. 1, 8.3.3.2)
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   294
        eventMask |= XConstants.PropertyChangeMask | XConstants.OwnerGrabButtonMask;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        params.put(EVENT_MASK, Long.valueOf(eventMask));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   299
     * Returns scale factor of the window. It is used to convert native
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   300
     * coordinates to local and vice verse.
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   301
     */
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   302
    protected int getScale() {
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   303
        return 1;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   304
    }
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   305
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   306
    protected int scaleUp(int x) {
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   307
        return x;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   308
    }
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   309
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   310
    protected int scaleDown(int x) {
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   311
        return x;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   312
    }
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   313
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   314
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 35658
diff changeset
   315
     * Creates window with parameters specified by {@code params}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @see #init
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
47971
75686e8da573 8190228: Remove redundant modifiers in java.desktop module.
ssadetsky
parents: 47216
diff changeset
   318
    private void create(XCreateWindowParams params) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            XSetWindowAttributes xattr = new XSetWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                checkParams(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                long value_mask = ((Long)params.get(VALUE_MASK)).longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                Long eventMask = (Long)params.get(EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                xattr.set_event_mask(eventMask.longValue());
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   329
                value_mask |= XConstants.CWEventMask;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                Long border_pixel = (Long)params.get(BORDER_PIXEL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                if (border_pixel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    xattr.set_border_pixel(border_pixel.longValue());
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   334
                    value_mask |= XConstants.CWBorderPixel;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                Long colormap = (Long)params.get(COLORMAP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                if (colormap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    xattr.set_colormap(colormap.longValue());
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   340
                    value_mask |= XConstants.CWColormap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                Long background_pixmap = (Long)params.get(BACKGROUND_PIXMAP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                if (background_pixmap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    xattr.set_background_pixmap(background_pixmap.longValue());
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   345
                    value_mask |= XConstants.CWBackPixmap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                Long parentWindow = (Long)params.get(PARENT_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                Rectangle bounds = (Rectangle)params.get(BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                Integer depth = (Integer)params.get(DEPTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                Integer visual_class = (Integer)params.get(VISUAL_CLASS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                Long visual = (Long)params.get(VISUAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                Boolean overrideRedirect = (Boolean)params.get(OVERRIDE_REDIRECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                if (overrideRedirect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    xattr.set_override_redirect(overrideRedirect.booleanValue());
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   356
                    value_mask |= XConstants.CWOverrideRedirect;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                Boolean saveUnder = (Boolean)params.get(SAVE_UNDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                if (saveUnder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    xattr.set_save_under(saveUnder.booleanValue());
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   362
                    value_mask |= XConstants.CWSaveUnder;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                Integer backingStore = (Integer)params.get(BACKING_STORE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                if (backingStore != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    xattr.set_backing_store(backingStore.intValue());
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   368
                    value_mask |= XConstants.CWBackingStore;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                Integer bitGravity = (Integer)params.get(BIT_GRAVITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                if (bitGravity != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    xattr.set_bit_gravity(bitGravity.intValue());
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   374
                    value_mask |= XConstants.CWBitGravity;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   377
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                    log.fine("Creating window for " + this + " with the following attributes: \n" + params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                window = XlibWrapper.XCreateWindow(XToolkit.getDisplay(),
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   381
                                                   parentWindow.longValue(),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   382
                                                   scaleUp(bounds.x),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   383
                                                   scaleUp(bounds.y),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   384
                                                   scaleUp(bounds.width),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   385
                                                   scaleUp(bounds.height),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   386
                                                   0, // border
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   387
                                                   depth.intValue(), // depth
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   388
                                                   visual_class.intValue(), // class
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   389
                                                   visual.longValue(), // visual
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   390
                                                   value_mask,  // value mask
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   391
                                                   xattr.pData); // attributes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                if (window == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    throw new IllegalStateException("Couldn't create window because of wrong parameters. Run with NOISY_AWT to see details");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                XToolkit.addToWinMap(window, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                xattr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    public XCreateWindowParams getDelayedParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return delayedParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    protected String getWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        return XToolkit.getCorrectXIDString(getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    protected void initClientLeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            if (wm_client_leader == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                wm_client_leader = XAtom.get("WM_CLIENT_LEADER");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            wm_client_leader.setWindowProperty(this, getXAWTRootWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    static XRootWindow getXAWTRootWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return XRootWindow.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    void destroy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            if (hints != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                XlibWrapper.XFree(hints.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                hints = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            XToolkit.removeFromWinMap(getWindow(), this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            XlibWrapper.XDestroyWindow(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            if (XPropertyCache.isCachingSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                XPropertyCache.clearCache(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            window = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if( !isDisposed() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                setDisposed( true );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            XAwtState.getGrabWindow(); // Magic - getGrabWindow clear state if grabbing window is disposed of.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    void flush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            XlibWrapper.XFlush(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * Helper function to set W
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public final void setWMHints(XWMHints hints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public XWMHints getWMHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        if (wmHints == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            wmHints = new XWMHints(XlibWrapper.XAllocWMHints());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
//              XlibWrapper.XGetWMHints(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
//                                      getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
//                                      wmHints.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        return wmHints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * Call this method under AWTLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * The lock should be acquired untill all operations with XSizeHints are completed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public XSizeHints getHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if (hints == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            long p_hints = XlibWrapper.XAllocSizeHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            hints = new XSizeHints(p_hints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
//              XlibWrapper.XGetWMNormalHints(XToolkit.getDisplay(), getWindow(), p_hints, XlibWrapper.larg1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            // TODO: Shouldn't we listen for WM updates on this property?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        return hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public void setSizeHints(long flags, int x, int y, int width, int height) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   499
        if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   500
            insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(flags));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   501
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            XSizeHints hints = getHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            // Note: if PPosition is not set in flags this means that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            // we want to reset PPosition in hints.  This is necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            // for locationByPlatform functionality
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   508
            if ((flags & XUtilConstants.PPosition) != 0) {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   509
                hints.set_x(scaleUp(x));
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   510
                hints.set_y(scaleUp(y));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   512
            if ((flags & XUtilConstants.PSize) != 0) {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   513
                hints.set_width(scaleUp(width));
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   514
                hints.set_height(scaleUp(height));
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   515
            } else if ((hints.get_flags() & XUtilConstants.PSize) != 0) {
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   516
                flags |= XUtilConstants.PSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   518
            if ((flags & XUtilConstants.PMinSize) != 0) {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   519
                hints.set_min_width(scaleUp(width));
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   520
                hints.set_min_height(scaleUp(height));
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   521
            } else if ((hints.get_flags() & XUtilConstants.PMinSize) != 0) {
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   522
                flags |= XUtilConstants.PMinSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                //Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                //We don't need to reset minimum size if it's already set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   526
            if ((flags & XUtilConstants.PMaxSize) != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                if (maxBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    if (maxBounds.width != Integer.MAX_VALUE) {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   529
                        hints.set_max_width(scaleUp(maxBounds.width));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    } else {
44149
92b8963f6498 8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents: 35989
diff changeset
   531
                        hints.set_max_width(XToolkit.getMaxWindowWidthInPixels());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    if (maxBounds.height != Integer.MAX_VALUE) {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   534
                        hints.set_max_height(scaleUp(maxBounds.height));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    } else {
44149
92b8963f6498 8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents: 35989
diff changeset
   536
                        hints.set_max_height(XToolkit.getMaxWindowHeightInPixels());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                } else {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   539
                    hints.set_max_width(scaleUp(width));
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   540
                    hints.set_max_height(scaleUp(height));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   542
            } else if ((hints.get_flags() & XUtilConstants.PMaxSize) != 0) {
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   543
                flags |= XUtilConstants.PMaxSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                if (maxBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    if (maxBounds.width != Integer.MAX_VALUE) {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   546
                        hints.set_max_width(scaleUp(maxBounds.width));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    } else {
44149
92b8963f6498 8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents: 35989
diff changeset
   548
                        hints.set_max_width(XToolkit.getMaxWindowWidthInPixels());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    if (maxBounds.height != Integer.MAX_VALUE) {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   551
                        hints.set_max_height(scaleUp(maxBounds.height));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    } else {
44149
92b8963f6498 8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents: 35989
diff changeset
   553
                        hints.set_max_height(XToolkit.getMaxWindowHeightInPixels());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    // Leave intact
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   559
            flags |= XUtilConstants.PWinGravity;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            hints.set_flags(flags);
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 18178
diff changeset
   561
            hints.set_win_gravity(XConstants.NorthWestGravity);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   562
            if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   563
                insLog.finer("Setting hints, resulted flags " + XlibWrapper.hintsToString(flags) +
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   564
                             ", values " + hints);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   565
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(), getWindow(), hints.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    public boolean isMinSizeSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        XSizeHints hints = getHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        long flags = hints.get_flags();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   575
        return ((flags & XUtilConstants.PMinSize) == XUtilConstants.PMinSize);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * This lock object can be used to protect instance data from concurrent access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * by two threads. If both state lock and AWT lock are taken, AWT Lock should be taken first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    Object getStateLock() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        return state_lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    public long getWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    public long getContentWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    public XBaseWindow getContentXWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        return XToolkit.windowToXWindow(getContentWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        return new Rectangle(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    public void toFront() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    public void xRequestFocus(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        try {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   616
            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   617
                focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()) + " with time " + time);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   618
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            XlibWrapper.XSetInputFocus2(XToolkit.getDisplay(), getWindow(), time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    public void xRequestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        try {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   627
            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   628
                focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   629
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
             XlibWrapper.XSetInputFocus(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    public static long xGetInputFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            return XlibWrapper.XGetInputFocus(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    public void xSetVisible(boolean visible) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   646
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   647
            log.fine("Setting visible on " + this + " to " + visible);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   648
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            this.visible = visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                XlibWrapper.XMapWindow(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            XlibWrapper.XFlush(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    boolean isMapped() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        return mapped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    void updateWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        String name = getWMName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                name = " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            XAtom nameAtom = XAtom.get(XAtom.XA_WM_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            nameAtom.setProperty(getWindow(), name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            XAtom netNameAtom = XAtom.get("_NET_WM_NAME");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            netNameAtom.setPropertyUTF8(getWindow(), name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    void setWMClass(String[] cl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        if (cl.length != 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            throw new IllegalArgumentException("WM_CLASS_NAME consists of exactly two strings");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            XAtom xa = XAtom.get(XAtom.XA_WM_CLASS);
35658
48bccfa61aef 6961123: setWMClass fails to null-terminate WM_CLASS string
omajid
parents: 34395
diff changeset
   690
            xa.setProperty8(getWindow(), cl[0] + '\0' + cl[1] + '\0');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        return visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    static long getScreenOfWindow(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            return XlibWrapper.getScreenOfWindow(XToolkit.getDisplay(), window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    long getScreenNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            return XlibWrapper.XScreenNumberOfScreen(getScreen());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    long getScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        if (screen == -1) { // Not initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            screen = getScreenOfWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        return screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    public void xSetBounds(Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        xSetBounds(bounds.x, bounds.y, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    public void xSetBounds(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        if (getWindow() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            insLog.warning("Attempt to resize uncreated window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            throw new IllegalStateException("Attempt to resize uncreated window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   733
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   734
            insLog.fine("Setting bounds on " + this + " to (" + x + ", " + y + "), " + width + "x" + height);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   735
        }
6637
64ecd501905b 6987945: XDecoratedPeer shouldn't allow to resize a frame to zero size
omajid
parents: 5506
diff changeset
   736
        width = Math.max(MIN_SIZE, width);
64ecd501905b 6987945: XDecoratedPeer shouldn't allow to resize a frame to zero size
omajid
parents: 5506
diff changeset
   737
        height = Math.max(MIN_SIZE, height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        try {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   740
            XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), getWindow(),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   741
                                          scaleUp(x), scaleUp(y),
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   742
                                          scaleUp(width), scaleUp(height));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * Translate coordinates from one window into another.  Optimized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * for XAWT - uses cached data when possible.  Preferable over
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * pure XTranslateCoordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @return coordinates relative to dst, or null if error happened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    static Point toOtherWindow(long src, long dst, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        Point rpt = new Point(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        // Check if both windows belong to XAWT - then no X calls are necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        XBaseWindow srcPeer = XToolkit.windowToXWindow(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        XBaseWindow dstPeer = XToolkit.windowToXWindow(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        if (srcPeer != null && dstPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            // (x, y) is relative to src
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            rpt.x = x + srcPeer.getAbsoluteX() - dstPeer.getAbsoluteX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            rpt.y = y + srcPeer.getAbsoluteY() - dstPeer.getAbsoluteY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        } else if (dstPeer != null && XlibUtil.isRoot(src, dstPeer.getScreenNumber())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            // from root into peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            rpt.x = x - dstPeer.getAbsoluteX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            rpt.y = y - dstPeer.getAbsoluteY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        } else if (srcPeer != null && XlibUtil.isRoot(dst, srcPeer.getScreenNumber())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            // from peer into root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            rpt.x = x + srcPeer.getAbsoluteX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            rpt.y = y + srcPeer.getAbsoluteY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        } else {
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   775
            int scale = srcPeer == null ? 1 : srcPeer.getScale();
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
   776
            rpt = XlibUtil.translateCoordinates(src, dst, new Point(x, y), scale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        return rpt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * Convert to global coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    Rectangle toGlobal(Rectangle rec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        Point p = toGlobal(rec.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        Rectangle newRec = new Rectangle(rec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            newRec.setLocation(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        return newRec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    Point toGlobal(Point pt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        Point p = toGlobal(pt.x, pt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            return new Point(pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    Point toGlobal(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        long root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            root = XlibWrapper.RootWindow(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                    getScreenNumber());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        Point p = toOtherWindow(getContentWindow(), root, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            return new Point(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * Convert to local coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    Point toLocal(Point pt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        Point p = toLocal(pt.x, pt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            return new Point(pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    Point toLocal(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        long root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            root = XlibWrapper.RootWindow(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    getScreenNumber());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        Point p = toOtherWindow(root, getContentWindow(), x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            return new Point(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * We should always grab both keyboard and pointer to control event flow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * on popups. This also simplifies synthetic grab implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * The active grab overrides activated automatic grab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    public boolean grabInput() {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   854
        if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   855
            grabLog.fine("Grab input on {0}", this);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   856
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            if (XAwtState.getGrabWindow() == this &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                XAwtState.isManualGrab())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                grabLog.fine("    Already Grabbed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            //6273031: PIT. Choice drop down does not close once it is right clicked to show a popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            //remember previous window having grab and if it's not null ungrab it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            XBaseWindow prevGrabWindow = XAwtState.getGrabWindow();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   869
            final int eventMask = (int) (XConstants.ButtonPressMask | XConstants.ButtonReleaseMask
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   870
                | XConstants.EnterWindowMask | XConstants.LeaveWindowMask | XConstants.PointerMotionMask
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   871
                | XConstants.ButtonMotionMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            final int ownerEvents = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
2471
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   875
            //6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   876
            //process on Linux
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   877
            //The user must pass the sun.awt.disablegrab property to disable
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   878
            //taking grabs. This prevents hanging of the GUI when a breakpoint
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   879
            //is hit while a popup window taking the grab is open.
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   880
            if (!XToolkit.getSunAwtDisableGrab()) {
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   881
                int ptrGrab = XlibWrapper.XGrabPointer(XToolkit.getDisplay(),
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   882
                        getContentWindow(), ownerEvents, eventMask, XConstants.GrabModeAsync,
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   883
                        XConstants.GrabModeAsync, XConstants.None, (XWM.isMotif() ? XToolkit.arrowCursor : XConstants.None),
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   884
                        XConstants.CurrentTime);
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   885
                // Check grab results to be consistent with X server grab
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   886
                if (ptrGrab != XConstants.GrabSuccess) {
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   887
                    XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), XConstants.CurrentTime);
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   888
                    XAwtState.setGrabWindow(null);
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   889
                    grabLog.fine("    Grab Failure - mouse");
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   890
                    return false;
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   891
                }
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   892
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   893
                int keyGrab = XlibWrapper.XGrabKeyboard(XToolkit.getDisplay(),
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   894
                        getContentWindow(), ownerEvents, XConstants.GrabModeAsync, XConstants.GrabModeAsync,
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   895
                        XConstants.CurrentTime);
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   896
                if (keyGrab != XConstants.GrabSuccess) {
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   897
                    XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), XConstants.CurrentTime);
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   898
                    XlibWrapper.XUngrabKeyboard(XToolkit.getDisplay(), XConstants.CurrentTime);
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   899
                    XAwtState.setGrabWindow(null);
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   900
                    grabLog.fine("    Grab Failure - keyboard");
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   901
                    return false;
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   902
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            if (prevGrabWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                prevGrabWindow.ungrabInputImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            XAwtState.setGrabWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            grabLog.fine("    Grab - success");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    static void ungrabInput() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            XBaseWindow grabWindow = XAwtState.getGrabWindow();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   919
            if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   920
                grabLog.fine("UnGrab input on {0}", grabWindow);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
   921
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            if (grabWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                grabWindow.ungrabInputImpl();
2471
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   924
                if (!XToolkit.getSunAwtDisableGrab()) {
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   925
                    XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), XConstants.CurrentTime);
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   926
                    XlibWrapper.XUngrabKeyboard(XToolkit.getDisplay(), XConstants.CurrentTime);
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 1962
diff changeset
   927
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                XAwtState.setGrabWindow(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                // we need to call XFlush() here to force ungrab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                // see 6384219 for details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                XlibWrapper.XFlush(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    // called from ungrabInput, used in popup windows to hide theirselfs in ungrabbing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    void ungrabInputImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    static void checkSecurity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        if (XToolkit.isSecurityWarningEnabled() && XToolkit.isToolkitThread()) {
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47971
diff changeset
   944
            StackTraceElement[] stack = (new Throwable()).getStackTrace();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            log.warning(stack[1] + ": Security violation: calling user code on toolkit thread");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    public Set<Long> getChildren() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            return new HashSet<Long>(children);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    // -------------- Event handling ----------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    public void handleMapNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        mapped = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    public void handleUnmapNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        mapped = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    public void handleReparentNotifyEvent(XEvent xev) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   963
        if (eventLog.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            XReparentEvent msg = xev.get_xreparent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            eventLog.finer(msg.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    public void handlePropertyNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        XPropertyEvent msg = xev.get_xproperty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        if (XPropertyCache.isCachingSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            XPropertyCache.clearCache(window, XAtom.get(msg.get_atom()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   973
        if (eventLog.isLoggable(PlatformLogger.Level.FINER)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3288
diff changeset
   974
            eventLog.finer("{0}", msg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    public void handleDestroyNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        XAnyEvent xany = xev.get_xany();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        if (xany.get_window() == getWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            XToolkit.removeFromWinMap(getWindow(), this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            if (XPropertyCache.isCachingSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                XPropertyCache.clearCache(getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        if (xany.get_window() != getWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                children.remove(xany.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    public void handleCreateNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        XAnyEvent xany = xev.get_xany();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        if (xany.get_window() != getWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                children.add(xany.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    public void handleClientMessage(XEvent xev) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1003
        if (eventLog.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            XClientMessageEvent msg = xev.get_xclient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            eventLog.finer(msg.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    public void handleVisibilityEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    public void handleKeyPress(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    public void handleKeyRelease(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    public void handleExposeEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * Activate automatic grab on first ButtonPress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * deactivate on full mouse release
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    public void handleButtonPressRelease(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        XButtonEvent xbe = xev.get_xbutton();
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2471
diff changeset
  1023
        /*
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2471
diff changeset
  1024
         * Ignore the buttons above 20 due to the bit limit for
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2471
diff changeset
  1025
         * InputEvent.BUTTON_DOWN_MASK.
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2471
diff changeset
  1026
         * One more bit is reserved for FIRST_HIGH_BIT.
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2471
diff changeset
  1027
         */
59186
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1028
        int theButton = xbe.get_button();
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1029
        if (theButton > SunToolkit.MAX_BUTTONS_SUPPORTED) {
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2471
diff changeset
  1030
            return;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2471
diff changeset
  1031
        }
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 439
diff changeset
  1032
        int buttonState = 0;
14888
7ad1550e7050 8005018: X11: focus problems with openjdk 1.7.0 under gnome3 when selected keyboard is not the first in keyboard list
neugens
parents: 13652
diff changeset
  1033
        buttonState = xbe.get_state() & XConstants.ALL_BUTTONS_MASK;
59186
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1034
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1035
        boolean isWheel = (theButton != XConstants.MouseWheelUp ||
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1036
                           theButton != XConstants.MouseWheelDown);
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1037
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1038
        // don't give focus if it's just the mouse wheel turning
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1039
        if (!isWheel) {
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1040
            switch (xev.get_type()) {
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1041
                case XConstants.ButtonPress:
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1042
                    if (buttonState == 0) {
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1043
                        XWindowPeer parent = getToplevelXWindow();
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1044
                        // See 6385277, 6981400.
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1045
                        if (parent != null && parent.isFocusableWindow()) {
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1046
                            // A click in a client area drops the actual focused window retaining.
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1047
                            parent.setActualFocusedWindow(null);
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1048
                            parent.requestWindowFocus(xbe.get_time(), true);
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1049
                        }
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1050
                        XAwtState.setAutoGrabWindow(this);
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1051
                    }
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1052
                    break;
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1053
                case XConstants.ButtonRelease:
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1054
                    if (isFullRelease(buttonState, xbe.get_button())) {
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1055
                        XAwtState.setAutoGrabWindow(null);
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1056
                    }
d5af26ef7b95 8231991: Mouse wheel change focus on awt/swing windows
neugens
parents: 52248
diff changeset
  1057
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    public void handleMotionNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    public void handleXCrossingEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    public void handleConfigureNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        XConfigureEvent xe = xev.get_xconfigure();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1067
        if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  1068
            insLog.finer("Configure, {0}", xe);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  1069
        }
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  1070
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  1071
        x = scaleDown(xe.get_x());
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  1072
        y = scaleDown(xe.get_y());
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  1073
        width = scaleDown(xe.get_width());
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32865
diff changeset
  1074
        height = scaleDown(xe.get_height());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * Checks ButtonRelease released all Mouse buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    static boolean isFullRelease(int buttonState, int button) {
14888
7ad1550e7050 8005018: X11: focus problems with openjdk 1.7.0 under gnome3 when selected keyboard is not the first in keyboard list
neugens
parents: 13652
diff changeset
  1080
        final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2471
diff changeset
  1081
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2471
diff changeset
  1082
        if (button < 0 || button > buttonsNumber) {
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 439
diff changeset
  1083
            return buttonState == 0;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 439
diff changeset
  1084
        } else {
14888
7ad1550e7050 8005018: X11: focus problems with openjdk 1.7.0 under gnome3 when selected keyboard is not the first in keyboard list
neugens
parents: 13652
diff changeset
  1085
            return buttonState == XlibUtil.getButtonMask(button);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    static boolean isGrabbedEvent(XEvent ev, XBaseWindow target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        switch (ev.get_type()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1091
          case XConstants.ButtonPress:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1092
          case XConstants.ButtonRelease:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1093
          case XConstants.MotionNotify:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1094
          case XConstants.KeyPress:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1095
          case XConstants.KeyRelease:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
              return true;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1097
          case XConstants.LeaveNotify:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1098
          case XConstants.EnterNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
              // We shouldn't dispatch this events to the grabbed components (see 6317481)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
              // But this logic is important if the grabbed component is top-level (see realSync)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
              return (target instanceof XWindowPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
              return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * Dispatches event to the grab Window or event source window depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * on whether the grab is active and on the event type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    static void dispatchToWindow(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        XBaseWindow target = XAwtState.getGrabWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        if (target == null || !isGrabbedEvent(ev, target)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            target = XToolkit.windowToXWindow(ev.get_xany().get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        if (target != null && target.checkInitialised()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            target.dispatchEvent(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    public void dispatchEvent(XEvent xev) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1121
        if (eventLog.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  1122
            eventLog.finest(xev.toString());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 14888
diff changeset
  1123
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        int type = xev.get_type();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        if (isDisposed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        switch (type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1132
          case XConstants.VisibilityNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
              handleVisibilityEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1135
          case XConstants.ClientMessage:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
              handleClientMessage(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1138
          case XConstants.Expose :
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1139
          case XConstants.GraphicsExpose :
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
              handleExposeEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1142
          case XConstants.ButtonPress:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1143
          case XConstants.ButtonRelease:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
              handleButtonPressRelease(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1147
          case XConstants.MotionNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
              handleMotionNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1150
          case XConstants.KeyPress:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
              handleKeyPress(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1153
          case XConstants.KeyRelease:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
              handleKeyRelease(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1156
          case XConstants.EnterNotify:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1157
          case XConstants.LeaveNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
              handleXCrossingEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1160
          case XConstants.ConfigureNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
              handleConfigureNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1163
          case XConstants.MapNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
              handleMapNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1166
          case XConstants.UnmapNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
              handleUnmapNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1169
          case XConstants.ReparentNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
              handleReparentNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1172
          case XConstants.PropertyNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
              handlePropertyNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1175
          case XConstants.DestroyNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
              handleDestroyNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
  1178
          case XConstants.CreateNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
              handleCreateNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    protected boolean isEventDisabled(XEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    int getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    int getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    void setDisposed(boolean d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        disposed = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
    boolean isDisposed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        return disposed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    public int getAbsoluteX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        XBaseWindow pw = getParentWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        if (pw != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            return pw.getAbsoluteX() + getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            // Overridden for top-levels as their (x,y) is Java (x, y), not native location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            return getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    public int getAbsoluteY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        XBaseWindow pw = getParentWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        if (pw != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            return pw.getAbsoluteY() + getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            return getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    public XBaseWindow getParentWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        return parentWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
    public XWindowPeer getToplevelXWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        XBaseWindow bw = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        while (bw != null && !(bw instanceof XWindowPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            bw = bw.getParentWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        return (XWindowPeer)bw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        return super.toString() + "(" + Long.toString(getWindow(), 16) + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * Returns whether the given point is inside of the window.  Coordinates are local.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    public boolean contains(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        return x >= 0 && y >= 0 && x < getWidth() && y < getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * Returns whether the given point is inside of the window.  Coordinates are global.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    public boolean containsGlobal(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        return x >= getAbsoluteX() && y >= getAbsoluteY() && x < (getAbsoluteX()+getWidth()) && y < (getAbsoluteY()+getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
}