示例#1
0
/*
 * Class:     sun_awt_DefaultMouseInfoPeer
 * Method:    isWindowUnderMouse
 * Signature: (Ljava/awt/Window)Z
 */
JNIEXPORT jboolean JNICALL Java_sun_awt_DefaultMouseInfoPeer_isWindowUnderMouse
  (JNIEnv * env, jclass cls, jobject window)
{
    Window rootWindow, childWindow;
    int i;
    int32_t xr, yr, xw, yw;
    uint32_t keys;
    BOOL pointerFound;
    struct FrameData *wdata;
    jobject winPeer;

    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
        return JNI_FALSE;
    }
    winPeer = (*env)->GetObjectField(env, window, componentIDs.peer);
    if (JNU_IsNull(env, winPeer)) {
        return JNI_FALSE;
    }
    wdata = (struct FrameData *)
        JNU_GetLongFieldAsPtr(env, winPeer, mComponentPeerIDs.pData);
    (*env)->DeleteLocalRef(env, winPeer);
    if (wdata == NULL) {
        return JNI_FALSE;
    }

    AWT_LOCK();
    pointerFound = XQueryPointer(awt_display, XtWindow(wdata->winData.shell),
                                 &rootWindow, &childWindow,
                                 &xr, &yr, &xw, &yw, &keys);
    AWT_UNLOCK();
    return pointerFound ? JNI_TRUE : JNI_FALSE;
}
示例#2
0
/**
 * This function invokes the native threadsafe locking mechanism (e.g.
 * the AWT_LOCK() macro in the GLX case) to ensure that any following OpenGL
 * commands have synchronized access to the OpenGL libraries/hardware.
 */
void
OGLSD_LockImpl(JNIEnv *env)
{
    J2dTraceLn(J2D_TRACE_INFO, "in OGLSD_LockImpl");

    AWT_LOCK();
}
示例#3
0
// this should be called from XRobotPeer constructor
JNIEXPORT void JNICALL
Java_sun_awt_X11_XRobotPeer_setup (JNIEnv * env, jclass cls, jint numberOfButtons, jintArray buttonDownMasks)
{
    int32_t xtestAvailable;
    jint *tmp;
    int i;

    DTRACE_PRINTLN("RobotPeer: setup()");

    num_buttons = numberOfButtons;
    tmp = (*env)->GetIntArrayElements(env, buttonDownMasks, JNI_FALSE);
    masks = (jint *)malloc(sizeof(jint) * num_buttons);
    if (masks == (jint *) NULL) {
        JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL);
        (*env)->ReleaseIntArrayElements(env, buttonDownMasks, tmp, 0);
        return;
    }
    for (i = 0; i < num_buttons; i++) {
        masks[i] = tmp[i];
    }
    (*env)->ReleaseIntArrayElements(env, buttonDownMasks, tmp, 0);

    AWT_LOCK();
    xtestAvailable = isXTestAvailable();
    DTRACE_PRINTLN1("RobotPeer: XTest available = %d", xtestAvailable);
    if (!xtestAvailable) {
        JNU_ThrowByName(env, "java/awt/AWTException", "java.awt.Robot requires your X server support the XTEST extension version 2.2");
    }

    AWT_UNLOCK();
}
JNIEXPORT void JNICALL
    awt_Lock(JNIEnv* env)
{
    if (awtLockInited) {
        AWT_LOCK();
    }
}
JNIEXPORT jobject JNICALL
    awt_GetComponent(JNIEnv* env, void* platformInfo)
{
    Window window = (Window)platformInfo;
    jobject peer = NULL;
    jobject target = NULL;

    AWT_LOCK();

    if (window != None) {
        peer = JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit",
            "windowToXWindow", "(J)Lsun/awt/X11/XBaseWindow;", (jlong)window).l;
    }
    if ((peer != NULL) &&
        (JNU_IsInstanceOfByName(env, peer, "sun/awt/X11/XWindow") == 1)) {
        target = (*env)->GetObjectField(env, peer, targetID);
    }

    if (target == NULL) {
        JNU_ThrowNullPointerException(env, "NullPointerException");
        AWT_UNLOCK();
        return (jobject)NULL;
    }

    AWT_UNLOCK();

    return target;
}
JNIEXPORT void JNICALL Java_sun_font_FontManager_setNativeFontPath
(JNIEnv *env, jclass obj, jstring theString) {
#ifdef HEADLESS
    return;
#else
    fDirRecord fDir;
    const char *theChars;

    if (awt_display == NULL) {
        return;
    }
    AWT_LOCK();
    if (shouldSetXFontPath(env)) {
        theChars = (*env)->GetStringUTFChars (env, theString, 0);
        fDir.num = 1;
        fDir.name[0] = theChars;
        /* printf ("Registering the font path here %s \n", theChars ); */
        AddFontsToX11FontPath ( &fDir );
        if (theChars) {
            (*env)->ReleaseStringUTFChars (env,
                                           theString, (const char*)theChars);
        }
    }
    AWT_UNLOCK();

#endif
}
示例#7
0
JNIEXPORT void JNICALL
Java_sun_awt_X11_XRobotPeer_mouseWheelImpl (JNIEnv *env,
                           jclass cls,
                           jint wheelAmt) {
/* Mouse wheel is implemented as a button press of button 4 and 5, so it */
/* probably could have been hacked into robot_mouseButtonEvent, but it's */
/* cleaner to give it its own command type, in case the implementation   */
/* needs to be changed later.  -bchristi, 6/20/01                        */

    int32_t repeat = abs(wheelAmt);
    int32_t button = wheelAmt < 0 ? 4 : 5;  /* wheel up:   button 4 */
                                                 /* wheel down: button 5 */
    int32_t loopIdx;

    AWT_LOCK();

    DTRACE_PRINTLN1("RobotPeer: mouseWheelImpl(%i)", wheelAmt);

    for (loopIdx = 0; loopIdx < repeat; loopIdx++) { /* do nothing for   */
                                                     /* wheelAmt == 0    */
        XTestFakeButtonEvent(awt_display, button, True, CurrentTime);
        XTestFakeButtonEvent(awt_display, button, False, CurrentTime);
    }
    XSync(awt_display, False);

    AWT_UNLOCK();
}
示例#8
0
/*
 * If the application doesn't receive events with timestamp for a long time
 * XtLastTimestampProcessed() will return out-of-date value. This may cause
 * selection handling routines to fail (see BugTraq ID 4085183).
 * This routine is to resolve this problem. It queries the current X server
 * time by appending a zero-length data to a property as prescribed by
 * X11 Reference Manual.
 * Note that this is a round-trip request, so it can be slow. If you know
 * that the Xt timestamp is up-to-date use XtLastTimestampProcessed().
 */
