jdk/src/solaris/native/sun/xawt/XToolkit.c
author art
Fri, 15 May 2009 15:40:35 +0400
changeset 2802 d05a9dcc8296
parent 2459 08f3416ff334
child 2810 fa49c6a06baf
permissions -rw-r--r--
6678385: Random java.lang.StackOverflowError from various JDKs Reviewed-by: stayer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <X11/Xlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <X11/Xutil.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <X11/Xos.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <X11/Xatom.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <execinfo.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <jvm.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <jlong.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <jni_util.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "awt_p.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include "awt_MenuComponent.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "awt_KeyboardFocusManager.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "awt_Font.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "sun_awt_X11_XToolkit.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "java_awt_SystemColor.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#include "java_awt_TrayIcon.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
uint32_t awt_NumLockMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
Boolean  awt_ModLockIsShiftLock = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
extern JavaVM *jvm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
// Tracing level
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
static int tracing = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#ifdef PRINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#undef PRINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#ifdef PRINT2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#undef PRINT2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#define PRINT if (tracing) printf
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#define PRINT2 if (tracing > 1) printf
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
struct ComponentIDs componentIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
struct MenuComponentIDs menuComponentIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
struct KeyboardFocusManagerIDs keyboardFocusManagerIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
extern Display* awt_init_Display(JNIEnv *env, jobject this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
extern struct MFontPeerIDs mFontPeerIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
Java_sun_awt_X11_XFontPeer_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    mFontPeerIDs.xfsname =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
      (*env)->GetFieldID(env, cls, "xfsname", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
/* This function gets called from the static initializer for FileDialog.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
   to initialize the fieldIDs for fields that may be accessed from C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
Java_java_awt_FileDialog_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
Java_sun_awt_X11_XToolkit_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  (JNIEnv *env, jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    jfieldID fid = (*env)->GetStaticFieldID(env, clazz, "numLockMask", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    awt_NumLockMask = (*env)->GetStaticIntField(env, clazz, fid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    DTRACE_PRINTLN1("awt_NumLockMask = %u", awt_NumLockMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    fid = (*env)->GetStaticFieldID(env, clazz, "modLockIsShiftLock", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    awt_ModLockIsShiftLock = (*env)->GetStaticIntField(env, clazz, fid) != 0 ? True : False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * Class:     sun_awt_X11_XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * Method:    getDefaultXColormap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * Signature: ()J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getDefaultXColormap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
  (JNIEnv *env, jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    AwtGraphicsConfigDataPtr defaultConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        getDefaultConfig(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    return (jlong) defaultConfig->awt_cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getDefaultScreenData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  (JNIEnv *env, jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    return ptr_to_jlong(getDefaultConfig(DefaultScreen(awt_display)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
JNI_OnLoad(JavaVM *vm, void *reserved)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    jvm = vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    return JNI_VERSION_1_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * Class:     sun_awt_X11_XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * Method:    nativeLoadSystemColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * Signature: ([I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_nativeLoadSystemColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
  (JNIEnv *env, jobject this, jintArray systemColors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    AwtGraphicsConfigDataPtr defaultConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        getDefaultConfig(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    awtJNI_CreateColorData(env, defaultConfig, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
Java_java_awt_Component_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    jclass keyclass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    componentIDs.x = (*env)->GetFieldID(env, cls, "x", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    componentIDs.y = (*env)->GetFieldID(env, cls, "y", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    componentIDs.width = (*env)->GetFieldID(env, cls, "width", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    componentIDs.height = (*env)->GetFieldID(env, cls, "height", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    componentIDs.isPacked = (*env)->GetFieldID(env, cls, "isPacked", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    componentIDs.peer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
      (*env)->GetFieldID(env, cls, "peer", "Ljava/awt/peer/ComponentPeer;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    componentIDs.background =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
      (*env)->GetFieldID(env, cls, "background", "Ljava/awt/Color;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    componentIDs.foreground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      (*env)->GetFieldID(env, cls, "foreground", "Ljava/awt/Color;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    componentIDs.graphicsConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        (*env)->GetFieldID(env, cls, "graphicsConfig",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                           "Ljava/awt/GraphicsConfiguration;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    componentIDs.name =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
      (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /* Use _NoClientCode() methods for trusted methods, so that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *  know that we are not invoking client code on trusted threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    componentIDs.getParent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
      (*env)->GetMethodID(env, cls, "getParent_NoClientCode",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                         "()Ljava/awt/Container;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    componentIDs.getLocationOnScreen =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
      (*env)->GetMethodID(env, cls, "getLocationOnScreen_NoTreeLock",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                         "()Ljava/awt/Point;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    keyclass = (*env)->FindClass(env, "java/awt/event/KeyEvent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    DASSERT (keyclass != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    componentIDs.isProxyActive =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        (*env)->GetFieldID(env, keyclass, "isProxyActive",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                           "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    componentIDs.appContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        (*env)->GetFieldID(env, cls, "appContext",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                           "Lsun/awt/AppContext;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    (*env)->DeleteLocalRef(env, keyclass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
Java_java_awt_Container_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
Java_java_awt_Button_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
Java_java_awt_Scrollbar_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
Java_java_awt_Window_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
Java_java_awt_Frame_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
Java_java_awt_MenuComponent_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    menuComponentIDs.appContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
      (*env)->GetFieldID(env, cls, "appContext", "Lsun/awt/AppContext;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
Java_java_awt_Cursor_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
JNIEXPORT void JNICALL Java_java_awt_MenuItem_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
JNIEXPORT void JNICALL Java_java_awt_Menu_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
Java_java_awt_TextArea_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
Java_java_awt_Checkbox_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
JNIEXPORT void JNICALL Java_java_awt_ScrollPane_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
Java_java_awt_TextField_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
JNIEXPORT jboolean JNICALL AWTIsHeadless() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
JNIEXPORT void JNICALL Java_java_awt_Dialog_initIDs (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
/* ========================== Begin poll section ================================ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
// Includes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
#include <sys/time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
#include <limits.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
#include <locale.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
#include <pthread.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
#include <fcntl.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
#include <poll.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
#ifndef POLLRDNORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
#define POLLRDNORM POLLIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
// Prototypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
static void     waitForEvents(JNIEnv *, jlong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
static void     awt_pipe_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
static void     processOneEvent(XtInputMask iMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
static void     performPoll(JNIEnv *, jlong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
static void     wakeUp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
static void     update_poll_timeout(int timeout_control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
static uint32_t get_poll_timeout(jlong nextTaskTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
// Defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
#ifndef bzero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
#define bzero(a,b) memset(a, 0, b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
#define AWT_POLL_BUFSIZE        100 /* bytes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
#define AWT_READPIPE            (awt_pipe_fds[0])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
#define AWT_WRITEPIPE           (awt_pipe_fds[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
#define DEF_AWT_MAX_POLL_TIMEOUT ((uint32_t)500) /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
#define DEF_AWT_FLUSH_TIMEOUT ((uint32_t)100) /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
#define AWT_MIN_POLL_TIMEOUT ((uint32_t)0) /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
#define TIMEOUT_TIMEDOUT 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
#define TIMEOUT_EVENTS 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
// Static fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
static uint32_t AWT_FLUSH_TIMEOUT  =  DEF_AWT_FLUSH_TIMEOUT; /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
static uint32_t AWT_MAX_POLL_TIMEOUT = DEF_AWT_MAX_POLL_TIMEOUT; /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
static pthread_t    awt_MainThread = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
static int32_t      awt_pipe_fds[2];                   /* fds for wkaeup pipe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
static Boolean      awt_pipe_inited = False;           /* make sure pipe is initialized before write */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
static jlong        awt_next_flush_time = 0LL; /* 0 == no scheduled flush */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
static jlong        awt_last_flush_time = 0LL; /* 0 == no scheduled flush */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
static uint32_t     curPollTimeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
static struct pollfd pollFds[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
static jlong        poll_sleep_time = 0LL; // Used for tracing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
static jlong        poll_wakeup_time = 0LL; // Used for tracing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
// AWT static poll timeout.  Zero means "not set", aging algorithm is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
// used.  Static poll timeout values higher than 50 cause application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
// look "slow" - they don't respond to user request fast
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
// enough. Static poll timeout value less than 10 are usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
// considered by schedulers as zero, so this might cause unnecessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
// CPU consumption by Java.  The values between 10 - 50 are suggested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
// for single client desktop configurations.  For SunRay servers, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
// is highly recomended to use aging algorithm (set static poll timeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
// to 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
static int32_t static_poll_timeout = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
static Bool isMainThread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    return awt_MainThread == pthread_self();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
 * Creates the AWT utility pipe. This pipe exists solely so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
 * we can cause the main event thread to wake up from a poll() or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
 * select() by writing to this pipe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
awt_pipe_init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    if (awt_pipe_inited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    if ( pipe ( awt_pipe_fds ) == 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        ** the write wakes us up from the infinite sleep, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        ** then we cause a delay of AWT_FLUSHTIME and then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        ** flush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        int32_t flags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        /* set the pipe to be non-blocking */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        flags = fcntl ( AWT_READPIPE, F_GETFL, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        fcntl( AWT_READPIPE, F_SETFL, flags | O_NDELAY | O_NONBLOCK );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        flags = fcntl ( AWT_WRITEPIPE, F_GETFL, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        fcntl( AWT_WRITEPIPE, F_SETFL, flags | O_NDELAY | O_NONBLOCK );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        awt_pipe_inited = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        AWT_READPIPE = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        AWT_WRITEPIPE = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
} /* awt_pipe_init() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
 * Reads environment variables to initialize timeout fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
static void readEnv() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    char * value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    static Boolean env_read = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    if (env_read) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    env_read = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    value = getenv("_AWT_MAX_POLL_TIMEOUT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        AWT_MAX_POLL_TIMEOUT = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if (AWT_MAX_POLL_TIMEOUT == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            AWT_MAX_POLL_TIMEOUT = DEF_AWT_MAX_POLL_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    curPollTimeout = AWT_MAX_POLL_TIMEOUT/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    value = getenv("_AWT_FLUSH_TIMEOUT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        AWT_FLUSH_TIMEOUT = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        if (AWT_FLUSH_TIMEOUT == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            AWT_FLUSH_TIMEOUT = DEF_AWT_FLUSH_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    value = getenv("_AWT_POLL_TRACING");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        tracing = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    value = getenv("_AWT_STATIC_POLL_TIMEOUT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        static_poll_timeout = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    if (static_poll_timeout != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        curPollTimeout = static_poll_timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
 * Returns the amount of milliseconds similar to System.currentTimeMillis()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
static jlong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
awtJNI_TimeMillis(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    struct timeval t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    gettimeofday(&t, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    return jlong_add(jlong_mul(jint_to_jlong(t.tv_sec), jint_to_jlong(1000)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
             jint_to_jlong(t.tv_usec / 1000));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
 * Updates curPollTimeout according to the aging algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
 * @param timeout_control Either TIMEOUT_TIMEDOUT or TIMEOUT_EVENTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
static void update_poll_timeout(int timeout_control) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    PRINT2("tout: %d\n", timeout_control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    // If static_poll_timeout is set, curPollTimeout has the fixed value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    if (static_poll_timeout != 0) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    // Update it otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    if (timeout_control == TIMEOUT_TIMEDOUT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        /* add 1/4 (plus 1, in case the division truncates to 0) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        curPollTimeout += ((curPollTimeout>>2) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        curPollTimeout = min(AWT_MAX_POLL_TIMEOUT, curPollTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    } else if (timeout_control == TIMEOUT_EVENTS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        /* subtract 1/4 (plus 1, in case the division truncates to 0) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        curPollTimeout -= ((curPollTimeout>>2) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        curPollTimeout = max(AWT_MIN_POLL_TIMEOUT, curPollTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
 * Gets the best timeout for the next call to poll().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
 * @param nextTaskTime -1, if there are no tasks; next time when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
 * timeout task needs to be run, in millis(of currentTimeMillis)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
static uint32_t get_poll_timeout(jlong nextTaskTime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    jlong curTime = awtJNI_TimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    uint32_t timeout = curPollTimeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    uint32_t taskTimeout = (nextTaskTime == -1) ? AWT_MAX_POLL_TIMEOUT : (uint32_t)max(0, (int32_t)(nextTaskTime - curTime));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    uint32_t flushTimeout = (awt_next_flush_time > 0) ? (uint32_t)max(0, (int32_t)(awt_next_flush_time - curTime)) : AWT_MAX_POLL_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    PRINT2("to: %d, ft: %d, to: %d, tt: %d, mil: %d\n", taskTimeout, flushTimeout, timeout, (int)nextTaskTime, (int)curTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    // Adjust timeout to flush_time and task_time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    return min(flushTimeout, min(taskTimeout, timeout));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
} /* awt_get_poll_timeout() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
 * Waits for X/Xt events to appear on the pipe. Returns only when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
 * it is likely (but not definite) that there are events waiting to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
 * be processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
 * This routine also flushes the outgoing X queue, when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
 * awt_next_flush_time has been reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
 * If fdAWTPipe is greater or equal than zero the routine also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
 * checks if there are events pending on the putback queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
waitForEvents(JNIEnv *env, jlong nextTaskTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    performPoll(env, nextTaskTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    if ((awt_next_flush_time > 0) && (awtJNI_TimeMillis() >= awt_next_flush_time)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        XFlush(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        awt_last_flush_time = awt_next_flush_time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        awt_next_flush_time = 0LL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
} /* waitForEvents() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_waitForEvents (JNIEnv *env, jclass class, jlong nextTaskTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    waitForEvents(env, nextTaskTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_awt_1toolkit_1init (JNIEnv *env, jclass class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    awt_MainThread = pthread_self();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    awt_pipe_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    readEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_awt_1output_1flush (JNIEnv *env, jclass class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    awt_output_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_wakeup_1poll (JNIEnv *env, jclass class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    wakeUp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
 * Polls both the X pipe and our AWT utility pipe. Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
 * when there is data on one of the pipes, or the operation times
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
 * out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
 * Not all Xt events come across the X pipe (e.g., timers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
 * and alternate inputs), so we must time out every now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
 * then to check the Xt event queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
 * The fdAWTPipe will be empty when this returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
performPoll(JNIEnv *env, jlong nextTaskTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    static Bool pollFdsInited = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    static char read_buf[AWT_POLL_BUFSIZE + 1];    /* dummy buf to empty pipe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    uint32_t timeout = get_poll_timeout(nextTaskTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    int32_t result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    if (!pollFdsInited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        pollFds[0].fd = ConnectionNumber(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        pollFds[0].events = POLLRDNORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        pollFds[0].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        pollFds[1].fd = AWT_READPIPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        pollFds[1].events = POLLRDNORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        pollFds[1].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        pollFdsInited = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        pollFds[0].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        pollFds[1].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    AWT_NOFLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    /* ACTUALLY DO THE POLL() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    if (timeout == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        // be sure other threads get a chance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        awtJNI_ThreadYield(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    if (tracing) poll_sleep_time = awtJNI_TimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    result = poll( pollFds, 2, (int32_t) timeout );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    if (tracing) poll_wakeup_time = awtJNI_TimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    PRINT("%d of %d, res: %d\n", (int)(poll_wakeup_time-poll_sleep_time), (int)timeout, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    if (result == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        /* poll() timed out -- update timeout value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        update_poll_timeout(TIMEOUT_TIMEDOUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    if (pollFds[1].revents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        PRINT("Woke up\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        /* There is data on the AWT pipe - empty it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            count = read(AWT_READPIPE, read_buf, AWT_POLL_BUFSIZE );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        } while (count == AWT_POLL_BUFSIZE );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    if (pollFds[0].revents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        // Events in X pipe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        update_poll_timeout(TIMEOUT_EVENTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
} /* performPoll() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
 * Schedules next auto-flush event or performs forced flush depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
 * on the time of the previous flush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
void awt_output_flush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    if (awt_next_flush_time == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        jlong curTime = awtJNI_TimeMillis(); // current time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        jlong l_awt_last_flush_time = awt_last_flush_time; // last time we flushed queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        jlong next_flush_time = l_awt_last_flush_time + AWT_FLUSH_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (curTime >= next_flush_time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            // Enough time passed from last flush
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            PRINT("f1\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            XFlush(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            awt_last_flush_time = curTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            AWT_NOFLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            awt_next_flush_time = next_flush_time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            PRINT("f2\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            wakeUp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
 * Wakes-up poll() in performPoll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
static void wakeUp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    static char wakeUp_char = 'p';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    if (!isMainThread() && awt_pipe_inited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        write ( AWT_WRITEPIPE, &wakeUp_char, 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
/* ========================== End poll section ================================= */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
 * Class:     java_awt_KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
Java_java_awt_KeyboardFocusManager_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
 * Class:     sun_awt_X11_XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
 * Method:    getEnv
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
 * Signature: (Ljava/lang/String;)Ljava/lang/String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
JNIEXPORT jstring JNICALL Java_sun_awt_X11_XToolkit_getEnv
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
(JNIEnv *env , jclass clazz, jstring key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    char *ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    const char *keystr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    jstring ret = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    keystr = JNU_GetStringPlatformChars(env, key, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    if (key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        ptr = getenv(keystr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        if (ptr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            ret = JNU_NewStringPlatform(env, (const char *) ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        JNU_ReleaseStringPlatformChars(env, key, (const char*)keystr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
void print_stack(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
  void *array[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
  size_t size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
  char **strings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
  size_t i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
  size = backtrace (array, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
  strings = backtrace_symbols (array, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
  fprintf (stderr, "Obtained %zd stack frames.\n", size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
  for (i = 0; i < size; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     fprintf (stderr, "%s\n", strings[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
  free (strings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
Window get_xawt_root_shell(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
  static jclass classXRootWindow = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
  static jmethodID methodGetXRootWindow = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
  static Window xawt_root_shell = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
  if (xawt_root_shell == None){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
      if (classXRootWindow == NULL){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
          jclass cls_tmp = (*env)->FindClass(env, "sun/awt/X11/XRootWindow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
          classXRootWindow = (jclass)(*env)->NewGlobalRef(env, cls_tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
          (*env)->DeleteLocalRef(env, cls_tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
      if( classXRootWindow != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
          methodGetXRootWindow = (*env)->GetStaticMethodID(env, classXRootWindow, "getXRootWindow", "()J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
      if( classXRootWindow != NULL && methodGetXRootWindow !=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
          xawt_root_shell = (Window) (*env)->CallStaticLongMethod(env, classXRootWindow, methodGetXRootWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
      if ((*env)->ExceptionCheck(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
  return xawt_root_shell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
 * Old, compatibility, backdoor for DT.  This is a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
 * implementation.  It keeps the signature, but acts on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
 * awt_root_shell, not the frame passed as an argument.  Note, that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
 * the code that uses the old backdoor doesn't work correctly with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
 * gnome session proxy that checks for WM_COMMAND when the window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
 * firts mapped, because DT code calls this old backdoor *after* the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
 * frame is shown or it would get NPE with old AWT (previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
 * implementation of this backdoor) otherwise.  Old style session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
 * managers (e.g. CDE) that check WM_COMMAND only during session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
 * checkpoint should work fine, though.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
 * NB: The function name looks deceptively like a JNI native method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
 * name.  It's not!  It's just a plain function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    jobject frame, jstring jcommand)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    const char *command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    XTextProperty text_prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    char *c[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    int32_t status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    Window xawt_root_window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    xawt_root_window = get_xawt_root_shell(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    if ( xawt_root_window == None ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        JNU_ThrowNullPointerException(env, "AWT root shell is unrealized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    command = (char *) JNU_GetStringPlatformChars(env, jcommand, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    c[0] = (char *)command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    status = XmbTextListToTextProperty(awt_display, c, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                                       XStdICCTextStyle, &text_prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    if (status == Success || status > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        XSetTextProperty(awt_display, xawt_root_window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                         &text_prop, XA_WM_COMMAND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        if (text_prop.value != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            XFree(text_prop.value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    JNU_ReleaseStringPlatformChars(env, jcommand, command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
 * New DT backdoor to set WM_COMMAND.  New code should use this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
 * backdoor and call it *before* the first frame is shown so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
 * gnome session proxy can correctly handle it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
 * NB: The function name looks deceptively like a JNI native method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
 * name.  It's not!  It's just a plain function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jargv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    static const char empty[] = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    int argc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    const char **cargv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    XTextProperty text_prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    int status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    Window xawt_root_window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    xawt_root_window = get_xawt_root_shell(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    if (xawt_root_window == None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
      JNU_ThrowNullPointerException(env, "AWT root shell is unrealized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
      AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    argc = (int)(*env)->GetArrayLength(env, jargv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    if (argc == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    /* array of C strings */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    cargv = (const char **)calloc(argc, sizeof(char *));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    if (cargv == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        JNU_ThrowOutOfMemoryError(env, "Unable to allocate cargv");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    /* fill C array with platform chars of java strings */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
      for (i = 0; i < argc; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        jstring js;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        const char *cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        cs = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        js = (*env)->GetObjectArrayElement(env, jargv, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        if (js != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            cs = JNU_GetStringPlatformChars(env, js, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        if (cs == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            cs = empty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        cargv[i] = cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        (*env)->DeleteLocalRef(env, js);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    /* grr, X prototype doesn't declare cargv as const, thought it really is */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    status = XmbTextListToTextProperty(awt_display, (char **)cargv, argc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                                       XStdICCTextStyle, &text_prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    if (status < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        switch (status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        case XNoMemory:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            JNU_ThrowOutOfMemoryError(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                "XmbTextListToTextProperty: XNoMemory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        case XLocaleNotSupported:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            JNU_ThrowInternalError(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                "XmbTextListToTextProperty: XLocaleNotSupported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        case XConverterNotFound:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            JNU_ThrowNullPointerException(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                "XmbTextListToTextProperty: XConverterNotFound");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            JNU_ThrowInternalError(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                "XmbTextListToTextProperty: unknown error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    XSetTextProperty(awt_display, xawt_root_window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                         &text_prop, XA_WM_COMMAND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    for (i = 0; i < argc; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        jstring js;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        if (cargv[i] == empty)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        js = (*env)->GetObjectArrayElement(env, jargv, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        JNU_ReleaseStringPlatformChars(env, js, cargv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        (*env)->DeleteLocalRef(env, js);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    if (text_prop.value != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        XFree(text_prop.value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
 * Class:     java_awt_TrayIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
JNIEXPORT void JNICALL Java_java_awt_TrayIcon_initIDs(JNIEnv *env , jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
 * Class:     java_awt_Cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
 * Method:    finalizeImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
Java_java_awt_Cursor_finalizeImpl(JNIEnv *env, jclass clazz, jlong pData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    Cursor xcursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    xcursor = (Cursor)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    if (xcursor != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        XFreeCursor(awt_display, xcursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
}