示例#1
0
Bool XIMSetFocusHandler(FcitxXimFrontend* xim, IMChangeFocusStruct * call_data)
{
    FcitxInputContext* ic =  FcitxInstanceFindIC(xim->owner, xim->frontendid, &call_data->icid);
    if (ic == NULL)
        return True;

    FcitxInputContext* oldic = FcitxInstanceGetCurrentIC(xim->owner);

    if (oldic && oldic != ic)
        FcitxUICommitPreedit(xim->owner);

    if (!FcitxInstanceSetCurrentIC(xim->owner, ic))
        return True;

    SetTrackPos(xim, ic, NULL);

    if (ic) {
        FcitxUIOnInputFocus(xim->owner);
    } else {
        FcitxUICloseInputWindow(xim->owner);
        FcitxUIMoveInputWindow(xim->owner);
    }

    return True;
}
示例#2
0
Bool XIMSetICValuesHandler(FcitxXimFrontend* xim, IMChangeICStruct * call_data)
{
    XimSetIC(xim, call_data);
    FcitxInputContext* ic = FcitxInstanceFindIC(xim->owner, xim->frontendid, &call_data->icid);
    SetTrackPos(xim, ic, call_data);

    return True;
}
示例#3
0
Bool XIMCreateICHandler(FcitxXimFrontend* xim, IMChangeICStruct * call_data)
{
    FcitxInstanceCreateIC(xim->owner, xim->frontendid, call_data);
    FcitxInputContext* ic = FcitxInstanceGetCurrentIC(xim->owner);

    if (ic == NULL) {
        ic = FcitxInstanceFindIC(xim->owner, xim->frontendid, &call_data->icid);
        if (FcitxInstanceSetCurrentIC(xim->owner, ic) && ic)
            FcitxUIOnInputFocus(xim->owner);
    }

    return True;
}
示例#4
0
文件: IC.c 项目: 13572293130/fcitx
/**
 * Set Input Context Data
 *
 * @param call_data
 * @return void
 **/
void XimSetIC(FcitxXimFrontend* xim, IMChangeICStruct * call_data)
{
    FcitxInputContext   *ic = FcitxInstanceFindIC(xim->owner, xim->frontendid, &call_data->icid);

    if (ic == NULL)
        return;
    FcitxXimIC* rec = (FcitxXimIC*) ic->privateic;
    StoreIC(rec, call_data);

    if (rec->input_style & XIMPreeditCallbacks)
        ic->contextCaps |= CAPACITY_PREEDIT;
    else
        ic->contextCaps &= ~CAPACITY_PREEDIT;

    return;
}
示例#5
0
文件: IC.c 项目: 13572293130/fcitx
/**
 * Fetch Input Context Data
 *
 * @param call_data
 * @return void
 **/
