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