Time
awt_util_getCurrentServerTime() {

    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
    static Atom _XA_JAVA_TIME_PROPERTY_ATOM = 0;
    Time server_time = 0;

    AWT_LOCK();

    if (_XA_JAVA_TIME_PROPERTY_ATOM == 0) {
        XtAddEventHandler(awt_root_shell, PropertyChangeMask, False,
                          propertyChangeEventHandler, NULL);
        _XA_JAVA_TIME_PROPERTY_ATOM = XInternAtom(awt_display, "_SUNW_JAVA_AWT_TIME", False);
    }

    timeStampUpdated = False;
    XChangeProperty(awt_display, XtWindow(awt_root_shell),
                    _XA_JAVA_TIME_PROPERTY_ATOM, XA_ATOM, 32, PropModeAppend,
                    (unsigned char *)"", 0);
    XFlush(awt_display);

    if (awt_currentThreadIsPrivileged(env)) {
        XEvent event;
        XMaskEvent(awt_display, PropertyChangeMask, &event);
        XtDispatchEvent(&event);
    } else {
        awt_MToolkit_modalWait(isTimeStampUpdated, NULL);
    }
    server_time = XtLastTimestampProcessed(awt_display);

    AWT_UNLOCK();

    return server_time;
}
示例#9
0
/*
 * The goal of this function is to find all "system" fonts which
 * are needed by the JRE to display text in supported locales etc, and
 * to support APIs which allow users to enumerate all system fonts and use
 * them from their Java applications.
 * The preferred mechanism is now using the new "fontconfig" library
 * This exists on newer versions of Linux and Solaris (S10 and above)
 * The library is dynamically located. The results are merged with
 * a set of "known" locations and with the X11 font path, if running in
 * a local X11 environment.
 * The hardwired paths are built into the JDK binary so as new font locations
 * are created on a host plaform for them to be located by the JRE they will
 * need to be added ito the host's font configuration database, typically
 * /etc/fonts/local.conf, and to ensure that directory contains a fonts.dir
 * NB: Fontconfig also depends heavily for performance on the host O/S
 * maintaining up to date caches.
 * This is consistent with the requirements of the desktop environments
 * on these OSes.
 * This also frees us from X11 APIs as JRE is required to function in
 * a "headless" mode where there is no Xserver.
 */
