Esempio n. 1
0
void
awt_util_convertEventTimeAndModifiers(XEvent *event,
                                      ConvertEventTimeAndModifiers *output) {
    switch (event->type) {
    case KeyPress:
    case KeyRelease:
        output->when = awt_util_nowMillisUTC_offset(event->xkey.time);
        output->modifiers = getModifiers(event->xkey.state, 0, 0);
        break;
    case ButtonPress:
    case ButtonRelease:
        output->when = awt_util_nowMillisUTC_offset(event->xbutton.time);
        output->modifiers = getModifiers(event->xbutton.state,
            getButton(event->xbutton.button), 0);
        break;
    default:
        output->when = awt_util_nowMillisUTC();
        output->modifiers =0;
        break;
    }
}
Esempio n. 2
0
Bool
awt_x11inputmethod_lookupString(XKeyPressedEvent *event, KeySym *keysymp)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
    X11InputMethodData *pX11IMData;
    KeySym keysym = NoSymbol;
    Status status;
    int mblen;
    jstring javastr;
    XIC ic;
    Bool result = True;
    static Bool composing = False;

    /*
      printf("lookupString: entering...\n");
     */

    pX11IMData = getX11InputMethodData(env, currentX11InputMethodInstance);

    if (pX11IMData == NULL) {
#ifdef __linux__
        return False;
#else
        return result;
#endif
    }

    if ((ic = pX11IMData->current_ic) == (XIC)0){
#ifdef __linux__
        return False;
#else
        return result;
#endif
    }

    /* allocate the lookup buffer at the first invocation */
    if (pX11IMData->lookup_buf_len == 0) {
	pX11IMData->lookup_buf = (char *)malloc(INITIAL_LOOKUP_BUF_SIZE);
	if (pX11IMData->lookup_buf == NULL) {
	    THROW_OUT_OF_MEMORY_ERROR();
	    return result;
	}
        pX11IMData->lookup_buf_len = INITIAL_LOOKUP_BUF_SIZE;
    }

    mblen = XmbLookupString(ic, event, pX11IMData->lookup_buf, 
                            pX11IMData->lookup_buf_len - 1, &keysym, &status);

    /*
     * In case of overflow, a buffer is allocated and it retries
     * XmbLookupString().
     */
    if (status == XBufferOverflow) {
	free((void *)pX11IMData->lookup_buf);
        pX11IMData->lookup_buf_len = 0;
	pX11IMData->lookup_buf = (char *)malloc(mblen + 1);
	if (pX11IMData->lookup_buf == NULL) {
	    THROW_OUT_OF_MEMORY_ERROR();
	    return result;
	}
        pX11IMData->lookup_buf_len = mblen + 1;
        mblen = XmbLookupString(ic, event, pX11IMData->lookup_buf, 
                            pX11IMData->lookup_buf_len - 1, &keysym, &status);
    }
    pX11IMData->lookup_buf[mblen] = 0;

    /* Get keysym without taking modifiers into account first to map
     * to AWT keyCode table.
     */
    if (((event->state & ShiftMask) ||
	(event->state & LockMask)) && 
	 keysym >= 'A' && keysym <= 'Z')
    {
        keysym = XLookupKeysym(event, 0);
    }

    switch (status) {
    case XLookupBoth:
	if (!composing) {
	    if (keysym < 128 || ((keysym & 0xff00) == 0xff00)) { 
		*keysymp = keysym;
		result = False;
		break;
	    }
	}
	composing = False;
	/*FALLTHRU*/ 
    case XLookupChars:
    /*
     printf("lookupString: status=XLookupChars, type=%d, state=%x, keycode=%x, keysym=%x\n",
       event->type, event->state, event->keycode, keysym);
    */
        javastr = JNU_NewStringPlatform(env, (const char *)pX11IMData->lookup_buf);
        if (javastr != NULL) {
            JNU_CallMethodByName(env, NULL,
				 currentX11InputMethodInstance,
				 "dispatchCommittedText",
				 "(Ljava/lang/String;J)V",
				 javastr,
#ifndef XAWT_HACK
                                 awt_util_nowMillisUTC_offset(event->time));
#else
                                 event->time);
#endif
        }
	break;

    case XLookupKeySym:
    /*
     printf("lookupString: status=XLookupKeySym, type=%d, state=%x, keycode=%x, keysym=%x\n",
       event->type, event->state, event->keycode, keysym);
    */
 	if (keysym == XK_Multi_key)
	    composing = True;
 	if (! composing) {
 	    *keysymp = keysym;
 	    result = False;
 	}
	break;

    case XLookupNone:
    /*
     printf("lookupString: status=XLookupNone, type=%d, state=%x, keycode=%x, keysym=%x\n",
        event->type, event->state, event->keycode, keysym);
    */
	break;
    }