void XimGetIC(FcitxXimFrontend* xim, IMChangeICStruct * call_data)
{
    XICAttribute   *ic_attr = call_data->ic_attr;
    XICAttribute   *pre_attr = call_data->preedit_attr;
    XICAttribute   *sts_attr = call_data->status_attr;
    register int    i;
    FcitxInputContext *ic = FcitxInstanceFindIC(xim->owner, xim->frontendid, &call_data->icid);
    if (ic == NULL)
        return;
    FcitxXimIC* rec = (FcitxXimIC*) ic->privateic;

    if (rec == NULL)
        return;
    for (i = 0; i < (int) call_data->ic_attr_num; i++, ic_attr++) {
        if (Is(XNFilterEvents, ic_attr)) {
            ic_attr->value = (void *) malloc(sizeof(CARD32));
            *(CARD32 *) ic_attr->value = KeyPressMask | KeyReleaseMask;
            ic_attr->value_length = sizeof(CARD32);
        }
    }

    /* preedit attributes */
    for (i = 0; i < (int) call_data->preedit_attr_num; i++, pre_attr++) {
        if (Is(XNArea, pre_attr)) {
            pre_attr->value = (void *) malloc(sizeof(XRectangle));
            *(XRectangle *) pre_attr->value = rec->pre_attr.area;
            pre_attr->value_length = sizeof(XRectangle);

        } else if (Is(XNAreaNeeded, pre_attr)) {
            pre_attr->value = (void *) malloc(sizeof(XRectangle));
            *(XRectangle *) pre_attr->value = rec->pre_attr.area_needed;
            pre_attr->value_length = sizeof(XRectangle);

        } else if (Is(XNSpotLocation, pre_attr)) {
            pre_attr->value = (void *) malloc(sizeof(XPoint));
            *(XPoint *) pre_attr->value = rec->pre_attr.spot_location;
            pre_attr->value_length = sizeof(XPoint);

        } else if (Is(XNFontSet, pre_attr)) {
            CARD16          base_len = (CARD16) strlen(rec->pre_attr.base_font);
            int             total_len = sizeof(CARD16) + (CARD16) base_len;
            char           *p;

            pre_attr->value = (void *) malloc(total_len);
            p = (char *) pre_attr->value;
            memcpy(p, &base_len, sizeof(CARD16));
            p += sizeof(CARD16);
            strncpy(p, rec->pre_attr.base_font, base_len);
            pre_attr->value_length = total_len;

        } else if (Is(XNForeground, pre_attr)) {
            pre_attr->value = (void *) malloc(sizeof(long));
            *(long *) pre_attr->value = rec->pre_attr.foreground;
            pre_attr->value_length = sizeof(long);

        } else if (Is(XNBackground, pre_attr)) {
            pre_attr->value = (void *) malloc(sizeof(long));
            *(long *) pre_attr->value = rec->pre_attr.background;
            pre_attr->value_length = sizeof(long);

        } else if (Is(XNLineSpace, pre_attr)) {
            pre_attr->value = (void *) malloc(sizeof(long));
            *(long *) pre_attr->value = 18;
            pre_attr->value_length = sizeof(long);
        }
    }

    /* status attributes */
    for (i = 0; i < (int) call_data->status_attr_num; i++, sts_attr++) {
        if (Is(XNArea, sts_attr)) {
            sts_attr->value = (void *) malloc(sizeof(XRectangle));
            *(XRectangle *) sts_attr->value = rec->sts_attr.area;
            sts_attr->value_length = sizeof(XRectangle);

        } else if (Is(XNAreaNeeded, sts_attr)) {
            sts_attr->value = (void *) malloc(sizeof(XRectangle));
            *(XRectangle *) sts_attr->value = rec->sts_attr.area_needed;
            sts_attr->value_length = sizeof(XRectangle);

        } else if (Is(XNFontSet, sts_attr)) {
            CARD16          base_len = (CARD16) strlen(rec->sts_attr.base_font);
            int             total_len = sizeof(CARD16) + (CARD16) base_len;
            char           *p;

            sts_attr->value = (void *) malloc(total_len);
            p = (char *) sts_attr->value;
            memcpy(p, &base_len, sizeof(CARD16));
            p += sizeof(CARD16);
            strncpy(p, rec->sts_attr.base_font, base_len);
            sts_attr->value_length = total_len;

        } else if (Is(XNForeground, sts_attr)) {
            sts_attr->value = (void *) malloc(sizeof(long));
            *(long *) sts_attr->value = rec->sts_attr.foreground;
            sts_attr->value_length = sizeof(long);

        } else if (Is(XNBackground, sts_attr)) {
            sts_attr->value = (void *) malloc(sizeof(long));
            *(long *) sts_attr->value = rec->sts_attr.background;
            sts_attr->value_length = sizeof(long);

        } else if (Is(XNLineSpace, sts_attr)) {
            sts_attr->value = (void *) malloc(sizeof(long));
            *(long *) sts_attr->value = 18;
            sts_attr->value_length = sizeof(long);
        }
    }
}
示例#6
0
void XIMProcessKey(FcitxXimFrontend* xim, IMForwardEventStruct * call_data)
{
    KeySym originsym;
    FcitxKeySym sym;
    XKeyEvent *kev;
    int keyCount;
    uint32_t state;
    char strbuf[STRBUFLEN];
    FcitxInputContext* ic = FcitxInstanceGetCurrentIC(xim->owner);
    FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(xim->owner);
    FcitxInputState* input = FcitxInstanceGetInputState(xim->owner);

    if (ic == NULL) {
        ic = FcitxInstanceFindIC(xim->owner, xim->frontendid, &call_data->icid);
        if (FcitxInstanceSetCurrentIC(xim->owner, ic) && ic)
            FcitxUIOnInputFocus(xim->owner);
    }

    if (ic == NULL)
        return;

    if (ic->frontendid != xim->frontendid || GetXimIC(ic)->id != call_data->icid) {
        ic = FcitxInstanceFindIC(xim->owner, xim->frontendid, &call_data->icid);
        if (ic == NULL)
            return;
        if (FcitxInstanceSetCurrentIC(xim->owner, ic))
            FcitxUIOnInputFocus(xim->owner);
    }

    kev = (XKeyEvent *) & call_data->event;
    memset(strbuf, 0, STRBUFLEN);
    keyCount = XLookupString(kev, strbuf, STRBUFLEN, &originsym, NULL);

    const uint32_t originstate = kev->state;
    state = kev->state - (kev->state & FcitxKeyState_NumLock) - (kev->state & FcitxKeyState_CapsLock) - (kev->state & FcitxKeyState_ScrollLock);
    state &= FcitxKeyState_UsedMask;
    FcitxHotkeyGetKey((FcitxKeySym) originsym, state, &sym, &state);
    FcitxLog(DEBUG,
             "KeyRelease=%d  state=%d  KEYCODE=%d  KEYSYM=%d  keyCount=%d",
             (call_data->event.type == KeyRelease), state, kev->keycode, (int) sym, keyCount);

    xim->currentSerialNumberCallData = call_data->serial_number;
    xim->currentSerialNumberKey = kev->serial;

    FcitxKeyEventType type = (call_data->event.type == KeyRelease) ? (FCITX_RELEASE_KEY) : (FCITX_PRESS_KEY);

    if (ic->state == IS_CLOSED) {
        if (type == FCITX_PRESS_KEY && FcitxHotkeyIsHotKey(sym, state, config->hkTrigger)) {
            FcitxInstanceEnableIM(xim->owner, ic, false);
            return;
        } else {
            XimForwardKeyInternal(xim,
                                  GetXimIC(ic),
                                  &call_data->event
                                 );
            return;
        }
    }

    FcitxInputStateSetKeyCode(input, kev->keycode);
    FcitxInputStateSetKeySym(input, originsym);
    FcitxInputStateSetKeyState(input, originstate);
    INPUT_RETURN_VALUE retVal = FcitxInstanceProcessKey(xim->owner, type,
                                           kev->time,
                                           sym, state);
    FcitxInputStateSetKeyCode(input, 0);
    FcitxInputStateSetKeySym(input, 0);
    FcitxInputStateSetKeyState(input, 0);

    if ((retVal & IRV_FLAG_FORWARD_KEY) || retVal == IRV_TO_PROCESS) {
        XimForwardKeyInternal(xim,
                              GetXimIC(ic),
                              &call_data->event
                             );
    } else {
        if (!GetXimIC(ic)->bHasCursorLocation)
            SetTrackPos(xim, ic, NULL);
    }
    xim->currentSerialNumberCallData = xim->currentSerialNumberKey = 0L;
}