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