/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#ifdef __linux__
#include <execinfo.h>
#endif
#include <jvm.h>
#include <jni.h>
#include <jlong.h>
#include <jni_util.h>
#include "awt_p.h"
#include "awt_Component.h"
#include "awt_MenuComponent.h"
#include "awt_KeyboardFocusManager.h"
#include "awt_Font.h"
#include "sun_awt_X11_XToolkit.h"
#include "java_awt_SystemColor.h"
#include "java_awt_TrayIcon.h"
#include <unistd.h>
// Tracing level
static int tracing = 0;
#ifdef PRINT
#endif
#ifdef PRINT2
#endif
#ifndef HEADLESS
extern struct MFontPeerIDs mFontPeerIDs;
{
}
#endif /* !HEADLESS */
/* This function gets called from the static initializer for FileDialog.java
to initialize the fieldIDs for fields that may be accessed from C */
{
}
{
}
/*
* Class: sun_awt_X11_XToolkit
* Method: getTrayIconDisplayTimeout
* Signature: ()J
*/
{
#ifndef JAVASE_EMBEDDED
return (jlong) 2000;
#else
return (jlong) 10000;
#endif
}
/*
* Class: sun_awt_X11_XToolkit
* Method: getDefaultXColormap
* Signature: ()J
*/
{
}
{
}
{
return JNI_VERSION_1_2;
}
/*
* Class: sun_awt_X11_XToolkit
* Method: nativeLoadSystemColors
* Signature: ([I)V
*/
{
}
{
/* Use _NoClientCode() methods for trusted methods, so that we
* know that we are not invoking client code on trusted threads
*/
return;
}
"Z");
"Lsun/awt/AppContext;");
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
#ifdef HEADLESS
return JNI_TRUE;
#else
return JNI_FALSE;
#endif
}
{
}
/* ========================== Begin poll section ================================ */
// Includes
#include <limits.h>
#include <locale.h>
#include <pthread.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <poll.h>
#ifndef POLLRDNORM
#endif
// Prototypes
static void awt_pipe_init();
static void wakeUp();
static void update_poll_timeout(int timeout_control);
// Defines
#ifndef bzero
#endif
#ifdef JAVASE_EMBEDDED
#else
#endif
#define TIMEOUT_TIMEDOUT 0
/* awt_poll_alg - AWT Poll Events Aging Algorithms */
// Static fields
#ifdef JAVASE_EMBEDDED
#else
#endif
// AWT static poll timeout. Zero means "not set", aging algorithm is
// used. Static poll timeout values higher than 50 cause application
// look "slow" - they don't respond to user request fast
// enough. Static poll timeout value less than 10 are usually
// considered by schedulers as zero, so this might cause unnecessary
// CPU consumption by Java. The values between 10 - 50 are suggested
// for single client desktop configurations. For SunRay servers, it
// is highly recomended to use aging algorithm (set static poll timeout
// to 0).
return awt_MainThread == pthread_self();
}
/*
* Creates the AWT utility pipe. This pipe exists solely so that
* we can cause the main event thread to wake up from a poll() or
* select() by writing to this pipe.
*/
static void
awt_pipe_init() {
if (awt_pipe_inited) {
return;
}
if ( pipe ( awt_pipe_fds ) == 0 )
{
/*
** the write wakes us up from the infinite sleep, which
** then we cause a delay of AWT_FLUSHTIME and then we
** flush.
*/
/* set the pipe to be non-blocking */
}
else
{
AWT_READPIPE = -1;
AWT_WRITEPIPE = -1;
}
} /* awt_pipe_init() */
/**
* Reads environment variables to initialize timeout fields.
*/
static void readEnv() {
char * value;
int tmp_poll_alg;
if (env_read) return;
if (AWT_MAX_POLL_TIMEOUT == 0) {
}
}
if (AWT_FLUSH_TIMEOUT == 0) {
}
}
}
}
if (static_poll_timeout != 0) {
}
// non-blocking poll()
switch(tmp_poll_alg) {
case AWT_POLL_FALSE:
case AWT_POLL_AGING_SLOW:
case AWT_POLL_AGING_FAST:
break;
default:
PRINT("Unknown value of _AWT_POLL_ALG, assuming Slow Aging Algorithm by default");
break;
}
}
}
/**
* Returns the amount of milliseconds similar to System.currentTimeMillis()
*/
static jlong
awtJNI_TimeMillis(void)
{
struct timeval t;
gettimeofday(&t, 0);
}
/**
* Updates curPollTimeout according to the aging algorithm.
* @param timeout_control Either TIMEOUT_TIMEDOUT or TIMEOUT_EVENTS
*/
// If static_poll_timeout is set, curPollTimeout has the fixed value
if (static_poll_timeout != 0) return;
// Update it otherwise
switch(awt_poll_alg) {
case AWT_POLL_AGING_SLOW:
if (timeout_control == TIMEOUT_TIMEDOUT) {
/* add 1/4 (plus 1, in case the division truncates to 0) */
} else if (timeout_control == TIMEOUT_EVENTS) {
/* subtract 1/4 (plus 1, in case the division truncates to 0) */
}
break;
case AWT_POLL_AGING_FAST:
if (timeout_control == TIMEOUT_TIMEDOUT) {
} else if (timeout_control == TIMEOUT_EVENTS) {
}
break;
}
}
/*
* Gets the best timeout for the next call to poll().
*
* @param nextTaskTime -1, if there are no tasks; next time when
* timeout task needs to be run, in millis(of currentTimeMillis)
*/
{
switch(awt_poll_alg) {
case AWT_POLL_AGING_SLOW:
case AWT_POLL_AGING_FAST:
taskTimeout = (nextTaskTime == -1) ? AWT_MAX_POLL_TIMEOUT : (uint32_t)max(0, (int32_t)(nextTaskTime - curTime));
flushTimeout = (awt_next_flush_time > 0) ? (uint32_t)max(0, (int32_t)(awt_next_flush_time - curTime)) : AWT_MAX_POLL_TIMEOUT;
PRINT2("to: %d, ft: %d, to: %d, tt: %d, mil: %d\n", taskTimeout, flushTimeout, timeout, (int)nextTaskTime, (int)curTime);
// Adjust timeout to flush_time and task_time
if((int)curPollTimeout == AWT_POLL_BLOCK)
break;
case AWT_POLL_FALSE:
(nextTaskTime - curTime) :
break;
}
return ret_timeout;
} /* get_poll_timeout() */
/*
* it is likely (but not definite) that there are events waiting to
* be processed.
*
* This routine also flushes the outgoing X queue, when the
* awt_next_flush_time has been reached.
*
* If fdAWTPipe is greater or equal than zero the routine also
* checks if there are events pending on the putback queue.
*/
void
}
} /* waitForEvents() */
JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_waitForEvents (JNIEnv *env, jclass class, jlong nextTaskTime) {
}
readEnv();
}
}
wakeUp();
}
/*
* Polls both the X pipe and our AWT utility pipe. Returns
* when there is data on one of the pipes, or the operation times
* out.
*
* Not all Xt events come across the X pipe (e.g., timers
* and alternate inputs), so we must time out every now and
* then to check the Xt event queue.
*
* The fdAWTPipe will be empty when this returns.
*/
static void
if (!pollFdsInited) {
} else {
}
/* ACTUALLY DO THE POLL() */
if (timeout == 0) {
// be sure other threads get a chance
}
AWT_LOCK();
if (result == 0) {
/* poll() timed out -- update timeout value */
PRINT2("%s(): TIMEOUT_TIMEDOUT curPollTimeout = %d \n",
}
int count;
PRINT("Woke up\n");
/* There is data on the AWT pipe - empty it */
do {
} while (count == AWT_POLL_BUFSIZE );
PRINT2("%s(): data on the AWT pipe: curPollTimeout = %d \n",
}
// Events in X pipe
PRINT2("%s(): TIMEOUT_EVENTS curPollTimeout = %ld \n",
}
return;
} /* performPoll() */
/**
* Schedules next auto-flush event or performs forced flush depending
* on the time of the previous flush.
*/
void awt_output_flush() {
if (awt_next_flush_time == 0) {
if (curTime >= next_flush_time) {
// Enough time passed from last flush
PRINT("f1\n");
AWT_LOCK();
} else {
PRINT("f2\n");
wakeUp();
}
}
}
/**
* Wakes-up poll() in performPoll
*/
static void wakeUp() {
if (!isMainThread() && awt_pipe_inited) {
}
}
/* ========================== End poll section ================================= */
/*
* Class: java_awt_KeyboardFocusManager
* Method: initIDs
* Signature: ()V
*/
{
}
/*
* Class: sun_awt_X11_XToolkit
* Method: getEnv
*/
if (keystr) {
if (ptr) {
}
}
return ret;
}
#ifdef __linux__
void print_stack(void)
{
char **strings;
size_t i;
for (i = 0; i < size; i++)
}
#endif
if (xawt_root_shell == None){
if (classXRootWindow == NULL){
}
}
if( classXRootWindow != NULL) {
}
xawt_root_shell = (Window) (*env)->CallStaticLongMethod(env, classXRootWindow, methodGetXRootWindow);
}
}
}
return xawt_root_shell;
}
/*
* Old, compatibility, backdoor for DT. This is a different
* implementation. It keeps the signature, but acts on
* awt_root_shell, not the frame passed as an argument. Note, that
* the code that uses the old backdoor doesn't work correctly with
* gnome session proxy that checks for WM_COMMAND when the window is
* firts mapped, because DT code calls this old backdoor *after* the
* frame is shown or it would get NPE with old AWT (previous
* implementation of this backdoor) otherwise. Old style session
* managers (e.g. CDE) that check WM_COMMAND only during session
* checkpoint should work fine, though.
*
* NB: The function name looks deceptively like a JNI native method
* name. It's not! It's just a plain function.
*/
{
const char *command;
char *c[1];
AWT_LOCK();
if ( xawt_root_window == None ) {
AWT_UNLOCK();
return;
}
c[0] = (char *)command;
}
AWT_UNLOCK();
}
/*
* New DT backdoor to set WM_COMMAND. New code should use this
* backdoor and call it *before* the first frame is shown so that
* gnome session proxy can correctly handle it.
*
* NB: The function name looks deceptively like a JNI native method
* name. It's not! It's just a plain function.
*/
{
int argc;
const char **cargv;
int status;
int i;
AWT_LOCK();
if (xawt_root_window == None) {
AWT_UNLOCK();
return;
}
if (argc == 0) {
AWT_UNLOCK();
return;
}
/* array of C strings */
AWT_UNLOCK();
return;
}
/* fill C array with platform chars of java strings */
for (i = 0; i < argc; ++i) {
const char *cs;
}
}
}
/* grr, X prototype doesn't declare cargv as const, thought it really is */
if (status < 0) {
switch (status) {
case XNoMemory:
"XmbTextListToTextProperty: XNoMemory");
break;
case XLocaleNotSupported:
"XmbTextListToTextProperty: XLocaleNotSupported");
break;
case XConverterNotFound:
"XmbTextListToTextProperty: XConverterNotFound");
break;
default:
"XmbTextListToTextProperty: unknown error");
}
} else {
}
for (i = 0; i < argc; ++i) {
continue;
}
AWT_UNLOCK();
}
/*
* Class: java_awt_TrayIcon
* Method: initIDs
* Signature: ()V
*/
{
}
/*
* Class: java_awt_Cursor
* Method: finalizeImpl
* Signature: ()V
*/
{
AWT_LOCK();
AWT_UNLOCK();
}
}
/*
* Class: sun_awt_X11_XToolkit
* Method: getNumberOfButtonsImpl
* Signature: ()I
*/
if (num_buttons == 0) {
num_buttons = getNumButtons();
}
return num_buttons;
}
/* 4700242:
* If XTest is asked to press a non-existant mouse button
* (i.e. press Button3 on a system configured with a 2-button mouse),
* then a crash may happen. To avoid this, we use the XInput
* extension to query for the number of buttons on the XPointer, and check
* before calling XTestFakeButtonEvent().
*/
DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XINPUT) returns major_opcode = %d, first_event = %d, first_error = %d",
if (xinputAvailable) {
#ifdef IsXExtensionPointer
break;
}
}
break;
}
#endif
if (local_num_buttons <= 0 ) {
break;
}
}
break;
}
}
}
}
else {
DTRACE_PRINTLN1("RobotPeer: XINPUT extension is unavailable, assuming %d mouse buttons", num_buttons);
}
if (local_num_buttons == 0 ) {
local_num_buttons = 3;
}
return local_num_buttons;
}
/*
* Class: sun_awt_X11_XWindowPeer
* Method: getJvmPID
* Signature: ()I
*/
{
/* Return the JVM's PID. */
return getpid();
}
#ifndef HOST_NAME_MAX
#endif
/*
* Class: sun_awt_X11_XWindowPeer
* Method: getLocalHostname
*/
{
/* Return the machine's FQDN. */
return res;
}
}