static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1, jboolean isX11) {

    char **fcdirs = NULL, **x11dirs = NULL, **knowndirs = NULL, *path = NULL;

    /* As of 1.5 we try to use fontconfig on both Solaris and Linux.
     * If its not available NULL is returned.
     */
    fcdirs = getFontConfigLocations();

#if defined(__linux__)
    knowndirs = fullLinuxFontPath;
#elif defined(__solaris__)
    knowndirs = fullSolarisFontPath;
#elif defined(_AIX)
    knowndirs = fullAixFontPath;
#endif
    /* REMIND: this code requires to be executed when the GraphicsEnvironment
     * is already initialised. That is always true, but if it were not so,
     * this code could throw an exception and the fontpath would fail to
     * be initialised.
     */
#ifndef HEADLESS
    if (isX11) { // The following only works in an x11 environment.
#if defined(__linux__)
    /* There's no headless build on linux ... */
    if (!AWTIsHeadless()) { /* .. so need to call a function to check */
#endif
      /* Using the X11 font path to locate font files is now a fallback
       * useful only if fontconfig failed, or is incomplete. So we could
       * remove this code completely and the consequences should be rare
       * and non-fatal. If this happens, then the calling Java code can
       * be modified to no longer require that the AWT lock (the X11GE)
       * be initialised prior to calling this code.
       */
    AWT_LOCK();
    if (isDisplayLocal(env)) {
        x11dirs = getX11FontPath();
    }
    AWT_UNLOCK();
#if defined(__linux__)
    }
#endif
    }
#endif /* !HEADLESS */
    path = mergePaths(fcdirs, x11dirs, knowndirs, noType1);
    if (fcdirs != NULL) {
        char **p = fcdirs;
        while (*p != NULL)  free(*p++);
        free(fcdirs);
    }

    if (x11dirs != NULL) {
        char **p = x11dirs;
        while (*p != NULL) free(*p++);
        free(x11dirs);
    }

    return path;
}
JNIEXPORT int32_t JNICALL
    awt_GetColor(JAWT_DrawingSurface* ds, int32_t r, int32_t g, int32_t b)
{
    JNIEnv* env;
    jobject target, peer;
    jclass componentClass;
    AwtGraphicsConfigDataPtr adata;
    int32_t result;
     jobject gc_object;
    if (ds == NULL) {
#ifdef DEBUG
        fprintf(stderr, "Drawing Surface is NULL\n");
#endif
        return (int32_t) 0;
    }

    env = ds->env;
    target = ds->target;

    /* Make sure the target is a java.awt.Component */
    componentClass = (*env)->FindClass(env, "java/awt/Component");
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
#ifdef DEBUG
        fprintf(stderr, "DrawingSurface target must be a component\n");
#endif
        return (int32_t) 0;
    }

    if (!awtLockInited) {
        return (int32_t) 0;
    }

    AWT_LOCK();

    /* Get the peer of the target component */
    peer = (*env)->GetObjectField(env, target, componentIDs.peer);
    if (JNU_IsNull(env, peer)) {
#ifdef DEBUG
        fprintf(stderr, "Component peer is NULL\n");
#endif
        AWT_UNLOCK();
        return (int32_t) 0;
    }
     /* GraphicsConfiguration object of MComponentPeer */
    gc_object = (*env)->GetObjectField(env, peer, graphicsConfigID);

    if (gc_object != NULL) {
        adata = (AwtGraphicsConfigDataPtr)
            JNU_GetLongFieldAsPtr(env, gc_object,
                                  x11GraphicsConfigIDs.aData);
    } else {
        adata = getDefaultConfig(DefaultScreen(awt_display));
    }

    result = adata->AwtColorMatch(r, g, b, adata);
        AWT_UNLOCK();
        return result;
}
示例#11
0
/**
 * This is the native dispose method that gets invoked when the Java-level
 * thread associated with this context is about to go away.  This method
 * invokes the AWT_LOCK mechanism for thread safety, then destroys the
 * OGLContext kept in thread-local storage.
 */
static void
GLXGC_DisposeOGLContext(JNIEnv *env, jlong pData)
{
    OGLContext *oglc = (OGLContext *)jlong_to_ptr(pData);

    J2dTraceLn(J2D_TRACE_INFO, "in GLXGC_DisposeOGLContext");

    AWT_LOCK();
    GLXGC_DestroyOGLContext(env, oglc);
    AWT_FLUSH_UNLOCK();
}
/*
 * Class:     java_awt_KeyboardFocusManager
 * Method:    getNativeFocusedWindow
 * Signature: ()Ljava/awt/Window;
 */
JNIEXPORT jobject JNICALL
Java_java_awt_KeyboardFocusManager_getNativeFocusedWindow
    (JNIEnv *env, jclass cls)
{
    jobject l_peer;

    AWT_LOCK();
    l_peer = awt_canvas_getFocusedWindowPeer();
    AWT_UNLOCK();

    return (l_peer != NULL)
        ? (*env)->GetObjectField(env, l_peer, mComponentPeerIDs.target)
        : NULL;
}
示例#13
0
/*
 * Lock the surface of the target component for native rendering.
 * When finished drawing, the surface must be unlocked with
 * Unlock().  This function returns a bitmask with one or more of the
 * following values:
 *
 * JAWT_LOCK_ERROR - When an error has occurred and the surface could not
 * be locked.
 *
 * JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.
 *
 * JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.
 *
 * JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed
 */
JNIEXPORT jint JNICALL awt_DrawingSurface_Lock(JAWT_DrawingSurface* ds)
{
    JNIEnv* env;
    jobject target, peer;
    jclass componentClass;
    jint drawState;

    if (ds == NULL) {
#ifdef DEBUG
        fprintf(stderr, "Drawing Surface is NULL\n");
#endif
        return (jint)JAWT_LOCK_ERROR;
    }
    env = ds->env;
    target = ds->target;

    /* Make sure the target is a java.awt.Component */
    componentClass = (*env)->FindClass(env, "java/awt/Component");
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
#ifdef DEBUG
	    fprintf(stderr, "Target is not a component\n");
#endif
        return (jint)JAWT_LOCK_ERROR;
	}

    if (!awtLockInited) {
        return (jint)JAWT_LOCK_ERROR;
    }
    AWT_LOCK();

    /* Get the peer of the target component */
    peer = (*env)->GetObjectField(env, target, componentIDs.peer);
    if (JNU_IsNull(env, peer)) {
#ifdef DEBUG
        fprintf(stderr, "Component peer is NULL\n");
#endif
		AWT_FLUSH_UNLOCK();
        return (jint)JAWT_LOCK_ERROR;
    }

#ifndef XAWT
    drawState = (*env)->GetIntField(env, peer, mComponentPeerIDs.drawState);
    (*env)->SetIntField(env, peer, mComponentPeerIDs.drawState, 0);
#else
   drawState = (*env)->GetIntField(env, peer, drawStateID);
    (*env)->SetIntField(env, peer, drawStateID, 0);
