jdk/src/solaris/native/sun/xawt/XToolkit.c
author dcherepanov
Mon, 27 Dec 2010 18:43:55 +0300
changeset 7770 8a5fd008f98b
parent 5506 202f599c92aa
child 9035 1255eb81cc2f
child 9002 6ee0abf0167f
permissions -rw-r--r--
6866808: nsk/stress/jck12a/jck12a014 crashes with SIGSEGV at [libjvm.so+0xc5b10] Reviewed-by: art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4260
diff changeset
     2
 * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4260
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4260
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4260
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4260
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4260
diff changeset
    23
 * questions.
2
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"
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
    48
#include <X11/extensions/XTest.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
uint32_t awt_NumLockMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
Boolean  awt_ModLockIsShiftLock = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
    53
static int32_t num_buttons = 0;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
    54
int32_t getNumButtons();
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
    55
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
extern JavaVM *jvm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
// Tracing level
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
static int tracing = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#ifdef PRINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
#undef PRINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#ifdef PRINT2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#undef PRINT2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#define PRINT if (tracing) printf
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#define PRINT2 if (tracing > 1) printf
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
struct ComponentIDs componentIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
struct MenuComponentIDs menuComponentIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
struct KeyboardFocusManagerIDs keyboardFocusManagerIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
extern Display* awt_init_Display(JNIEnv *env, jobject this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
extern struct MFontPeerIDs mFontPeerIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
Java_sun_awt_X11_XFontPeer_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    mFontPeerIDs.xfsname =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
      (*env)->GetFieldID(env, cls, "xfsname", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
/* This function gets called from the static initializer for FileDialog.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
   to initialize the fieldIDs for fields that may be accessed from C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
Java_java_awt_FileDialog_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
Java_sun_awt_X11_XToolkit_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  (JNIEnv *env, jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    jfieldID fid = (*env)->GetStaticFieldID(env, clazz, "numLockMask", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    awt_NumLockMask = (*env)->GetStaticIntField(env, clazz, fid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    DTRACE_PRINTLN1("awt_NumLockMask = %u", awt_NumLockMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    fid = (*env)->GetStaticFieldID(env, clazz, "modLockIsShiftLock", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    awt_ModLockIsShiftLock = (*env)->GetStaticIntField(env, clazz, fid) != 0 ? True : False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * Class:     sun_awt_X11_XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * Method:    getDefaultXColormap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * Signature: ()J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getDefaultXColormap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  (JNIEnv *env, jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    AwtGraphicsConfigDataPtr defaultConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        getDefaultConfig(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    return (jlong) defaultConfig->awt_cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getDefaultScreenData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  (JNIEnv *env, jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    return ptr_to_jlong(getDefaultConfig(DefaultScreen(awt_display)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
JNI_OnLoad(JavaVM *vm, void *reserved)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    jvm = vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    return JNI_VERSION_1_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * Class:     sun_awt_X11_XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * Method:    nativeLoadSystemColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * Signature: ([I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_nativeLoadSystemColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
  (JNIEnv *env, jobject this, jintArray systemColors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    AwtGraphicsConfigDataPtr defaultConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        getDefaultConfig(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    awtJNI_CreateColorData(env, defaultConfig, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
Java_java_awt_Component_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    jclass keyclass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    componentIDs.x = (*env)->GetFieldID(env, cls, "x", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    componentIDs.y = (*env)->GetFieldID(env, cls, "y", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    componentIDs.width = (*env)->GetFieldID(env, cls, "width", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    componentIDs.height = (*env)->GetFieldID(env, cls, "height", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    componentIDs.isPacked = (*env)->GetFieldID(env, cls, "isPacked", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    componentIDs.peer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      (*env)->GetFieldID(env, cls, "peer", "Ljava/awt/peer/ComponentPeer;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    componentIDs.background =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
      (*env)->GetFieldID(env, cls, "background", "Ljava/awt/Color;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    componentIDs.foreground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      (*env)->GetFieldID(env, cls, "foreground", "Ljava/awt/Color;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    componentIDs.graphicsConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        (*env)->GetFieldID(env, cls, "graphicsConfig",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                           "Ljava/awt/GraphicsConfiguration;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    componentIDs.name =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
      (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /* Use _NoClientCode() methods for trusted methods, so that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *  know that we are not invoking client code on trusted threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    componentIDs.getParent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
      (*env)->GetMethodID(env, cls, "getParent_NoClientCode",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                         "()Ljava/awt/Container;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    componentIDs.getLocationOnScreen =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
      (*env)->GetMethodID(env, cls, "getLocationOnScreen_NoTreeLock",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                         "()Ljava/awt/Point;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    keyclass = (*env)->FindClass(env, "java/awt/event/KeyEvent");
7770
8a5fd008f98b 6866808: nsk/stress/jck12a/jck12a014 crashes with SIGSEGV at [libjvm.so+0xc5b10]
dcherepanov
parents: 5506
diff changeset
   190
    if (JNU_IsNull(env, keyclass)) {
8a5fd008f98b 6866808: nsk/stress/jck12a/jck12a014 crashes with SIGSEGV at [libjvm.so+0xc5b10]
dcherepanov
parents: 5506
diff changeset
   191
        return;
8a5fd008f98b 6866808: nsk/stress/jck12a/jck12a014 crashes with SIGSEGV at [libjvm.so+0xc5b10]
dcherepanov
parents: 5506
diff changeset
   192
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    componentIDs.isProxyActive =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        (*env)->GetFieldID(env, keyclass, "isProxyActive",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                           "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    componentIDs.appContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        (*env)->GetFieldID(env, cls, "appContext",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                           "Lsun/awt/AppContext;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    (*env)->DeleteLocalRef(env, keyclass);
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
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
Java_java_awt_Container_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
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
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
Java_java_awt_Button_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
{
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
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
Java_java_awt_Scrollbar_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
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
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
Java_java_awt_Window_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
{
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
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
Java_java_awt_Frame_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
Java_java_awt_MenuComponent_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    menuComponentIDs.appContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
      (*env)->GetFieldID(env, cls, "appContext", "Lsun/awt/AppContext;");
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
Java_java_awt_Cursor_initIDs(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_MenuItem_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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
JNIEXPORT void JNICALL Java_java_awt_Menu_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
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
Java_java_awt_TextArea_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
{
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
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
Java_java_awt_Checkbox_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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
JNIEXPORT void JNICALL Java_java_awt_ScrollPane_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 void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
Java_java_awt_TextField_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
JNIEXPORT jboolean JNICALL AWTIsHeadless() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
JNIEXPORT void JNICALL Java_java_awt_Dialog_initIDs (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
/* ========================== Begin poll section ================================ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
// Includes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
#include <sys/time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
#include <limits.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
#include <locale.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
#include <pthread.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
#include <fcntl.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
#include <poll.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
#ifndef POLLRDNORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
#define POLLRDNORM POLLIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
// Prototypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
static void     waitForEvents(JNIEnv *, jlong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
static void     awt_pipe_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
static void     processOneEvent(XtInputMask iMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
static void     performPoll(JNIEnv *, jlong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
static void     wakeUp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
static void     update_poll_timeout(int timeout_control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
static uint32_t get_poll_timeout(jlong nextTaskTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
// Defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
#ifndef bzero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
#define bzero(a,b) memset(a, 0, b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
#define AWT_POLL_BUFSIZE        100 /* bytes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
#define AWT_READPIPE            (awt_pipe_fds[0])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
#define AWT_WRITEPIPE           (awt_pipe_fds[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
#define DEF_AWT_MAX_POLL_TIMEOUT ((uint32_t)500) /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
#define DEF_AWT_FLUSH_TIMEOUT ((uint32_t)100) /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
#define AWT_MIN_POLL_TIMEOUT ((uint32_t)0) /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
#define TIMEOUT_TIMEDOUT 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
#define TIMEOUT_EVENTS 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
// Static fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
static uint32_t AWT_FLUSH_TIMEOUT  =  DEF_AWT_FLUSH_TIMEOUT; /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
static uint32_t AWT_MAX_POLL_TIMEOUT = DEF_AWT_MAX_POLL_TIMEOUT; /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
static pthread_t    awt_MainThread = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
static int32_t      awt_pipe_fds[2];                   /* fds for wkaeup pipe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
static Boolean      awt_pipe_inited = False;           /* make sure pipe is initialized before write */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
static jlong        awt_next_flush_time = 0LL; /* 0 == no scheduled flush */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
static jlong        awt_last_flush_time = 0LL; /* 0 == no scheduled flush */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
static uint32_t     curPollTimeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
static struct pollfd pollFds[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
static jlong        poll_sleep_time = 0LL; // Used for tracing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
static jlong        poll_wakeup_time = 0LL; // Used for tracing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
// AWT static poll timeout.  Zero means "not set", aging algorithm is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
// used.  Static poll timeout values higher than 50 cause application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
// look "slow" - they don't respond to user request fast
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
// enough. Static poll timeout value less than 10 are usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
// considered by schedulers as zero, so this might cause unnecessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
// CPU consumption by Java.  The values between 10 - 50 are suggested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
// for single client desktop configurations.  For SunRay servers, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
// is highly recomended to use aging algorithm (set static poll timeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
// to 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
static int32_t static_poll_timeout = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
static Bool isMainThread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    return awt_MainThread == pthread_self();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
 * Creates the AWT utility pipe. This pipe exists solely so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
 * we can cause the main event thread to wake up from a poll() or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
 * select() by writing to this pipe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
awt_pipe_init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    if (awt_pipe_inited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    if ( pipe ( awt_pipe_fds ) == 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        ** the write wakes us up from the infinite sleep, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        ** then we cause a delay of AWT_FLUSHTIME and then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        ** flush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        int32_t flags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        /* set the pipe to be non-blocking */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        flags = fcntl ( AWT_READPIPE, F_GETFL, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        fcntl( AWT_READPIPE, F_SETFL, flags | O_NDELAY | O_NONBLOCK );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        flags = fcntl ( AWT_WRITEPIPE, F_GETFL, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        fcntl( AWT_WRITEPIPE, F_SETFL, flags | O_NDELAY | O_NONBLOCK );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        awt_pipe_inited = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        AWT_READPIPE = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        AWT_WRITEPIPE = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
} /* awt_pipe_init() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
 * Reads environment variables to initialize timeout fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
static void readEnv() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    char * value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    static Boolean env_read = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    if (env_read) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    env_read = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    value = getenv("_AWT_MAX_POLL_TIMEOUT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        AWT_MAX_POLL_TIMEOUT = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        if (AWT_MAX_POLL_TIMEOUT == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            AWT_MAX_POLL_TIMEOUT = DEF_AWT_MAX_POLL_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    curPollTimeout = AWT_MAX_POLL_TIMEOUT/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    value = getenv("_AWT_FLUSH_TIMEOUT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        AWT_FLUSH_TIMEOUT = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (AWT_FLUSH_TIMEOUT == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            AWT_FLUSH_TIMEOUT = DEF_AWT_FLUSH_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    value = getenv("_AWT_POLL_TRACING");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        tracing = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    value = getenv("_AWT_STATIC_POLL_TIMEOUT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        static_poll_timeout = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    if (static_poll_timeout != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        curPollTimeout = static_poll_timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
 * Returns the amount of milliseconds similar to System.currentTimeMillis()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
static jlong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
awtJNI_TimeMillis(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    struct timeval t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    gettimeofday(&t, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    return jlong_add(jlong_mul(jint_to_jlong(t.tv_sec), jint_to_jlong(1000)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
             jint_to_jlong(t.tv_usec / 1000));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
 * Updates curPollTimeout according to the aging algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
 * @param timeout_control Either TIMEOUT_TIMEDOUT or TIMEOUT_EVENTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
static void update_poll_timeout(int timeout_control) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    PRINT2("tout: %d\n", timeout_control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    // If static_poll_timeout is set, curPollTimeout has the fixed value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    if (static_poll_timeout != 0) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    // Update it otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    if (timeout_control == TIMEOUT_TIMEDOUT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        /* add 1/4 (plus 1, in case the division truncates to 0) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        curPollTimeout += ((curPollTimeout>>2) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        curPollTimeout = min(AWT_MAX_POLL_TIMEOUT, curPollTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    } else if (timeout_control == TIMEOUT_EVENTS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        /* subtract 1/4 (plus 1, in case the division truncates to 0) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        curPollTimeout -= ((curPollTimeout>>2) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        curPollTimeout = max(AWT_MIN_POLL_TIMEOUT, curPollTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
 * Gets the best timeout for the next call to poll().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
 * @param nextTaskTime -1, if there are no tasks; next time when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
 * timeout task needs to be run, in millis(of currentTimeMillis)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
static uint32_t get_poll_timeout(jlong nextTaskTime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    jlong curTime = awtJNI_TimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    uint32_t timeout = curPollTimeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    uint32_t taskTimeout = (nextTaskTime == -1) ? AWT_MAX_POLL_TIMEOUT : (uint32_t)max(0, (int32_t)(nextTaskTime - curTime));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    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
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    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
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    // Adjust timeout to flush_time and task_time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    return min(flushTimeout, min(taskTimeout, timeout));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
} /* awt_get_poll_timeout() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
 * Waits for X/Xt events to appear on the pipe. Returns only when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
 * it is likely (but not definite) that there are events waiting to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
 * be processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
 * This routine also flushes the outgoing X queue, when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
 * awt_next_flush_time has been reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
 * If fdAWTPipe is greater or equal than zero the routine also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
 * checks if there are events pending on the putback queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
waitForEvents(JNIEnv *env, jlong nextTaskTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    performPoll(env, nextTaskTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    if ((awt_next_flush_time > 0) && (awtJNI_TimeMillis() >= awt_next_flush_time)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        XFlush(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        awt_last_flush_time = awt_next_flush_time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        awt_next_flush_time = 0LL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
} /* waitForEvents() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_waitForEvents (JNIEnv *env, jclass class, jlong nextTaskTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    waitForEvents(env, nextTaskTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_awt_1toolkit_1init (JNIEnv *env, jclass class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    awt_MainThread = pthread_self();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    awt_pipe_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    readEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_awt_1output_1flush (JNIEnv *env, jclass class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    awt_output_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_wakeup_1poll (JNIEnv *env, jclass class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    wakeUp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
 * Polls both the X pipe and our AWT utility pipe. Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
 * when there is data on one of the pipes, or the operation times
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
 * out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
 * Not all Xt events come across the X pipe (e.g., timers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
 * and alternate inputs), so we must time out every now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
 * then to check the Xt event queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
 * The fdAWTPipe will be empty when this returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
performPoll(JNIEnv *env, jlong nextTaskTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    static Bool pollFdsInited = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    static char read_buf[AWT_POLL_BUFSIZE + 1];    /* dummy buf to empty pipe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    uint32_t timeout = get_poll_timeout(nextTaskTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    int32_t result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    if (!pollFdsInited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        pollFds[0].fd = ConnectionNumber(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        pollFds[0].events = POLLRDNORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        pollFds[0].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        pollFds[1].fd = AWT_READPIPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        pollFds[1].events = POLLRDNORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        pollFds[1].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        pollFdsInited = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        pollFds[0].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        pollFds[1].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    AWT_NOFLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    /* ACTUALLY DO THE POLL() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    if (timeout == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        // be sure other threads get a chance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        awtJNI_ThreadYield(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    if (tracing) poll_sleep_time = awtJNI_TimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    result = poll( pollFds, 2, (int32_t) timeout );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    if (tracing) poll_wakeup_time = awtJNI_TimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    PRINT("%d of %d, res: %d\n", (int)(poll_wakeup_time-poll_sleep_time), (int)timeout, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    if (result == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        /* poll() timed out -- update timeout value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        update_poll_timeout(TIMEOUT_TIMEDOUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    if (pollFds[1].revents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        PRINT("Woke up\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        /* There is data on the AWT pipe - empty it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            count = read(AWT_READPIPE, read_buf, AWT_POLL_BUFSIZE );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        } while (count == AWT_POLL_BUFSIZE );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    if (pollFds[0].revents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        // Events in X pipe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        update_poll_timeout(TIMEOUT_EVENTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
} /* performPoll() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
 * Schedules next auto-flush event or performs forced flush depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
 * on the time of the previous flush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
void awt_output_flush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    if (awt_next_flush_time == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        jlong curTime = awtJNI_TimeMillis(); // current time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        jlong l_awt_last_flush_time = awt_last_flush_time; // last time we flushed queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        jlong next_flush_time = l_awt_last_flush_time + AWT_FLUSH_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        if (curTime >= next_flush_time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            // Enough time passed from last flush
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            PRINT("f1\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            XFlush(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            awt_last_flush_time = curTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            AWT_NOFLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            awt_next_flush_time = next_flush_time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            PRINT("f2\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            wakeUp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
 * Wakes-up poll() in performPoll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
static void wakeUp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    static char wakeUp_char = 'p';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    if (!isMainThread() && awt_pipe_inited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        write ( AWT_WRITEPIPE, &wakeUp_char, 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
/* ========================== End poll section ================================= */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
 * Class:     java_awt_KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
Java_java_awt_KeyboardFocusManager_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
 * Class:     sun_awt_X11_XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
 * Method:    getEnv
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
 * Signature: (Ljava/lang/String;)Ljava/lang/String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
JNIEXPORT jstring JNICALL Java_sun_awt_X11_XToolkit_getEnv
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
(JNIEnv *env , jclass clazz, jstring key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    char *ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    const char *keystr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    jstring ret = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    keystr = JNU_GetStringPlatformChars(env, key, NULL);
4260
913d5ec97629 6891483: XToolkit.getEnv() checks for NULL on a wrong symbol
anthony
parents: 2811
diff changeset
   682
    if (keystr) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        ptr = getenv(keystr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        if (ptr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            ret = JNU_NewStringPlatform(env, (const char *) ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        JNU_ReleaseStringPlatformChars(env, key, (const char*)keystr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
void print_stack(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
  void *array[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
  size_t size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
  char **strings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
  size_t i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
  size = backtrace (array, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
  strings = backtrace_symbols (array, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
  fprintf (stderr, "Obtained %zd stack frames.\n", size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
  for (i = 0; i < size; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     fprintf (stderr, "%s\n", strings[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
  free (strings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
Window get_xawt_root_shell(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
  static jclass classXRootWindow = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
  static jmethodID methodGetXRootWindow = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
  static Window xawt_root_shell = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
  if (xawt_root_shell == None){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
      if (classXRootWindow == NULL){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
          jclass cls_tmp = (*env)->FindClass(env, "sun/awt/X11/XRootWindow");
7770
8a5fd008f98b 6866808: nsk/stress/jck12a/jck12a014 crashes with SIGSEGV at [libjvm.so+0xc5b10]
dcherepanov
parents: 5506
diff changeset
   720
          if (!JNU_IsNull(env, cls_tmp)) {
8a5fd008f98b 6866808: nsk/stress/jck12a/jck12a014 crashes with SIGSEGV at [libjvm.so+0xc5b10]
dcherepanov
parents: 5506
diff changeset
   721
              classXRootWindow = (jclass)(*env)->NewGlobalRef(env, cls_tmp);
8a5fd008f98b 6866808: nsk/stress/jck12a/jck12a014 crashes with SIGSEGV at [libjvm.so+0xc5b10]
dcherepanov
parents: 5506
diff changeset
   722
              (*env)->DeleteLocalRef(env, cls_tmp);
8a5fd008f98b 6866808: nsk/stress/jck12a/jck12a014 crashes with SIGSEGV at [libjvm.so+0xc5b10]
dcherepanov
parents: 5506
diff changeset
   723
          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
      if( classXRootWindow != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
          methodGetXRootWindow = (*env)->GetStaticMethodID(env, classXRootWindow, "getXRootWindow", "()J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
      if( classXRootWindow != NULL && methodGetXRootWindow !=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
          xawt_root_shell = (Window) (*env)->CallStaticLongMethod(env, classXRootWindow, methodGetXRootWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
      if ((*env)->ExceptionCheck(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
  return xawt_root_shell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
 * Old, compatibility, backdoor for DT.  This is a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
 * implementation.  It keeps the signature, but acts on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
 * awt_root_shell, not the frame passed as an argument.  Note, that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
 * the code that uses the old backdoor doesn't work correctly with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
 * gnome session proxy that checks for WM_COMMAND when the window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
 * firts mapped, because DT code calls this old backdoor *after* the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
 * frame is shown or it would get NPE with old AWT (previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
 * implementation of this backdoor) otherwise.  Old style session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
 * managers (e.g. CDE) that check WM_COMMAND only during session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
 * checkpoint should work fine, though.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
 * NB: The function name looks deceptively like a JNI native method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
 * name.  It's not!  It's just a plain function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    jobject frame, jstring jcommand)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    const char *command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    XTextProperty text_prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    char *c[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    int32_t status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    Window xawt_root_window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    xawt_root_window = get_xawt_root_shell(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    if ( xawt_root_window == None ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        JNU_ThrowNullPointerException(env, "AWT root shell is unrealized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    command = (char *) JNU_GetStringPlatformChars(env, jcommand, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    c[0] = (char *)command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    status = XmbTextListToTextProperty(awt_display, c, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                                       XStdICCTextStyle, &text_prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    if (status == Success || status > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        XSetTextProperty(awt_display, xawt_root_window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                         &text_prop, XA_WM_COMMAND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        if (text_prop.value != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            XFree(text_prop.value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    JNU_ReleaseStringPlatformChars(env, jcommand, command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
 * New DT backdoor to set WM_COMMAND.  New code should use this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
 * backdoor and call it *before* the first frame is shown so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
 * gnome session proxy can correctly handle it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
 * NB: The function name looks deceptively like a JNI native method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
 * name.  It's not!  It's just a plain function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jargv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    static const char empty[] = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    int argc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    const char **cargv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    XTextProperty text_prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    int status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    Window xawt_root_window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    xawt_root_window = get_xawt_root_shell(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    if (xawt_root_window == None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
      JNU_ThrowNullPointerException(env, "AWT root shell is unrealized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
      AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    argc = (int)(*env)->GetArrayLength(env, jargv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    if (argc == 0) {
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
    /* array of C strings */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    cargv = (const char **)calloc(argc, sizeof(char *));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    if (cargv == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        JNU_ThrowOutOfMemoryError(env, "Unable to allocate cargv");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    /* fill C array with platform chars of java strings */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
      for (i = 0; i < argc; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        jstring js;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        const char *cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        cs = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        js = (*env)->GetObjectArrayElement(env, jargv, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        if (js != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            cs = JNU_GetStringPlatformChars(env, js, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        if (cs == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            cs = empty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        cargv[i] = cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        (*env)->DeleteLocalRef(env, js);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    /* grr, X prototype doesn't declare cargv as const, thought it really is */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    status = XmbTextListToTextProperty(awt_display, (char **)cargv, argc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                                       XStdICCTextStyle, &text_prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    if (status < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        switch (status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        case XNoMemory:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            JNU_ThrowOutOfMemoryError(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                "XmbTextListToTextProperty: XNoMemory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        case XLocaleNotSupported:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            JNU_ThrowInternalError(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                "XmbTextListToTextProperty: XLocaleNotSupported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        case XConverterNotFound:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            JNU_ThrowNullPointerException(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                "XmbTextListToTextProperty: XConverterNotFound");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            JNU_ThrowInternalError(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                "XmbTextListToTextProperty: unknown error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    XSetTextProperty(awt_display, xawt_root_window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                         &text_prop, XA_WM_COMMAND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    for (i = 0; i < argc; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        jstring js;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        if (cargv[i] == empty)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        js = (*env)->GetObjectArrayElement(env, jargv, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        JNU_ReleaseStringPlatformChars(env, js, cargv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        (*env)->DeleteLocalRef(env, js);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    if (text_prop.value != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        XFree(text_prop.value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    AWT_UNLOCK();
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
 * Class:     java_awt_TrayIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
JNIEXPORT void JNICALL Java_java_awt_TrayIcon_initIDs(JNIEnv *env , jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
 * Class:     java_awt_Cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
 * Method:    finalizeImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
Java_java_awt_Cursor_finalizeImpl(JNIEnv *env, jclass clazz, jlong pData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    Cursor xcursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    xcursor = (Cursor)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    if (xcursor != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        XFreeCursor(awt_display, xcursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
}
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   919
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   920
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   921
/*
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   922
 * Class:     sun_awt_X11_XToolkit
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   923
 * Method:    getNumberOfButtonsImpl
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   924
 * Signature: ()I
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   925
 */
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   926
JNIEXPORT jint JNICALL Java_sun_awt_X11_XToolkit_getNumberOfButtonsImpl
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   927
(JNIEnv * env, jobject cls){
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   928
    if (num_buttons == 0) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   929
        num_buttons = getNumButtons();
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   930
    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   931
    return num_buttons;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   932
}
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   933
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   934
int32_t getNumButtons() {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   935
    int32_t major_opcode, first_event, first_error;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   936
    int32_t xinputAvailable;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   937
    int32_t numDevices, devIdx, clsIdx;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   938
    XDeviceInfo* devices;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   939
    XDeviceInfo* aDevice;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   940
    XButtonInfo* bInfo;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   941
    int32_t local_num_buttons = 0;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   942
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   943
    /* 4700242:
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   944
     * If XTest is asked to press a non-existant mouse button
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   945
     * (i.e. press Button3 on a system configured with a 2-button mouse),
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   946
     * then a crash may happen.  To avoid this, we use the XInput
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   947
     * extension to query for the number of buttons on the XPointer, and check
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   948
     * before calling XTestFakeButtonEvent().
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   949
     */
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   950
    xinputAvailable = XQueryExtension(awt_display, INAME, &major_opcode, &first_event, &first_error);
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   951
    DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XINPUT) returns major_opcode = %d, first_event = %d, first_error = %d",
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   952
                    major_opcode, first_event, first_error);
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   953
    if (xinputAvailable) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   954
        devices = XListInputDevices(awt_display, &numDevices);
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   955
        for (devIdx = 0; devIdx < numDevices; devIdx++) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   956
            aDevice = &(devices[devIdx]);
2811
8828b8313cab 6844750: Solaris build failed after 6799099
dav
parents: 2810
diff changeset
   957
#ifdef IsXExtensionPointer
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   958
            if (aDevice->use == IsXExtensionPointer) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   959
                for (clsIdx = 0; clsIdx < aDevice->num_classes; clsIdx++) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   960
                    if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   961
                        bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx]));
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   962
                        local_num_buttons = bInfo->num_buttons;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   963
                        DTRACE_PRINTLN1("RobotPeer: XPointer has %d buttons", num_buttons);
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   964
                        break;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   965
                    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   966
                }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   967
                break;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   968
            }
2811
8828b8313cab 6844750: Solaris build failed after 6799099
dav
parents: 2810
diff changeset
   969
#endif
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   970
            if (local_num_buttons <= 0 ) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   971
                if (aDevice->use == IsXPointer) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   972
                    for (clsIdx = 0; clsIdx < aDevice->num_classes; clsIdx++) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   973
                        if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   974
                            bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx]));
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   975
                            local_num_buttons = bInfo->num_buttons;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   976
                            DTRACE_PRINTLN1("RobotPeer: XPointer has %d buttons", num_buttons);
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   977
                            break;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   978
                        }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   979
                    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   980
                    break;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   981
                }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   982
            }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   983
        }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   984
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   985
        XFreeDeviceList(devices);
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   986
    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   987
    else {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   988
        DTRACE_PRINTLN1("RobotPeer: XINPUT extension is unavailable, assuming %d mouse buttons", num_buttons);
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   989
    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   990
    if (local_num_buttons == 0 ) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   991
        local_num_buttons = 3;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   992
    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   993
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   994
    return local_num_buttons;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   995
}