XToolkit.c revision 1225
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved.
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * This code is free software; you can redistribute it and/or modify it
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * under the terms of the GNU General Public License version 2 only, as
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * published by the Free Software Foundation. Sun designates this
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * particular file as subject to the "Classpath" exception as provided
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * by Sun in the LICENSE file that accompanied this code.
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * This code is distributed in the hope that it will be useful, but WITHOUT
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * version 2 for more details (a copy is included in the LICENSE file that
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * accompanied this code).
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * You should have received a copy of the GNU General Public License version
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * 2 along with this work; if not, write to the Free Software Foundation,
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * CA 95054 USA or visit www.sun.com if you need additional information or
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * have any questions.
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne// Tracing level
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Brownestatic int tracing = 0;
da94b90a76ad985d8b442a0571f96a2cf8e1d551Elizabeth Brownestruct KeyboardFocusManagerIDs keyboardFocusManagerIDs;
d5b7485f164e9584d8b84bd882cb8df10c61bfa9Elizabeth Browneextern Display* awt_init_Display(JNIEnv *env, jobject this);
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne (*env)->GetFieldID(env, cls, "xfsname", "Ljava/lang/String;");
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne#endif /* !HEADLESS */
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne/* This function gets called from the static initializer for FileDialog.java
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne to initialize the fieldIDs for fields that may be accessed from C */
95f6a8dff82d34449590f9a50ccc70df924d5a8fJason Browne jfieldID fid = (*env)->GetStaticFieldID(env, clazz, "numLockMask", "I");
95f6a8dff82d34449590f9a50ccc70df924d5a8fJason Browne awt_NumLockMask = (*env)->GetStaticIntField(env, clazz, fid);
95f6a8dff82d34449590f9a50ccc70df924d5a8fJason Browne DTRACE_PRINTLN1("awt_NumLockMask = %u", awt_NumLockMask);
95f6a8dff82d34449590f9a50ccc70df924d5a8fJason Browne fid = (*env)->GetStaticFieldID(env, clazz, "modLockIsShiftLock", "I");
95f6a8dff82d34449590f9a50ccc70df924d5a8fJason Browne awt_ModLockIsShiftLock = (*env)->GetStaticIntField(env, clazz, fid) != 0 ? True : False;
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * Class: sun_awt_X11_XToolkit
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * Method: getDefaultXColormap
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * Signature: ()J
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth BrowneJNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getDefaultXColormap
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth BrowneJNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getDefaultScreenData
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne return ptr_to_jlong(getDefaultConfig(DefaultScreen(awt_display)));
cbbe3a4aab44b4352cec9dac8831028f16c392d2Elizabeth Browne * Class: sun_awt_X11_XToolkit
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne * Method: nativeLoadSystemColors
cbbe3a4aab44b4352cec9dac8831028f16c392d2Elizabeth Browne * Signature: ([I)V
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth BrowneJNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_nativeLoadSystemColors
c54f5c9f018cfaf6792ae351d3f0be15efdd175eJake Feasel (JNIEnv *env, jobject this, jintArray systemColors)
d5b7485f164e9584d8b84bd882cb8df10c61bfa9Elizabeth Browne getDefaultConfig(DefaultScreen(awt_display));
d5b7485f164e9584d8b84bd882cb8df10c61bfa9Elizabeth Browne componentIDs.x = (*env)->GetFieldID(env, cls, "x", "I");
d5b7485f164e9584d8b84bd882cb8df10c61bfa9Elizabeth Browne componentIDs.y = (*env)->GetFieldID(env, cls, "y", "I");
d5b7485f164e9584d8b84bd882cb8df10c61bfa9Elizabeth Browne componentIDs.width = (*env)->GetFieldID(env, cls, "width", "I");
95f6a8dff82d34449590f9a50ccc70df924d5a8fJason Browne componentIDs.height = (*env)->GetFieldID(env, cls, "height", "I");
95f6a8dff82d34449590f9a50ccc70df924d5a8fJason Browne componentIDs.isPacked = (*env)->GetFieldID(env, cls, "isPacked", "Z");
d5b7485f164e9584d8b84bd882cb8df10c61bfa9Elizabeth Browne (*env)->GetFieldID(env, cls, "peer", "Ljava/awt/peer/ComponentPeer;");
4e74818e3d2f5b362c256e8d08ea2da2222f7a4bJake Feasel (*env)->GetFieldID(env, cls, "background", "Ljava/awt/Color;");
d5b7485f164e9584d8b84bd882cb8df10c61bfa9Elizabeth Browne (*env)->GetFieldID(env, cls, "foreground", "Ljava/awt/Color;");
4e74818e3d2f5b362c256e8d08ea2da2222f7a4bJake Feasel (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;");
4e74818e3d2f5b362c256e8d08ea2da2222f7a4bJake Feasel /* Use _NoClientCode() methods for trusted methods, so that we
da94b90a76ad985d8b442a0571f96a2cf8e1d551Elizabeth Browne * know that we are not invoking client code on trusted threads
48ddd46e9e22ee57a7fb400c6296f977c11173b3Elizabeth Browne (*env)->GetMethodID(env, cls, "getParent_NoClientCode",
"Lsun/awt/AppContext;");
#ifdef HEADLESS
return JNI_TRUE;
return JNI_FALSE;
#include <limits.h>
#include <locale.h>
#include <pthread.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <poll.h>
#ifndef POLLRDNORM
static void awt_pipe_init();
static void wakeUp();
#ifndef bzero
#define TIMEOUT_TIMEDOUT 0
awt_pipe_init() {
if (awt_pipe_inited) {
static void readEnv() {
char * value;
if (env_read) return;
if (AWT_MAX_POLL_TIMEOUT == 0) {
if (AWT_FLUSH_TIMEOUT == 0) {
if (static_poll_timeout != 0) {
* Returns the amount of milliseconds similar to System.currentTimeMillis()
static jlong
awtJNI_TimeMillis(void)
struct timeval t;
gettimeofday(&t, 0);
if (static_poll_timeout != 0) return;
uint32_t taskTimeout = (nextTaskTime == -1) ? AWT_MAX_POLL_TIMEOUT : (uint32_t)max(0, (int32_t)(nextTaskTime - curTime));
uint32_t flushTimeout = (awt_next_flush_time > 0) ? (uint32_t)max(0, (int32_t)(awt_next_flush_time - curTime)) : AWT_MAX_POLL_TIMEOUT;
PRINT2("to: %d, ft: %d, to: %d, tt: %d, mil: %d\n", taskTimeout, flushTimeout, timeout, (int)nextTaskTime, (int)curTime);
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_waitForEvents (JNIEnv *env, jclass class, jlong nextTaskTime) {
readEnv();
wakeUp();
if (!pollFdsInited) {
if (timeout == 0) {
AWT_LOCK();
if (result == 0) {
int count;
void awt_output_flush() {
if (awt_next_flush_time == 0) {
AWT_LOCK();
wakeUp();
static void wakeUp() {
if (key) {
if (ptr) {
return ret;
#ifdef __linux__
void print_stack(void)
char **strings;
size_t i;
for (i = 0; i < size; i++)
xawt_root_shell = (Window) (*env)->CallStaticLongMethod(env, classXRootWindow, methodGetXRootWindow);
return xawt_root_shell;
const char *command;
AWT_LOCK();
AWT_UNLOCK();
c[0] = (char *)command;
AWT_UNLOCK();
int argc;
const char **cargv;
int status;
AWT_LOCK();
AWT_UNLOCK();
if (argc == 0) {
AWT_UNLOCK();
AWT_UNLOCK();
for (i = 0; i < argc; ++i) {
const char *cs;
if (status < 0) {
switch (status) {
case XNoMemory:
case XLocaleNotSupported:
case XConverterNotFound:
for (i = 0; i < argc; ++i) {
AWT_UNLOCK();
AWT_LOCK();
AWT_UNLOCK();
if (num_buttons == 0) {
return num_buttons;
DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XINPUT) returns major_opcode = %d, first_event = %d, first_error = %d",
if (xinputAvailable) {
#ifdef IsXExtensionPointer
if (local_num_buttons <= 0 ) {
DTRACE_PRINTLN1("RobotPeer: XINPUT extension is unavailable, assuming %d mouse buttons", num_buttons);
if (local_num_buttons == 0 ) {
return local_num_buttons;