#endif    
    return drawState;
}
示例#14
0
JNIEXPORT void JNICALL
Java_java_awt_AWTEvent_nativeSetSource(JNIEnv *env, jobject self,
				       jobject newSource)
{
    jbyteArray bdata;

    AWT_LOCK();

    bdata = (jbyteArray)(*env)->GetObjectField(env, self, awtEventIDs.bdata);

    if (bdata != NULL) {
	XEvent *xev;
	Window w;
	jboolean dummy;

	/* get the widget out of the peer newSource */
	struct ComponentData *cdata = (struct ComponentData *)
	    JNU_GetLongFieldAsPtr(env, newSource, mComponentPeerIDs.pData);
	if (JNU_IsNull(env, cdata) || (cdata == NULL) ||
	    ((cdata->widget != NULL) && (XtIsObject(cdata->widget)) &&
	     (cdata->widget->core.being_destroyed))) {
	    JNU_ThrowNullPointerException(env, "null widget");
	    AWT_UNLOCK();
	    return;
	}
	
	/* get the Window out of the widget */
	w = XtWindow(cdata->widget);

	if (w == None) {
	    JNU_ThrowNullPointerException(env, "null window");
	    AWT_UNLOCK();
	    return;
	}

	/* reset the filed in the event */
	xev = (XEvent *)(*env)->GetPrimitiveArrayCritical(env, bdata, &dummy);
	if (xev == NULL) {
	    JNU_ThrowNullPointerException(env, "null data");
	    AWT_UNLOCK();
	    return;
	}
	xev->xany.window = w;
	(*env)->ReleasePrimitiveArrayCritical(env, bdata, (void *)xev, 0);
    }

    AWT_UNLOCK();
}
/*
 * The goal of this function is to find all "system" fonts which
 * are needed by the JRE to display text in supported locales etc, and
 * to support APIs which allow users to enumerate all system fonts and use
 * them from their Java applications.
 * The preferred mechanism is now using the new "fontconfig" library
 * This exists on newer versions of Linux and Solaris (S10 and above)
 * The library is dynamically located. The results are merged with
 * a set of "known" locations and with the X11 font path, if running in
 * a local X11 environment.
 * The hardwired paths are built into the JDK binary so as new font locations
 * are created on a host plaform for them to be located by the JRE they will
 * need to be added ito the host's font configuration database, typically
 * /etc/fonts/local.conf, and to ensure that directory contains a fonts.dir
 * NB: Fontconfig also depends heavily for performance on the host O/S
 * maintaining up to date caches.
 * This is consistent with the requirements of the desktop environments
 * on these OSes.
 * This also frees us from X11 APIs as JRE is required to function in
 * a "headless" mode where there is no Xserver.
 */
static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1) {

    char **fcdirs = NULL, **x11dirs = NULL, **knowndirs = NULL, *path = NULL;

    /* As of 1.5 we try to use fontconfig on both Solaris and Linux.
     * If its not available NULL is returned.
     */
    fcdirs = getFontConfigLocations();

#ifdef __linux__
    knowndirs = fullLinuxFontPath;
#else /* IF SOLARIS */
    knowndirs = fullSolarisFontPath;
#endif

    /* REMIND: this code requires to be executed when the GraphicsEnvironment
     * is already initialised. That is always true, but if it were not so,
     * this code could throw an exception and the fontpath would fail to
     * be initialised.
     */
#ifndef HEADLESS
#ifdef __linux__        /* There's no headless build on linux ... */
    if (!AWTIsHeadless()) { /* .. so need to call a function to check */
#endif
    AWT_LOCK();
    if (isDisplayLocal(env)) {
        x11dirs = getX11FontPath();
    }
    AWT_UNLOCK();
#ifdef __linux__
    }
#endif
#endif /* !HEADLESS */
    path = mergePaths(fcdirs, x11dirs, knowndirs, noType1);
    if (fcdirs != NULL) {
        char **p = fcdirs;
        while (*p != NULL)  free(*p++);
        free(fcdirs);
    }

    if (x11dirs != NULL) {
        char **p = x11dirs;
        while (*p != NULL) free(*p++);
        free(x11dirs);
    }

    return path;
}
/*
 * Class:     sun_awt_motif_MCustomCursor
 * Method:    queryBestCursor
 * Signature: (Ljava/awt/Dimension;)V
 */
JNIEXPORT void JNICALL Java_sun_awt_motif_MCustomCursor_queryBestCursor
  (JNIEnv *env, jclass cls, jobject dimension)
{
    Window root;
    uint32_t width, height;

    AWT_LOCK();
    root = RootWindow(awt_display, DefaultScreen(awt_display));
    XQueryBestCursor(awt_display, root,
                     (*env)->GetIntField(env, dimension, widthID),
                     (*env)->GetIntField(env, dimension, heightID),
                     &width, &height);
    (*env)->SetIntField(env, dimension, widthID, (int32_t) width);
    (*env)->SetIntField(env, dimension, heightID, (int32_t) height);
    AWT_UNLOCK();
}
示例#17
0
/*
 * Class:     sun_awt_DefaultMouseInfoPeer
 * Method:    isWindowUnderMouse
 * Signature: (Ljava/awt/Window)Z
 */
