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