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