JNIEXPORT jboolean JNICALL Java_sun_awt_DefaultMouseInfoPeer_isWindowUnderMouse
  (JNIEnv * env, jclass cls, jobject window)
{
    Window rootWindow = None, parentWindow = None, siblingWindow = None;
    Window * children = NULL;
    int i = 0;
    int is_the_same_screen = 0;
    int32_t xr = 0, yr = 0, xw = 0, yw = 0;
    uint32_t keys = 0;
    uint32_t nchildren = 0;
    Bool pointerFound = 0;
    struct FrameData *wdata = NULL;
    jobject winPeer = NULL;

    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
        return JNI_FALSE;
    }
    winPeer = (*env)->GetObjectField(env, window, componentIDs.peer);
    if (JNU_IsNull(env, winPeer)) {
        return JNI_FALSE;
    }

    wdata = (struct FrameData *)
        JNU_GetLongFieldAsPtr(env, winPeer, mComponentPeerIDs.pData);
    (*env)->DeleteLocalRef(env, winPeer);

    if (wdata == NULL) {
        return JNI_FALSE;
    }

    AWT_LOCK();

    XQueryTree(awt_display, XtWindow(wdata->winData.comp.widget),
                    &rootWindow, &parentWindow, &children, &nchildren);

    is_the_same_screen = XQueryPointer(awt_display, parentWindow,
            &rootWindow, &siblingWindow, &xr, &yr, &xw, &yw, &keys);

    if (siblingWindow == XtWindow(wdata->winData.comp.widget) && is_the_same_screen) {
        AWT_UNLOCK();
        return JNI_TRUE;
    }

    AWT_UNLOCK();
    return JNI_FALSE ;

}
示例#18
0
/*
 * Registered with the 2D disposer to be called after the Font is GC'd.
 */
static void pDataDisposeMethod(JNIEnv *env, jlong pData)
{
    struct FontData *fdata = NULL;
    int32_t i = 0;
    Display *display = XDISPLAY;

    AWT_LOCK();
    fdata = (struct FontData *)pData;

    if (fdata == NULL) {
        AWT_UNLOCK();
        return;
    }

    if (fdata->xfs != NULL) {
        XFreeFontSet(display, fdata->xfs);
    }

    /* AWT fonts are always "multifonts" and probably have been in
     * all post 1.0 releases, so this test for multi fonts is
     * probably not needed, and the singleton xfont is probably never used.
     */
    if (fdata->charset_num > 0) {
        for (i = 0; i < fdata->charset_num; i++) {
            free((void *)fdata->flist[i].xlfd);
            JNU_ReleaseStringPlatformChars(env, NULL,
                                           fdata->flist[i].charset_name);
            if (fdata->flist[i].load) {
                XFreeFont(display, fdata->flist[i].xfont);
            }
        }

        free((void *)fdata->flist);

        /* Don't free fdata->xfont because it is equal to fdata->flist[i].xfont
           for some 'i' */
    } else {
        if (fdata->xfont != NULL) {
            XFreeFont(display, fdata->xfont);
        }
    }

    free((void *)fdata);

    AWT_UNLOCK();
}
示例#19
0
JNIEXPORT void JNICALL
Java_sun_awt_X11_XRobotPeer_keyReleaseImpl (JNIEnv *env,
                           jclass cls,
                           jint keycode) {
    AWT_LOCK();

    DTRACE_PRINTLN1("RobotPeer: keyReleaseImpl(%i)", keycode);

    XTestFakeKeyEvent(awt_display,
                      XKeysymToKeycode(awt_display, awt_getX11KeySym(keycode)),
                      False,
                      CurrentTime);

    XSync(awt_display, False);

    AWT_UNLOCK();
}
/*
 * Class:     java_awt_KeyboardFocusManager
 * Method:    clearGlobalFocusOwner
 * Signature: ()V
 */
JNIEXPORT void JNICALL
Java_java_awt_KeyboardFocusManager__1clearGlobalFocusOwner
    (JNIEnv *env, jobject self)
{
  /* Redirect focus to the focus proxy of the active Window. The effect
     we want is for the active Window to remain active, but for none of
     its children to be the focus owner. AWT maintains state to know
     that any key events delivered after this call (but before focus is
     re-established elsewhere) get ignored. */

    jobject activeWindow;
    Widget proxy;

    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
        return;
    }

    AWT_LOCK();

    activeWindow = (*env)->CallStaticObjectMethod
        (env, keyboardFocusManagerIDs.keyboardFocusManagerCls,
         keyboardFocusManagerIDs.markClearGlobalFocusOwnerMID);

    if (activeWindow != NULL) {
        // Setting focus owner to proxy will be equivalent haveing
        // null focus owner in Java layer while we will still be
        // able to receive key events.
        proxy = findWindowsProxy(activeWindow, env);

        if (proxy != NULL) {
            Widget curFocusWidget = XmGetFocusWidget(proxy);
            if (curFocusWidget != NULL) {
                callFocusHandler(curFocusWidget, FocusOut);
            }

            // Disable all but proxy widgets
            processTree(curFocusWidget, proxy, False);
            
            XmProcessTraversal(proxy, XmTRAVERSE_CURRENT);
        }
    }

    AWT_UNLOCK();
}
示例#21
0
/*
 * Class:     sun_awt_DefaultMouseInfoPeer
 * Method:    fillPointWithCoords
 * Signature: (Ljava/awt/Point)I
 */
