/* * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package sun.awt.motif; import java.awt.*; import java.awt.im.InputMethodHighlight; import java.awt.im.spi.InputMethodDescriptor; import java.awt.image.*; import java.awt.peer.*; import java.awt.datatransfer.Clipboard; import java.awt.event.*; import java.lang.reflect.*; import java.lang.Math; import java.io.*; import java.security.AccessController; import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.Properties; import java.util.Map; import java.util.Iterator; import sun.awt.AppContext; import sun.awt.AWTAutoShutdown; import sun.awt.SunToolkit; import sun.awt.UNIXToolkit; import sun.awt.GlobalCursorManager; import sun.awt.datatransfer.DataTransferer; import java.awt.dnd.DragSource; import java.awt.dnd.DragGestureListener; import java.awt.dnd.DragGestureEvent; import java.awt.dnd.DragGestureRecognizer; import java.awt.dnd.MouseDragGestureRecognizer; import java.awt.dnd.InvalidDnDOperationException; import java.awt.dnd.peer.DragSourceContextPeer; //import sun.awt.motif.MInputMethod; import sun.awt.X11FontManager; import sun.awt.X11GraphicsConfig; import sun.awt.X11GraphicsEnvironment; import sun.awt.XSettings; //import sun.awt.motif.MDragSourceContextPeer; import sun.print.PrintJob2D; import sun.misc.PerformanceLogger; import sun.misc.Unsafe; import sun.security.action.GetBooleanAction; import sun.util.logging.PlatformLogger; public class MToolkit extends UNIXToolkit implements Runnable { private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.motif.MToolkit"); // the system clipboard - CLIPBOARD selection //X11Clipboard clipboard; // the system selection - PRIMARY selection //X11Clipboard selection; // Dynamic Layout Resize client code setting protected static boolean dynamicLayoutSetting = false; /** * True when the x settings have been loaded. */ private boolean loadedXSettings; /** * XSETTINGS for the default screen. *
* XXX: see
* NB: This could be called from any thread if triggered by
* MToolkit.parseXSettings
* and awt_xsettings_update
in
* awt_MToolkit.c
*/
private XSettings xs;
/*
* Note: The MToolkit object depends on the static initializer
* of X11GraphicsEnvironment to initialize the connection to
* the X11 server.
*/
static final X11GraphicsConfig config;
private static final boolean motifdnd;
static {
if (GraphicsEnvironment.isHeadless()) {
config = null;
} else {
config = (X11GraphicsConfig) (GraphicsEnvironment.
getLocalGraphicsEnvironment().
getDefaultScreenDevice().
getDefaultConfiguration());
}
/* Add font properties font directories to the X11 font path.
* Its called here *after* the X connection has been initialised
* and when we know that MToolkit is the one that will be used,
* since XToolkit doesn't need the X11 font path set
*/
X11FontManager.getInstance().setNativeFontPath();
motifdnd = ((Boolean)java.security.AccessController.doPrivileged(
new GetBooleanAction("awt.dnd.motifdnd"))).booleanValue();
}
//public static final String DATA_TRANSFERER_CLASS_NAME = "sun.awt.motif.MDataTransferer";
public MToolkit() {
super();
if (PerformanceLogger.loggingEnabled()) {
PerformanceLogger.setTime("MToolkit construction");
}
if (!GraphicsEnvironment.isHeadless()) {
String mainClassName = null;
StackTraceElement trace[] = (new Throwable()).getStackTrace();
int bottom = trace.length - 1;
if (bottom >= 0) {
mainClassName = trace[bottom].getClassName();
}
if (mainClassName == null || mainClassName.equals("")) {
mainClassName = "AWT";
}
init(mainClassName);
//SunToolkit.setDataTransfererClassName(DATA_TRANSFERER_CLASS_NAME);
Thread toolkitThread = new Thread(this, "AWT-Motif");
toolkitThread.setPriority(Thread.NORM_PRIORITY + 1);
toolkitThread.setDaemon(true);
PrivilegedActiondata
is the byte array directly from the x server and
* may be in little endian format.
* loadXSettings
. It is called from the toolkit
* thread if triggered by an XSETTINGS change.
*/
private void parseXSettings(int screen_XXX_ignored, byte[] data) {
// XXX: notyet: map screen -> per screen XSettings object
// for now native code only calls us for default screen
// see awt_MToolkit.c awt_xsettings_update().
if (xs == null) {
xs = new XSettings();
}
Map updatedSettings = xs.update(data);
if (updatedSettings == null || updatedSettings.isEmpty()) {
return;
}
Iterator i = updatedSettings.entrySet().iterator();
while (i.hasNext()) {
Map.Entry e = (Map.Entry)i.next();
String name = (String)e.getKey();
name = "gnome." + name;
setDesktopProperty(name, e.getValue());
// XXX: we probably want to do something smarter. In
// particular, "Net" properties are of interest to the
// "core" AWT itself. E.g.
//
// Net/DndDragThreshold -> ???
// Net/DoubleClickTime -> awt.multiClickInterval
}
setDesktopProperty(SunToolkit.DESKTOPFONTHINTS,
SunToolkit.getDesktopFontHints());
Integer dragThreshold = null;
synchronized (this) {
dragThreshold = (Integer)desktopProperties.get("gnome.Net/DndDragThreshold");
}
if (dragThreshold != null) {
setDesktopProperty("DnD.gestureMotionThreshold", dragThreshold);
}
}
protected boolean needsXEmbedImpl() {
return true;
}
public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
return (modalityType == Dialog.ModalityType.MODELESS) ||
(modalityType == Dialog.ModalityType.APPLICATION_MODAL);
}
public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
return (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE);
}
private native boolean isSyncUpdated();
private native boolean isSyncFailed();
private native int getEventNumber();
private native void updateSyncSelection();
private static final long WORKAROUND_SLEEP = 100;
/**
* @inheritDoc
*/
protected boolean syncNativeQueue(final long timeout) {
awtLock();
try {
long event_number = getEventNumber();
updateSyncSelection();
// Wait for selection notify for oops on win
long start = System.currentTimeMillis();
while (!isSyncUpdated() && !isSyncFailed()) {
try {
awtLockWait(timeout);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// This "while" is a protection from spurious
// wake-ups. However, we shouldn't wait for too long
if (((System.currentTimeMillis() - start) > timeout) && (timeout >= 0)) {
throw new OperationTimedOut();
}
}
if (isSyncFailed() && getEventNumber() - event_number == 1) {
awtUnlock();
try {
Thread.sleep(WORKAROUND_SLEEP);
} catch (InterruptedException ie) {
throw new RuntimeException(ie);
} finally {
awtLock();
}
}
return getEventNumber() - event_number > 2;
} finally {
awtUnlock();
}
}
public void grab(Window w) {
WindowPeer peer = (WindowPeer)w.getPeer();
if (peer != null) {
nativeGrab(peer);
}
}
public void ungrab(Window w) {
WindowPeer peer = (WindowPeer)w.getPeer();
if (peer != null) {
nativeUnGrab(peer);
}
}
private native void nativeGrab(WindowPeer peer);
private native void nativeUnGrab(WindowPeer peer);
public boolean isDesktopSupported(){
return false;
}
public DesktopPeer createDesktopPeer(Desktop target)
throws HeadlessException{
throw new UnsupportedOperationException();
}
public final static int
UNDETERMINED_WM = 1,
NO_WM = 2,
OTHER_WM = 3,
OPENLOOK_WM = 4,
MOTIF_WM = 5,
CDE_WM = 6,
ENLIGHTEN_WM = 7,
KDE2_WM = 8,
SAWFISH_WM = 9,
ICE_WM = 10,
METACITY_WM = 11,
COMPIZ_WM = 12,
LG3D_WM = 13;
public static int getWMID() {
String wmName = getWMName();
if ("NO_WM".equals(wmName)) {
return NO_WM;
} else if ("OTHER_WM".equals(wmName)) {
return OTHER_WM;
} else if ("ENLIGHTEN_WM".equals(wmName)) {
return ENLIGHTEN_WM;
} else if ("KDE2_WM".equals(wmName)) {
return KDE2_WM;
} else if ("SAWFISH_WM".equals(wmName)) {
return SAWFISH_WM;
} else if ("ICE_WM".equals(wmName)) {
return ICE_WM;
} else if ("METACITY_WM".equals(wmName)) {
return METACITY_WM;
} else if ("OPENLOOK_WM".equals(wmName)) {
return OPENLOOK_WM;
} else if ("MOTIF_WM".equals(wmName)) {
return MOTIF_WM;
} else if ("CDE_WM".equals(wmName)) {
return CDE_WM;
} else if ("COMPIZ_WM".equals(wmName)) {
return COMPIZ_WM;
} else if ("LG3D_WM".equals(wmName)) {
return LG3D_WM;
}
return UNDETERMINED_WM;
}
private static native String getWMName();
} // class MToolkit