jdk/src/solaris/classes/sun/awt/X11/XToolkit.java
author anthony
Tue, 12 Aug 2014 14:22:05 +0400
changeset 26342 3637212ae8f2
parent 26021 847033cb0339
permissions -rw-r--r--
8049065: [JLightweightFrame] Support DnD for SwingNode Summary: Delegate DnD operations to LightweightContent when appropriate Reviewed-by: ant, pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 22060
diff changeset
     2
 * Copyright (c) 2002, 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: 5445
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: 5445
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: 5445
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5445
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5445
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    28
import java.awt.event.InputEvent;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    29
import java.awt.event.MouseEvent;
1966
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
    30
import java.awt.event.KeyEvent;
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    31
import java.awt.datatransfer.Clipboard;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.dnd.DragSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.dnd.DragGestureListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.dnd.DragGestureEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.dnd.DragGestureRecognizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.dnd.MouseDragGestureRecognizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.dnd.InvalidDnDOperationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.dnd.peer.DragSourceContextPeer;
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
    39
import java.awt.font.TextAttribute;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.im.InputMethodHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.im.spi.InputMethodDescriptor;
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    42
import java.awt.image.ColorModel;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    43
import java.awt.peer.*;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    44
import java.beans.PropertyChangeListener;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    45
import java.security.AccessController;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    46
import java.security.PrivilegedAction;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    47
import java.util.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.swing.LookAndFeel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.swing.UIDefaults;
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    50
import sun.awt.*;
23260
d68cbf54738f 8029893: Remove reflection from DataTransferer.getInstance
pchelko
parents: 21278
diff changeset
    51
import sun.awt.datatransfer.DataTransferer;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3088
diff changeset
    52
import sun.font.FontConfigManager;
11083
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
    53
import sun.java2d.SunGraphicsEnvironment;
23900
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
    54
import sun.misc.*;
24520
e8afd90fcb69 8035169: Move ThreadGroupUtils from the sun.misc package
pchelko
parents: 23900
diff changeset
    55
import sun.awt.util.ThreadGroupUtils;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.print.PrintJob2D;
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 11083
diff changeset
    57
import sun.security.action.GetPropertyAction;
2471
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 2451
diff changeset
    58
import sun.security.action.GetBooleanAction;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
    59
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
    61