JNIEXPORT jint JNICALL
Java_sun_awt_DefaultMouseInfoPeer_fillPointWithCoords(JNIEnv *env, jclass cls,
                                                          jobject point)
{
     static jclass pointClass = NULL;
     jclass pointClassLocal;
     static jfieldID xID, yID;
     Window rootWindow, childWindow;
     int i;
     int32_t xr, yr, xw, yw;
     uint32_t keys;
     BOOL pointerFound;

     AWT_LOCK();
     if (pointClass == NULL) {
         pointClassLocal = (*env)->FindClass(env, "java/awt/Point");
         DASSERT(pointClassLocal != NULL);
         if (pointClassLocal == NULL) {
             AWT_UNLOCK();
             return (jint)0;
         }
         pointClass = (jclass)(*env)->NewGlobalRef(env, pointClassLocal);
         (*env)->DeleteLocalRef(env, pointClassLocal);
         xID = (*env)->GetFieldID(env, pointClass, "x", "I");
         yID = (*env)->GetFieldID(env, pointClass, "y", "I");
     }

     for (i = 0; i < awt_numScreens; i++) {
         pointerFound = XQueryPointer(awt_display, x11Screens[i].root,
                           &rootWindow, &childWindow,
                           &xr, &yr, &xw, &yw, &keys);
         if (pointerFound) {
             (*env)->SetIntField(env, point, xID, xr);
             (*env)->SetIntField(env, point, yID, yr);
             AWT_UNLOCK();
             return (jint)i;
         }
     }
     /* This should never happen */
     DASSERT(FALSE);
     AWT_UNLOCK();
     return (jint)0;
}
示例#22
0
/*
  * Function joining the code of mousePressImpl and mouseReleaseImpl
  */
void mouseAction(JNIEnv *env,
                 jclass cls,
                 jint buttonMask,
                 Bool isMousePress)
{
    AWT_LOCK();

    DTRACE_PRINTLN1("RobotPeer: mouseAction(%i)", buttonMask);
    DTRACE_PRINTLN1("RobotPeer: mouseAction, press = %d", isMousePress);

    if (buttonMask & java_awt_event_InputEvent_BUTTON1_MASK ||
        buttonMask & java_awt_event_InputEvent_BUTTON1_DOWN_MASK )
    {
        XTestFakeButtonEvent(awt_display, 1, isMousePress, CurrentTime);
    }
    if ((buttonMask & java_awt_event_InputEvent_BUTTON2_MASK ||
         buttonMask & java_awt_event_InputEvent_BUTTON2_DOWN_MASK) &&
        (num_buttons >= 2)) {
        XTestFakeButtonEvent(awt_display, 2, isMousePress, CurrentTime);
    }
    if ((buttonMask & java_awt_event_InputEvent_BUTTON3_MASK ||
         buttonMask & java_awt_event_InputEvent_BUTTON3_DOWN_MASK) &&
        (num_buttons >= 3)) {
        XTestFakeButtonEvent(awt_display, 3, isMousePress, CurrentTime);
    }

    if (num_buttons > 3){
        int32_t i;
        int32_t button = 0;
        for (i = 3; i<num_buttons; i++){
            if ((buttonMask & masks[i])) {
                // arrays starts from zero index => +1
                // users wants to affect 4 or 5 button but they are assigned
                // to the wheel so => we have to shift it to the right by 2.
                button = i + 3;
                XTestFakeButtonEvent(awt_display, button, isMousePress, CurrentTime);
            }
        }
    }

    XSync(awt_display, False);
    AWT_UNLOCK();
}
示例#23
0
JNIEXPORT void JNICALL
Java_sun_awt_X11_XRobotPeer_mouseMoveImpl (JNIEnv *env,
                          jclass cls,
                          jobject xgc,
                          jint root_x,
                          jint root_y) {

    AwtGraphicsConfigDataPtr adata;

    AWT_LOCK();

    DTRACE_PRINTLN3("RobotPeer: mouseMoveImpl(%lx, %i, %i)", xgc, root_x, root_y);

    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
    DASSERT(adata != NULL);

    XWarpPointer(awt_display, None, XRootWindow(awt_display, adata->awt_visInfo.screen), 0, 0, 0, 0, root_x, root_y);
    XSync(awt_display, False);

    AWT_UNLOCK();
}
示例#24
0
JNIEXPORT jobject JNICALL
    awt_GetComponent(JNIEnv* env, void* platformInfo)
{
    Window window = (Window)platformInfo;
    Widget widget = NULL;
    jobject peer = NULL;
    jobject target = NULL;

    AWT_LOCK();

    target =  (*env)->GetObjectField(env, peer, targetID);

    if (target == NULL) {
        JNU_ThrowNullPointerException(env, "NullPointerException");
        AWT_UNLOCK();
        return (jobject)NULL;
    }


    AWT_UNLOCK();

    return target;
}
示例#25
0
JNIEXPORT jobject JNICALL
    awt_GetComponent(JNIEnv* env, void* platformInfo)
{
    Window window = (Window)platformInfo;
    Widget widget = NULL;
    jobject peer = NULL;
    jobject target = NULL;

    AWT_LOCK();

#ifndef XAWT
    if (window != None) {
        widget = XtWindowToWidget(awt_display, window);
    }

    if (widget != NULL) {
        XtVaGetValues (widget, XmNuserData, &peer, NULL);
    }

    if (peer != NULL) {
        target = (*env)->GetObjectField(env, peer, mComponentPeerIDs.target);
    }
#else
    target =  (*env)->GetObjectField(env, peer, targetID);
#endif

    if (target == NULL) {
        JNU_ThrowNullPointerException(env, "NullPointerException");
        AWT_UNLOCK();
        return (jobject)NULL;
    }

    
    AWT_UNLOCK();

    return target;
}
示例#26
0
文件: awt_Robot.c 项目: lmsf/jdk9-dev
JNIEXPORT void JNICALL
Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
                             jclass cls,
                             jobject xgc,
                             jint jx,
                             jint jy,
                             jint jwidth,
                             jint jheight,
                             jint scale,
                             jintArray pixelArray,
                             jboolean useGtk) {
    XImage *image;
    jint *ary;               /* Array of jints for sending pixel values back
                              * to parent process.
                              */
    Window rootWindow;
    XWindowAttributes attr;
    AwtGraphicsConfigDataPtr adata;

    DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, jx, jy, jwidth, jheight, pixelArray);

    if (jwidth <= 0 || jheight <= 0) {
        return;
    }

    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
    DASSERT(adata != NULL);

    AWT_LOCK();

    jint sx = jx * scale;
    jint sy = jy * scale;
    jint swidth = jwidth * scale;
    jint sheight = jheight * scale;

    rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);

    if (!useGtk) {
        if (hasXCompositeOverlayExtension(awt_display) &&
            isXCompositeDisplay(awt_display, adata->awt_visInfo.screen))
        {
            rootWindow = compositeGetOverlayWindow(awt_display, rootWindow);
        }
    }

    if (!XGetWindowAttributes(awt_display, rootWindow, &attr)
            || sx + swidth <= attr.x
            || attr.x + attr.width <= sx
            || sy + sheight <= attr.y
            || attr.y + attr.height <= sy) {

        AWT_UNLOCK();
        return; // Does not intersect with root window
    }

    gboolean gtk_failed = TRUE;
    jint _x, _y;

    jint x = MAX(sx, attr.x);
    jint y = MAX(sy, attr.y);
    jint width = MIN(sx + swidth, attr.x + attr.width) - x;
    jint height = MIN(sy + sheight, attr.y + attr.height) - y;


    int dx = attr.x > sx ? attr.x - sx : 0;
    int dy = attr.y > sy ? attr.y - sy : 0;

    int index;

    if (useGtk) {
        gtk->gdk_threads_enter();
        gtk_failed = gtk->get_drawable_data(env, pixelArray, x, y, width,
                                            height, jwidth, dx, dy, scale);
        gtk->gdk_threads_leave();
    }

    if (gtk_failed) {
        image = getWindowImage(awt_display, rootWindow, sx, sy, swidth, sheight);

        ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL);

        if (!ary) {
            XDestroyImage(image);
            AWT_UNLOCK();
            return;
        }

        dx /= scale;
        dy /= scale;
        width /= scale;
        height /= scale;

        /* convert to Java ARGB pixels */
        for (_y = 0; _y < height; _y++) {
            for (_x = 0; _x < width; _x++) {
                jint pixel = (jint) XGetPixel(image, _x * scale, _y * scale);
                                                              /* Note ignore upper
                                                               * 32-bits on 64-bit
                                                               * OSes.
                                                               */
                pixel |= 0xff000000; /* alpha - full opacity */

                index = (_y + dy) * jwidth + (_x + dx);
                ary[index] = pixel;
            }
        }

        XDestroyImage(image);
        (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0);
    }
    AWT_UNLOCK();
}
示例#27
0
static void awt_lock_wrapper(JNIEnv *env) {
  AWT_LOCK();
}
/*
 * Get the drawing surface info.
 * The value returned may be cached, but the values may change if
 * additional calls to Lock() or Unlock() are made.
 * Lock() must be called before this can return a valid value.
 * Returns NULL if an error has occurred.
 * When finished with the returned value, FreeDrawingSurfaceInfo must be
 * called.
 */
