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