XToolkit.java revision 1045
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * Copyright 2002-2009 Sun Microsystems, Inc. All Rights Reserved.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * This code is free software; you can redistribute it and/or modify it
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * under the terms of the GNU General Public License version 2 only, as
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * published by the Free Software Foundation. Sun designates this
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * particular file as subject to the "Classpath" exception as provided
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * by Sun in the LICENSE file that accompanied this code.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * This code is distributed in the hope that it will be useful, but WITHOUT
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * version 2 for more details (a copy is included in the LICENSE file that
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * accompanied this code).
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * You should have received a copy of the GNU General Public License version
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * 2 along with this work; if not, write to the Free Software Foundation,
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * CA 95054 USA or visit www.sun.com if you need additional information or
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * have any questions.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenkimport java.awt.dnd.InvalidDnDOperationException;
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenkimport java.lang.reflect.InvocationTargetException;
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenkpublic final class XToolkit extends UNIXToolkit implements Runnable {
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk private static Logger log = Logger.getLogger("sun.awt.X11.XToolkit");
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk private static Logger eventLog = Logger.getLogger("sun.awt.X11.event.XToolkit");
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk private static final Logger timeoutTaskLog = Logger.getLogger("sun.awt.X11.timeoutTask.XToolkit");
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk private static Logger keyEventLog = Logger.getLogger("sun.awt.X11.kye.XToolkit");
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk private static final Logger backingStoreLog = Logger.getLogger("sun.awt.X11.backingStore.XToolkit");
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk //There is 400 ms is set by default on Windows and 500 by default on KDE and GNOME.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk //We use the same hardcoded constant.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk private final static int AWT_MULTICLICK_DEFAULT_TIME = 500;
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk static final boolean PRIMARY_LOOP = false;
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk static final boolean SECONDARY_LOOP = true;
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk // the system clipboard - CLIPBOARD selection
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk // the system selection - PRIMARY selection
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk // Dynamic Layout Resize client code setting
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk protected static boolean dynamicLayoutSetting = false;
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk //Is it allowed to generate events assigned to extra mouse buttons.
dbcf55756e293292dfbfbb75fe317dd094b0585fjeff.schenk //Set to true by default.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk private static boolean areExtraMouseButtonsEnabled = true;
dbcf55756e293292dfbfbb75fe317dd094b0585fjeff.schenk * Number of buttons.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * By default it's taken from the system. If system value does not
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * fit into int type range, use our own MAX_BUTTONS_SUPPORT value.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk /* XFree standard mention 24 buttons as maximum:
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * We workaround systems supporting more than 24 buttons.
dbcf55756e293292dfbfbb75fe317dd094b0585fjeff.schenk * Otherwise, we have to use long type values as masks
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * which leads to API change.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * True when the x settings have been loaded.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk private boolean loadedXSettings;
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * XSETTINGS for the default screen.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk private static long _display;
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk // WeakSet should be used here, but there is no such class
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk // in JDK (at least in JDK6 and earlier versions)
dbcf55756e293292dfbfbb75fe317dd094b0585fjeff.schenk private WeakHashMap<Window, Boolean> overrideRedirectWindows =
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk private static int screenWidth = -1, screenHeight = -1; // Dimensions of default screen
initIDs();
m_removeSourceEvents = SunToolkit.getMethod(EventQueue.class, "removeSourceEvents", new Class[] {Object.class, Boolean.TYPE}) ;
static long saved_error_handler;
XSync();
static void RESTORE_XERROR_HANDLER() {
XSync();
interface XErrorHandler {
private native static void initIDs();
static boolean isToolkitThread() {
static void initSecurityWarning() {
static boolean isSecurityWarningEnabled() {
return securityWarningEnabled;
static native void awt_output_flush();
static final void awtFUnlock() {
awtUnlock();
return uidefaults;
static void initUIDefaults() {
catch (Exception e)
e.printStackTrace();
public static long getDisplay() {
return _display;
public static long getDefaultRootWindow() {
awtLock();
return res;
awtUnlock();
void init() {
awtLock();
areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
awtUnlock();
public void run() {
dumpPeers();
return val;
return awtAppClassName;
public XToolkit() {
init();
new PrivilegedAction() {
return currentTG;
return peer;
return peer;
synchronized(winMap) {
synchronized(winMap) {
synchronized(winMap) {
synchronized(winToDispatcher) {
synchronized(winToDispatcher) {
awtLock();
awtUnlock();
awtLock();
awtUnlock();
awtLock();
awtUnlock();
awtLock();
awtUnlock();
public interface XEventListener {
synchronized (listeners) {
synchronized (listeners) {
(ev.get_type() == XConstants.MotionNotify || ev.get_type() == XConstants.EnterNotify || ev.get_type() == XConstants.LeaveNotify))
synchronized(winToDispatcher) {
static native void awt_toolkit_init();
public void run() {
awtLock();
eventNumber++;
if( keyEventLog.isLoggable(Level.FINE) && (ev.get_type() == XConstants.KeyPress || ev.get_type() == XConstants.KeyRelease) ) {
if( keyEventLog.isLoggable(Level.FINE) && (ev.get_type() == XConstants.KeyPress || ev.get_type() == XConstants.KeyRelease) ) {
awtUnlock();
static int getDefaultScreenWidth() {
awtLock();
awtUnlock();
return screenWidth;
static int getDefaultScreenHeight() {
awtLock();
awtUnlock();
return screenHeight;
protected int getScreenWidth() {
return getDefaultScreenWidth();
protected int getScreenHeight() {
return getDefaultScreenHeight();
if (workareaPresent)
return null;
workArea.x,
boolean strutPresent = XA_NET_WM_STRUT_PARTIAL.getAtomData(window, XAtom.XA_CARDINAL, native_ptr, 4);
if (!strutPresent)
if (strutPresent)
return insets;
if (p != null) return p;
public void setDynamicLayout(boolean b) {
dynamicLayoutSetting = b;
protected boolean isDynamicLayoutSet() {
return dynamicLayoutSetting;
protected boolean isDynamicLayoutSupported() {
public boolean isDynamicLayoutActive() {
return isDynamicLayoutSupported();
public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
public <T extends DragGestureRecognizer> T
Component c,
int srcActions,
return null;
return peer;
return peer;
return peer;
return peer;
return peer;
return peer;
return peer;
return peer;
return peer;
return peer;
XCanvasPeer peer = (isXEmbedServerRequested() ? new XEmbedCanvasPeer(target) : new XCanvasPeer(target));
return peer;
return peer;
return peer;
return peer;
return peer;
return peer;
return peer;
return peer;
return xPeer;
return peer;
return peer;
public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) throws HeadlessException {
return peer;
throws IndexOutOfBoundsException {
return peer;
return peer;
public boolean isTraySupported() {
public int getMaximumCursorColors() {
awtLock();
awtUnlock();
return clipboard;
return selection;
public void beep() {
awtLock();
awtUnlock();
throw new IllegalArgumentException();
return printJob;
throw new IllegalArgumentException();
return printJob;
static void XSync() {
awtLock();
awtUnlock();
public int getScreenResolution() {
awtLock();
awtUnlock();
static native long getDefaultXColormap();
static native long getDefaultScreenData();
return screenmodel;
return getStaticColorModel();
return new XInputMethodDescriptor();
static int getMultiClickTime() {
return awt_multiclick_time;
static void initializeMultiClickTime() {
awtLock();
String multiclick_time_query = XlibWrapper.XGetDefault(XToolkit.getDisplay(), "*", "multiClickTime");
awtUnlock();
throws HeadlessException
synchronized (overrideRedirectWindows) {
synchronized (overrideRedirectWindows) {
static void dumpPeers() {
private static boolean initialized;
private static boolean timeStampUpdated;
private static long timeStamp;
new XEventDispatcher() {
awtLock();
timeStampUpdated = true;
awtUnlock();
static long getCurrentServerTime() {
awtLock();
if (!initialized) {
initialized = true;
timeStampUpdated = false;
if (isToolkitThread()) {
while (!timeStampUpdated) {
awtLockWait();
if (log.isLoggable(Level.FINE)) log.fine("Catched exception, timeStamp may not be correct (ie = " + ie + ")");
awtUnlock();
return timeStamp;
protected void initializeDesktopProperties() {
public static int getNumMouseButtons() {
awtLock();
return numberOfButtons;
awtUnlock();
if (!loadedXSettings &&
loadedXSettings = true;
/* set the fontconfig/KDE property so that
hint);
private void loadXSettings() {
while (i.hasNext()) {
// Net/DndDragThreshold -> ???
// Net/DoubleClickTime -> awt.multiClickInterval
static int altMask;
static int metaMask;
static int numLockMask;
static int modeSwitchMask;
static int modLockIsShiftLock;
awtLock();
return code;
awtUnlock();
awtLock();
awtUnlock();
static void setupModifierMap() {
final int modmask[] = { XConstants.ShiftMask, XConstants.LockMask, XConstants.ControlMask, XConstants.Mod1Mask,
awtLock();
++modn)
awtUnlock();
awtLock();
boolean removed = false;
awtUnlock();
static native void wakeup_poll();
awtLock();
wakeup_poll();
awtUnlock();
private long getNextTaskTime() {
awtLock();
awtUnlock();
private static void callTimeoutTasks() {
throw td;
static long getAwtDefaultFg() {
return awt_defaultFg;
int numButtons = ((Integer)getDefaultToolkit().getDesktopProperty("awt.mouse.numButtons")).intValue();
static long reset_time_utc;
protected boolean needsXEmbedImpl() {
return null;
catch (IllegalAccessException e)
e.printStackTrace();
catch (InvocationTargetException e) {
e.printStackTrace();
public boolean isAlwaysOnTopSupported() {
public boolean useBufferPerWindow() {
static int getBackingStoreType() {
return backingStoreType;
private static void setBackingStoreType() {
awtLock();
awtUnlock();
private static int backingStoreType;
static boolean awt_ServerInquired = false;
static boolean awt_IsXsunServer = false;
static boolean awt_XKBInquired = false;
static boolean awt_UseXKB = false;
static boolean isXsunServer() {
awtLock();
if( awt_ServerInquired ) {
return awt_IsXsunServer;
awt_ServerInquired = true;
awt_IsXsunServer = false;
awt_ServerInquired = true;
awt_IsXsunServer = false;
awt_ServerInquired = true;
awt_IsXsunServer = true;
awtUnlock();
static boolean isXKBenabled() {
awtLock();
if( awt_XKBInquired ) {
return awt_UseXKB;
awt_XKBInquired = true;
awt_UseXKB = XlibWrapper.XQueryExtension( getDisplay(), name, XlibWrapper.larg1, XlibWrapper.larg2, XlibWrapper.larg3);
return awt_UseXKB;
awtUnlock();
private static long eventNumber;
public static long getEventNumber() {
awtLock();
return eventNumber;
awtUnlock();
private static boolean oops_updated;
private static boolean oops_failed;
oops_updated = true;
oops_failed = true;
awtLock();
oops_updated = false;
oops_failed = false;
eventLog.log(Level.FINER, "WM_S0 selection owner {0}", new Object[] {XlibWrapper.XGetSelectionOwner(getDisplay(), atom.getAtom())});
XSync();
} catch (InterruptedException e) {
throw new RuntimeException(e);
awtUnlock();
awtLock();
awtUnlock();
public boolean isDesktopSupported(){
return new XDesktopPeer();
public static native void setNoisyXErrorHandler();
return areExtraMouseButtonsEnabled;
public boolean isWindowOpacitySupported() {
public boolean isWindowShapingSupported() {
public boolean isWindowTranslucencySupported() {