JNIEXPORT JAWT_DrawingSurfaceInfo* JNICALL
awt_DrawingSurface_GetDrawingSurfaceInfo(JAWT_DrawingSurface* ds)
{
    JNIEnv* env;
    jobject target, peer;
    jclass componentClass;
    JAWT_X11DrawingSurfaceInfo* px;
    JAWT_DrawingSurfaceInfo* p;
    XWindowAttributes attrs;

    if (ds == NULL) {
#ifdef DEBUG
        fprintf(stderr, "Drawing Surface is NULL\n");
#endif
        return NULL;
    }

    env = ds->env;
    target = ds->target;

    /* Make sure the target is a java.awt.Component */
    componentClass = (*env)->FindClass(env, "java/awt/Component");
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
#ifdef DEBUG
        fprintf(stderr, "DrawingSurface target must be a component\n");
#endif
        return NULL;
        }

    if (!awtLockInited) {
        return NULL;
    }

    AWT_LOCK();

    /* Get the peer of the target component */
    peer = (*env)->GetObjectField(env, target, componentIDs.peer);
    if (JNU_IsNull(env, peer)) {
#ifdef DEBUG
        fprintf(stderr, "Component peer is NULL\n");
#endif
                AWT_UNLOCK();
        return NULL;
    }

    AWT_UNLOCK();

    /* Allocate platform-specific data */
    px = (JAWT_X11DrawingSurfaceInfo*)
        malloc(sizeof(JAWT_X11DrawingSurfaceInfo));

    /* Set drawable and display */
    px->drawable = (*env)->GetLongField(env, peer, windowID);
    px->display = awt_display;

    /* Get window attributes to set other values */
    XGetWindowAttributes(awt_display, (Window)(px->drawable), &attrs);

    /* Set the other values */
    px->visualID = XVisualIDFromVisual(attrs.visual);
    px->colormapID = attrs.colormap;
    px->depth = attrs.depth;
    px->GetAWTColor = awt_GetColor;

    /* Allocate and initialize platform-independent data */
    p = (JAWT_DrawingSurfaceInfo*)malloc(sizeof(JAWT_DrawingSurfaceInfo));
    p->platformInfo = px;
    p->ds = ds;
    p->bounds.x = (*env)->GetIntField(env, target, componentIDs.x);
    p->bounds.y = (*env)->GetIntField(env, target, componentIDs.y);
    p->bounds.width = (*env)->GetIntField(env, target, componentIDs.width);
    p->bounds.height = (*env)->GetIntField(env, target, componentIDs.height);
    p->clipSize = 1;
    p->clip = &(p->bounds);

    /* Return our new structure */
    return p;
}
示例#29
0
JNIEXPORT void JNICALL
Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
                             jclass cls,
                             jobject xgc,
                             jint x,
                             jint y,
                             jint width,
                             jint height,
                             jintArray pixelArray) {

    XImage *image;
    jint *ary;               /* Array of jints for sending pixel values back
                              * to parent process.
                              */
    Window rootWindow;
    AwtGraphicsConfigDataPtr adata;

    DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, x, y, width, height, pixelArray);

    AWT_LOCK();

    /* avoid a lot of work for empty rectangles */
    if ((width * height) == 0) {
        AWT_UNLOCK();
        return;
    }
    DASSERT(width * height > 0); /* only allow positive size */

    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
    DASSERT(adata != NULL);

    rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
    image = getWindowImage(awt_display, rootWindow, x, y, width, height);

    /* Array to use to crunch around the pixel values */
    ary = (jint *) malloc(width * height * sizeof (jint));
    if (ary == NULL) {
        JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
        XDestroyImage(image);
        AWT_UNLOCK();
        return;
    }
    /* convert to Java ARGB pixels */
    for (y = 0; y < height; y++) {
        for (x = 0; x < width; x++) {
            jint pixel = (jint) XGetPixel(image, x, y); /* Note ignore upper
                                                         * 32-bits on 64-bit
                                                         * OSes.
                                                         */

            pixel |= 0xff000000; /* alpha - full opacity */

            ary[(y * width) + x] = pixel;
        }
    }
    (*env)->SetIntArrayRegion(env, pixelArray, 0, height * width, ary);
    free(ary);

    XDestroyImage(image);

    AWT_UNLOCK();
}
示例#30
0
/*
 * Class:     sun_awt_X11SurfaceData
 * Method:    initIDs
 * Signature: ()V
 */
