blob: 3a71353c1f7ed0e45d343429b7c95bef5a7308b8 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.awt.motif;
27
28import java.awt.*;
29import java.awt.im.InputMethodHighlight;
30import java.awt.im.spi.InputMethodDescriptor;
31import java.awt.image.*;
32import java.awt.peer.*;
33import java.awt.datatransfer.Clipboard;
34import java.awt.event.*;
35import java.lang.reflect.*;
36import java.lang.Math;
37import java.io.*;
38import java.security.AccessController;
39import java.security.PrivilegedAction;
40import java.security.PrivilegedActionException;
41import java.security.PrivilegedExceptionAction;
42
43import java.util.Properties;
44import java.util.Map;
45import java.util.Iterator;
46import java.util.logging.*;
47
48import sun.awt.AppContext;
49import sun.awt.AWTAutoShutdown;
50import sun.awt.SunToolkit;
51import sun.awt.UNIXToolkit;
52import sun.awt.GlobalCursorManager;
53import sun.awt.datatransfer.DataTransferer;
54
55import java.awt.dnd.DragSource;
56import java.awt.dnd.DragGestureListener;
57import java.awt.dnd.DragGestureEvent;
58import java.awt.dnd.DragGestureRecognizer;
59import java.awt.dnd.MouseDragGestureRecognizer;
60import java.awt.dnd.InvalidDnDOperationException;
61import java.awt.dnd.peer.DragSourceContextPeer;
62
63import sun.awt.motif.MInputMethod;
64import sun.awt.X11GraphicsConfig;
65import sun.awt.X11GraphicsEnvironment;
66import sun.awt.XSettings;
67
68import sun.awt.motif.MDragSourceContextPeer;
69
70import sun.print.PrintJob2D;
71
72import sun.misc.PerformanceLogger;
73import sun.misc.Unsafe;
74
75import sun.security.action.GetBooleanAction;
76
77public class MToolkit extends UNIXToolkit implements Runnable {
78
79 private static final Logger log = Logger.getLogger("sun.awt.motif.MToolkit");
80
81 // the system clipboard - CLIPBOARD selection
82 X11Clipboard clipboard;
83 // the system selection - PRIMARY selection
84 X11Clipboard selection;
85
86 // Dynamic Layout Resize client code setting
87 protected static boolean dynamicLayoutSetting = false;
88
89 /**
90 * True when the x settings have been loaded.
91 */
92 private boolean loadedXSettings;
93
94 /**
95 * XSETTINGS for the default screen.
96 * <p>
97 * <strong>XXX:</strong> see <code>MToolkit.parseXSettings</code>
98 * and <code>awt_xsettings_update</code> in
99 * <samp>awt_MToolkit.c</samp>
100 */
101 private XSettings xs;
102
103 /*
104 * Note: The MToolkit object depends on the static initializer
105 * of X11GraphicsEnvironment to initialize the connection to
106 * the X11 server.
107 */
108 static final X11GraphicsConfig config;
109
110 private static final boolean motifdnd;
111
112 static {
113 if (GraphicsEnvironment.isHeadless()) {
114 config = null;
115 } else {
116 config = (X11GraphicsConfig) (GraphicsEnvironment.
117 getLocalGraphicsEnvironment().
118 getDefaultScreenDevice().
119 getDefaultConfiguration());
120 }
121
122 /* Add font properties font directories to the X11 font path.
123 * Its called here *after* the X connection has been initialised
124 * and when we know that MToolkit is the one that will be used,
125 * since XToolkit doesn't need the X11 font path set
126 */
127 X11GraphicsEnvironment.setNativeFontPath();
128
129 motifdnd = ((Boolean)java.security.AccessController.doPrivileged(
130 new GetBooleanAction("awt.dnd.motifdnd"))).booleanValue();
131 }
132
133 public static final String DATA_TRANSFERER_CLASS_NAME = "sun.awt.motif.MDataTransferer";
134
135 public MToolkit() {
136 super();
137 if (PerformanceLogger.loggingEnabled()) {
138 PerformanceLogger.setTime("MToolkit construction");
139 }
140 if (!GraphicsEnvironment.isHeadless()) {
141 String mainClassName = null;
142
143 StackTraceElement trace[] = (new Throwable()).getStackTrace();
144 int bottom = trace.length - 1;
145 if (bottom >= 0) {
146 mainClassName = trace[bottom].getClassName();
147 }
148 if (mainClassName == null || mainClassName.equals("")) {
149 mainClassName = "AWT";
150 }
151
152 init(mainClassName);
153 SunToolkit.setDataTransfererClassName(DATA_TRANSFERER_CLASS_NAME);
154
155 Thread toolkitThread = new Thread(this, "AWT-Motif");
156 toolkitThread.setPriority(Thread.NORM_PRIORITY + 1);
157 toolkitThread.setDaemon(true);
158 ThreadGroup mainTG = (ThreadGroup)AccessController.doPrivileged(
159 new PrivilegedAction() {
160 public Object run() {
161 ThreadGroup currentTG =
162 Thread.currentThread().getThreadGroup();
163 ThreadGroup parentTG = currentTG.getParent();
164 while (parentTG != null) {
165 currentTG = parentTG;
166 parentTG = currentTG.getParent();
167 }
168 return currentTG;
169 }
170 });
171
172 Runtime.getRuntime().addShutdownHook(
173 new Thread(mainTG, new Runnable() {
174 public void run() {
175 shutdown();
176 }
177 }, "Shutdown-Thread")
178 );
179
180 /*
181 * Fix for 4701990.
182 * AWTAutoShutdown state must be changed before the toolkit thread
183 * starts to avoid race condition.
184 */
185 AWTAutoShutdown.notifyToolkitThreadBusy();
186
187 toolkitThread.start();
188 }
189 }
190
191 public native void init(String mainClassName);
192 public native void run();
193 private native void shutdown();
194
195 /*
196 * Create peer objects.
197 */
198
199 public ButtonPeer createButton(Button target) {
200 ButtonPeer peer = new MButtonPeer(target);
201 targetCreatedPeer(target, peer);
202 return peer;
203 }
204
205 public TextFieldPeer createTextField(TextField target) {
206 TextFieldPeer peer = new MTextFieldPeer(target);
207 targetCreatedPeer(target, peer);
208 return peer;
209 }
210
211 public LabelPeer createLabel(Label target) {
212 LabelPeer peer = new MLabelPeer(target);
213 targetCreatedPeer(target, peer);
214 return peer;
215 }
216
217 public ListPeer createList(List target) {
218 ListPeer peer = new MListPeer(target);
219 targetCreatedPeer(target, peer);
220 return peer;
221 }
222
223 public CheckboxPeer createCheckbox(Checkbox target) {
224 CheckboxPeer peer = new MCheckboxPeer(target);
225 targetCreatedPeer(target, peer);
226 return peer;
227 }
228
229 public ScrollbarPeer createScrollbar(Scrollbar target) {
230 ScrollbarPeer peer = new MScrollbarPeer(target);
231 targetCreatedPeer(target, peer);
232 return peer;
233 }
234
235 public ScrollPanePeer createScrollPane(ScrollPane target) {
236 ScrollPanePeer peer = new MScrollPanePeer(target);
237 targetCreatedPeer(target, peer);
238 return peer;
239 }
240
241 public TextAreaPeer createTextArea(TextArea target) {
242 TextAreaPeer peer = new MTextAreaPeer(target);
243 targetCreatedPeer(target, peer);
244 return peer;
245 }
246
247 public ChoicePeer createChoice(Choice target) {
248 ChoicePeer peer = new MChoicePeer(target);
249 targetCreatedPeer(target, peer);
250 return peer;
251 }
252
253 public FramePeer createFrame(Frame target) {
254 FramePeer peer = new MFramePeer(target);
255 targetCreatedPeer(target, peer);
256 return peer;
257 }
258
259 public CanvasPeer createCanvas(Canvas target) {
260 CanvasPeer peer = (isXEmbedServerRequested() ? new MEmbedCanvasPeer(target) : new MCanvasPeer(target));
261 targetCreatedPeer(target, peer);
262 return peer;
263 }
264
265 public PanelPeer createPanel(Panel target) {
266 PanelPeer peer = new MPanelPeer(target);
267 targetCreatedPeer(target, peer);
268 return peer;
269 }
270
271 public WindowPeer createWindow(Window target) {
272 WindowPeer peer = new MWindowPeer(target);
273 targetCreatedPeer(target, peer);
274 return peer;
275 }
276
277 public DialogPeer createDialog(Dialog target) {
278 DialogPeer peer = new MDialogPeer(target);
279 targetCreatedPeer(target, peer);
280 return peer;
281 }
282
283 public FileDialogPeer createFileDialog(FileDialog target) {
284 FileDialogPeer peer = new MFileDialogPeer(target);
285 targetCreatedPeer(target, peer);
286 return peer;
287 }
288
289 public MenuBarPeer createMenuBar(MenuBar target) {
290 MenuBarPeer peer = new MMenuBarPeer(target);
291 targetCreatedPeer(target, peer);
292 return peer;
293 }
294
295 public MenuPeer createMenu(Menu target) {
296 MenuPeer peer = new MMenuPeer(target);
297 targetCreatedPeer(target, peer);
298 return peer;
299 }
300
301 public PopupMenuPeer createPopupMenu(PopupMenu target) {
302 PopupMenuPeer peer = new MPopupMenuPeer(target);
303 targetCreatedPeer(target, peer);
304 return peer;
305 }
306
307 public MenuItemPeer createMenuItem(MenuItem target) {
308 MenuItemPeer peer = new MMenuItemPeer(target);
309 targetCreatedPeer(target, peer);
310 return peer;
311 }
312
313 public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) {
314 CheckboxMenuItemPeer peer = new MCheckboxMenuItemPeer(target);
315 targetCreatedPeer(target, peer);
316 return peer;
317 }
318
319 public MEmbeddedFramePeer createEmbeddedFrame(MEmbeddedFrame target)
320 {
321 MEmbeddedFramePeer peer = new MEmbeddedFramePeer(target);
322 targetCreatedPeer(target, peer);
323 return peer;
324 }
325
326
327 public FontPeer getFontPeer(String name, int style){
328 return new MFontPeer(name, style);
329 }
330
331 /*
332 * On X, support for dynamic layout on resizing is governed by the
333 * window manager. If the window manager supports it, it happens
334 * automatically. The setter method for this property is
335 * irrelevant on X.
336 */
337 public void setDynamicLayout(boolean b) {
338 dynamicLayoutSetting = b;
339 }
340
341 protected boolean isDynamicLayoutSet() {
342 return dynamicLayoutSetting;
343 }
344
345 /* Called from isDynamicLayoutActive() and from
346 * lazilyLoadDynamicLayoutSupportedProperty()
347 */
348 protected native boolean isDynamicLayoutSupportedNative();
349
350 public boolean isDynamicLayoutActive() {
351 return isDynamicLayoutSupportedNative();
352 }
353
354 public native boolean isFrameStateSupported(int state);
355
356 public TrayIconPeer createTrayIcon(TrayIcon target) throws HeadlessException {
357 return null;
358 }
359
360 public SystemTrayPeer createSystemTray(SystemTray target) throws HeadlessException {
361 return null;
362 }
363
364 public boolean isTraySupported() {
365 return false;
366 }
367
368 static native ColorModel makeColorModel();
369 static ColorModel screenmodel;
370
371 static ColorModel getStaticColorModel() {
372 if (screenmodel == null) {
373 screenmodel = config.getColorModel ();
374 }
375 return screenmodel;
376 }
377
378 public ColorModel getColorModel() {
379 return getStaticColorModel();
380 }
381
382 public native int getScreenResolution();
383
384 public Insets getScreenInsets(GraphicsConfiguration gc) {
385 return new Insets(0,0,0,0);
386 }
387
388 protected native int getScreenWidth();
389 protected native int getScreenHeight();
390
391 public FontMetrics getFontMetrics(Font font) {
392 /*
393 // REMIND: platform font flag should be obsolete soon
394 if (!RasterOutputManager.usesPlatformFont()) {
395 return super.getFontMetrics(font);
396 } else {
397 return X11FontMetrics.getFontMetrics(font);
398 }
399 */
400 return super.getFontMetrics(font);
401 }
402
403 public PrintJob getPrintJob(final Frame frame, final String doctitle,
404 final Properties props) {
405
406 if (GraphicsEnvironment.isHeadless()) {
407 throw new IllegalArgumentException();
408 }
409
410 PrintJob2D printJob = new PrintJob2D(frame, doctitle, props);
411
412 if (printJob.printDialog() == false) {
413 printJob = null;
414 }
415
416 return printJob;
417 }
418
419 public PrintJob getPrintJob(final Frame frame, final String doctitle,
420 final JobAttributes jobAttributes,
421 final PageAttributes pageAttributes) {
422
423
424 if (GraphicsEnvironment.isHeadless()) {
425 throw new IllegalArgumentException();
426 }
427
428 PrintJob2D printJob = new PrintJob2D(frame, doctitle,
429 jobAttributes, pageAttributes);
430
431 if (printJob.printDialog() == false) {
432 printJob = null;
433 }
434
435 return printJob;
436 }
437
438 public native void beep();
439
440 public Clipboard getSystemClipboard() {
441 SecurityManager security = System.getSecurityManager();
442 if (security != null) {
443 security.checkSystemClipboardAccess();
444 }
445 synchronized (this) {
446 if (clipboard == null) {
447 clipboard = new X11Clipboard("System", "CLIPBOARD");
448 }
449 }
450 return clipboard;
451 }
452
453 public Clipboard getSystemSelection() {
454 SecurityManager security = System.getSecurityManager();
455 if (security != null) {
456 security.checkSystemClipboardAccess();
457 }
458 synchronized (this) {
459 if (selection == null) {
460 selection = new X11Clipboard("Selection", "PRIMARY");
461 }
462 }
463 return selection;
464 }
465
466 public boolean getLockingKeyState(int key) {
467 if (! (key == KeyEvent.VK_CAPS_LOCK || key == KeyEvent.VK_NUM_LOCK ||
468 key == KeyEvent.VK_SCROLL_LOCK || key == KeyEvent.VK_KANA_LOCK)) {
469 throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
470 }
471 return getLockingKeyStateNative(key);
472 }
473
474 public native boolean getLockingKeyStateNative(int key);
475
476 public native void loadSystemColors(int[] systemColors);
477
478 /**
479 * Give native peers the ability to query the native container
480 * given a native component (e.g. the direct parent may be lightweight).
481 */
482 public static Container getNativeContainer(Component c) {
483 return Toolkit.getNativeContainer(c);
484 }
485
486 protected static final Object targetToPeer(Object target) {
487 return SunToolkit.targetToPeer(target);
488 }
489
490 protected static final void targetDisposedPeer(Object target, Object peer) {
491 SunToolkit.targetDisposedPeer(target, peer);
492 }
493
494 public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
495 if (MToolkit.useMotifDnD()) {
496 return MDragSourceContextPeer.createDragSourceContextPeer(dge);
497 } else {
498 return X11DragSourceContextPeer.createDragSourceContextPeer(dge);
499 }
500 }
501
502 public <T extends DragGestureRecognizer> T
503 createDragGestureRecognizer(Class<T> abstractRecognizerClass,
504 DragSource ds, Component c, int srcActions,
505 DragGestureListener dgl)
506 {
507 if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass))
508 return (T)new MMouseDragGestureRecognizer(ds, c, srcActions, dgl);
509 else
510 return null;
511 }
512
513 /**
514 * Returns a new input method adapter descriptor for native input methods.
515 */
516 public InputMethodDescriptor getInputMethodAdapterDescriptor() throws AWTException {
517 return new MInputMethodDescriptor();
518 }
519
520 /**
521 * Returns a style map for the input method highlight.
522 */
523 public Map mapInputMethodHighlight(InputMethodHighlight highlight) {
524 return MInputMethod.mapInputMethodHighlight(highlight);
525 }
526
527 /**
528 * Returns a new custom cursor.
529 */
530 public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
531 throws IndexOutOfBoundsException {
532 return new MCustomCursor(cursor, hotSpot, name);
533 }
534
535 /**
536 * Returns the supported cursor size
537 */
538 public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) {
539 return MCustomCursor.getBestCursorSize(
540 java.lang.Math.max(1,preferredWidth), java.lang.Math.max(1,preferredHeight));
541 }
542
543 public int getMaximumCursorColors() {
544 return 2; // Black and white.
545 }
546
547 private final static String prefix = "DnD.Cursor.";
548 private final static String postfix = ".32x32";
549 private static final String dndPrefix = "DnD.";
550
551 protected Object lazilyLoadDesktopProperty(String name) {
552 if (name.startsWith(prefix)) {
553 String cursorName = name.substring(prefix.length(), name.length()) + postfix;
554
555 try {
556 return Cursor.getSystemCustomCursor(cursorName);
557 } catch (AWTException awte) {
558 System.err.println("cannot load system cursor: " + cursorName);
559
560 return null;
561 }
562 }
563
564 if (name.equals("awt.dynamicLayoutSupported")) {
565 return lazilyLoadDynamicLayoutSupportedProperty(name);
566 }
567
568 if (!loadedXSettings &&
569 (name.startsWith("gnome.") ||
570 name.equals(SunToolkit.DESKTOPFONTHINTS) ||
571 name.startsWith(dndPrefix))) {
572 loadedXSettings = true;
573 if (!GraphicsEnvironment.isHeadless()) {
574 loadXSettings();
575 desktopProperties.put(SunToolkit.DESKTOPFONTHINTS,
576 SunToolkit.getDesktopFontHints());
577 return desktopProperties.get(name);
578 }
579 }
580
581 return super.lazilyLoadDesktopProperty(name);
582 }
583
584 /*
585 * Called from lazilyLoadDesktopProperty because we may not know if
586 * the user has quit the previous window manager and started another.
587 */
588 protected Boolean lazilyLoadDynamicLayoutSupportedProperty(String name) {
589 boolean nativeDynamic = isDynamicLayoutSupportedNative();
590
591 if (log.isLoggable(Level.FINER)) {
592 log.log(Level.FINER, "nativeDynamic == " + nativeDynamic);
593 }
594
595 return Boolean.valueOf(nativeDynamic);
596 }
597
598 private native int getMulticlickTime();
599 private native int getNumMouseButtons();
600
601 protected void initializeDesktopProperties() {
602 desktopProperties.put("DnD.Autoscroll.initialDelay", Integer.valueOf(50));
603 desktopProperties.put("DnD.Autoscroll.interval", Integer.valueOf(50));
604 desktopProperties.put("DnD.Autoscroll.cursorHysteresis", Integer.valueOf(5));
605
606 /* As of 1.4, no wheel mice are supported on Solaris
607 * however, they are on Linux, and there isn't a way to detect them,
608 * so we leave this property unset to indicate we're not sure if there's
609 * a wheel mouse or not.
610 */
611 //desktopProperties.put("awt.wheelMousePresent", Boolean.valueOf(false));
612
613 // We don't want to call getMultilclickTime() if we're headless
614 if (!GraphicsEnvironment.isHeadless()) {
615 desktopProperties.put("awt.multiClickInterval",
616 Integer.valueOf(getMulticlickTime()));
617 desktopProperties.put("awt.mouse.numButtons",
618 Integer.valueOf(getNumMouseButtons()));
619 }
620 }
621
622 public RobotPeer createRobot(Robot target, GraphicsDevice screen) {
623 /* 'target' is unused for now... */
624 return new MRobotPeer(screen.getDefaultConfiguration());
625 }
626
627 static boolean useMotifDnD() {
628 return motifdnd;
629 }
630
631 //
632 // The following support Gnome's equivalent of desktop properties.
633 // A writeup of this can be found at:
634 // http://www.freedesktop.org/standards/xsettings/xsettings.html
635 //
636
637 /**
638 * Triggers a callback to parseXSettings with the x settings values
639 * from the window server. Note that this will NOT call
640 * parseXSettings if we are not running on a GNOME desktop.
641 */
642 private native void loadXSettings();
643
644 /**
645 * Callback from the native side indicating some, or all, of the
646 * desktop properties have changed and need to be reloaded.
647 * <code>data</code> is the byte array directly from the x server and
648 * may be in little endian format.
649 * <p>
650 * NB: This could be called from any thread if triggered by
651 * <code>loadXSettings</code>. It is called from the toolkit
652 * thread if triggered by an XSETTINGS change.
653 */
654 private void parseXSettings(int screen_XXX_ignored, byte[] data) {
655 // XXX: notyet: map screen -> per screen XSettings object
656 // for now native code only calls us for default screen
657 // see awt_MToolkit.c awt_xsettings_update().
658 if (xs == null) {
659 xs = new XSettings();
660 }
661
662 Map updatedSettings = xs.update(data);
663 if (updatedSettings == null || updatedSettings.isEmpty()) {
664 return;
665 }
666
667 Iterator i = updatedSettings.entrySet().iterator();
668 while (i.hasNext()) {
669 Map.Entry e = (Map.Entry)i.next();
670 String name = (String)e.getKey();
671
672 name = "gnome." + name;
673 setDesktopProperty(name, e.getValue());
674
675 // XXX: we probably want to do something smarter. In
676 // particular, "Net" properties are of interest to the
677 // "core" AWT itself. E.g.
678 //
679 // Net/DndDragThreshold -> ???
680 // Net/DoubleClickTime -> awt.multiClickInterval
681 }
682
683 setDesktopProperty(SunToolkit.DESKTOPFONTHINTS,
684 SunToolkit.getDesktopFontHints());
685
686 Integer dragThreshold = null;
687 synchronized (this) {
688 dragThreshold = (Integer)desktopProperties.get("gnome.Net/DndDragThreshold");
689 }
690 if (dragThreshold != null) {
691 setDesktopProperty("DnD.gestureMotionThreshold", dragThreshold);
692 }
693 }
694
695 protected boolean needsXEmbedImpl() {
696 return true;
697 }
698
699 public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
700 return (modalityType == Dialog.ModalityType.MODELESS) ||
701 (modalityType == Dialog.ModalityType.APPLICATION_MODAL);
702 }
703
704 public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
705 return (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE);
706 }
707
708 private native boolean isSyncUpdated();
709 private native boolean isSyncFailed();
710 private native int getEventNumber();
711 private native void updateSyncSelection();
712 private static final long WORKAROUND_SLEEP = 100;
713
714 /**
715 * @inheritDoc
716 */
717 protected boolean syncNativeQueue(final long timeout) {
718 awtLock();
719 try {
720 long event_number = getEventNumber();
721 updateSyncSelection();
722
723 // Wait for selection notify for oops on win
724 long start = System.currentTimeMillis();
725 while (!isSyncUpdated() && !isSyncFailed()) {
726 try {
727 awtLockWait(timeout);
728 } catch (InterruptedException e) {
729 throw new RuntimeException(e);
730 }
731 // This "while" is a protection from spurious
732 // wake-ups. However, we shouldn't wait for too long
733 if (((System.currentTimeMillis() - start) > timeout) && (timeout >= 0)) {
734 throw new OperationTimedOut();
735 }
736 }
737 if (isSyncFailed() && getEventNumber() - event_number == 1) {
738 awtUnlock();
739 try {
740 Thread.sleep(WORKAROUND_SLEEP);
741 } catch (InterruptedException ie) {
742 throw new RuntimeException(ie);
743 } finally {
744 awtLock();
745 }
746 }
747 return getEventNumber() - event_number > 2;
748 } finally {
749 awtUnlock();
750 }
751 }
752
753 public void grab(Window w) {
754 WindowPeer peer = (WindowPeer)w.getPeer();
755 if (peer != null) {
756 nativeGrab(peer);
757 }
758 }
759
760 public void ungrab(Window w) {
761 WindowPeer peer = (WindowPeer)w.getPeer();
762 if (peer != null) {
763 nativeUnGrab(peer);
764 }
765 }
766 private native void nativeGrab(WindowPeer peer);
767 private native void nativeUnGrab(WindowPeer peer);
768
769
770 public boolean isDesktopSupported(){
771 return false;
772 }
773
774 public DesktopPeer createDesktopPeer(Desktop target)
775 throws HeadlessException{
776 throw new UnsupportedOperationException();
777 }
778
779 public final static int
780 UNDETERMINED_WM = 1,
781 NO_WM = 2,
782 OTHER_WM = 3,
783 OPENLOOK_WM = 4,
784 MOTIF_WM = 5,
785 CDE_WM = 6,
786 ENLIGHTEN_WM = 7,
787 KDE2_WM = 8,
788 SAWFISH_WM = 9,
789 ICE_WM = 10,
790 METACITY_WM = 11,
791 COMPIZ_WM = 12,
792 LG3D_WM = 13;
793
794 public static int getWMID() {
795 String wmName = getWMName();
796
797 if ("NO_WM".equals(wmName)) {
798 return NO_WM;
799 } else if ("OTHER_WM".equals(wmName)) {
800 return OTHER_WM;
801 } else if ("ENLIGHTEN_WM".equals(wmName)) {
802 return ENLIGHTEN_WM;
803 } else if ("KDE2_WM".equals(wmName)) {
804 return KDE2_WM;
805 } else if ("SAWFISH_WM".equals(wmName)) {
806 return SAWFISH_WM;
807 } else if ("ICE_WM".equals(wmName)) {
808 return ICE_WM;
809 } else if ("METACITY_WM".equals(wmName)) {
810 return METACITY_WM;
811 } else if ("OPENLOOK_WM".equals(wmName)) {
812 return OPENLOOK_WM;
813 } else if ("MOTIF_WM".equals(wmName)) {
814 return MOTIF_WM;
815 } else if ("CDE_WM".equals(wmName)) {
816 return CDE_WM;
817 } else if ("COMPIZ_WM".equals(wmName)) {
818 return COMPIZ_WM;
819 } else if ("LG3D_WM".equals(wmName)) {
820 return LG3D_WM;
821 }
822 return UNDETERMINED_WM;
823 }
824
825 private static native String getWMName();
826
827} // class MToolkit