src/java.desktop/unix/native/libawt_xawt/xawt/XToolkit.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
40192
64c0b3d47afb 8140723: Remove source code conditionalized on JAVASE_EMBEDDED
dholmes
parents: 37699
diff changeset
     2
 * Copyright (c) 2002, 2016, 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_Font.h"
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
    43
#include "awt_util.h"
2
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
11090
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
    50
#include <unistd.h>
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
    51
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
uint32_t awt_NumLockMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
Boolean  awt_ModLockIsShiftLock = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
    55
static int32_t num_buttons = 0;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
    56
int32_t getNumButtons();
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
    57
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
extern JavaVM *jvm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
// Tracing level
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
static int tracing = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#ifdef PRINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#undef PRINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#ifdef PRINT2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#undef PRINT2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#define PRINT if (tracing) printf
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#define PRINT2 if (tracing > 1) printf
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
struct ComponentIDs componentIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
struct MenuComponentIDs menuComponentIDs;
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);
28079
a0965f7bbb05 8064700: [parfait] Function Call Mismatch in jdk/src/java/desktop/unix/native/libawt_xawt/xawt/XToolkit.c
azvegint
parents: 26751
diff changeset
    80
extern void freeNativeStringArray(char **array, jsize length);
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
    81
extern char** stringArrayToNative(JNIEnv *env, jobjectArray array, jsize * ret_length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
11093
e753252dc8a9 6996291: command line selection of MToolkit by -Dawt.toolkit=sun.awt.motif.MToolkit fails from jdk7 b21 on
serb
parents: 11090
diff changeset
    83
struct XFontPeerIDs xFontPeerIDs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
Java_sun_awt_X11_XFontPeer_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
{
11093
e753252dc8a9 6996291: command line selection of MToolkit by -Dawt.toolkit=sun.awt.motif.MToolkit fails from jdk7 b21 on
serb
parents: 11090
diff changeset
    89
    xFontPeerIDs.xfsname =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      (*env)->GetFieldID(env, cls, "xfsname", "Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
/* This function gets called from the static initializer for FileDialog.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
   to initialize the fieldIDs for fields that may be accessed from C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
Java_java_awt_FileDialog_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
Java_sun_awt_X11_XToolkit_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  (JNIEnv *env, jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    jfieldID fid = (*env)->GetStaticFieldID(env, clazz, "numLockMask", "I");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   109
    CHECK_NULL(fid);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    awt_NumLockMask = (*env)->GetStaticIntField(env, clazz, fid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    DTRACE_PRINTLN1("awt_NumLockMask = %u", awt_NumLockMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    fid = (*env)->GetStaticFieldID(env, clazz, "modLockIsShiftLock", "I");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   113
    CHECK_NULL(fid);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    awt_ModLockIsShiftLock = (*env)->GetStaticIntField(env, clazz, fid) != 0 ? True : False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * Class:     sun_awt_X11_XToolkit
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   119
 * Method:    getTrayIconDisplayTimeout
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   120
 * Signature: ()J
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   121
 */
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   122
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getTrayIconDisplayTimeout
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   123
  (JNIEnv *env, jclass clazz)
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   124
{
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   125
    return (jlong) 2000;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   126
}
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   127
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   128
/*
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   129
 * Class:     sun_awt_X11_XToolkit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * Method:    getDefaultXColormap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * Signature: ()J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getDefaultXColormap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  (JNIEnv *env, jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    AwtGraphicsConfigDataPtr defaultConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        getDefaultConfig(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    return (jlong) defaultConfig->awt_cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getDefaultScreenData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
  (JNIEnv *env, jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    return ptr_to_jlong(getDefaultConfig(DefaultScreen(awt_display)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
JNIEXPORT jint JNICALL
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31655
diff changeset
   150
DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    jvm = vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    return JNI_VERSION_1_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * Class:     sun_awt_X11_XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * Method:    nativeLoadSystemColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * Signature: ([I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_nativeLoadSystemColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
  (JNIEnv *env, jobject this, jintArray systemColors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    AwtGraphicsConfigDataPtr defaultConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        getDefaultConfig(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    awtJNI_CreateColorData(env, defaultConfig, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
Java_java_awt_Component_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    jclass keyclass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    componentIDs.x = (*env)->GetFieldID(env, cls, "x", "I");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   177
    CHECK_NULL(componentIDs.x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    componentIDs.y = (*env)->GetFieldID(env, cls, "y", "I");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   179
    CHECK_NULL(componentIDs.y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    componentIDs.width = (*env)->GetFieldID(env, cls, "width", "I");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   181
    CHECK_NULL(componentIDs.width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    componentIDs.height = (*env)->GetFieldID(env, cls, "height", "I");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   183
    CHECK_NULL(componentIDs.height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    componentIDs.isPacked = (*env)->GetFieldID(env, cls, "isPacked", "Z");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   185
    CHECK_NULL(componentIDs.isPacked);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    componentIDs.peer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
      (*env)->GetFieldID(env, cls, "peer", "Ljava/awt/peer/ComponentPeer;");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   188
    CHECK_NULL(componentIDs.peer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    componentIDs.background =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      (*env)->GetFieldID(env, cls, "background", "Ljava/awt/Color;");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   191
    CHECK_NULL(componentIDs.background);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    componentIDs.foreground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
      (*env)->GetFieldID(env, cls, "foreground", "Ljava/awt/Color;");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   194
    CHECK_NULL(componentIDs.foreground);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    componentIDs.graphicsConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        (*env)->GetFieldID(env, cls, "graphicsConfig",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                           "Ljava/awt/GraphicsConfiguration;");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   198
    CHECK_NULL(componentIDs.graphicsConfig);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    componentIDs.name =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
      (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   201
    CHECK_NULL(componentIDs.name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /* Use _NoClientCode() methods for trusted methods, so that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *  know that we are not invoking client code on trusted threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    componentIDs.getParent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
      (*env)->GetMethodID(env, cls, "getParent_NoClientCode",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                         "()Ljava/awt/Container;");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   209
    CHECK_NULL(componentIDs.getParent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    componentIDs.getLocationOnScreen =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
      (*env)->GetMethodID(env, cls, "getLocationOnScreen_NoTreeLock",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                         "()Ljava/awt/Point;");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   214
    CHECK_NULL(componentIDs.getLocationOnScreen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    keyclass = (*env)->FindClass(env, "java/awt/event/KeyEvent");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   217
    CHECK_NULL(keyclass);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    componentIDs.isProxyActive =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        (*env)->GetFieldID(env, keyclass, "isProxyActive",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                           "Z");
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   222
    CHECK_NULL(componentIDs.isProxyActive);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    componentIDs.appContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        (*env)->GetFieldID(env, cls, "appContext",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                           "Lsun/awt/AppContext;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    (*env)->DeleteLocalRef(env, keyclass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
Java_java_awt_Container_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
Java_java_awt_Button_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
Java_java_awt_Scrollbar_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
Java_java_awt_Window_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
Java_java_awt_Frame_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
Java_java_awt_MenuComponent_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    menuComponentIDs.appContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
      (*env)->GetFieldID(env, cls, "appContext", "Lsun/awt/AppContext;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
Java_java_awt_Cursor_initIDs(JNIEnv *env, jclass cls)
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
JNIEXPORT void JNICALL Java_java_awt_MenuItem_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
JNIEXPORT void JNICALL Java_java_awt_Menu_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
Java_java_awt_TextArea_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
Java_java_awt_Checkbox_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
JNIEXPORT void JNICALL Java_java_awt_ScrollPane_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
Java_java_awt_TextField_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
  (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   319
JNIEXPORT jboolean JNICALL AWTIsHeadless(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
JNIEXPORT void JNICALL Java_java_awt_Dialog_initIDs (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
/* ========================== Begin poll section ================================ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
// Includes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
#include <sys/time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
#include <limits.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
#include <locale.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
#include <pthread.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
#include <fcntl.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
#include <poll.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
#ifndef POLLRDNORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
#define POLLRDNORM POLLIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
// Prototypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
static void     waitForEvents(JNIEnv *, jlong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
static void     awt_pipe_init();
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   353
static Boolean  performPoll(JNIEnv *, jlong);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
static void     wakeUp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
static void     update_poll_timeout(int timeout_control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
static uint32_t get_poll_timeout(jlong nextTaskTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
// Defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
#ifndef bzero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
#define bzero(a,b) memset(a, 0, b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
#define AWT_POLL_BUFSIZE        100 /* bytes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
#define AWT_READPIPE            (awt_pipe_fds[0])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
#define AWT_WRITEPIPE           (awt_pipe_fds[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
40192
64c0b3d47afb 8140723: Remove source code conditionalized on JAVASE_EMBEDDED
dholmes
parents: 37699
diff changeset
   368
#define DEF_AWT_MAX_POLL_TIMEOUT ((uint32_t)500) /* milliseconds */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
#define DEF_AWT_FLUSH_TIMEOUT ((uint32_t)100) /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
#define AWT_MIN_POLL_TIMEOUT ((uint32_t)0) /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
#define TIMEOUT_TIMEDOUT 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
#define TIMEOUT_EVENTS 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   375
/* awt_poll_alg - AWT Poll Events Aging Algorithms */
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   376
#define AWT_POLL_FALSE        1
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   377
#define AWT_POLL_AGING_SLOW   2
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   378
#define AWT_POLL_AGING_FAST   3
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   379
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   380
#define AWT_POLL_THRESHOLD 1000  // msec, Block if delay is larger
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   381
#define AWT_POLL_BLOCK       -1  // cause poll() block
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   382
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
// Static fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
40192
64c0b3d47afb 8140723: Remove source code conditionalized on JAVASE_EMBEDDED
dholmes
parents: 37699
diff changeset
   385
static int          awt_poll_alg = AWT_POLL_AGING_SLOW;
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   386
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
static uint32_t AWT_FLUSH_TIMEOUT  =  DEF_AWT_FLUSH_TIMEOUT; /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
static uint32_t AWT_MAX_POLL_TIMEOUT = DEF_AWT_MAX_POLL_TIMEOUT; /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
static pthread_t    awt_MainThread = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
static int32_t      awt_pipe_fds[2];                   /* fds for wkaeup pipe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
static Boolean      awt_pipe_inited = False;           /* make sure pipe is initialized before write */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
static jlong        awt_next_flush_time = 0LL; /* 0 == no scheduled flush */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
static jlong        awt_last_flush_time = 0LL; /* 0 == no scheduled flush */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
static uint32_t     curPollTimeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
static struct pollfd pollFds[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
static jlong        poll_sleep_time = 0LL; // Used for tracing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
static jlong        poll_wakeup_time = 0LL; // Used for tracing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
// AWT static poll timeout.  Zero means "not set", aging algorithm is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
// used.  Static poll timeout values higher than 50 cause application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
// look "slow" - they don't respond to user request fast
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
// enough. Static poll timeout value less than 10 are usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
// considered by schedulers as zero, so this might cause unnecessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
// CPU consumption by Java.  The values between 10 - 50 are suggested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
// for single client desktop configurations.  For SunRay servers, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
// is highly recomended to use aging algorithm (set static poll timeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
// to 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
static int32_t static_poll_timeout = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   410
static Bool isMainThread(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    return awt_MainThread == pthread_self();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
 * Creates the AWT utility pipe. This pipe exists solely so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
 * we can cause the main event thread to wake up from a poll() or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
 * select() by writing to this pipe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
static void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   420
awt_pipe_init(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    if (awt_pipe_inited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    if ( pipe ( awt_pipe_fds ) == 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        ** the write wakes us up from the infinite sleep, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        ** then we cause a delay of AWT_FLUSHTIME and then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        ** flush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        int32_t flags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        /* set the pipe to be non-blocking */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        flags = fcntl ( AWT_READPIPE, F_GETFL, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        fcntl( AWT_READPIPE, F_SETFL, flags | O_NDELAY | O_NONBLOCK );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        flags = fcntl ( AWT_WRITEPIPE, F_GETFL, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        fcntl( AWT_WRITEPIPE, F_SETFL, flags | O_NDELAY | O_NONBLOCK );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        awt_pipe_inited = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        AWT_READPIPE = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        AWT_WRITEPIPE = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
} /* awt_pipe_init() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
 * Reads environment variables to initialize timeout fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
 */
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   453
static void readEnv(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    char * value;
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   455
    int tmp_poll_alg;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    static Boolean env_read = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    if (env_read) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    env_read = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    value = getenv("_AWT_MAX_POLL_TIMEOUT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        AWT_MAX_POLL_TIMEOUT = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (AWT_MAX_POLL_TIMEOUT == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            AWT_MAX_POLL_TIMEOUT = DEF_AWT_MAX_POLL_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    curPollTimeout = AWT_MAX_POLL_TIMEOUT/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    value = getenv("_AWT_FLUSH_TIMEOUT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        AWT_FLUSH_TIMEOUT = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (AWT_FLUSH_TIMEOUT == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            AWT_FLUSH_TIMEOUT = DEF_AWT_FLUSH_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    value = getenv("_AWT_POLL_TRACING");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        tracing = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    value = getenv("_AWT_STATIC_POLL_TIMEOUT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    if (value != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        static_poll_timeout = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    if (static_poll_timeout != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        curPollTimeout = static_poll_timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   490
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   491
    // non-blocking poll()
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   492
    value = getenv("_AWT_POLL_ALG");
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   493
    if (value != NULL) {
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   494
        tmp_poll_alg = atoi(value);
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   495
        switch(tmp_poll_alg) {
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   496
        case AWT_POLL_FALSE:
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   497
        case AWT_POLL_AGING_SLOW:
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   498
        case AWT_POLL_AGING_FAST:
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   499
            awt_poll_alg = tmp_poll_alg;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   500
            break;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   501
        default:
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   502
            PRINT("Unknown value of _AWT_POLL_ALG, assuming Slow Aging Algorithm by default");
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   503
            awt_poll_alg = AWT_POLL_AGING_SLOW;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   504
            break;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   505
        }
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   506
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
 * Returns the amount of milliseconds similar to System.currentTimeMillis()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
static jlong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
awtJNI_TimeMillis(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    struct timeval t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    gettimeofday(&t, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    return jlong_add(jlong_mul(jint_to_jlong(t.tv_sec), jint_to_jlong(1000)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
             jint_to_jlong(t.tv_usec / 1000));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
 * Updates curPollTimeout according to the aging algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
 * @param timeout_control Either TIMEOUT_TIMEDOUT or TIMEOUT_EVENTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
static void update_poll_timeout(int timeout_control) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    PRINT2("tout: %d\n", timeout_control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    // If static_poll_timeout is set, curPollTimeout has the fixed value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    if (static_poll_timeout != 0) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    // Update it otherwise
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   534
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   535
    switch(awt_poll_alg) {
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   536
    case AWT_POLL_AGING_SLOW:
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   537
        if (timeout_control == TIMEOUT_TIMEDOUT) {
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   538
            /* add 1/4 (plus 1, in case the division truncates to 0) */
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   539
            curPollTimeout += ((curPollTimeout>>2) + 1);
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   540
            curPollTimeout = min(AWT_MAX_POLL_TIMEOUT, curPollTimeout);
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   541
        } else if (timeout_control == TIMEOUT_EVENTS) {
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   542
            /* subtract 1/4 (plus 1, in case the division truncates to 0) */
31655
6bc54745fef4 8098535: Test closed/java/awt/Clipboard/ImageTransferTest/ImageTransferTest fails on OEL 7.1
ssadetsky
parents: 28079
diff changeset
   543
            if (curPollTimeout > 0) {
6bc54745fef4 8098535: Test closed/java/awt/Clipboard/ImageTransferTest/ImageTransferTest fails on OEL 7.1
ssadetsky
parents: 28079
diff changeset
   544
                curPollTimeout -= ((curPollTimeout>>2) + 1);
6bc54745fef4 8098535: Test closed/java/awt/Clipboard/ImageTransferTest/ImageTransferTest fails on OEL 7.1
ssadetsky
parents: 28079
diff changeset
   545
                curPollTimeout = max(AWT_MIN_POLL_TIMEOUT, curPollTimeout);
6bc54745fef4 8098535: Test closed/java/awt/Clipboard/ImageTransferTest/ImageTransferTest fails on OEL 7.1
ssadetsky
parents: 28079
diff changeset
   546
            }
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   547
        }
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   548
        break;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   549
    case AWT_POLL_AGING_FAST:
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   550
        if (timeout_control == TIMEOUT_TIMEDOUT) {
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   551
            curPollTimeout += ((curPollTimeout>>2) + 1);
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   552
            curPollTimeout = min(AWT_MAX_POLL_TIMEOUT, curPollTimeout);
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   553
            if((int)curPollTimeout > AWT_POLL_THRESHOLD || (int)curPollTimeout == AWT_POLL_BLOCK)
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   554
                curPollTimeout = AWT_POLL_BLOCK;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   555
        } else if (timeout_control == TIMEOUT_EVENTS) {
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   556
            curPollTimeout = max(AWT_MIN_POLL_TIMEOUT, 1);
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   557
        }
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   558
        break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
 * Gets the best timeout for the next call to poll().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
 * @param nextTaskTime -1, if there are no tasks; next time when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
 * timeout task needs to be run, in millis(of currentTimeMillis)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
static uint32_t get_poll_timeout(jlong nextTaskTime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
{
42455
a66ed8458668 8170525: Fix minor issues in AWT/ECC/PKCS11 coding
goetz
parents: 40205
diff changeset
   570
    uint32_t ret_timeout = 0;
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   571
    uint32_t timeout;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   572
    uint32_t taskTimeout;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   573
    uint32_t flushTimeout;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   574
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    jlong curTime = awtJNI_TimeMillis();
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   576
    timeout = curPollTimeout;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   577
    switch(awt_poll_alg) {
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   578
    case AWT_POLL_AGING_SLOW:
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   579
    case AWT_POLL_AGING_FAST:
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   580
        taskTimeout = (nextTaskTime == -1) ? AWT_MAX_POLL_TIMEOUT : (uint32_t)max(0, (int32_t)(nextTaskTime - curTime));
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   581
        flushTimeout = (awt_next_flush_time > 0) ? (uint32_t)max(0, (int32_t)(awt_next_flush_time - curTime)) : AWT_MAX_POLL_TIMEOUT;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   582
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   583
        PRINT2("to: %d, ft: %d, to: %d, tt: %d, mil: %d\n", taskTimeout, flushTimeout, timeout, (int)nextTaskTime, (int)curTime);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   585
        // Adjust timeout to flush_time and task_time
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   586
        ret_timeout = min(flushTimeout, min(taskTimeout, timeout));
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   587
        if((int)curPollTimeout == AWT_POLL_BLOCK)
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   588
           ret_timeout = AWT_POLL_BLOCK;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   589
        break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
9002
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   591
    case AWT_POLL_FALSE:
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   592
        ret_timeout = (nextTaskTime > curTime) ?
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   593
            (nextTaskTime - curTime) :
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   594
            ((nextTaskTime == -1) ? -1 : 0);
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   595
        break;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   596
    }
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   597
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   598
    return ret_timeout;
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   599
6ee0abf0167f 7030063: AWT support for SE-Embedded integration
dholmes
parents: 7770
diff changeset
   600
} /* get_poll_timeout() */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
/*
37699
c3d9835483f9 8154269: Remove unused or unnecessary Xm/Xt files and header includes
prr
parents: 33653
diff changeset
   603
 * Waits for X events to appear on the pipe. Returns only when
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
 * it is likely (but not definite) that there are events waiting to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
 * be processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
 * This routine also flushes the outgoing X queue, when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
 * awt_next_flush_time has been reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
 * If fdAWTPipe is greater or equal than zero the routine also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
 * checks if there are events pending on the putback queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
waitForEvents(JNIEnv *env, jlong nextTaskTime) {
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   615
    if (performPoll(env, nextTaskTime)
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   616
          && (awt_next_flush_time > 0)
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   617
          && (awtJNI_TimeMillis() >= awt_next_flush_time)) {
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   618
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   619
                XFlush(awt_display);
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   620
                awt_last_flush_time = awt_next_flush_time;
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   621
                awt_next_flush_time = 0LL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
} /* waitForEvents() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_waitForEvents (JNIEnv *env, jclass class, jlong nextTaskTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    waitForEvents(env, nextTaskTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_awt_1toolkit_1init (JNIEnv *env, jclass class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    awt_MainThread = pthread_self();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    awt_pipe_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    readEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_awt_1output_1flush (JNIEnv *env, jclass class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    awt_output_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_wakeup_1poll (JNIEnv *env, jclass class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    wakeUp();
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
 * Polls both the X pipe and our AWT utility pipe. Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
 * when there is data on one of the pipes, or the operation times
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
 * out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
 * Not all Xt events come across the X pipe (e.g., timers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
 * and alternate inputs), so we must time out every now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
 * then to check the Xt event queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
 * The fdAWTPipe will be empty when this returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
 */
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   655
static Boolean
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
performPoll(JNIEnv *env, jlong nextTaskTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    static Bool pollFdsInited = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    static char read_buf[AWT_POLL_BUFSIZE + 1];    /* dummy buf to empty pipe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    uint32_t timeout = get_poll_timeout(nextTaskTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    int32_t result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    if (!pollFdsInited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        pollFds[0].fd = ConnectionNumber(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        pollFds[0].events = POLLRDNORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        pollFds[0].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        pollFds[1].fd = AWT_READPIPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        pollFds[1].events = POLLRDNORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        pollFds[1].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        pollFdsInited = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        pollFds[0].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        pollFds[1].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    AWT_NOFLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    /* ACTUALLY DO THE POLL() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    if (timeout == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        // be sure other threads get a chance
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   682
        if (!awtJNI_ThreadYield(env)) {
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   683
            return FALSE;
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   684
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    if (tracing) poll_sleep_time = awtJNI_TimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    result = poll( pollFds, 2, (int32_t) timeout );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    if (tracing) poll_wakeup_time = awtJNI_TimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    PRINT("%d of %d, res: %d\n", (int)(poll_wakeup_time-poll_sleep_time), (int)timeout, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    if (result == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        /* poll() timed out -- update timeout value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        update_poll_timeout(TIMEOUT_TIMEDOUT);
18135
d9be76f1a19c 8005661: [parfait] Possible buffer overrun in jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c
pchelko
parents: 11093
diff changeset
   696
        PRINT2("performPoll(): TIMEOUT_TIMEDOUT curPollTimeout = %d \n", curPollTimeout);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    if (pollFds[1].revents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        PRINT("Woke up\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        /* There is data on the AWT pipe - empty it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            count = read(AWT_READPIPE, read_buf, AWT_POLL_BUFSIZE );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        } while (count == AWT_POLL_BUFSIZE );
18135
d9be76f1a19c 8005661: [parfait] Possible buffer overrun in jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c
pchelko
parents: 11093
diff changeset
   705
        PRINT2("performPoll():  data on the AWT pipe: curPollTimeout = %d \n", curPollTimeout);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    if (pollFds[0].revents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        // Events in X pipe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        update_poll_timeout(TIMEOUT_EVENTS);
23304
bb48872f9326 8035287: gcc warnings compiling various libraries files
mikael
parents: 18135
diff changeset
   710
        PRINT2("performPoll(): TIMEOUT_EVENTS curPollTimeout = %d \n", curPollTimeout);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   712
    return TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
} /* performPoll() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
 * Schedules next auto-flush event or performs forced flush depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
 * on the time of the previous flush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
 */
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   720
void awt_output_flush(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    if (awt_next_flush_time == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        jlong curTime = awtJNI_TimeMillis(); // current time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        jlong l_awt_last_flush_time = awt_last_flush_time; // last time we flushed queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        jlong next_flush_time = l_awt_last_flush_time + AWT_FLUSH_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        if (curTime >= next_flush_time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            // Enough time passed from last flush
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            PRINT("f1\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            XFlush(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            awt_last_flush_time = curTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            AWT_NOFLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            awt_next_flush_time = next_flush_time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            PRINT("f2\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            wakeUp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
 * Wakes-up poll() in performPoll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
 */
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   747
static void wakeUp(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    static char wakeUp_char = 'p';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    if (!isMainThread() && awt_pipe_inited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        write ( AWT_WRITEPIPE, &wakeUp_char, 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
/* ========================== End poll section ================================= */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
 * Class:     java_awt_KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
Java_java_awt_KeyboardFocusManager_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    (JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
 * Class:     sun_awt_X11_XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
 * Method:    getEnv
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
 * Signature: (Ljava/lang/String;)Ljava/lang/String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
JNIEXPORT jstring JNICALL Java_sun_awt_X11_XToolkit_getEnv
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
(JNIEnv *env , jclass clazz, jstring key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    char *ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    const char *keystr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    jstring ret = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    keystr = JNU_GetStringPlatformChars(env, key, NULL);
4260
913d5ec97629 6891483: XToolkit.getEnv() checks for NULL on a wrong symbol
anthony
parents: 2811
diff changeset
   780
    if (keystr) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        ptr = getenv(keystr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        if (ptr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            ret = JNU_NewStringPlatform(env, (const char *) ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        JNU_ReleaseStringPlatformChars(env, key, (const char*)keystr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
void print_stack(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
  void *array[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
  size_t size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
  char **strings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
  size_t i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
  size = backtrace (array, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
  strings = backtrace_symbols (array, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
  fprintf (stderr, "Obtained %zd stack frames.\n", size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
  for (i = 0; i < size; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     fprintf (stderr, "%s\n", strings[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
  free (strings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
Window get_xawt_root_shell(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
  static jclass classXRootWindow = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
  static jmethodID methodGetXRootWindow = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
  static Window xawt_root_shell = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
  if (xawt_root_shell == None){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
      if (classXRootWindow == NULL){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
          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
   818
          if (!JNU_IsNull(env, cls_tmp)) {
8a5fd008f98b 6866808: nsk/stress/jck12a/jck12a014 crashes with SIGSEGV at [libjvm.so+0xc5b10]
dcherepanov
parents: 5506
diff changeset
   819
              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
   820
              (*env)->DeleteLocalRef(env, cls_tmp);
8a5fd008f98b 6866808: nsk/stress/jck12a/jck12a014 crashes with SIGSEGV at [libjvm.so+0xc5b10]
dcherepanov
parents: 5506
diff changeset
   821
          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
      if( classXRootWindow != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
          methodGetXRootWindow = (*env)->GetStaticMethodID(env, classXRootWindow, "getXRootWindow", "()J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
      if( classXRootWindow != NULL && methodGetXRootWindow !=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
          xawt_root_shell = (Window) (*env)->CallStaticLongMethod(env, classXRootWindow, methodGetXRootWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
      if ((*env)->ExceptionCheck(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
  return xawt_root_shell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
 * Old, compatibility, backdoor for DT.  This is a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
 * implementation.  It keeps the signature, but acts on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
 * awt_root_shell, not the frame passed as an argument.  Note, that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
 * the code that uses the old backdoor doesn't work correctly with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
 * gnome session proxy that checks for WM_COMMAND when the window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
 * firts mapped, because DT code calls this old backdoor *after* the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
 * frame is shown or it would get NPE with old AWT (previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
 * implementation of this backdoor) otherwise.  Old style session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
 * managers (e.g. CDE) that check WM_COMMAND only during session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
 * checkpoint should work fine, though.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
 * NB: The function name looks deceptively like a JNI native method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
 * name.  It's not!  It's just a plain function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    jobject frame, jstring jcommand)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    const char *command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    XTextProperty text_prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    char *c[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    int32_t status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    Window xawt_root_window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    xawt_root_window = get_xawt_root_shell(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    if ( xawt_root_window == None ) {
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   867
        AWT_UNLOCK();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        JNU_ThrowNullPointerException(env, "AWT root shell is unrealized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    command = (char *) JNU_GetStringPlatformChars(env, jcommand, NULL);
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   873
    if (command != NULL) {
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   874
        c[0] = (char *)command;
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   875
        status = XmbTextListToTextProperty(awt_display, c, 1,
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   876
                                           XStdICCTextStyle, &text_prop);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   878
        if (status == Success || status > 0) {
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   879
            XSetTextProperty(awt_display, xawt_root_window,
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   880
                             &text_prop, XA_WM_COMMAND);
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   881
            if (text_prop.value != NULL)
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   882
                XFree(text_prop.value);
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   883
        }
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   884
        JNU_ReleaseStringPlatformChars(env, jcommand, command);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
 * New DT backdoor to set WM_COMMAND.  New code should use this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
 * backdoor and call it *before* the first frame is shown so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
 * gnome session proxy can correctly handle it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
 * NB: The function name looks deceptively like a JNI native method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
 * name.  It's not!  It's just a plain function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
JNIEXPORT void JNICALL
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   899
Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jarray)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
{
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   901
    jsize length;
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   902
    char ** array;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    XTextProperty text_prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    int status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    Window xawt_root_window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    xawt_root_window = get_xawt_root_shell(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    if (xawt_root_window == None) {
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   911
      AWT_UNLOCK();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
      JNU_ThrowNullPointerException(env, "AWT root shell is unrealized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   916
    array = stringArrayToNative(env, jarray, &length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   918
    if (array != NULL) {
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   919
        status = XmbTextListToTextProperty(awt_display, array, length,
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   920
                                           XStdICCTextStyle, &text_prop);
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   921
        if (status < 0) {
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   922
            switch (status) {
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   923
            case XNoMemory:
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   924
                JNU_ThrowOutOfMemoryError(env,
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   925
                    "XmbTextListToTextProperty: XNoMemory");
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   926
                break;
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   927
            case XLocaleNotSupported:
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   928
                JNU_ThrowInternalError(env,
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   929
                    "XmbTextListToTextProperty: XLocaleNotSupported");
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   930
                break;
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   931
            case XConverterNotFound:
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   932
                JNU_ThrowNullPointerException(env,
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   933
                    "XmbTextListToTextProperty: XConverterNotFound");
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   934
                break;
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   935
            default:
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   936
                JNU_ThrowInternalError(env,
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   937
                    "XmbTextListToTextProperty: unknown error");
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   938
            }
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   939
        } else {
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   940
            XSetTextProperty(awt_display, xawt_root_window,
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   941
                                 &text_prop, XA_WM_COMMAND);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   944
        if (text_prop.value != NULL)
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   945
            XFree(text_prop.value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
24165
fb4f67872b27 8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt
azvegint
parents: 23328
diff changeset
   947
        freeNativeStringArray(array, length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
 * Class:     java_awt_TrayIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
JNIEXPORT void JNICALL Java_java_awt_TrayIcon_initIDs(JNIEnv *env , jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
 * Class:     java_awt_Cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
 * Method:    finalizeImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
Java_java_awt_Cursor_finalizeImpl(JNIEnv *env, jclass clazz, jlong pData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    Cursor xcursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    xcursor = (Cursor)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    if (xcursor != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        XFreeCursor(awt_display, xcursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
}
2810
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
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
 * Class:     sun_awt_X11_XToolkit
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   983
 * Method:    getNumberOfButtonsImpl
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   984
 * Signature: ()I
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   985
 */
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   986
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
   987
(JNIEnv * env, jobject cls){
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   988
    if (num_buttons == 0) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   989
        num_buttons = getNumButtons();
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   990
    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   991
    return num_buttons;
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
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   994
int32_t getNumButtons(void) {
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   995
    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
   996
    int32_t xinputAvailable;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   997
    int32_t numDevices, devIdx, clsIdx;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   998
    XDeviceInfo* devices;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
   999
    XDeviceInfo* aDevice;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1000
    XButtonInfo* bInfo;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1001
    int32_t local_num_buttons = 0;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1002
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1003
    /* 4700242:
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1004
     * 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
  1005
     * (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
  1006
     * 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
  1007
     * 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
  1008
     * before calling XTestFakeButtonEvent().
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1009
     */
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1010
    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
  1011
    if (xinputAvailable) {
40148
f590f972ba1a 8161742: [parfait] Uninitialised memory in isXTestAvailable of awt_Robot.c:65
vadim
parents: 37699
diff changeset
  1012
        DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XINPUT) returns major_opcode = %d, first_event = %d, first_error = %d",
f590f972ba1a 8161742: [parfait] Uninitialised memory in isXTestAvailable of awt_Robot.c:65
vadim
parents: 37699
diff changeset
  1013
                        major_opcode, first_event, first_error);
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1014
        devices = XListInputDevices(awt_display, &numDevices);
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1015
        for (devIdx = 0; devIdx < numDevices; devIdx++) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1016
            aDevice = &(devices[devIdx]);
2811
8828b8313cab 6844750: Solaris build failed after 6799099
dav
parents: 2810
diff changeset
  1017
#ifdef IsXExtensionPointer
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1018
            if (aDevice->use == IsXExtensionPointer) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1019
                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
  1020
                    if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1021
                        bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx]));
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1022
                        local_num_buttons = bInfo->num_buttons;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1023
                        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
  1024
                        break;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1025
                    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1026
                }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1027
                break;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1028
            }
2811
8828b8313cab 6844750: Solaris build failed after 6799099
dav
parents: 2810
diff changeset
  1029
#endif
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1030
            if (local_num_buttons <= 0 ) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1031
                if (aDevice->use == IsXPointer) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1032
                    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
  1033
                        if (aDevice->inputclassinfo[clsIdx].class == ButtonClass) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1034
                            bInfo = (XButtonInfo*)(&(aDevice->inputclassinfo[clsIdx]));
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1035
                            local_num_buttons = bInfo->num_buttons;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1036
                            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
  1037
                            break;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1038
                        }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1039
                    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1040
                    break;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1041
                }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1042
            }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1043
        }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1044
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1045
        XFreeDeviceList(devices);
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1046
    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1047
    else {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1048
        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
  1049
    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1050
    if (local_num_buttons == 0 ) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1051
        local_num_buttons = 3;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1052
    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1053
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1054
    return local_num_buttons;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2802
diff changeset
  1055
}
11090
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1056
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1057
/*
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1058
 * Class:     sun_awt_X11_XWindowPeer
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1059
 * Method:    getJvmPID
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1060
 * Signature: ()I
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1061
 */
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1062
JNIEXPORT jint JNICALL Java_sun_awt_X11_XWindowPeer_getJvmPID
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1063
(JNIEnv *env, jclass cls)
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1064
{
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1065
    /* Return the JVM's PID. */
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1066
    return getpid();
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1067
}
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1068
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1069
#ifndef HOST_NAME_MAX
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1070
#define HOST_NAME_MAX 1024 /* Overestimated */
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1071
#endif
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1072
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1073
/*
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1074
 * Class:     sun_awt_X11_XWindowPeer
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1075
 * Method:    getLocalHostname
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1076
 * Signature: ()Ljava/lang/String;
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1077
 */
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1078
JNIEXPORT jstring JNICALL Java_sun_awt_X11_XWindowPeer_getLocalHostname
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1079
(JNIEnv *env, jclass cls)
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1080
{
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1081
    /* Return the machine's FQDN. */
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1082
    char hostname[HOST_NAME_MAX + 1];
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1083
    if (gethostname(hostname, HOST_NAME_MAX + 1) == 0) {
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1084
        hostname[HOST_NAME_MAX] = '\0';
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1085
        jstring res = (*env)->NewStringUTF(env, hostname);
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1086
        return res;
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1087
    }
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1088
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1089
    return (jstring)NULL;
6c62c6d19ea1 7103610: _NET_WM_PID and WM_CLIENT_MACHINE are not set
anthony
parents: 9050
diff changeset
  1090
}