JNIEXPORT void JNICALL
Java_sun_awt_X11SurfaceData_initIDs(JNIEnv *env, jclass xsd, jclass XORComp)
{
#ifndef HEADLESS
    void *lib = 0;

    union {
        char c[4];
        int i;
    } endian;
    
    endian.i = 0xff000000;
    nativeByteOrder = (endian.c[0]) ? MSBFirst : LSBFirst;

    cachedXImage = NULL;

    if (sizeof(X11RIPrivate) > SD_RASINFO_PRIVATE_SIZE) {
	JNU_ThrowInternalError(env, "Private RasInfo structure too large!");
	return;
    }

    xorCompClass = (*env)->NewGlobalRef(env, XORComp);

    if (getenv("NO_J2D_DGA") == NULL) {
    /* we use RTLD_NOW because of bug 4032715 */
#ifdef DEBUG
        lib = dlopen("libsunwjdga_g.so", RTLD_NOW);
#else
        lib = dlopen("libsunwjdga.so", RTLD_NOW);
#endif
    }
    dgaAvailable = JNI_FALSE;
    if (lib != NULL) {
	JDgaStatus ret = JDGA_FAILED;
	void *sym = dlsym(lib, "JDgaLibInit");
	if (sym != NULL) {
	    theJDgaInfo.display = awt_display;
	    AWT_LOCK();
	    ret = (*(JDgaLibInitFunc *)sym)(env, &theJDgaInfo);
	    AWT_UNLOCK();
	}
	if (ret == JDGA_SUCCESS) {
	    pJDgaInfo = &theJDgaInfo;
	    dgaAvailable = JNI_TRUE;
	    useDGAWithPixmaps = (getenv("USE_DGA_PIXMAPS") != NULL);
	} else {
	    dlclose(lib);
	    lib = NULL;
	}
    }

#ifdef MITSHM
    if (getenv("NO_AWT_MITSHM") == NULL && 
	getenv("NO_J2D_MITSHM") == NULL) {
	char * force;
	TryInitMITShm(env, &useMitShmExt, &useMitShmPixmaps);
	useMitShmPixmaps = (useMitShmPixmaps == CAN_USE_MITSHM);
	force = getenv("J2D_PIXMAPS");
	if (force != NULL) {
	    if (strcmp(force, "shared") == 0) {
		forceSharedPixmaps = JNI_TRUE;
	    } else if (strcmp(force, "server") == 0) {
		useMitShmPixmaps = JNI_FALSE;
	    }
	}
    }
#endif /* MITSHM */

#endif /* !HEADLESS */
}