public final class XToolkit extends UNIXToolkit implements Runnable {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
    62
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XToolkit");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
    63
    private static final PlatformLogger eventLog = PlatformLogger.getLogger("sun.awt.X11.event.XToolkit");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
    64
    private static final PlatformLogger timeoutTaskLog = PlatformLogger.getLogger("sun.awt.X11.timeoutTask.XToolkit");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
    65
    private static final PlatformLogger keyEventLog = PlatformLogger.getLogger("sun.awt.X11.kye.XToolkit");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
    66
    private static final PlatformLogger backingStoreLog = PlatformLogger.getLogger("sun.awt.X11.backingStore.XToolkit");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
1969
07500c30ab46 5076635: Double click speed is not honored in KDE linux
dav
parents: 439
diff changeset
    68
    //There is 400 ms is set by default on Windows and 500 by default on KDE and GNOME.
07500c30ab46 5076635: Double click speed is not honored in KDE linux
dav
parents: 439
diff changeset
    69
    //We use the same hardcoded constant.
07500c30ab46 5076635: Double click speed is not honored in KDE linux
dav
parents: 439
diff changeset
    70
    private final static int AWT_MULTICLICK_DEFAULT_TIME = 500;
07500c30ab46 5076635: Double click speed is not honored in KDE linux
dav
parents: 439
diff changeset
    71
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    static final boolean PRIMARY_LOOP = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    static final boolean SECONDARY_LOOP = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static String awtAppClassName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // the system clipboard - CLIPBOARD selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    XClipboard clipboard;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // the system selection - PRIMARY selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    XClipboard selection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // Dynamic Layout Resize client code setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected static boolean dynamicLayoutSetting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
    85
    //Is it allowed to generate events assigned to extra mouse buttons.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
    86
    //Set to true by default.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
    87
    private static boolean areExtraMouseButtonsEnabled = true;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
    88
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * True when the x settings have been loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private boolean loadedXSettings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    * XSETTINGS for the default screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private XSettings xs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3088
diff changeset
   100
    private FontConfigManager fcManager = new FontConfigManager();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3088
diff changeset
   101
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    static int arrowCursor;
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   103
    static TreeMap<Long, XBaseWindow> winMap = new TreeMap<>();
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   104
    static HashMap<Object, Object> specialPeerMap = new HashMap<>();
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   105
    static HashMap<Long, Collection<XEventDispatcher>> winToDispatcher = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private static long _display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    static UIDefaults uidefaults;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    static X11GraphicsEnvironment localEnv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    static X11GraphicsDevice device;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    static final X11GraphicsConfig config;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    static int awt_multiclick_time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    static boolean securityWarningEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
11083
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   114
    private static volatile int screenWidth = -1, screenHeight = -1; // Dimensions of default screen
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    static long awt_defaultFg; // Pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private static XMouseInfoPeer xPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        initSecurityWarning();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            config = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            localEnv = (X11GraphicsEnvironment) GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                .getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            device = (X11GraphicsDevice) localEnv.getDefaultScreenDevice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            config = (X11GraphicsConfig) (device.getDefaultConfiguration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            if (device != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                _display = device.getDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            setupModifierMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            setBackingStoreType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2660
diff changeset
   134
    }
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2660
diff changeset
   135
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 6820
diff changeset
   136
    /*
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 6820
diff changeset
   137
     * Return (potentially) platform specific display timeout for the
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 6820
diff changeset
   138
     * tray icon
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 6820
diff changeset
   139
     */
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 6820
diff changeset
   140
    static native long getTrayIconDisplayTimeout();
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 6820
diff changeset
   141
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private native static void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    native static void waitForEvents(long nextTaskTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    static Thread toolkitThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    static boolean isToolkitThread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return Thread.currentThread() == toolkitThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    static void initSecurityWarning() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        // Enable warning only for internal builds
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 11083
diff changeset
   151
        String runtime = AccessController.doPrivileged(
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 11083
diff changeset
   152
                             new GetPropertyAction("java.runtime.version"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        securityWarningEnabled = (runtime != null && runtime.contains("internal"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    static boolean isSecurityWarningEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return securityWarningEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    static native void awt_output_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
26004
7507a1b93f67 6521783: Unnecessary final modifier for a method in a final class
serb
parents: 24538
diff changeset
   162
    static void  awtFUnlock() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        awt_output_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
26021
847033cb0339 8033141: Cleanup of sun.awt.X11 package
serb
parents: 26004
diff changeset
   168
    private native void nativeLoadSystemColors(int[] systemColors);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    static UIDefaults getUIDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (uidefaults == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            initUIDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return uidefaults;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public void loadSystemColors(int[] systemColors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        nativeLoadSystemColors(systemColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        MotifColorUtilities.loadSystemColors(systemColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    static void initUIDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            // Load Defaults from MotifLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            // This dummy load is necessary to get SystemColor initialized. !!!!!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            Color c = SystemColor.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            LookAndFeel lnf = new XAWTLookAndFeel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            uidefaults = lnf.getDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        catch (Exception e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    static Object displayLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public static long getDisplay() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return _display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public static long getDefaultRootWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            long res = XlibWrapper.RootWindow(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                XlibWrapper.DefaultScreen(XToolkit.getDisplay()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            if (res == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
               throw new IllegalStateException("Root window must not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            XlibWrapper.XSupportsLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            if (XlibWrapper.XSetLocaleModifiers("") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                log.finer("X locale modifiers are not supported, using default");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
   228
            tryXKB();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            AwtScreenData defaultScreen = new AwtScreenData(XToolkit.getDefaultScreenData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            awt_defaultFg = defaultScreen.get_blackpixel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            arrowCursor = XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                XCursorFontConstants.XC_arrow);
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
   235
            areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
   236
            //set system property if not yet assigned
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
   237
            System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2660
diff changeset
   238
11083
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   239
            // Detect display mode changes
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   240
            XlibWrapper.XSelectInput(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), XConstants.StructureNotifyMask);
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   241
            XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() {
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   242
                @Override
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   243
                public void dispatchEvent(XEvent ev) {
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   244
                    if (ev.get_type() == XConstants.ConfigureNotify) {
20460
a60499e6e190 7158311: GraphicsDevice.setDisplayMode(...) leads to hang when DISPLAY variable points to Oracle Linux
pchelko
parents: 20155
diff changeset
   245
                        awtUnlock();
a60499e6e190 7158311: GraphicsDevice.setDisplayMode(...) leads to hang when DISPLAY variable points to Oracle Linux
pchelko
parents: 20155
diff changeset
   246
                        try {
a60499e6e190 7158311: GraphicsDevice.setDisplayMode(...) leads to hang when DISPLAY variable points to Oracle Linux
pchelko
parents: 20155
diff changeset
   247
                            ((X11GraphicsEnvironment)GraphicsEnvironment.
a60499e6e190 7158311: GraphicsDevice.setDisplayMode(...) leads to hang when DISPLAY variable points to Oracle Linux
pchelko
parents: 20155
diff changeset
   248
                             getLocalGraphicsEnvironment()).
a60499e6e190 7158311: GraphicsDevice.setDisplayMode(...) leads to hang when DISPLAY variable points to Oracle Linux
pchelko
parents: 20155
diff changeset
   249
                                displayChanged();
a60499e6e190 7158311: GraphicsDevice.setDisplayMode(...) leads to hang when DISPLAY variable points to Oracle Linux
pchelko
parents: 20155
diff changeset
   250
                        } finally {
a60499e6e190 7158311: GraphicsDevice.setDisplayMode(...) leads to hang when DISPLAY variable points to Oracle Linux
pchelko
parents: 20155
diff changeset
   251
                            awtLock();
a60499e6e190 7158311: GraphicsDevice.setDisplayMode(...) leads to hang when DISPLAY variable points to Oracle Linux
pchelko
parents: 20155
diff changeset
   252
                        }
11083
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   253
                    }
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   254
                }
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   255
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
23900
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   259
        PrivilegedAction<Void> a = () -> {
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   260
            Thread shutdownThread = new Thread(ThreadGroupUtils.getRootThreadGroup(), "XToolkt-Shutdown-Thread") {
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   261
                    public void run() {
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   262
                        XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   263
                        if (peer != null) {
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   264
                            peer.dispose();
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   265
                        }
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   266
                        if (xs != null) {
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   267
                            ((XAWTXSettings)xs).dispose();
5275
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4376
diff changeset
   268
                        }
23900
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   269
                        freeXKB();
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   270
                        if (log.isLoggable(PlatformLogger.Level.FINE)) {
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   271
                            dumpPeers();
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   272
                        }
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   273
                    }
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   274
                };
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   275
            shutdownThread.setContextClassLoader(null);
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   276
            Runtime.getRuntime().addShutdownHook(shutdownThread);
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   277
            return null;
5275
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4376
diff changeset
   278
        };
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4376
diff changeset
   279
        AccessController.doPrivileged(a);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    static String getCorrectXIDString(String val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (val != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            return val.replace('.', '-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            return val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    static native String getEnv(String key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    static String getAWTAppClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return awtAppClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public XToolkit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (PerformanceLogger.loggingEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            PerformanceLogger.setTime("XToolkit construction");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            String mainClassName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            StackTraceElement trace[] = (new Throwable()).getStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            int bottom = trace.length - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            if (bottom >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                mainClassName = trace[bottom].getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            if (mainClassName == null || mainClassName.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                mainClassName = "AWT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            awtAppClassName = getCorrectXIDString(mainClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            XWM.init();
6820
bd6e9b4e1460 6828273: javax/swing/system/6799345/TestShutdown.java test fails with RuntimeException.
art
parents: 6642
diff changeset
   318
23900
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   319
            toolkitThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   320
                Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), XToolkit.this, "AWT-XAWT");
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   321
                thread.setContextClassLoader(null);
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   322
                thread.setPriority(Thread.NORM_PRIORITY + 1);
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   323
                thread.setDaemon(true);
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   324
                return thread;
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23893
diff changeset
   325
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            toolkitThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public ButtonPeer createButton(Button target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        ButtonPeer peer = new XButtonPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 14888
diff changeset
   336
    public FramePeer createLightweightFrame(LightweightFrame target) {
16706
4b243017cd27 8010375: sun.swing.JLightweightFrame should be implemented for XToolkit
ant
parents: 15983
diff changeset
   337
        FramePeer peer = new XLightweightFramePeer(target);
4b243017cd27 8010375: sun.swing.JLightweightFrame should be implemented for XToolkit
ant
parents: 15983
diff changeset
   338
        targetCreatedPeer(target, peer);
4b243017cd27 8010375: sun.swing.JLightweightFrame should be implemented for XToolkit
ant
parents: 15983
diff changeset
   339
        return peer;
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 14888
diff changeset
   340
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents: 14888
diff changeset
   341
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public FramePeer createFrame(Frame target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        FramePeer peer = new XFramePeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    static void addToWinMap(long window, XBaseWindow xwin)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        synchronized(winMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            winMap.put(Long.valueOf(window),xwin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    static void removeFromWinMap(long window, XBaseWindow xwin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        synchronized(winMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            winMap.remove(Long.valueOf(window));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    static XBaseWindow windowToXWindow(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        synchronized(winMap) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   362
            return winMap.get(Long.valueOf(window));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    static void addEventDispatcher(long window, XEventDispatcher dispatcher) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        synchronized(winToDispatcher) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            Long key = Long.valueOf(window);
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   369
            Collection<XEventDispatcher> dispatchers = winToDispatcher.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            if (dispatchers == null) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   371
                dispatchers = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                winToDispatcher.put(key, dispatchers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            dispatchers.add(dispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    static void removeEventDispatcher(long window, XEventDispatcher dispatcher) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        synchronized(winToDispatcher) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            Long key = Long.valueOf(window);
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   380
            Collection<XEventDispatcher> dispatchers = winToDispatcher.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (dispatchers != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                dispatchers.remove(dispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    private Point lastCursorPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Returns whether there is last remembered cursor position.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * position is remembered from X mouse events on our peers.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * position is stored in <code>p</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @return true, if there is remembered last cursor position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    boolean getLastCursorPos(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            if (lastCursorPos == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            p.setLocation(lastCursorPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    private void processGlobalMotionEvent(XEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        // Only our windows guaranteely generate MotionNotify, so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // should track enter/leave, to catch the moment when to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        // switch to XQueryPointer
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   413
        if (e.get_type() == XConstants.MotionNotify) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            XMotionEvent ev = e.get_xmotion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                if (lastCursorPos == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    lastCursorPos = new Point(ev.get_x_root(), ev.get_y_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    lastCursorPos.setLocation(ev.get_x_root(), ev.get_y_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   425
        } else if (e.get_type() == XConstants.LeaveNotify) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            // Leave from our window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                lastCursorPos = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   433
        } else if (e.get_type() == XConstants.EnterNotify) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            // Entrance into our window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            XCrossingEvent ev = e.get_xcrossing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                if (lastCursorPos == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    lastCursorPos = new Point(ev.get_x_root(), ev.get_y_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    lastCursorPos.setLocation(ev.get_x_root(), ev.get_y_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                awtUnlock();
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public interface XEventListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        public void eventProcessed(XEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    private Collection<XEventListener> listeners = new LinkedList<XEventListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public void addXEventListener(XEventListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        synchronized (listeners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            listeners.add(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    private void notifyListeners(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        synchronized (listeners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            if (listeners.size() == 0) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            XEvent copy = xev.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                for (XEventListener listener : listeners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    listener.eventProcessed(copy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                copy.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    private void dispatchEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        final XAnyEvent xany = ev.get_xany();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (windowToXWindow(xany.get_window()) != null &&
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   480
             (ev.get_type() == XConstants.MotionNotify || ev.get_type() == XConstants.EnterNotify || ev.get_type() == XConstants.LeaveNotify))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            processGlobalMotionEvent(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
4370
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
   485
        if( ev.get_type() == XConstants.MappingNotify ) {
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
   486
            // The 'window' field in this event is unused.
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
   487
            // This application itself does nothing to initiate such an event
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
   488
            // (no calls of XChangeKeyboardMapping etc.).
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
   489
            // SunRay server sends this event to the application once on every
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
   490
            // keyboard (not just layout) change which means, quite seldom.
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
   491
            XlibWrapper.XRefreshKeyboardMapping(ev.pData);
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
   492
            resetKeyboardSniffer();
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
   493
            setupModifierMap();
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
   494
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        XBaseWindow.dispatchToWindow(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   497
        Collection<XEventDispatcher> dispatchers = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        synchronized(winToDispatcher) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            Long key = Long.valueOf(xany.get_window());
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   500
            dispatchers = winToDispatcher.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            if (dispatchers != null) { // Clone it to avoid synchronization during dispatching
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   502
                dispatchers = new Vector<>(dispatchers);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if (dispatchers != null) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   506
            Iterator<XEventDispatcher> iter = dispatchers.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            while (iter.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   508
                XEventDispatcher disp = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                disp.dispatchEvent(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        notifyListeners(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    static void processException(Throwable thr) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   516
        if (log.isLoggable(PlatformLogger.Level.WARNING)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
   517
            log.warning("Exception on Toolkit thread", thr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    static native void awt_toolkit_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        awt_toolkit_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        run(PRIMARY_LOOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    public void run(boolean loop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        XEvent ev = new XEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        while(true) {
2650
44d88464a573 6829923: Test javax/swing/system/6799345/TestShutdown.java fails on X11 platforms
art
parents: 1970
diff changeset
   532
            // Fix for 6829923: we should gracefully handle toolkit thread interruption
44d88464a573 6829923: Test javax/swing/system/6799345/TestShutdown.java fails on X11 platforms
art
parents: 1970
diff changeset
   533
            if (Thread.currentThread().isInterrupted()) {
44d88464a573 6829923: Test javax/swing/system/6799345/TestShutdown.java fails on X11 platforms
art
parents: 1970
diff changeset
   534
                // We expect interruption from the AppContext.dispose() method only.
44d88464a573 6829923: Test javax/swing/system/6799345/TestShutdown.java fails on X11 platforms
art
parents: 1970
diff changeset
   535
                // If the thread is interrupted from another place, let's skip it
44d88464a573 6829923: Test javax/swing/system/6799345/TestShutdown.java fails on X11 platforms
art
parents: 1970
diff changeset
   536
                // for compatibility reasons. Probably some time later we'll remove
44d88464a573 6829923: Test javax/swing/system/6799345/TestShutdown.java fails on X11 platforms
art
parents: 1970
diff changeset
   537
                // the check for AppContext.isDisposed() and will unconditionally
44d88464a573 6829923: Test javax/swing/system/6799345/TestShutdown.java fails on X11 platforms
art
parents: 1970
diff changeset
   538
                // break the loop here.
44d88464a573 6829923: Test javax/swing/system/6799345/TestShutdown.java fails on X11 platforms
art
parents: 1970
diff changeset
   539
                if (AppContext.getAppContext().isDisposed()) {
44d88464a573 6829923: Test javax/swing/system/6799345/TestShutdown.java fails on X11 platforms
art
parents: 1970
diff changeset
   540
                    break;
44d88464a573 6829923: Test javax/swing/system/6799345/TestShutdown.java fails on X11 platforms
art
parents: 1970
diff changeset
   541
                }
44d88464a573 6829923: Test javax/swing/system/6799345/TestShutdown.java fails on X11 platforms
art
parents: 1970
diff changeset
   542
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                if (loop == SECONDARY_LOOP) {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20460
diff changeset
   546
                    // In the secondary loop we may have already acquired awt_lock
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    // several times, so waitForEvents() might be unable to release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    // the awt_lock and this causes lock up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    // For now, we just avoid waitForEvents in the secondary loop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    if (!XlibWrapper.XNextSecondaryLoopEvent(getDisplay(),ev.pData)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    callTimeoutTasks();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    // If no events are queued, waitForEvents() causes calls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    // awtUnlock(), awtJNI_ThreadYield, poll, awtLock(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    // so it spends most of its time in poll, without holding the lock.
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   558
                    while ((XlibWrapper.XEventsQueued(getDisplay(), XConstants.QueuedAfterReading) == 0) &&
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   559
                           (XlibWrapper.XEventsQueued(getDisplay(), XConstants.QueuedAfterFlush) == 0)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                        callTimeoutTasks();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                        waitForEvents(getNextTaskTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                    XlibWrapper.XNextEvent(getDisplay(),ev.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   566
                if (ev.get_type() != XConstants.NoExpose) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                    eventNumber++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                }
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
   569
                if (awt_UseXKB_Calls && ev.get_type() ==  awt_XKBBaseEventCode) {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
   570
                    processXkbChanges(ev);
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
   571
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                if (XDropTargetEventProcessor.processEvent(ev) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    XDragSourceContextPeer.processEvent(ev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   578
                if (eventLog.isLoggable(PlatformLogger.Level.FINER)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
   579
                    eventLog.finer("{0}", ev);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                // Check if input method consumes the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                long w = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                if (windowToXWindow(ev.get_xany().get_window()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    Component owner =
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11083
diff changeset
   586
                        XKeyboardFocusManagerPeer.getInstance().getCurrentFocusOwner();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                    if (owner != null) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
   588
                        XWindow ownerWindow = (XWindow) AWTAccessor.getComponentAccessor().getPeer(owner);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                        if (ownerWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                            w = ownerWindow.getContentWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   594
                if( keyEventLog.isLoggable(PlatformLogger.Level.FINE) && (ev.get_type() == XConstants.KeyPress || ev.get_type() == XConstants.KeyRelease) ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    keyEventLog.fine("before XFilterEvent:"+ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                if (XlibWrapper.XFilterEvent(ev.getPData(), w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   600
                if( keyEventLog.isLoggable(PlatformLogger.Level.FINE) && (ev.get_type() == XConstants.KeyPress || ev.get_type() == XConstants.KeyRelease) ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                    keyEventLog.fine("after XFilterEvent:"+ev); // IS THIS CORRECT?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                dispatchEvent(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            } catch (ThreadDeath td) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                XBaseWindow.ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            } catch (Throwable thr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                XBaseWindow.ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                processException(thr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
11083
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   617
    static {
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   618
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   619
        if (ge instanceof SunGraphicsEnvironment) {
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   620
            ((SunGraphicsEnvironment)ge).addDisplayChangedListener(
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   621
                new DisplayChangedListener() {
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   622
                    @Override
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   623
                    public void displayChanged() {
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   624
                        // 7045370: Reset the cached values
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   625
                        XToolkit.screenWidth = -1;
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   626
                        XToolkit.screenHeight = -1;
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   627
                    }
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   628
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   629
                    @Override
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   630
                    public void paletteChanged() {}
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   631
            });
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   632
        }
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   633
    }
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   634
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   635
    private static void initScreenSize() {
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   636
        if (screenWidth == -1 || screenHeight == -1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            try {
11083
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   639
                XWindowAttributes pattr = new XWindowAttributes();
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   640
                try {
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   641
                    XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), pattr.pData);
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 22567
diff changeset
   642
                    screenWidth  = pattr.get_width();
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 22567
diff changeset
   643
                    screenHeight = pattr.get_height();
11083
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   644
                } finally {
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   645
                    pattr.dispose();
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   646
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        }
11083
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   651
    }
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   652
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   653
    static int getDefaultScreenWidth() {
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   654
        initScreenSize();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        return screenWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    static int getDefaultScreenHeight() {
11083
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10319
diff changeset
   659
        initScreenSize();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        return screenHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    protected int getScreenWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        return getDefaultScreenWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    protected int getScreenHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        return getDefaultScreenHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    private static Rectangle getWorkArea(long root)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        XAtom XA_NET_WORKAREA = XAtom.get("_NET_WORKAREA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        long native_ptr = Native.allocateLongArray(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            boolean workareaPresent = XA_NET_WORKAREA.getAtomData(root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                XAtom.XA_CARDINAL, native_ptr, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            if (workareaPresent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                int rootX = (int)Native.getLong(native_ptr, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                int rootY = (int)Native.getLong(native_ptr, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                int rootWidth = (int)Native.getLong(native_ptr, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                int rootHeight = (int)Native.getLong(native_ptr, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                return new Rectangle(rootX, rootY, rootWidth, rootHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            XlibWrapper.unsafe.freeMemory(native_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * If we're running in non-Xinerama environment and the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * window manager supports _NET protocol then the screen insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * are calculated using _NET_WM_WORKAREA property of the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * Otherwise, i. e. if Xinerama is on or _NET_WM_WORKAREA is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * not set, we try to calculate the insets ourselves using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * getScreenInsetsManually method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    public Insets getScreenInsets(GraphicsConfiguration gc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        XNETProtocol netProto = XWM.getWM().getNETProtocol();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        if ((netProto == null) || !netProto.active())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            return super.getScreenInsets(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            X11GraphicsConfig x11gc = (X11GraphicsConfig)gc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            X11GraphicsDevice x11gd = (X11GraphicsDevice)x11gc.getDevice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            long root = XlibUtil.getRootWindow(x11gd.getScreen());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            Rectangle rootBounds = XlibUtil.getWindowGeometry(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            X11GraphicsEnvironment x11ge = (X11GraphicsEnvironment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            if (!x11ge.runningXinerama())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                Rectangle workArea = XToolkit.getWorkArea(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                if (workArea != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                    return new Insets(workArea.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                                      workArea.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                                      rootBounds.height - workArea.height - workArea.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                                      rootBounds.width - workArea.width - workArea.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            return getScreenInsetsManually(root, rootBounds, gc.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * Manual calculation of screen insets: get all the windows with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * _NET_WM_STRUT/_NET_WM_STRUT_PARTIAL hints and add these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * hints' values to screen insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * This method should be called under XToolkit.awtLock()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    private Insets getScreenInsetsManually(long root, Rectangle rootBounds, Rectangle screenBounds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
         * During the manual calculation of screen insets we iterate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
         * all the X windows hierarchy starting from root window. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
         * constant is the max level inspected in this hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
         * 3 is a heuristic value: I suppose any the toolbar-like
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
         * window is a child of either root or desktop window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        final int MAX_NESTED_LEVEL = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        XAtom XA_NET_WM_STRUT = XAtom.get("_NET_WM_STRUT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        XAtom XA_NET_WM_STRUT_PARTIAL = XAtom.get("_NET_WM_STRUT_PARTIAL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        Insets insets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   768
        java.util.List<Object> search = new LinkedList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        search.add(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        search.add(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        while (!search.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            long window = (Long)search.remove(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            int windowLevel = (Integer)search.remove(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
             * Note that most of the modern window managers unmap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
             * application window if it is iconified. Thus, any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
             * _NET_WM_STRUT[_PARTIAL] hints for iconified windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
             * are not included to the screen insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
             */
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   782
            if (XlibUtil.getWindowMapState(window) == XConstants.IsUnmapped)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            long native_ptr = Native.allocateLongArray(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                // first, check if _NET_WM_STRUT or _NET_WM_STRUT_PARTIAL are present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                // if both are set on the window, _NET_WM_STRUT_PARTIAL is used (see _NET spec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                boolean strutPresent = XA_NET_WM_STRUT_PARTIAL.getAtomData(window, XAtom.XA_CARDINAL, native_ptr, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                if (!strutPresent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                    strutPresent = XA_NET_WM_STRUT.getAtomData(window, XAtom.XA_CARDINAL, native_ptr, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                if (strutPresent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                    // second, verify that window is located on the proper screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                    Rectangle windowBounds = XlibUtil.getWindowGeometry(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                    if (windowLevel > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                        windowBounds = XlibUtil.translateCoordinates(window, root, windowBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    // if _NET_WM_STRUT_PARTIAL is present, we should use its values to detect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                    // if the struts area intersects with screenBounds, however some window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                    // managers don't set this hint correctly, so we just get intersection with windowBounds
5760
4177643566d5 6961754: JCK tests CvsEventTest0001 and CvsEventTest0002 fail under FF 3.5 on OEL 5
anthony
parents: 5758
diff changeset
   808
                    if (windowBounds != null && windowBounds.intersects(screenBounds))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                    {
23285
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   810
                        int left = (int)Native.getLong(native_ptr, 0);
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   811
                        int right = (int)Native.getLong(native_ptr, 1);
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   812
                        int top = (int)Native.getLong(native_ptr, 2);
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   813
                        int bottom = (int)Native.getLong(native_ptr, 3);
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   814
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   815
                        /*
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   816
                         * struts could be relative to root window bounds, so
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   817
                         * make them relative to the screen bounds in this case
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   818
                         */
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   819
                        left = rootBounds.x + left > screenBounds.x ?
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   820
                                rootBounds.x + left - screenBounds.x : 0;
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   821
                        right = rootBounds.x + rootBounds.width - right <
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   822
                                screenBounds.x + screenBounds.width ?
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   823
                                screenBounds.x + screenBounds.width -
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   824
                                (rootBounds.x + rootBounds.width - right) : 0;
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   825
                        top = rootBounds.y + top > screenBounds.y ?
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   826
                                rootBounds.y + top - screenBounds.y : 0;
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   827
                        bottom = rootBounds.y + rootBounds.height - bottom <
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   828
                                screenBounds.y + screenBounds.height ?
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   829
                                screenBounds.y + screenBounds.height -
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   830
                                (rootBounds.y + rootBounds.height - bottom) : 0;
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   831
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   832
                        insets.left = Math.max(left, insets.left);
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   833
                        insets.right = Math.max(right, insets.right);
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   834
                        insets.top = Math.max(top, insets.top);
ae856aaa48b0 8020443: Frame is not created on the specified GraphicsDevice with two monitors
bagiras
parents: 23276
diff changeset
   835
                        insets.bottom = Math.max(bottom, insets.bottom);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                XlibWrapper.unsafe.freeMemory(native_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            if (windowLevel < MAX_NESTED_LEVEL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                Set<Long> children = XlibUtil.getChildWindows(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                for (long child : children)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                    search.add(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                    search.add(windowLevel + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * The current implementation of disabling background erasing for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * canvases is that we don't set any native background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * (with XSetWindowBackground) for the canvas window. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * this color is set in the peer constructor - see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * XWindow.postInit() for details. That's why this method from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * SunToolkit is not overridden in XToolkit: it's too late to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * disable background erasing :(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    public void disableBackgroundErase(Canvas canvas) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        XCanvasPeer peer = (XCanvasPeer)canvas.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            throw new IllegalStateException("Canvas must have a valid peer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        peer.disableBackgroundErase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    // Need this for XMenuItemPeer.
26004
7507a1b93f67 6521783: Unnecessary final modifier for a method in a final class
serb
parents: 24538
diff changeset
   879
    protected static Object targetToPeer(Object target) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        Object p=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        if (target != null && !GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            p = specialPeerMap.get(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        if (p != null) return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            return SunToolkit.targetToPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    // Need this for XMenuItemPeer.
26004
7507a1b93f67 6521783: Unnecessary final modifier for a method in a final class
serb
parents: 24538
diff changeset
   890
    protected static void targetDisposedPeer(Object target, Object peer) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        SunToolkit.targetDisposedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    public RobotPeer createRobot(Robot target, GraphicsDevice screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        return new XRobotPeer(screen.getDefaultConfiguration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
  /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * On X, support for dynamic layout on resizing is governed by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * window manager.  If the window manager supports it, it happens
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * automatically.  The setter method for this property is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * irrelevant on X.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    public void setDynamicLayout(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        dynamicLayoutSetting = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    protected boolean isDynamicLayoutSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        return dynamicLayoutSetting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    /* Called from isDynamicLayoutActive() and from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * lazilyLoadDynamicLayoutSupportedProperty()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    protected boolean isDynamicLayoutSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        return XWM.getWM().supportsDynamicLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    public boolean isDynamicLayoutActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        return isDynamicLayoutSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    public FontPeer getFontPeer(String name, int style){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        return new XFontPeer(name, style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
26342
3637212ae8f2 8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents: 26021
diff changeset
   930
        final LightweightFrame f = SunToolkit.getLightweightFrame(dge.getComponent());
3637212ae8f2 8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents: 26021
diff changeset
   931
        if (f != null) {
3637212ae8f2 8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents: 26021
diff changeset
   932
            return f.createDragSourceContextPeer(dge);
3637212ae8f2 8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents: 26021
diff changeset
   933
        }
3637212ae8f2 8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents: 26021
diff changeset
   934
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        return XDragSourceContextPeer.createDragSourceContextPeer(dge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   938
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    public <T extends DragGestureRecognizer> T
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    createDragGestureRecognizer(Class<T> recognizerClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                    DragSource ds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                    Component c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                    int srcActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                    DragGestureListener dgl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    {
26342
3637212ae8f2 8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents: 26021
diff changeset
   946
        final LightweightFrame f = SunToolkit.getLightweightFrame(c);
3637212ae8f2 8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents: 26021
diff changeset
   947
        if (f != null) {
3637212ae8f2 8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents: 26021
diff changeset
   948
            return f.createDragGestureRecognizer(recognizerClass, ds, c, srcActions, dgl);
3637212ae8f2 8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents: 26021
diff changeset
   949
        }
3637212ae8f2 8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents: 26021
diff changeset
   950
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        if (MouseDragGestureRecognizer.class.equals(recognizerClass))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            return (T)new XMouseDragGestureRecognizer(ds, c, srcActions, dgl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        XCheckboxMenuItemPeer peer = new XCheckboxMenuItemPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        //vb157120: looks like we don't need to map menu items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        //in new menus implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        //targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    public MenuItemPeer createMenuItem(MenuItem target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        XMenuItemPeer peer = new XMenuItemPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        //vb157120: looks like we don't need to map menu items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        //in new menus implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        //targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    public TextFieldPeer createTextField(TextField target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        TextFieldPeer  peer = new XTextFieldPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    public LabelPeer createLabel(Label target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        LabelPeer  peer = new XLabelPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        return peer;
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 ListPeer createList(java.awt.List target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        ListPeer peer = new XListPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    public CheckboxPeer createCheckbox(Checkbox target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        CheckboxPeer peer = new XCheckboxPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    public ScrollbarPeer createScrollbar(Scrollbar target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        XScrollbarPeer peer = new XScrollbarPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    public ScrollPanePeer createScrollPane(ScrollPane target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        XScrollPanePeer peer = new XScrollPanePeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    public TextAreaPeer createTextArea(TextArea target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        TextAreaPeer peer = new XTextAreaPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    public ChoicePeer createChoice(Choice target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        XChoicePeer peer = new XChoicePeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    public CanvasPeer createCanvas(Canvas target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        XCanvasPeer peer = (isXEmbedServerRequested() ? new XEmbedCanvasPeer(target) : new XCanvasPeer(target));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    public PanelPeer createPanel(Panel target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        PanelPeer peer = new XPanelPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    public WindowPeer createWindow(Window target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        WindowPeer peer = new XWindowPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    public DialogPeer createDialog(Dialog target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        DialogPeer peer = new XDialogPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
5944
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1045
    private static Boolean sunAwtDisableGtkFileDialogs = null;
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1046
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1047
    /**
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1048
     * Returns the value of "sun.awt.disableGtkFileDialogs" property. Default
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1049
     * value is {@code false}.
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1050
     */
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1051
    public synchronized static boolean getSunAwtDisableGtkFileDialogs() {
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1052
        if (sunAwtDisableGtkFileDialogs == null) {
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 11083
diff changeset
  1053
            sunAwtDisableGtkFileDialogs = AccessController.doPrivileged(
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 11083
diff changeset
  1054
                                              new GetBooleanAction("sun.awt.disableGtkFileDialogs"));
5944
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1055
        }
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1056
        return sunAwtDisableGtkFileDialogs.booleanValue();
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1057
    }
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1058
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    public FileDialogPeer createFileDialog(FileDialog target) {
5944
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1060
        FileDialogPeer peer = null;
5444
f7c5aeb82a14 6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents: 4376
diff changeset
  1061
        // The current GtkFileChooser is available from GTK+ 2.4
5944
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1062
        if (!getSunAwtDisableGtkFileDialogs() && checkGtkVersion(2, 4, 0)) {
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1063
            peer = new GtkFileDialogPeer(target);
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1064
        } else {
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1065
            peer = new XFileDialogPeer(target);
1041870341a8 6959174: Need to introduce sun.awt.disableGtkFileDialogs system property
dcherepanov
parents: 5760
diff changeset
  1066
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    public MenuBarPeer createMenuBar(MenuBar target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        XMenuBarPeer peer = new XMenuBarPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    public MenuPeer createMenu(Menu target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        XMenuPeer peer = new XMenuPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        //vb157120: looks like we don't need to map menu items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        //in new menus implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        //targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    public PopupMenuPeer createPopupMenu(PopupMenu target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        XPopupMenuPeer peer = new XPopupMenuPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    public synchronized MouseInfoPeer getMouseInfoPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        if (xPeer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            xPeer = new XMouseInfoPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        return xPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    public XEmbeddedFramePeer createEmbeddedFrame(XEmbeddedFrame target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        XEmbeddedFramePeer peer = new XEmbeddedFramePeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    XEmbedChildProxyPeer createEmbedProxy(XEmbedChildProxy target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        XEmbedChildProxyPeer peer = new XEmbedChildProxyPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11083
diff changeset
  1111
    public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() throws HeadlessException {
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 11083
diff changeset
  1112
        return XKeyboardFocusManagerPeer.getInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * Returns a new custom cursor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
      throws IndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        return new XCustomCursor(cursor, hotSpot, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    public TrayIconPeer createTrayIcon(TrayIcon target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
      throws HeadlessException, AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        TrayIconPeer peer = new XTrayIconPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    public SystemTrayPeer createSystemTray(SystemTray target) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        SystemTrayPeer peer = new XSystemTrayPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    public boolean isTraySupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            return peer.isAvailable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
23260
d68cbf54738f 8029893: Remove reflection from DataTransferer.getInstance
pchelko
parents: 21278
diff changeset
  1144
    @Override
d68cbf54738f 8029893: Remove reflection from DataTransferer.getInstance
pchelko
parents: 21278
diff changeset
  1145
    public DataTransferer getDataTransferer() {
d68cbf54738f 8029893: Remove reflection from DataTransferer.getInstance
pchelko
parents: 21278
diff changeset
  1146
        return XDataTransferer.getInstanceImpl();
d68cbf54738f 8029893: Remove reflection from DataTransferer.getInstance
pchelko
parents: 21278
diff changeset
  1147
    }
d68cbf54738f 8029893: Remove reflection from DataTransferer.getInstance
pchelko
parents: 21278
diff changeset
  1148
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * Returns the supported cursor size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        return XCustomCursor.getBestCursorSize(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                                               java.lang.Math.max(1,preferredWidth), java.lang.Math.max(1,preferredHeight));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    public int getMaximumCursorColors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        return 2;  // Black and white.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1162
    public Map<TextAttribute, ?> mapInputMethodHighlight( InputMethodHighlight highlight) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        return XInputMethod.mapInputMethodHighlight(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    }
1966
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1165
    @Override
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1166
    public boolean getLockingKeyState(int key) {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1167
        if (! (key == KeyEvent.VK_CAPS_LOCK || key == KeyEvent.VK_NUM_LOCK ||
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1168
               key == KeyEvent.VK_SCROLL_LOCK || key == KeyEvent.VK_KANA_LOCK)) {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1169
            throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1170
        }
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1171
        awtLock();
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1172
        try {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1173
            return getModifierState( key );
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1174
        } finally {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1175
            awtUnlock();
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1176
        }
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1177
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    public  Clipboard getSystemClipboard() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        if (security != null) {
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21278
diff changeset
  1182
            security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            if (clipboard == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                clipboard = new XClipboard("System", "CLIPBOARD");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        return clipboard;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    public Clipboard getSystemSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        if (security != null) {
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21278
diff changeset
  1195
            security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            if (selection == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                selection = new XClipboard("Selection", "PRIMARY");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        return selection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    public void beep() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            XlibWrapper.XBell(getDisplay(), 0);
3083
1954edd3b7a7 6721086: Toolkit beep does not work consistently
langel
parents: 2810
diff changeset
  1209
            XlibWrapper.XFlush(getDisplay());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    public PrintJob getPrintJob(final Frame frame, final String doctitle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                                final Properties props) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
8947
35ff89272f4f 7023011: Toolkit.getPrintJob(Frame,String,Properties) throws HE instead of specified NPE
dav
parents: 6820
diff changeset
  1218
        if (frame == null) {
35ff89272f4f 7023011: Toolkit.getPrintJob(Frame,String,Properties) throws HE instead of specified NPE
dav
parents: 6820
diff changeset
  1219
            throw new NullPointerException("frame must not be null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        PrintJob2D printJob = new PrintJob2D(frame, doctitle, props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        if (printJob.printDialog() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            printJob = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        return printJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    public PrintJob getPrintJob(final Frame frame, final String doctitle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                final JobAttributes jobAttributes,
8947
35ff89272f4f 7023011: Toolkit.getPrintJob(Frame,String,Properties) throws HE instead of specified NPE
dav
parents: 6820
diff changeset
  1232
                final PageAttributes pageAttributes)
35ff89272f4f 7023011: Toolkit.getPrintJob(Frame,String,Properties) throws HE instead of specified NPE
dav
parents: 6820
diff changeset
  1233
    {
35ff89272f4f 7023011: Toolkit.getPrintJob(Frame,String,Properties) throws HE instead of specified NPE
dav
parents: 6820
diff changeset
  1234
        if (frame == null) {
35ff89272f4f 7023011: Toolkit.getPrintJob(Frame,String,Properties) throws HE instead of specified NPE
dav
parents: 6820
diff changeset
  1235
            throw new NullPointerException("frame must not be null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        PrintJob2D printJob = new PrintJob2D(frame, doctitle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                                             jobAttributes, pageAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        if (printJob.printDialog() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            printJob = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        return printJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    static void XSync() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            XlibWrapper.XSync(getDisplay(),0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    public int getScreenResolution() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        long display = getDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            return (int) ((XlibWrapper.DisplayWidth(display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                XlibWrapper.DefaultScreen(display)) * 25.4) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                    XlibWrapper.DisplayWidthMM(display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                XlibWrapper.DefaultScreen(display)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    static native long getDefaultXColormap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    static native long getDefaultScreenData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    static ColorModel screenmodel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    static ColorModel getStaticColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        if (screenmodel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            screenmodel = config.getColorModel ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        return screenmodel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    public ColorModel getColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        return getStaticColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * Returns a new input method adapter descriptor for native input methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    public InputMethodDescriptor getInputMethodAdapterDescriptor() throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        return new XInputMethodDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
14652
e83b878abcab 8000423: Diacritic is not applyed to a base letter on Linux
alexsch
parents: 13656
diff changeset
  1293
    /**
e83b878abcab 8000423: Diacritic is not applyed to a base letter on Linux
alexsch
parents: 13656
diff changeset
  1294
     * Returns whether enableInputMethods should be set to true for peered
e83b878abcab 8000423: Diacritic is not applyed to a base letter on Linux
alexsch
parents: 13656
diff changeset
  1295
     * TextComponent instances on this platform. True by default.
e83b878abcab 8000423: Diacritic is not applyed to a base letter on Linux
alexsch
parents: 13656
diff changeset
  1296
     */
e83b878abcab 8000423: Diacritic is not applyed to a base letter on Linux
alexsch
parents: 13656
diff changeset
  1297
    @Override
e83b878abcab 8000423: Diacritic is not applyed to a base letter on Linux
alexsch
parents: 13656
diff changeset
  1298
    public boolean enableInputMethodsForTextComponent() {
e83b878abcab 8000423: Diacritic is not applyed to a base letter on Linux
alexsch
parents: 13656
diff changeset
  1299
        return true;
e83b878abcab 8000423: Diacritic is not applyed to a base letter on Linux
alexsch
parents: 13656
diff changeset
  1300
    }
e83b878abcab 8000423: Diacritic is not applyed to a base letter on Linux
alexsch
parents: 13656
diff changeset
  1301
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    static int getMultiClickTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        if (awt_multiclick_time == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            initializeMultiClickTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        return awt_multiclick_time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    static void initializeMultiClickTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                String multiclick_time_query = XlibWrapper.XGetDefault(XToolkit.getDisplay(), "*", "multiClickTime");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                if (multiclick_time_query != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                    awt_multiclick_time = (int)Long.parseLong(multiclick_time_query);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                    multiclick_time_query = XlibWrapper.XGetDefault(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                                                                    "OpenWindows", "MultiClickTimeout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                    if (multiclick_time_query != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                        /* Note: OpenWindows.MultiClickTimeout is in tenths of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                           a second, so we need to multiply by 100 to convert to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                           milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                        awt_multiclick_time = (int)Long.parseLong(multiclick_time_query) * 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                    } else {
1969
07500c30ab46 5076635: Double click speed is not honored in KDE linux
dav
parents: 439
diff changeset
  1324
                        awt_multiclick_time = AWT_MULTICLICK_DEFAULT_TIME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            } catch (NumberFormatException nf) {
1969
07500c30ab46 5076635: Double click speed is not honored in KDE linux
dav
parents: 439
diff changeset
  1328
                awt_multiclick_time = AWT_MULTICLICK_DEFAULT_TIME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            } catch (NullPointerException npe) {
1969
07500c30ab46 5076635: Double click speed is not honored in KDE linux
dav
parents: 439
diff changeset
  1330
                awt_multiclick_time = AWT_MULTICLICK_DEFAULT_TIME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        if (awt_multiclick_time == 0) {
1969
07500c30ab46 5076635: Double click speed is not honored in KDE linux
dav
parents: 439
diff changeset
  1336
            awt_multiclick_time = AWT_MULTICLICK_DEFAULT_TIME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    public boolean isFrameStateSupported(int state)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
      throws HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        if (state == Frame.NORMAL || state == Frame.ICONIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            return XWM.getWM().supportsExtendedState(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    static void dumpPeers() {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1351
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            log.fine("Mapped windows:");
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1353
            winMap.forEach((k, v) -> {
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1354
                log.fine(k + "->" + v);
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1355
                if (v instanceof XComponentPeer) {
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1356
                    Component target = (Component)((XComponentPeer)v).getTarget();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                    log.fine("\ttarget: " + target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                }
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1359
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            SunToolkit.dumpPeers(log);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            log.fine("Mapped special peers:");
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1364
            specialPeerMap.forEach((k, v) -> {
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1365
                log.fine(k + "->" + v);
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1366
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            log.fine("Mapped dispatchers:");
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1369
            winToDispatcher.forEach((k, v) -> {
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1370
                log.fine(k + "->" + v);
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1371
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
    /* Protected with awt_lock. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    private static boolean initialized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    private static boolean timeStampUpdated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    private static long timeStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    private static final XEventDispatcher timeFetcher =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
    new XEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            public void dispatchEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                switch (ev.get_type()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1384
                  case XConstants.PropertyNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                      XPropertyEvent xpe = ev.get_xproperty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                      awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                      try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                          timeStamp = xpe.get_time();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                          timeStampUpdated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                          awtLockNotifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                      } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                          awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    private static XAtom _XA_JAVA_TIME_PROPERTY_ATOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    static long getCurrentServerTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                if (!initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                    XToolkit.addEventDispatcher(XBaseWindow.getXAWTRootWindow().getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                                                timeFetcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                    _XA_JAVA_TIME_PROPERTY_ATOM = XAtom.get("_SUNW_JAVA_AWT_TIME");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                    initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                timeStampUpdated = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                XlibWrapper.XChangeProperty(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                                            XBaseWindow.getXAWTRootWindow().getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                                            _XA_JAVA_TIME_PROPERTY_ATOM.getAtom(), XAtom.XA_ATOM, 32,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1417
                                            XConstants.PropModeAppend,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                                            0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                XlibWrapper.XFlush(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                if (isToolkitThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                    XEvent event = new XEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                        XlibWrapper.XWindowEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                                                 XBaseWindow.getXAWTRootWindow().getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                                                 XConstants.PropertyChangeMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                                                 event.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                        timeFetcher.dispatchEvent(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                    finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                        event.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                    while (!timeStampUpdated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                        awtLockWait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
            } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            // Note: the returned timeStamp can be incorrect in this case.
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1441
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 16706
diff changeset
  1442
                    log.fine("Catched exception, timeStamp may not be correct (ie = " + ie + ")");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 16706
diff changeset
  1443
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        return timeStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    protected void initializeDesktopProperties() {
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 3083
diff changeset
  1451
        desktopProperties.put("DnD.Autoscroll.initialDelay",
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 3083
diff changeset
  1452
                              Integer.valueOf(50));
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 3083
diff changeset
  1453
        desktopProperties.put("DnD.Autoscroll.interval",
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 3083
diff changeset
  1454
                              Integer.valueOf(50));
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 3083
diff changeset
  1455
        desktopProperties.put("DnD.Autoscroll.cursorHysteresis",
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 3083
diff changeset
  1456
                              Integer.valueOf(5));
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 3083
diff changeset
  1457
        desktopProperties.put("Shell.shellFolderManager",
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 3083
diff changeset
  1458
                              "sun.awt.shell.ShellFolderManager");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        // Don't want to call getMultiClickTime() if we are headless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            desktopProperties.put("awt.multiClickInterval",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                                  Integer.valueOf(getMultiClickTime()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            desktopProperties.put("awt.mouse.numButtons",
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2803
diff changeset
  1464
                                  Integer.valueOf(getNumberOfButtons()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2803
diff changeset
  1468
    /**
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2803
diff changeset
  1469
     * This method runs through the XPointer and XExtendedPointer array.
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2803
diff changeset
  1470
     * XExtendedPointer has priority because on some systems XPointer
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2803
diff changeset
  1471
     * (which is assigned to the virtual pointer) reports the maximum
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2803
diff changeset
  1472
     * capabilities of the mouse pointer (i.e. 32 physical buttons).
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2803
diff changeset
  1473
     */
4376
61cb05d6efa2 6903893: Fix failed for CR 6834576: RemoveChild/ test fail with deadlock on rhel and sles
dav
parents: 4372
diff changeset
  1474
    private native int getNumberOfButtonsImpl();
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2803
diff changeset
  1475
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2803
diff changeset
  1476
    @Override
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2803
diff changeset
  1477
    public int getNumberOfButtons(){
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        try {
1967
a103c7d1eea6 6750288: Regression after 6315717. ArrayIndexOutOfBoundsException.
dav
parents: 1962
diff changeset
  1480
            if (numberOfButtons == 0) {
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2803
diff changeset
  1481
                numberOfButtons = getNumberOfButtonsImpl();
6642
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5944
diff changeset
  1482
                numberOfButtons = (numberOfButtons > MAX_BUTTONS_SUPPORTED)? MAX_BUTTONS_SUPPORTED : numberOfButtons;
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5944
diff changeset
  1483
                //4th and 5th buttons are for wheel and shouldn't be reported as buttons.
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5944
diff changeset
  1484
                //If we have more than 3 physical buttons and a wheel, we report N-2 buttons.
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5944
diff changeset
  1485
                //If we have 3 physical buttons and a wheel, we report 3 buttons.
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5944
diff changeset
  1486
                //If we have 1,2,3 physical buttons, we report it as is i.e. 1,2 or 3 respectively.
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5944
diff changeset
  1487
                if (numberOfButtons >=5) {
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5944
diff changeset
  1488
                    numberOfButtons -= 2;
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5944
diff changeset
  1489
                } else if (numberOfButtons == 4 || numberOfButtons ==5){
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5944
diff changeset
  1490
                    numberOfButtons = 3;
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5944
diff changeset
  1491
                }
1967
a103c7d1eea6 6750288: Regression after 6315717. ArrayIndexOutOfBoundsException.
dav
parents: 1962
diff changeset
  1492
            }
6642
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5944
diff changeset
  1493
            //Assume don't have to re-query the number again and again.
9d6f6dbb16a4 6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents: 5944
diff changeset
  1494
            return numberOfButtons;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
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: 14652
diff changeset
  1500
    static int getNumberOfButtonsForMask() {
7ad1550e7050 8005018: X11: focus problems with openjdk 1.7.0 under gnome3 when selected keyboard is not the first in keyboard list
neugens
parents: 14652
diff changeset
  1501
        return Math.min(XConstants.MAX_BUTTONS, ((SunToolkit) (Toolkit.getDefaultToolkit())).getNumberOfButtons());
7ad1550e7050 8005018: X11: focus problems with openjdk 1.7.0 under gnome3 when selected keyboard is not the first in keyboard list
neugens
parents: 14652
diff changeset
  1502
    }
7ad1550e7050 8005018: X11: focus problems with openjdk 1.7.0 under gnome3 when selected keyboard is not the first in keyboard list
neugens
parents: 14652
diff changeset
  1503
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    private final static String prefix  = "DnD.Cursor.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
    private final static String postfix = ".32x32";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
    private static final String dndPrefix  = "DnD.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
    protected Object lazilyLoadDesktopProperty(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        if (name.startsWith(prefix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            String cursorName = name.substring(prefix.length(), name.length()) + postfix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                return Cursor.getSystemCustomCursor(cursorName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            } catch (AWTException awte) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                throw new RuntimeException("cannot load system cursor: " + cursorName, awte);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        if (name.equals("awt.dynamicLayoutSupported")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            return  Boolean.valueOf(isDynamicLayoutSupported());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        if (initXSettingsIfNeeded(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            return desktopProperties.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        return super.lazilyLoadDesktopProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
10319
dbbded066362 7072645: Toolkit.addPropertyChangeListener(name, pcl) throws NPE for null name
denis
parents: 9030
diff changeset
  1531
        if (name == null) {
dbbded066362 7072645: Toolkit.addPropertyChangeListener(name, pcl) throws NPE for null name
denis
parents: 9030
diff changeset
  1532
            // See JavaDoc for the Toolkit.addPropertyChangeListener() method
dbbded066362 7072645: Toolkit.addPropertyChangeListener(name, pcl) throws NPE for null name
denis
parents: 9030
diff changeset
  1533
            return;
dbbded066362 7072645: Toolkit.addPropertyChangeListener(name, pcl) throws NPE for null name
denis
parents: 9030
diff changeset
  1534
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        initXSettingsIfNeeded(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        super.addPropertyChangeListener(name, pcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     * Initializes XAWTXSettings if a property for a given property name is provided by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
     * XSettings and they are not initialized yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     * @return true if the method has initialized XAWTXSettings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
    private boolean initXSettingsIfNeeded(final String propName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        if (!loadedXSettings &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
            (propName.startsWith("gnome.") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
             propName.equals(SunToolkit.DESKTOPFONTHINTS) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
             propName.startsWith(dndPrefix)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            loadedXSettings = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
            if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                loadXSettings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                /* If no desktop font hint could be retrieved, check for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                 * KDE running KWin and retrieve settings from fontconfig.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                 * If that isn't found let SunToolkit will see if there's a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                 * system property set by a user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                if (desktopProperties.get(SunToolkit.DESKTOPFONTHINTS) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                    if (XWM.isKDE2()) {
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 22060
diff changeset
  1561
                        Object hint = FontConfigManager.getFontConfigAAHint();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                        if (hint != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                            /* set the fontconfig/KDE property so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                             * getDesktopHints() below will see it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                             * and set the public property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                            desktopProperties.put(UNIXToolkit.FONTCONFIGAAHINT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                                                  hint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                    desktopProperties.put(SunToolkit.DESKTOPFONTHINTS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                                          SunToolkit.getDesktopFontHints());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    private void loadXSettings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
       xs = new XAWTXSettings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * Callback from the native side indicating some, or all, of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * desktop properties have changed and need to be reloaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     * <code>data</code> is the byte array directly from the x server and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     * may be in little endian format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     * NB: This could be called from any thread if triggered by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     * <code>loadXSettings</code>.  It is called from the System EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     * if triggered by an XSETTINGS change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
     */
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1595
    void parseXSettings(int screen_XXX_ignored,Map<String, Object> updatedSettings) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
        if (updatedSettings == null || updatedSettings.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1601
        Iterator<Map.Entry<String, Object>> i = updatedSettings.entrySet().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
        while (i.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1603
            Map.Entry<String, Object> e = i.next();
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1604
            String name = e.getKey();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
            name = "gnome." + name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            setDesktopProperty(name, e.getValue());
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1608
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 16706
diff changeset
  1609
                log.fine("name = " + name + " value = " + e.getValue());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 16706
diff changeset
  1610
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
            // XXX: we probably want to do something smarter.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
            // particular, "Net" properties are of interest to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
            // "core" AWT itself.  E.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            // Net/DndDragThreshold -> ???
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
            // Net/DoubleClickTime  -> awt.multiClickInterval
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        setDesktopProperty(SunToolkit.DESKTOPFONTHINTS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                           SunToolkit.getDesktopFontHints());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        Integer dragThreshold = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
            dragThreshold = (Integer)desktopProperties.get("gnome.Net/DndDragThreshold");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
        if (dragThreshold != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
            setDesktopProperty("DnD.gestureMotionThreshold", dragThreshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
    static int altMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
    static int metaMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    static int numLockMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    static int modeSwitchMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    static int modLockIsShiftLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
    /* Like XKeysymToKeycode, but ensures that keysym is the primary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
    * symbol on the keycode returned.  Returns zero otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
    static int keysymToPrimaryKeycode(long sym) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
            int code = XlibWrapper.XKeysymToKeycode(getDisplay(), sym);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
            if (code == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
            long primary = XlibWrapper.XKeycodeToKeysym(getDisplay(), code, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
            if (sym != primary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
            return code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
    }
1966
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1660
    static boolean getModifierState( int jkc ) {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1661
        int iKeyMask = 0;
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1662
        long ks = XKeysym.javaKeycode2Keysym( jkc );
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1663
        int  kc = XlibWrapper.XKeysymToKeycode(getDisplay(), ks);
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1664
        if (kc == 0) {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1665
            return false;
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1666
        }
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1667
        awtLock();
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1668
        try {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1669
            XModifierKeymap modmap = new XModifierKeymap(
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1670
                 XlibWrapper.XGetModifierMapping(getDisplay()));
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1671
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1672
            int nkeys = modmap.get_max_keypermod();
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1673
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1674
            long map_ptr = modmap.get_modifiermap();
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1675
            for( int k = 0; k < 8; k++ ) {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1676
                for (int i = 0; i < nkeys; ++i) {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1677
                    int keycode = Native.getUByte(map_ptr, k * nkeys + i);
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1678
                    if (keycode == 0) {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1679
                        continue; // ignore zero keycode
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1680
                    }
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1681
                    if (kc == keycode) {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1682
                        iKeyMask = 1 << k;
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1683
                        break;
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1684
                    }
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1685
                }
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1686
                if( iKeyMask != 0 ) {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1687
                    break;
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1688
                }
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1689
            }
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1690
            XlibWrapper.XFreeModifiermap(modmap.pData);
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1691
            if (iKeyMask == 0 ) {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1692
                return false;
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1693
            }
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1694
            // Now we know to which modifier is assigned the keycode
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1695
            // correspondent to the keysym correspondent to the java
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1696
            // keycode. We are going to check a state of this modifier.
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1697
            // If a modifier is a weird one, we cannot help it.
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1698
            long window = 0;
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1699
            try{
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1700
                // get any application window
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1701
                window = winMap.firstKey().longValue();
1966
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1702
            }catch(NoSuchElementException nex) {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1703
                // get root window
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1704
                window = getDefaultRootWindow();
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1705
            }
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1706
            boolean res = XlibWrapper.XQueryPointer(getDisplay(), window,
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1707
                                            XlibWrapper.larg1, //root
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1708
                                            XlibWrapper.larg2, //child
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1709
                                            XlibWrapper.larg3, //root_x
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1710
                                            XlibWrapper.larg4, //root_y
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1711
                                            XlibWrapper.larg5, //child_x
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1712
                                            XlibWrapper.larg6, //child_y
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1713
                                            XlibWrapper.larg7);//mask
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1714
            int mask = Native.getInt(XlibWrapper.larg7);
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1715
            return ((mask & iKeyMask) != 0);
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1716
        } finally {
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1717
            awtUnlock();
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1718
        }
12a51fb0db0d 5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif
yan
parents: 1962
diff changeset
  1719
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
    /* Assign meaning - alt, meta, etc. - to X modifiers mod1 ... mod5.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     * Only consider primary symbols on keycodes attached to modifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
    static void setupModifierMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
        final int metaL = keysymToPrimaryKeycode(XKeySymConstants.XK_Meta_L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        final int metaR = keysymToPrimaryKeycode(XKeySymConstants.XK_Meta_R);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
        final int altL = keysymToPrimaryKeycode(XKeySymConstants.XK_Alt_L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
        final int altR = keysymToPrimaryKeycode(XKeySymConstants.XK_Alt_R);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        final int numLock = keysymToPrimaryKeycode(XKeySymConstants.XK_Num_Lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
        final int modeSwitch = keysymToPrimaryKeycode(XKeySymConstants.XK_Mode_switch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        final int shiftLock = keysymToPrimaryKeycode(XKeySymConstants.XK_Shift_Lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        final int capsLock  = keysymToPrimaryKeycode(XKeySymConstants.XK_Caps_Lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1734
        final int modmask[] = { XConstants.ShiftMask, XConstants.LockMask, XConstants.ControlMask, XConstants.Mod1Mask,
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1735
            XConstants.Mod2Mask, XConstants.Mod3Mask, XConstants.Mod4Mask, XConstants.Mod5Mask };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        log.fine("In setupModifierMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            XModifierKeymap modmap = new XModifierKeymap(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                 XlibWrapper.XGetModifierMapping(getDisplay()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            int nkeys = modmap.get_max_keypermod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            long map_ptr = modmap.get_modifiermap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
            for (int modn = XConstants.Mod1MapIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                 modn <= XConstants.Mod5MapIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                 ++modn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
                for (int i = 0; i < nkeys; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                    /* for each keycode attached to this modifier */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                    int keycode = Native.getUByte(map_ptr, modn * nkeys + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                    if (keycode == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                    if (metaMask == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
                        (keycode == metaL || keycode == metaR))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                        metaMask = modmask[modn];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                    if (altMask == 0 && (keycode == altL || keycode == altR)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                        altMask = modmask[modn];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                    if (numLockMask == 0 && keycode == numLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                        numLockMask = modmask[modn];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
                    if (modeSwitchMask == 0 && keycode == modeSwitch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                        modeSwitchMask = modmask[modn];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            modLockIsShiftLock = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
            for (int j = 0; j < nkeys; ++j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
                int keycode = Native.getUByte(map_ptr, XConstants.LockMapIndex * nkeys + j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
                if (keycode == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                if (keycode == shiftLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                    modLockIsShiftLock = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                if (keycode == capsLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
            XlibWrapper.XFreeModifiermap(modmap.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1797
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
            log.fine("metaMask = " + metaMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
            log.fine("altMask = " + altMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
            log.fine("numLockMask = " + numLockMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
            log.fine("modeSwitchMask = " + modeSwitchMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
            log.fine("modLockIsShiftLock = " + modLockIsShiftLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1807
    private static SortedMap<Long, java.util.List<Runnable>> timeoutTasks;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * Removed the task from the list of waiting-to-be called tasks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     * If the task has been scheduled several times removes only first one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
    static void remove(Runnable task) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
        if (task == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
            throw new NullPointerException("task is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
        try {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1819
            if (timeoutTaskLog.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                timeoutTaskLog.finer("Removing task " + task);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
            if (timeoutTasks == null) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1823
                if (timeoutTaskLog.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                    timeoutTaskLog.finer("Task is not scheduled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
            }
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1828
            Collection<java.util.List<Runnable>> values = timeoutTasks.values();
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1829
            Iterator<java.util.List<Runnable>> iter = values.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
            while (iter.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1831
                java.util.List<Runnable> list = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                boolean removed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                if (list.contains(task)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                    list.remove(task);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                    if (list.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                        iter.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
    static native void wakeup_poll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
     * Registers a Runnable which <code>run()</code> method will be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     * once on the toolkit thread when a specified interval of time elapses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     * @param task a Runnable which <code>run</code> method will be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     *        on the toolkit thread when <code>interval</code> milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     *        elapse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
     * @param interval an interal in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * @throws NullPointerException if <code>task</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * @throws IllegalArgumentException if <code>interval</code> is not positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
    static void schedule(Runnable task, long interval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        if (task == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
            throw new NullPointerException("task is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        if (interval <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
            throw new IllegalArgumentException("interval " + interval + " is not positive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        try {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1870
            if (timeoutTaskLog.isLoggable(PlatformLogger.Level.FINER)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  1871
                timeoutTaskLog.finer("XToolkit.schedule(): current time={0}" +
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  1872
                                     ";  interval={1}" +
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  1873
                                     ";  task being added={2}" + ";  tasks before addition={3}",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  1874
                                     Long.valueOf(System.currentTimeMillis()), Long.valueOf(interval), task, timeoutTasks);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            if (timeoutTasks == null) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1878
                timeoutTasks = new TreeMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
            Long time = Long.valueOf(System.currentTimeMillis() + interval);
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1882
            java.util.List<Runnable> tasks = timeoutTasks.get(time);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
            if (tasks == null) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1884
                tasks = new ArrayList<>(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                timeoutTasks.put(time, tasks);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
            tasks.add(task);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            if (timeoutTasks.get(timeoutTasks.firstKey()) == tasks && tasks.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                // Added task became first task - poll won't know
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                // about it so we need to wake it up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
                wakeup_poll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        }  finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
    private long getNextTaskTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
            if (timeoutTasks == null || timeoutTasks.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                return -1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
            }
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1906
            return timeoutTasks.firstKey();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     * Executes mature timeout tasks registered with schedule().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     * Called from run() under awtLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
    private static void callTimeoutTasks() {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1917
        if (timeoutTaskLog.isLoggable(PlatformLogger.Level.FINER)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  1918
            timeoutTaskLog.finer("XToolkit.callTimeoutTasks(): current time={0}" +
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  1919
                                 ";  tasks={1}", Long.valueOf(System.currentTimeMillis()), timeoutTasks);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
        if (timeoutTasks == null || timeoutTasks.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
        Long currentTime = Long.valueOf(System.currentTimeMillis());
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1927
        Long time = timeoutTasks.firstKey();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        while (time.compareTo(currentTime) <= 0) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1930
            java.util.List<Runnable> tasks = timeoutTasks.remove(time);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1932
            for (Iterator<Runnable> iter = tasks.iterator(); iter.hasNext();) {
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1933
                Runnable task = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1935
                if (timeoutTaskLog.isLoggable(PlatformLogger.Level.FINER)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  1936
                    timeoutTaskLog.finer("XToolkit.callTimeoutTasks(): current time={0}" +
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  1937
                                         ";  about to run task={1}", Long.valueOf(currentTime), task);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                    task.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
                } catch (ThreadDeath td) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                    throw td;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
                } catch (Throwable thr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                    processException(thr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
            if (timeoutTasks.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
            }
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
  1952
            time = timeoutTasks.firstKey();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
    static long getAwtDefaultFg() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
        return awt_defaultFg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
    static boolean isLeftMouseButton(MouseEvent me) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
        switch (me.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
          case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
          case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
              return (me.getButton() == MouseEvent.BUTTON1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
          case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
          case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
          case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
          case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
              return ((me.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
    static boolean isRightMouseButton(MouseEvent me) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
        int numButtons = ((Integer)getDefaultToolkit().getDesktopProperty("awt.mouse.numButtons")).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
        switch (me.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
          case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
          case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
              return ((numButtons == 2 && me.getButton() == MouseEvent.BUTTON2) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                       (numButtons > 2 && me.getButton() == MouseEvent.BUTTON3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
          case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
          case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
          case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
          case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
              return ((numButtons == 2 && (me.getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK) != 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
                      (numButtons > 2 && (me.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
    static long reset_time_utc;
5758
6fef7077b8a6 6860491: WRAP_TIME_MILLIS incorrectly set
coffeys
parents: 5506
diff changeset
  1992
    static final long WRAP_TIME_MILLIS = 0x00000000FFFFFFFFL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
     * This function converts between the X server time (number of milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
     * since the last server reset) and the UTC time for the 'when' field of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     * InputEvent (or another event type with a timestamp).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
    static long nowMillisUTC_offset(long server_offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
        // ported from awt_util.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
         * Because Time is of type 'unsigned long', it is possible that Time will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
         * never wrap when using 64-bit Xlib. However, if a 64-bit client
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
         * connects to a 32-bit server, I suspect the values will still wrap. So
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
         * we should not attempt to remove the wrap checking even if _LP64 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
         * true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
        long current_time_utc = System.currentTimeMillis();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  2010
        if (log.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
            log.finer("reset_time=" + reset_time_utc + ", current_time=" + current_time_utc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
                      + ", server_offset=" + server_offset + ", wrap_time=" + WRAP_TIME_MILLIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        if ((current_time_utc - reset_time_utc) > WRAP_TIME_MILLIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            reset_time_utc = System.currentTimeMillis() - getCurrentServerTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  2019
        if (log.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            log.finer("result = " + (reset_time_utc + server_offset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
        return reset_time_utc + server_offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
     * @see sun.awt.SunToolkit#needsXEmbedImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
    protected boolean needsXEmbedImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
        // XToolkit implements supports for XEmbed-client protocol and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
        // requires the supports from the embedding host for it to work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
    public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
        return (modalityType == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
               (modalityType == Dialog.ModalityType.MODELESS) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
               (modalityType == Dialog.ModalityType.DOCUMENT_MODAL) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
               (modalityType == Dialog.ModalityType.APPLICATION_MODAL) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
               (modalityType == Dialog.ModalityType.TOOLKIT_MODAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
    public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
        return (exclusionType == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
               (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
               (exclusionType == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
               (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
    static EventQueue getEventQueue(Object target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
        AppContext appContext = targetToAppContext(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
        if (appContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
            return (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 11083
diff changeset
  2057
    static void removeSourceEvents(EventQueue queue,
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 11083
diff changeset
  2058
                                   Object source,
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 11083
diff changeset
  2059
                                   boolean removeAllEvents) {
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 11083
diff changeset
  2060
        AWTAccessor.getEventQueueAccessor()
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 11083
diff changeset
  2061
            .removeSourceEvents(queue, source, removeAllEvents);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
    public boolean isAlwaysOnTopSupported() {
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  2065
        for (XLayerProtocol proto : XWM.getWM().getProtocols(XLayerProtocol.class)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
            if (proto.supportsLayer(XLayerProtocol.LAYER_ALWAYS_ON_TOP)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
    public boolean useBufferPerWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
        return XToolkit.getBackingStoreType() == XConstants.NotUseful;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
     * Returns one of XConstants: NotUseful, WhenMapped or Always.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
     * If backing store is not available on at least one screen, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
     * java2d uses DGA(which conflicts with backing store) on at least one screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
     * or the string system property "sun.awt.backingStore" is neither "Always"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
     * nor "WhenMapped", then the method returns XConstants.NotUseful.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
     * Otherwise, if the system property "sun.awt.backingStore" is "WhenMapped",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
     * then the method returns XConstants.WhenMapped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
     * Otherwise (i.e., if the system property "sun.awt.backingStore" is "Always"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
     * the method returns XConstants.Always.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
    static int getBackingStoreType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
        return backingStoreType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
    private static void setBackingStoreType() {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 22567
diff changeset
  2093
        String prop = AccessController.doPrivileged(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                new sun.security.action.GetPropertyAction("sun.awt.backingStore"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
        if (prop == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
            backingStoreType = XConstants.NotUseful;
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  2098
            if (backingStoreLog.isLoggable(PlatformLogger.Level.CONFIG)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
                backingStoreLog.config("The system property sun.awt.backingStore is not set" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                                       ", by default backingStore=NotUseful");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  2105
        if (backingStoreLog.isLoggable(PlatformLogger.Level.CONFIG)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
            backingStoreLog.config("The system property sun.awt.backingStore is " + prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
        prop = prop.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
        if (prop.equals("always")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
            backingStoreType = XConstants.Always;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
        } else if (prop.equals("whenmapped")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
            backingStoreType = XConstants.WhenMapped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
            backingStoreType = XConstants.NotUseful;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  2117
        if (backingStoreLog.isLoggable(PlatformLogger.Level.CONFIG)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
            backingStoreLog.config("backingStore(as provided by the system property)=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
                                   ( backingStoreType == XConstants.NotUseful ? "NotUseful"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
                                     : backingStoreType == XConstants.WhenMapped ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                                     "WhenMapped" : "Always") );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
        if (sun.java2d.x11.X11SurfaceData.isDgaAvailable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
            backingStoreType = XConstants.NotUseful;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  2127
            if (backingStoreLog.isLoggable(PlatformLogger.Level.CONFIG)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
                backingStoreLog.config("DGA is available, backingStore=NotUseful");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
            int screenCount = XlibWrapper.ScreenCount(getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
            for (int i = 0; i < screenCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                if (XlibWrapper.DoesBackingStore(XlibWrapper.ScreenOfDisplay(getDisplay(), i))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
                        == XConstants.NotUseful) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
                    backingStoreType = XConstants.NotUseful;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  2142
                    if (backingStoreLog.isLoggable(PlatformLogger.Level.CONFIG)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
                        backingStoreLog.config("Backing store is not available on the screen " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
                                               i + ", backingStore=NotUseful");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
     * One of XConstants: NotUseful, WhenMapped or Always.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
    private static int backingStoreType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
3088
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2160
    static final int XSUN_KP_BEHAVIOR = 1;
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2161
    static final int XORG_KP_BEHAVIOR = 2;
4370
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2162
    static final int    IS_SUN_KEYBOARD = 1;
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2163
    static final int IS_NONSUN_KEYBOARD = 2;
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2164
    static final int    IS_KANA_KEYBOARD = 1;
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2165
    static final int IS_NONKANA_KEYBOARD = 2;
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2166
3088
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2167
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2168
    static int     awt_IsXsunKPBehavior = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
    static boolean awt_UseXKB         = false;
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2170
    static boolean awt_UseXKB_Calls   = false;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2171
    static int     awt_XKBBaseEventCode = 0;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2172
    static int     awt_XKBEffectiveGroup = 0; // so far, I don't use it leaving all calculations
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2173
                                              // to XkbTranslateKeyCode
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2174
    static long    awt_XKBDescPtr     = 0;
3088
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2175
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
    /**
3088
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2177
     * Check for Xsun convention regarding numpad keys.
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2178
     * Xsun and some other servers (i.e. derived from Xsun)
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2179
     * under certain conditions process numpad keys unlike Xorg.
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2180
     */
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2181
    static boolean isXsunKPBehavior() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
        try {
3088
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2184
            if( awt_IsXsunKPBehavior == 0 ) {
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2185
                if( XlibWrapper.IsXsunKPBehavior(getDisplay()) ) {
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2186
                    awt_IsXsunKPBehavior = XSUN_KP_BEHAVIOR;
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2187
                }else{
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2188
                    awt_IsXsunKPBehavior = XORG_KP_BEHAVIOR;
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2189
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
            }
3088
b0260407a050 6711676: Numpad keys trigger more than one KeyEvent.
yan
parents: 3084
diff changeset
  2191
            return awt_IsXsunKPBehavior == XSUN_KP_BEHAVIOR ? true : false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
    }
4370
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2196
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2197
    static int  sunOrNotKeyboard = 0;
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2198
    static int kanaOrNotKeyboard = 0;
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2199
    static void resetKeyboardSniffer() {
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2200
        sunOrNotKeyboard  = 0;
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2201
        kanaOrNotKeyboard = 0;
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2202
    }
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2203
    static boolean isSunKeyboard() {
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2204
        if( sunOrNotKeyboard == 0 ) {
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2205
            if( XlibWrapper.IsSunKeyboard( getDisplay() )) {
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2206
                sunOrNotKeyboard = IS_SUN_KEYBOARD;
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2207
            }else{
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2208
                sunOrNotKeyboard = IS_NONSUN_KEYBOARD;
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2209
            }
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2210
        }
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2211
        return (sunOrNotKeyboard == IS_SUN_KEYBOARD);
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2212
    }
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2213
    static boolean isKanaKeyboard() {
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2214
        if( kanaOrNotKeyboard == 0 ) {
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2215
            if( XlibWrapper.IsKanaKeyboard( getDisplay() )) {
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2216
                kanaOrNotKeyboard = IS_KANA_KEYBOARD;
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2217
            }else{
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2218
                kanaOrNotKeyboard = IS_NONKANA_KEYBOARD;
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2219
            }
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2220
        }
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2221
        return (kanaOrNotKeyboard == IS_KANA_KEYBOARD);
cc409c51b108 5099725: AWT doesn't seem to handle MappingNotify events under X11.
yan
parents: 4366
diff changeset
  2222
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
    static boolean isXKBenabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
        try {
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2226
            return awt_UseXKB;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2227
        } finally {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2228
            awtUnlock();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2229
        }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2230
    }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2231
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2232
    /**
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2233
      Query XKEYBOARD extension.
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2234
      If possible, initialize xkb library.
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2235
    */
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2236
    static boolean tryXKB() {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2237
        awtLock();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2238
        try {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2239
            String name = "XKEYBOARD";
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2240
            // First, if there is extension at all.
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2241
            awt_UseXKB = XlibWrapper.XQueryExtension( getDisplay(), name, XlibWrapper.larg1, XlibWrapper.larg2, XlibWrapper.larg3);
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2242
            if( awt_UseXKB ) {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2243
                // There is a keyboard extension. Check if a client library is compatible.
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2244
                // If not, don't use xkb calls.
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2245
                // In this case we still may be Xkb-capable application.
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2246
                awt_UseXKB_Calls = XlibWrapper.XkbLibraryVersion( XlibWrapper.larg1, XlibWrapper.larg2);
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2247
                if( awt_UseXKB_Calls ) {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2248
                    awt_UseXKB_Calls = XlibWrapper.XkbQueryExtension( getDisplay(),  XlibWrapper.larg1, XlibWrapper.larg2,
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2249
                                     XlibWrapper.larg3, XlibWrapper.larg4, XlibWrapper.larg5);
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2250
                    if( awt_UseXKB_Calls ) {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2251
                        awt_XKBBaseEventCode = Native.getInt(XlibWrapper.larg2);
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2252
                        XlibWrapper.XkbSelectEvents (getDisplay(),
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2253
                                         XConstants.XkbUseCoreKbd,
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2254
                                         XConstants.XkbNewKeyboardNotifyMask |
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2255
                                                 XConstants.XkbMapNotifyMask ,//|
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2256
                                                 //XConstants.XkbStateNotifyMask,
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2257
                                         XConstants.XkbNewKeyboardNotifyMask |
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2258
                                                 XConstants.XkbMapNotifyMask );//|
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2259
                                                 //XConstants.XkbStateNotifyMask);
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2260
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2261
                        XlibWrapper.XkbSelectEventDetails(getDisplay(), XConstants.XkbUseCoreKbd,
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2262
                                                     XConstants.XkbStateNotify,
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2263
                                                     XConstants.XkbGroupStateMask,
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2264
                                                     XConstants.XkbGroupStateMask);
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2265
                                                     //XXX ? XkbGroupLockMask last, XkbAllStateComponentsMask before last?
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2266
                        awt_XKBDescPtr = XlibWrapper.XkbGetMap(getDisplay(),
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2267
                                                     XConstants.XkbKeyTypesMask    |
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2268
                                                     XConstants.XkbKeySymsMask     |
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2269
                                                     XConstants.XkbModifierMapMask |
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2270
                                                     XConstants.XkbVirtualModsMask,
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2271
                                                     XConstants.XkbUseCoreKbd);
20155
65bcc88496eb 8019282: keyRelesed is reached even though key was NOT released
serb
parents: 19807
diff changeset
  2272
65bcc88496eb 8019282: keyRelesed is reached even though key was NOT released
serb
parents: 19807
diff changeset
  2273
                        XlibWrapper.XkbSetDetectableAutoRepeat(getDisplay(), true);
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2274
                    }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2275
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
            return awt_UseXKB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
    }
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2282
    static boolean canUseXKBCalls() {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2283
        awtLock();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2284
        try {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2285
            return awt_UseXKB_Calls;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2286
        } finally {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2287
            awtUnlock();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2288
        }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2289
    }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2290
    static int getXKBEffectiveGroup() {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2291
        awtLock();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2292
        try {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2293
            return awt_XKBEffectiveGroup;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2294
        } finally {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2295
            awtUnlock();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2296
        }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2297
    }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2298
    static int getXKBBaseEventCode() {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2299
        awtLock();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2300
        try {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2301
            return awt_XKBBaseEventCode;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2302
        } finally {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2303
            awtUnlock();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2304
        }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2305
    }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2306
    static long getXKBKbdDesc() {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2307
        awtLock();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2308
        try {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2309
            return awt_XKBDescPtr;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2310
        } finally {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2311
            awtUnlock();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2312
        }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2313
    }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2314
    void freeXKB() {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2315
        awtLock();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2316
        try {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2317
            if (awt_UseXKB_Calls && awt_XKBDescPtr != 0) {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2318
                XlibWrapper.XkbFreeKeyboard(awt_XKBDescPtr, 0xFF, true);
2803
e0fa1a27f1c1 6834525: PIT: RowToleranceTransitivityTest test fail with crash on rhel4 x86 and rhel 5x86
yan
parents: 2802
diff changeset
  2319
                awt_XKBDescPtr = 0;
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2320
            }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2321
        } finally {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2322
            awtUnlock();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2323
        }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2324
    }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2325
    private void processXkbChanges(XEvent ev) {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2326
        // mapping change --> refresh kbd map
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2327
        // state change --> get a new effective group; do I really need it
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2328
        //  or that should be left for XkbTranslateKeyCode?
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2329
        XkbEvent xke = new XkbEvent( ev.getPData() );
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2330
        int xkb_type = xke.get_any().get_xkb_type();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2331
        switch( xkb_type ) {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2332
            case XConstants.XkbNewKeyboardNotify :
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2333
                 if( awt_XKBDescPtr != 0 ) {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2334
                     freeXKB();
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2335
                 }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2336
                 awt_XKBDescPtr = XlibWrapper.XkbGetMap(getDisplay(),
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2337
                                              XConstants.XkbKeyTypesMask    |
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2338
                                              XConstants.XkbKeySymsMask     |
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2339
                                              XConstants.XkbModifierMapMask |
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2340
                                              XConstants.XkbVirtualModsMask,
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2341
                                              XConstants.XkbUseCoreKbd);
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2342
                 //System.out.println("XkbNewKeyboard:"+(xke.get_new_kbd()));
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2343
                 break;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2344
            case XConstants.XkbMapNotify :
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2345
                 //TODO: provide a simple unit test.
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2346
                 XlibWrapper.XkbGetUpdatedMap(getDisplay(),
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2347
                                              XConstants.XkbKeyTypesMask    |
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2348
                                              XConstants.XkbKeySymsMask     |
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2349
                                              XConstants.XkbModifierMapMask |
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2350
                                              XConstants.XkbVirtualModsMask,
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2351
                                              awt_XKBDescPtr);
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2352
                 //System.out.println("XkbMap:"+(xke.get_map()));
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2353
                 break;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2354
            case XConstants.XkbStateNotify :
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2355
                 // May use it later e.g. to obtain an effective group etc.
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2356
                 //System.out.println("XkbState:"+(xke.get_state()));
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2357
                 break;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2358
            default:
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2359
                 //System.out.println("XkbEvent of xkb_type "+xkb_type);
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2360
                 break;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2361
        }
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 2471
diff changeset
  2362
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
    private static long eventNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
    public static long getEventNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
            return eventNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
    private static XEventDispatcher oops_waiter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
    private static boolean oops_updated;
23286
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2376
    private static boolean oops_move;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
     * @inheritDoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
    protected boolean syncNativeQueue(final long timeout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
        XBaseWindow win = XBaseWindow.getXAWTRootWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
        if (oops_waiter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
            oops_waiter = new XEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
                    public void dispatchEvent(XEvent e) {
23286
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2387
                        if (e.get_type() == XConstants.ConfigureNotify) {
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2388
                            // OOPS ConfigureNotify event catched
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2389
                            oops_updated = true;
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2390
                            awtLockNotifyAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
            addEventDispatcher(win.getWindow(), oops_waiter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
            oops_updated = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
            long event_number = getEventNumber();
23286
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2402
            // Generate OOPS ConfigureNotify event
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2403
            XlibWrapper.XMoveWindow(getDisplay(), win.getWindow(), oops_move ? 0 : 1, 0);
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2404
            // Change win position each time to avoid system optimization
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2405
            oops_move = !oops_move;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
            XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
23286
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2408
            eventLog.finer("Generated OOPS ConfigureNotify event");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
            long start = System.currentTimeMillis();
23286
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2411
            while (!oops_updated) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
                try {
23286
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2413
                    // Wait for OOPS ConfigureNotify event
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
                    awtLockWait(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
                } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
                    throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
                // This "while" is a protection from spurious
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
                // wake-ups.  However, we shouldn't wait for too long
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
                if ((System.currentTimeMillis() - start > timeout) && timeout >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
                    throw new OperationTimedOut(Long.toString(System.currentTimeMillis() - start));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
            }
23286
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2424
            // Don't take into account OOPS ConfigureNotify event
b0eb66adf69d 7033533: realSync() doesn't work with Xfce
bagiras
parents: 23285
diff changeset
  2425
            return getEventNumber() - event_number > 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
            removeEventDispatcher(win.getWindow(), oops_waiter);
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  2428
            eventLog.finer("Exiting syncNativeQueue");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
            awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
    public void grab(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        if (w.getPeer() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
            ((XWindowPeer)w.getPeer()).setGrab(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
    public void ungrab(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
        if (w.getPeer() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
           ((XWindowPeer)w.getPeer()).setGrab(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
     * Returns if the java.awt.Desktop class is supported on the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
     * desktop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
     * The methods of java.awt.Desktop class are supported on the Gnome desktop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
     * Check if the running desktop is Gnome by checking the window manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
    public boolean isDesktopSupported(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
        return XDesktopPeer.isDesktopSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
    public DesktopPeer createDesktopPeer(Desktop target){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
        return new XDesktopPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  2458
    public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  2459
        return areExtraMouseButtonsEnabled;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  2460
    }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2461
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2462
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2463
    public boolean isWindowOpacitySupported() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2464
        XNETProtocol net_protocol = XWM.getWM().getNETProtocol();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2465
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2466
        if (net_protocol == null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2467
            return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2468
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2469
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2470
        return net_protocol.doOpacityProtocol();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2471
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2472
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2473
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2474
    public boolean isWindowShapingSupported() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2475
        return XlibUtil.isShapingSupported();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2476
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2477
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2478
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2479
    public boolean isWindowTranslucencySupported() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2480
        //NOTE: it may not be supported. The actual check is being performed
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2481
        //      at com.sun.awt.AWTUtilities(). In X11 we need to check
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2482
        //      whether there's any translucency-capable GC available.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2483
        return true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2484
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2485
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2486
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2487
    public boolean isTranslucencyCapable(GraphicsConfiguration gc) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2488
        if (!(gc instanceof X11GraphicsConfig)) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2489
            return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2490
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2491
        return ((X11GraphicsConfig)gc).isTranslucencyCapable();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1970
diff changeset
  2492
    }
2471
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 2451
diff changeset
  2493
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 2451
diff changeset
  2494
    /**
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 2451
diff changeset
  2495
     * Returns the value of "sun.awt.disablegrab" property. Default
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 2451
diff changeset
  2496
     * value is {@code false}.
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 2451
diff changeset
  2497
     */
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 2451
diff changeset
  2498
    public static boolean getSunAwtDisableGrab() {
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 2451
diff changeset
  2499
        return AccessController.doPrivileged(new GetBooleanAction("sun.awt.disablegrab"));
71401ceec494 6714678: IDE (Netbeans, Eclipse, JDeveloper) Debugger hangs process on Linux
anthony
parents: 2451
diff changeset
  2500
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
}