Ejemplo n.º 1
0
void ResetAutoEng(void *arg)
{
    FcitxAutoEngState *autoEngState = (FcitxAutoEngState*)arg;
    autoEngState->index = 0;
    AutoEngSetBuffLen(autoEngState, 0);
    autoEngState->active = false;
}
Ejemplo n.º 2
0
static void
AutoEngCommit(FcitxAutoEngState *autoEngState)
{
    FcitxInstance *instance = autoEngState->owner;
    FcitxInputContext *currentIC = FcitxInstanceGetCurrentIC(instance);
    FcitxInstanceCommitString(instance, currentIC, autoEngState->buf);
    AutoEngSetBuffLen(autoEngState, 0);
}
Ejemplo n.º 3
0
static boolean PreInputProcessAutoEng(void* arg, FcitxKeySym sym,
                                      unsigned int state,
                                      INPUT_RETURN_VALUE *retval)
{
    FcitxAutoEngState *autoEngState = (FcitxAutoEngState*)arg;
    FcitxInputState *input = FcitxInstanceGetInputState(autoEngState->owner);
    //boolean disableCheckUAZ = FcitxInstanceGetContextBoolean(
    //    autoEngState->owner, CONTEXT_DISABLE_AUTOENG);
    //if (disableCheckUAZ)
    //    return false;
    if (autoEngState->enable == false)
        return false;
	
	FcitxIM *im = FcitxInstanceGetCurrentIM(autoEngState->owner);
	if (im == NULL || strcmp("sogoupinyin", im->uniqueName) != 0)
		return false;

    FcitxKeySym keymain = FcitxHotkeyPadToMain(sym);
    if (!autoEngState->active) {
        if (FcitxHotkeyIsHotKeySimple(sym, state)) {
            AutoEngSetBuff(autoEngState,
                           FcitxInputStateGetRawInputBuffer(input), keymain);
            if (SwitchToEng(autoEngState, autoEngState->buf)) {
                AutoEngActivate(autoEngState, input, retval);
                return true;
            }
        }
        return false;
    }
    if ((*retval = AutoEngCheckSelect(autoEngState, sym, state))) {
        return true;
    } else if (FcitxHotkeyIsHotKeySimple(keymain, state)) {
        *retval = AutoEngPushKey(autoEngState, keymain);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) {
        AutoEngSetBuffLen(autoEngState, --autoEngState->index);
        if (autoEngState->index == 0) {
            ResetAutoEng(autoEngState);
            *retval = IRV_CLEAN;
        } else {
            *retval = IRV_DISPLAY_MESSAGE;
        }
    } else if (FcitxHotkeyIsHotkeyCursorMove(sym, state)) {
        *retval = IRV_DO_NOTHING;
        return true;
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)) {
        AutoEngCommit(autoEngState);
        ResetAutoEng(autoEngState);
        *retval = IRV_FLAG_UPDATE_INPUT_WINDOW | IRV_FLAG_RESET_INPUT;
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) {
        *retval = IRV_CLEAN;
        return true;
    }
    ShowAutoEngMessage(autoEngState, retval);
    return true;
}
Ejemplo n.º 4
0
static void
AutoEngSetBuff(FcitxAutoEngState* autoEngState, const char *str, char extra)
{
    size_t len = str ? strlen(str) : 0;
    autoEngState->index = len + (extra ? 1 : 0);
    AutoEngSetBuffLen(autoEngState, autoEngState->index);
    if (len) {
        memcpy(autoEngState->buf, str, len);
    }
    if (extra) {
        autoEngState->buf[len] = extra;
    }
}
Ejemplo n.º 5
0
void ResetAutoEng(void *arg)
{
    FcitxAutoEngState *autoEngState = (FcitxAutoEngState*)arg;

    if (autoEngState->enable == false)
        return;

	FcitxIM *im = FcitxInstanceGetCurrentIM(autoEngState->owner);
	if (im == NULL || strcmp("sogoupinyin", im->uniqueName) != 0)
		return;
	
    autoEngState->index = 0;
    AutoEngSetBuffLen(autoEngState, 0);
    autoEngState->active = false;
    autoEngState->cursor_moved = false;
}
Ejemplo n.º 6
0
static INPUT_RETURN_VALUE
AutoEngPushKey(FcitxAutoEngState *autoEngState, char key)
{
    INPUT_RETURN_VALUE res = IRV_DISPLAY_MESSAGE;

    if (autoEngState->auto_space) {
        if (AutoEngCheckAutoSpace(autoEngState, key)) {
            return res;
        }
    }

    if (autoEngState->config.maxKeep == 0) {
        if (key == ' ') {
            FcitxInstance *instance = autoEngState->owner;
            FcitxInputContext *currentIC = FcitxInstanceGetCurrentIC(instance);
            FcitxInstanceCommitString(instance, currentIC, autoEngState->buf);
            FcitxInstanceCommitString(instance, currentIC, " ");
            ResetAutoEng(autoEngState);
            return res | IRV_CLEAN;
        }
    } else if (autoEngState->config.maxKeep > 0) {
        char *found = autoEngState->buf + autoEngState->index;
        int i = autoEngState->config.maxKeep;
        do {
            found = memrchr(autoEngState->buf, ' ', found - autoEngState->buf);
            if (!found) {
                break;
            }
        } while (--i > 0);
        if (found && found != autoEngState->buf) {
            FcitxInstance *instance = autoEngState->owner;
            FcitxInputContext *currentIC = FcitxInstanceGetCurrentIC(instance);
            *found = '\0';
            FcitxInstanceCommitString(instance, currentIC, autoEngState->buf);
            autoEngState->index = (autoEngState->buf + autoEngState->index
                                   - found);
            memmove(autoEngState->buf + 1, found + 1, autoEngState->index);
            *autoEngState->buf = ' ';
        }
    }
    autoEngState->buf[autoEngState->index++] = key;
    AutoEngSetBuffLen(autoEngState, autoEngState->index);
    return res;
}
Ejemplo n.º 7
0
static boolean
AutoEngCheckAutoSpace(FcitxAutoEngState *autoEngState, char key)
{
    autoEngState->auto_space = false;
    if (autoEngState->buf[autoEngState->index - 1] != ' ') {
        return false;
    }
    switch (key) {
    case_autoeng_replace:
        autoEngState->buf[autoEngState->index - 1] = key;
        break;
    case_autoeng_exchange:
        autoEngState->buf[autoEngState->index - 1] = key;
        autoEngState->buf[autoEngState->index] = ' ';
        AutoEngSetBuffLen(autoEngState, ++autoEngState->index);
        autoEngState->auto_space = true;
        break;
    default:
        return false;
    }
    return true;
}