Exemple #1
0
INPUT_RETURN_VALUE QuickPhraseDoInput(void* arg, FcitxKeySym sym, int state)
{
    QuickPhraseState *qpstate = (QuickPhraseState*) arg;
    FcitxInputState *input = FcitxInstanceGetInputState(qpstate->owner);
    FcitxGlobalConfig* fc = FcitxInstanceGetGlobalConfig(qpstate->owner);
    int retVal = IRV_TO_PROCESS;

    const FcitxHotkey* hkPrevPage = FcitxInstanceGetContextHotkey(qpstate->owner, CONTEXT_ALTERNATIVE_PREVPAGE_KEY);
    if (hkPrevPage == NULL)
        hkPrevPage = fc->hkPrevPage;

    const FcitxHotkey* hkNextPage = FcitxInstanceGetContextHotkey(qpstate->owner, CONTEXT_ALTERNATIVE_NEXTPAGE_KEY);
    if (hkNextPage == NULL)
        hkNextPage = fc->hkNextPage;

    if (FcitxHotkeyIsHotKey(sym, state, hkPrevPage)) {
        if (FcitxCandidateWordGoPrevPage(FcitxInputStateGetCandidateList(input)))
            retVal = IRV_DISPLAY_MESSAGE;
    } else if (FcitxHotkeyIsHotKey(sym, state, hkNextPage)) {
        if (FcitxCandidateWordGoNextPage(FcitxInputStateGetCandidateList(input)))
            retVal = IRV_DISPLAY_MESSAGE;
    } else if (FcitxHotkeyIsHotKeyDigit(sym, state)) {
        int iKey = FcitxHotkeyCheckChooseKey(sym, state, DIGIT_STR_CHOOSE);
        if (iKey >= 0)
            retVal = FcitxCandidateWordChooseByIndex(FcitxInputStateGetCandidateList(input), iKey);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) {
        if (FcitxCandidateWordPageCount(FcitxInputStateGetCandidateList(input)) != 0)
            retVal = FcitxCandidateWordChooseByIndex(FcitxInputStateGetCandidateList(input), 0);
    }

    return retVal;
}
Exemple #2
0
boolean IMSelectorPreFilter(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retval)
{
    IMSelector* imselector = arg;
    FcitxInstance* instance = imselector->owner;
    FcitxInputState *input = FcitxInstanceGetInputState(instance);
    FcitxGlobalConfig* fc = FcitxInstanceGetGlobalConfig(instance);
    if (!imselector->triggered)
        return false;
    FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input);
    if (FcitxHotkeyIsHotKey(sym, state,
                            FcitxConfigPrevPageKey(instance, fc))) {
        FcitxCandidateWordGoPrevPage(candList);
        *retval = IRV_DISPLAY_MESSAGE;
    } else if (FcitxHotkeyIsHotKey(sym, state,
                                   FcitxConfigNextPageKey(instance, fc))) {
        FcitxCandidateWordGoNextPage(candList);
        *retval = IRV_DISPLAY_MESSAGE;
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) {
        if (FcitxCandidateWordPageCount(candList) != 0)
            *retval = FcitxCandidateWordChooseByIndex(candList, 0);
    } else if (FcitxHotkeyIsHotKeyDigit(sym, state)) {
        int iKey = FcitxHotkeyCheckChooseKey(sym, state, DIGIT_STR_CHOOSE);
        if (iKey >= 0)
            *retval = FcitxCandidateWordChooseByIndex(candList, iKey);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) {
        *retval = IRV_CLEAN;
    }
    if (*retval == IRV_TO_PROCESS)
        *retval = IRV_DO_NOTHING;
    return true;
}
Exemple #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;
}
Exemple #4
0
boolean QuickPhrasePreFilter(void *arg, FcitxKeySym sym,
                             unsigned int state,
                             INPUT_RETURN_VALUE *retval)
{
    QuickPhraseState *qpstate = (QuickPhraseState*) arg;
    FcitxInputState *input = FcitxInstanceGetInputState(qpstate->owner);
    if (!qpstate->enabled)
        return false;
    char c[2];
    QuickPhraseFillKeyString(qpstate, c);
    FcitxKeySym keymain = FcitxHotkeyPadToMain(sym);
    *retval = QuickPhraseDoInput(qpstate, keymain, state);
    if (*retval != IRV_TO_PROCESS)
        return true;
    if (FcitxHotkeyIsHotKeySimple(keymain, state)) {
        if (c[0] && strlen(qpstate->buffer) == 0 &&
            ((qpstate->useDupKeyInput &&
              FcitxHotkeyIsHotKey(keymain, state, qpstate->curTriggerKey)) ||
             FcitxHotkeyIsHotKey(keymain, state, FCITX_SPACE))) {
            int s = qpstate->curTriggerKey[0].sym;
            char *strTemp = FcitxPuncGetPunc(qpstate->owner, &s);
            strcpy(FcitxInputStateGetOutputString(input), strTemp ? strTemp : c);
            *retval = IRV_COMMIT_STRING;
        } else {
            char buf[2];
            buf[0] = keymain;
            buf[1] = '\0';
            if (strlen(qpstate->buffer) < MAX_USER_INPUT)
                strcat(qpstate->buffer, buf);
            ShowQuickPhraseMessage(qpstate);
            *retval = QuickPhraseGetCandWords(qpstate);
        }
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) {
        size_t len = strlen(qpstate->buffer);
        if (len > 0)
            qpstate->buffer[--len] = '\0';
        if (len == 0) {
            *retval = IRV_CLEAN;
        } else {
            ShowQuickPhraseMessage(qpstate);
            *retval = QuickPhraseGetCandWords(qpstate);
        }
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)) {
        size_t len = strlen(qpstate->buffer);
        if (len > 0) {
            if (qpstate->append) {
                fcitx_utils_cat_str(FcitxInputStateGetOutputString(input),
                                    2, (const char*[]){c, qpstate->buffer},
                                    (size_t[]){strlen(c), len});
            } else {
Exemple #5
0
INPUT_RETURN_VALUE FcitxKkcDoInputReal(void* arg, FcitxKeySym sym, unsigned int state)
{
    FcitxKkc *kkc = (FcitxKkc*)arg;
    state = state & (FcitxKeyState_SimpleMask | _FcitxKeyState_Release);
    KkcCandidateList* kkcCandidates = kkc_context_get_candidates(kkc->context);

    if (kkc_candidate_list_get_page_visible(kkcCandidates)) {
        if (FcitxHotkeyIsHotKeyDigit(sym, state)) {
            return IRV_TO_PROCESS;
        } else if (FcitxHotkeyIsHotKey(sym, state, kkc->config.prevPageKey)) {
            return IRV_TO_PROCESS;
        } else if (FcitxHotkeyIsHotKey(sym, state, kkc->config.nextPageKey)) {
            return IRV_TO_PROCESS;
        } else if (FcitxHotkeyIsHotKey(sym, state, kkc->config.cursorUpKey)) {
            if (!(state & _FcitxKeyState_Release)) {
                KkcCandidateList* kkcCandidates = kkc_context_get_candidates(kkc->context);
                kkc_candidate_list_cursor_up(kkcCandidates);
                return IRV_DISPLAY_CANDWORDS;
            } else {
                return IRV_TO_PROCESS;
            }
        } else if (FcitxHotkeyIsHotKey(sym, state, kkc->config.cursorDownKey)) {
            if (!(state & _FcitxKeyState_Release)) {
                KkcCandidateList* kkcCandidates = kkc_context_get_candidates(kkc->context);
                kkc_candidate_list_cursor_down(kkcCandidates);
                return IRV_DISPLAY_CANDWORDS;
            } else {
                return IRV_TO_PROCESS;
            }
        }
    }

    FcitxInputState* input = FcitxInstanceGetInputState(kkc->owner);
    uint32_t keycode = FcitxInputStateGetKeyCode(input);
    KkcKeyEvent* key = kkc_key_event_new_from_x_event(sym, keycode - 8, state);
    if (!key) {
        return IRV_TO_PROCESS;
    }

    gboolean retval = kkc_context_process_key_event(kkc->context, key);

    g_object_unref(key);
    if (retval) {
        return IRV_DISPLAY_CANDWORDS;
    }
    return IRV_TO_PROCESS;
}
Exemple #6
0
INPUT_RETURN_VALUE DoQWInput(void* arg, FcitxKeySym sym, unsigned int state)
{
    FcitxQWState* qwstate = (FcitxQWState*) arg;
    FcitxInputState* input = FcitxInstanceGetInputState(qwstate->owner);
    char* strCodeInput = FcitxInputStateGetRawInputBuffer(input);
    INPUT_RETURN_VALUE retVal;

    retVal = IRV_TO_PROCESS;
    if (FcitxHotkeyIsHotKeyDigit(sym, state)) {
        if (FcitxInputStateGetRawInputBufferSize(input) != 4) {
            strCodeInput[FcitxInputStateGetRawInputBufferSize(input)] = sym;
            strCodeInput[FcitxInputStateGetRawInputBufferSize(input) + 1] = '\0';
            FcitxInputStateSetRawInputBufferSize(input, FcitxInputStateGetRawInputBufferSize(input) + 1);
            if (FcitxInputStateGetRawInputBufferSize(input) == 4) {
                retVal = IRV_TO_PROCESS;
            } else
                retVal = IRV_DISPLAY_CANDWORDS;
        }
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) {
        if (!FcitxInputStateGetRawInputBufferSize(input))
            return IRV_DONOT_PROCESS_CLEAN;
        FcitxInputStateSetRawInputBufferSize(input, FcitxInputStateGetRawInputBufferSize(input) - 1);
        strCodeInput[FcitxInputStateGetRawInputBufferSize(input)] = '\0';

        if (!FcitxInputStateGetRawInputBufferSize(input))
            retVal = IRV_CLEAN;
        else {
            retVal = IRV_DISPLAY_CANDWORDS;
        }
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) {
        if (!FcitxInputStateGetRawInputBufferSize(input))
            return IRV_TO_PROCESS;
        if (FcitxInputStateGetRawInputBufferSize(input) != 3)
            return IRV_DO_NOTHING;

        retVal = FcitxCandidateWordChooseByIndex(FcitxInputStateGetCandidateList(input), 0);
    } else
        return IRV_TO_PROCESS;


    return retVal;
}
Exemple #7
0
boolean IsHotKeyPunc(FcitxKeySym sym, unsigned int state)
{
    if (FcitxHotkeyIsHotKeySimple(sym, state)
            && !FcitxHotkeyIsHotKeyDigit(sym, state)
            && !FcitxHotkeyIsHotKeyLAZ(sym, state)
            && !FcitxHotkeyIsHotKeyUAZ(sym, state)
            && !FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE))
        return true;

    return false;
}
Exemple #8
0
// This function is called from within fcitx. It is called when user
// input is detected. This may be a keypress, or it may be triggered by
// a new stroke on the tablet (see FcitxTabletProcess)
INPUT_RETURN_VALUE FcitxTabletDoInput(void* arg, FcitxKeySym sym, unsigned int action) {
	// The event module uses VoidSymbol as a trigger, this means other input methods
	// will ignore it, actual actions will be passed in the action variable
	FcitxTablet* tablet = (FcitxTablet*) arg;
	if(sym == FcitxKey_VoidSymbol) {
		// Depending on the tablet driver, we could add more actions, for
		// example selecting candidates via the tablet
		switch(action) {
		case IME_RECOGNISE:
			tablet->engineInstance->Process(tablet->engineData, tablet->strokesBuffer, (tablet->strokesPtr - tablet->strokesBuffer));
			// call into recognition library, update candidate lists
			return IRV_DISPLAY_CANDWORDS;
			break;
		case IME_COMMIT:
			CommitFirstCandidate(tablet);
			return IRV_CLEAN;
			break;
		default:
			FcitxLog(ERROR, "IME asked to perform unknown action");
		}
	}
	// Backspace and spacebar need to be handled specially
	if(FcitxHotkeyIsHotKey(sym, action, FCITX_BACKSPACE)) {
		if(CharacterInProgress(tablet)) {
			// scrap the current character
			ClearCharacter(tablet);
			CommitFirstCandidate(tablet);
			return IRV_CLEAN;
		} else
			return IRV_TO_PROCESS;
	} else if(FcitxHotkeyIsHotKey(sym, action, FCITX_SPACE) || FcitxHotkeyIsHotKey(sym, action, FCITX_ENTER)) {
		if(CharacterInProgress(tablet)) {
			// commit the current character
			return IRV_CLEAN;
		} else
			return IRV_TO_PROCESS;
	}
	return IRV_TO_PROCESS;
}
Exemple #9
0
boolean IMSelectorPreFilter(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retval)
{
    IMSelector* imselector = arg;
    FcitxInstance* instance = imselector->owner;
    FcitxInputState *input = FcitxInstanceGetInputState(instance);
    FcitxGlobalConfig* fc = FcitxInstanceGetGlobalConfig(instance);
    if (!imselector->triggered)
        return false;

    const FcitxHotkey* hkPrevPage = FcitxInstanceGetContextHotkey(instance, CONTEXT_ALTERNATIVE_PREVPAGE_KEY);
    if (hkPrevPage == NULL)
        hkPrevPage = fc->hkPrevPage;

    const FcitxHotkey* hkNextPage = FcitxInstanceGetContextHotkey(instance, CONTEXT_ALTERNATIVE_NEXTPAGE_KEY);
    if (hkNextPage == NULL)
        hkNextPage = fc->hkNextPage;

    FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input);

    if (FcitxHotkeyIsHotKey(sym, state, hkPrevPage)) {
        FcitxCandidateWordGoPrevPage(candList);
        *retval = IRV_DISPLAY_MESSAGE;
    } else if (FcitxHotkeyIsHotKey(sym, state, hkNextPage)) {
        FcitxCandidateWordGoNextPage(candList);
        *retval = IRV_DISPLAY_MESSAGE;
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) {
        if (FcitxCandidateWordPageCount(candList) != 0)
            *retval = FcitxCandidateWordChooseByIndex(candList, 0);
    } else if (FcitxHotkeyIsHotKeyDigit(sym, state)) {
        int iKey = FcitxHotkeyCheckChooseKey(sym, state, DIGIT_STR_CHOOSE);
        if (iKey >= 0)
            *retval = FcitxCandidateWordChooseByIndex(candList, iKey);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) {
        *retval = IRV_CLEAN;
    } else {
        *retval = IRV_DO_NOTHING;
    }
    return true;
}
Exemple #10
0
boolean QuickPhrasePostFilter(void* arg, FcitxKeySym sym,
                              unsigned int state,
                              INPUT_RETURN_VALUE *retval
                             )
{
    QuickPhraseState *qpstate = (QuickPhraseState*) arg;
    FcitxInputState *input = FcitxInstanceGetInputState(qpstate->owner);
    boolean disableQuickPhrase = FcitxInstanceGetContextBoolean(qpstate->owner, CONTEXT_DISABLE_QUICKPHRASE);

    if (*retval != IRV_TO_PROCESS)
        return false;

    if (!disableQuickPhrase
        && !qpstate->enabled
        && FcitxInputStateGetRawInputBufferSize(input) == 0
        && FcitxHotkeyIsHotKey(sym, state, QuickPhraseTriggerKeys[qpstate->triggerKey])) {
        FcitxInstanceCleanInputWindow(qpstate->owner);
        FcitxInputStateSetShowCursor(input, true);
        FcitxMessagesAddMessageAtLast(FcitxInputStateGetAuxUp(input), MSG_TIPS, "%s", _("Quick Phrase: "));
        FcitxInputStateSetCursorPos(input, 0);

        char c[2] = { (char) (QuickPhraseTriggerKeys[qpstate->triggerKey][0].sym & 0xff), '\0'};
        FcitxModuleFunctionArg farg;
        FcitxKeySym s = QuickPhraseTriggerKeys[qpstate->triggerKey][0].sym;
        farg.args[0] = &s;
        char* strTemp = InvokeFunction(qpstate->owner, FCITX_PUNC, GETPUNC, farg);
        const char* full = strTemp ? strTemp : c;
        FcitxMessagesAddMessageAtLast(FcitxInputStateGetAuxDown(input), MSG_TIPS, _("Space for %s Enter for %s") , full, c);

        qpstate->enabled = true;
        *retval = IRV_DISPLAY_MESSAGE;

        return true;
    }
    return false;
}
Exemple #11
0
static boolean
ClipboardPostHook(void *arg, FcitxKeySym sym, unsigned int state,
                  INPUT_RETURN_VALUE *ret_val)
{
    FcitxClipboard *clipboard = arg;
    FcitxClipboardConfig *config = &clipboard->config;
    if (!((clipboard->primary.len && config->use_primary) ||
          clipboard->clp_hist_len))
        return false;
    FcitxInstance *instance = clipboard->owner;
    FcitxInputState *input = FcitxInstanceGetInputState(instance);
    if (FcitxInputStateGetRawInputBufferSize(input))
        return false;
    if (!FcitxHotkeyIsHotKey(sym, state, config->trigger_key))
        return false;
    clipboard->active = true;
    FcitxCandidateWordList *cand_list = FcitxInputStateGetCandidateList(input);
    FcitxGlobalConfig *gconfig = FcitxInstanceGetGlobalConfig(instance);
    FcitxMessages *msg;
    FcitxCandidateWord cand_word = {
        .callback = ClipboardCommitCallback,
        .wordType = MSG_OTHER,
        .owner = clipboard
    };
    FcitxInstanceCleanInputWindow(instance);
    FcitxCandidateWordSetLayoutHint(cand_list, CLH_Vertical);
    FcitxCandidateWordSetPageSize(cand_list, gconfig->iMaxCandWord);
    FcitxCandidateWordSetChooseAndModifier(
        cand_list, DIGIT_STR_CHOOSE, cmodifiers[config->choose_modifier]);
    if (clipboard->clp_hist_len) {
        ClipboardSetCandWord(clipboard, &cand_word, clipboard->clp_hist_lst);
        FcitxCandidateWordAppend(cand_list, &cand_word);
    }
    int primary_found;
    if (clipboard->primary.len && config->use_primary) {
        primary_found = ClipboardSelectionClipboardFind(
            clipboard, clipboard->primary.str, clipboard->primary.len);
        if (primary_found == 0)
            goto skip_primary;
        ClipboardSetCandWord(clipboard, &cand_word, &clipboard->primary);
        FcitxCandidateWordAppend(cand_list, &cand_word);
    } else {
        primary_found = -1;
    }
skip_primary:
    msg = FcitxInputStateGetAuxUp(input);
    FcitxInputStateSetShowCursor(input, false);
    FcitxMessagesSetMessageCount(msg, 0);
    FcitxMessagesAddMessageStringsAtLast(msg, MSG_TIPS,
                                         _("Select to paste"));
    unsigned int i;
    for (i = 1;i < clipboard->clp_hist_len;i++) {
        if ((int)i == primary_found)
            continue;
        ClipboardSetCandWord(clipboard, &cand_word,
                             clipboard->clp_hist_lst + i);
        FcitxCandidateWordAppend(cand_list, &cand_word);
    }
    *ret_val = IRV_FLAG_UPDATE_INPUT_WINDOW;
    return true;
}
Exemple #12
0
boolean UnicodePreFilter(void* arg, FcitxKeySym sym, unsigned int state,
                         INPUT_RETURN_VALUE *r)
{
    INPUT_RETURN_VALUE retVal = IRV_TO_PROCESS;
    do {
        UnicodeModule *uni = arg;
        if (!uni->enable) {
            return false;
        }
        FcitxInstance *instance = uni->owner;
        FcitxInputState *input = FcitxInstanceGetInputState(instance);
        FcitxGlobalConfig *fc = FcitxInstanceGetGlobalConfig(instance);
        FcitxCandidateWordList *candList;
        FcitxCandidateWord *candWord;
        candList = FcitxInputStateGetCandidateList(input);

        FcitxCandidateWordSetPageSize(candList, fc->iMaxCandWord);
        FcitxCandidateWordSetChooseAndModifier(candList, DIGIT_STR_CHOOSE,
                                               FcitxKeyState_Alt);
        if (FcitxHotkeyIsHotKey(sym, state,
                                FcitxConfigPrevPageKey(instance, fc))) {
            if (FcitxCandidateWordGoPrevPage(candList))
                retVal = IRV_DISPLAY_MESSAGE;
            else
                retVal = IRV_DO_NOTHING;
        } else if (FcitxHotkeyIsHotKey(sym, state,
                                       FcitxConfigNextPageKey(instance, fc))) {
            if (FcitxCandidateWordGoNextPage(candList))
                retVal = IRV_DISPLAY_MESSAGE;
            else
                retVal = IRV_DO_NOTHING;
        } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) {
            size_t len = strlen(uni->buffer);
            if (len > 0)
                uni->buffer[--len] = '\0';
            if (len == 0) {
                retVal = IRV_CLEAN;
            } else {
                retVal = UnicodeGetCandWords(uni);
            }
        } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) {
            retVal = IRV_CLEAN;
        } else if (FcitxHotkeyIsHotKey(sym, state, fc->nextWord)) {
            candWord = FcitxCandidateWordGetFocus(candList, true);
            candWord = FcitxCandidateWordGetNext(candList, candWord);
            if (!candWord) {
                FcitxCandidateWordSetPage(candList, 0);
                candWord = FcitxCandidateWordGetFirst(candList);
            } else {
                FcitxCandidateWordSetFocus(
                    candList, FcitxCandidateWordGetIndex(candList, candWord));
            }
            if (candWord) {
                FcitxCandidateWordSetType(candWord, MSG_CANDIATE_CURSOR);
                retVal = IRV_FLAG_UPDATE_INPUT_WINDOW;
            }
        } else if (FcitxHotkeyIsHotKey(sym, state, fc->prevWord)) {
            candWord = FcitxCandidateWordGetFocus(candList, true);
            candWord = FcitxCandidateWordGetPrev(candList, candWord);
            if (!candWord) {
                FcitxCandidateWordSetPage(
                    candList, FcitxCandidateWordPageCount(candList) - 1);
                candWord = FcitxCandidateWordGetLast(candList);
            } else {
                FcitxCandidateWordSetFocus(
                    candList, FcitxCandidateWordGetIndex(candList, candWord));
            }
            if (candWord) {
                FcitxCandidateWordSetType(candWord, MSG_CANDIATE_CURSOR);
                retVal = IRV_FLAG_UPDATE_INPUT_WINDOW;
            }
        } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)) {
            candWord = FcitxCandidateWordGetFocus(candList, true);
            if (candWord) {
                retVal = FcitxCandidateWordChooseByTotalIndex(
                    candList, FcitxCandidateWordGetIndex(candList, candWord));
            }
        }

        if (retVal == IRV_TO_PROCESS) {
            int index = FcitxCandidateWordCheckChooseKey(candList, sym, state);
            if (index >= 0)
                retVal = FcitxCandidateWordChooseByIndex(candList, index);
        }

        FcitxKeySym keymain = FcitxHotkeyPadToMain(sym);
        if (retVal == IRV_TO_PROCESS && FcitxHotkeyIsHotKeySimple(keymain, state)) {
            char buf[2];
            buf[0] = keymain;
            buf[1] = '\0';
            if (strlen(uni->buffer) < MAX_USER_INPUT)
                strcat(uni->buffer, buf);
            retVal = UnicodeGetCandWords(uni);
        }
    } while(0);

    if (retVal == IRV_TO_PROCESS) {
        retVal = IRV_DO_NOTHING;
    }
    *r = retVal;
    return true;
}
Exemple #13
0
static INPUT_RETURN_VALUE
AutoEngCheckSelect(FcitxAutoEngState *autoEngState,
                   FcitxKeySym sym, unsigned int state)
{
    FcitxInstance *instance = autoEngState->owner;
    FcitxCandidateWordList *cand_list = FcitxInputStateGetCandidateList(
        FcitxInstanceGetInputState(autoEngState->owner));
    if (!FcitxCandidateWordGetListSize(cand_list))
        return IRV_TO_PROCESS;
    FcitxInputState *input = FcitxInstanceGetInputState(instance);
    FcitxGlobalConfig *fc = FcitxInstanceGetGlobalConfig(instance);
    int key;
    FcitxCandidateWord *cand_word;
    if (FcitxHotkeyIsHotKey(sym, state, fc->nextWord)) {
        if (!autoEngState->cursor_moved) {
            cand_word = FcitxCandidateWordGetCurrentWindow(cand_list);
        } else {
            cand_word = FcitxCandidateWordGetFocus(cand_list, true);
            cand_word = FcitxCandidateWordGetNext(cand_list, cand_word);
            if (!cand_word) {
                FcitxCandidateWordSetPage(cand_list, 0);
            } else {
                FcitxCandidateWordSetFocus(
                    cand_list, FcitxCandidateWordGetIndex(cand_list,
                                                          cand_word));
            }
        }
    } else if (FcitxHotkeyIsHotKey(sym, state, fc->prevWord)) {
        if (!autoEngState->cursor_moved) {
            cand_word = FcitxCandidateWordGetByIndex(
                cand_list,
                FcitxCandidateWordGetCurrentWindowSize(cand_list) - 1);
        } else {
            cand_word = FcitxCandidateWordGetFocus(cand_list, true);
            cand_word = FcitxCandidateWordGetPrev(cand_list, cand_word);
            if (cand_word) {
                FcitxCandidateWordSetFocus(
                    cand_list, FcitxCandidateWordGetIndex(cand_list,
                                                          cand_word));
            }
        }
    } else if (FcitxHotkeyIsHotKey(sym, state,
                                   FcitxConfigPrevPageKey(instance, fc))) {
        boolean has_prev_page;
        cand_word = FcitxCandidateWordGetFocus(cand_list, true);
        has_prev_page = FcitxCandidateWordGoPrevPage(cand_list);
        if (!autoEngState->cursor_moved) {
            cand_word = NULL;
        } else if (has_prev_page) {
            cand_word = FcitxCandidateWordGetCurrentWindow(cand_list) +
                FcitxCandidateWordGetCurrentWindowSize(cand_list) - 1;
        }
    } else if (FcitxHotkeyIsHotKey(sym, state,
                                   FcitxConfigNextPageKey(instance, fc))) {
        boolean has_next_page;
        cand_word = FcitxCandidateWordGetFocus(cand_list, true);
        has_next_page = FcitxCandidateWordGoNextPage(cand_list);
        if (!autoEngState->cursor_moved) {
            cand_word = NULL;
        } else if (has_next_page) {
            cand_word = FcitxCandidateWordGetCurrentWindow(cand_list);
        }
    } else if ((key = FcitxCandidateWordCheckChooseKey(cand_list,
                                                       sym, state)) >= 0) {
        return FcitxCandidateWordChooseByIndex(cand_list, key);
    } else {
        return IRV_TO_PROCESS;
    }
    if (cand_word) {
        FcitxCandidateWordSetType(cand_word, MSG_CANDIATE_CURSOR);
        if (!autoEngState->cursor_moved)
            AutoEngSwapBuff(autoEngState);
        AutoEngSetBuff(autoEngState, cand_word->strWord, '\0');
        autoEngState->cursor_moved = true;
    } else if (autoEngState->cursor_moved) {
        AutoEngSwapBuff(autoEngState);
        autoEngState->cursor_moved = false;
    } else {
        return IRV_FLAG_UPDATE_INPUT_WINDOW;
    }
    FcitxMessages *client_preedit = FcitxInputStateGetClientPreedit(input);
    FcitxMessages *preedit = FcitxInputStateGetPreedit(input);
    FcitxMessagesSetMessageCount(client_preedit, 0);
    FcitxMessagesSetMessageCount(preedit, 0);
    FcitxMessagesAddMessageStringsAtLast(client_preedit, MSG_INPUT,
                                         autoEngState->buf);
    FcitxMessagesAddMessageStringsAtLast(preedit, MSG_INPUT,
                                         autoEngState->buf);
    FcitxInputStateSetCursorPos(input, autoEngState->index);
    FcitxInputStateSetClientCursorPos(input, autoEngState->index);
    return IRV_FLAG_UPDATE_INPUT_WINDOW;
}
Exemple #14
0
static boolean
ClipboardPreHook(void *arg, FcitxKeySym sym, unsigned int state,
                 INPUT_RETURN_VALUE *ret_val)
{
    FcitxClipboard *clipboard = arg;
    FcitxInstance *instance = clipboard->owner;
    if (!clipboard->active)
        return false;
    FcitxInputState *input = FcitxInstanceGetInputState(instance);
    FcitxCandidateWordList *cand_list = FcitxInputStateGetCandidateList(input);
    FcitxGlobalConfig *fc = FcitxInstanceGetGlobalConfig(instance);
    *ret_val = IRV_TO_PROCESS;
    int key;
    FcitxCandidateWord *cand_word;
    if (FcitxHotkeyIsHotKey(sym, state, fc->nextWord)) {
        cand_word = FcitxCandidateWordGetFocus(cand_list, true);
        cand_word = FcitxCandidateWordGetNext(cand_list, cand_word);
        if (!cand_word) {
            FcitxCandidateWordSetPage(cand_list, 0);
            cand_word = FcitxCandidateWordGetFirst(cand_list);
        } else {
            FcitxCandidateWordSetFocus(
                cand_list, FcitxCandidateWordGetIndex(cand_list, cand_word));
        }
    } else if (FcitxHotkeyIsHotKey(sym, state, fc->prevWord)) {
        cand_word = FcitxCandidateWordGetFocus(cand_list, true);
        cand_word = FcitxCandidateWordGetPrev(cand_list, cand_word);
        if (!cand_word) {
            FcitxCandidateWordSetPage(
                cand_list, FcitxCandidateWordPageCount(cand_list) - 1);
            cand_word = FcitxCandidateWordGetLast(cand_list);
        } else {
            FcitxCandidateWordSetFocus(
                cand_list, FcitxCandidateWordGetIndex(cand_list, cand_word));
        }
    } else if (FcitxHotkeyIsHotKey(sym, state,
                                   FcitxConfigPrevPageKey(instance, fc))) {
        cand_word = FcitxCandidateWordGetFocus(cand_list, true);
        if (!FcitxCandidateWordGoPrevPage(cand_list)) {
            FcitxCandidateWordSetType(cand_word, MSG_CANDIATE_CURSOR);
            *ret_val = IRV_DO_NOTHING;
            return true;
        }
        cand_word = FcitxCandidateWordGetCurrentWindow(cand_list) +
            FcitxCandidateWordGetCurrentWindowSize(cand_list) - 1;
    } else if (FcitxHotkeyIsHotKey(sym, state,
                                   FcitxConfigNextPageKey(instance, fc))) {
        cand_word = FcitxCandidateWordGetFocus(cand_list, true);
        if (!FcitxCandidateWordGoNextPage(cand_list)) {
            FcitxCandidateWordSetType(cand_word, MSG_CANDIATE_CURSOR);
            *ret_val = IRV_DO_NOTHING;
            return true;
        }
        cand_word = FcitxCandidateWordGetCurrentWindow(cand_list);
    } else if ((key = FcitxCandidateWordCheckChooseKey(cand_list,
                                                       sym, state)) >= 0) {
        *ret_val = FcitxCandidateWordChooseByIndex(cand_list, key);
        return true;
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) {
        cand_word = FcitxCandidateWordGetFocus(cand_list, true);
        *ret_val = FcitxCandidateWordChooseByTotalIndex(
            cand_list, FcitxCandidateWordGetIndex(cand_list, cand_word));
        return true;
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) {
        *ret_val = IRV_FLAG_RESET_INPUT | IRV_FLAG_UPDATE_INPUT_WINDOW;
        return true;
    } else {
        *ret_val = IRV_DO_NOTHING;
        return true;
    }

    FcitxCandidateWordSetType(cand_word, MSG_CANDIATE_CURSOR);
    *ret_val = IRV_FLAG_UPDATE_INPUT_WINDOW;
    return true;
}
Exemple #15
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;
}
Exemple #16
0
boolean ProcessPunc(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retVal)
{
    FcitxPuncState* puncState = (FcitxPuncState*) arg;
    FcitxInstance* instance = puncState->owner;
    FcitxInputState* input = FcitxInstanceGetInputState(puncState->owner);
    FcitxProfile* profile = FcitxInstanceGetProfile(instance);
    FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(instance);

    char *pPunc = NULL;

    if (*retVal != IRV_TO_PROCESS)
        return false;

    FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input);
    if (FcitxCandidateWordPageCount(candList) != 0 && FcitxCandidateWordGetHasGoneToNextPage(candList) ) {
        const FcitxHotkey* hkPrevPage = FcitxInstanceGetContextHotkey(instance, CONTEXT_ALTERNATIVE_PREVPAGE_KEY);
        if (hkPrevPage == NULL)
            hkPrevPage = config->hkPrevPage;

        if (FcitxHotkeyIsHotKey(sym, state, hkPrevPage)) {
            return false;
        }
    }

    /*
     * comparing with upper case, if paging is occupied,
     * punc will not let next page pass
     */
    if (FcitxCandidateWordPageCount(candList) != 0) {
        const FcitxHotkey* hkNextPage = FcitxInstanceGetContextHotkey(instance, CONTEXT_ALTERNATIVE_NEXTPAGE_KEY);
        if (hkNextPage == NULL)
            hkNextPage = config->hkNextPage;

        if (FcitxHotkeyIsHotKey(sym, state, hkNextPage)) {
            return false;
        }
    }

    FcitxKeySym origsym = sym;
    sym = FcitxHotkeyPadToMain(sym);
    if (profile->bUseWidePunc) {

        if (puncState->bLastIsNumber && config->bEngPuncAfterNumber
                && (FcitxHotkeyIsHotKey(origsym, state, FCITX_PERIOD)
                    || FcitxHotkeyIsHotKey(origsym, state, FCITX_SEMICOLON)
                    || FcitxHotkeyIsHotKey(origsym, state, FCITX_COMMA))) {
            puncState->cLastIsAutoConvert = origsym;
            puncState->bLastIsNumber = false;
            *retVal = IRV_DONOT_PROCESS;
            return true;
        }
        if (FcitxHotkeyIsHotKeySimple(sym, state))
            pPunc = GetPunc(puncState, origsym);
    }

    /*
     * 在有候选词未输入的情况下,选择第一个候选词并输入标点
     */
    if (IsHotKeyPunc(sym, state)) {
        FcitxInputStateGetOutputString(input)[0] = '\0';
        INPUT_RETURN_VALUE ret = IRV_TO_PROCESS;
        if (!FcitxInputStateGetIsInRemind(input))
            ret = FcitxCandidateWordChooseByTotalIndex(FcitxInputStateGetCandidateList(input), 0);

        /* if there is nothing to commit */
        if (ret == IRV_TO_PROCESS) {
            if (pPunc) {
                strcat(FcitxInputStateGetOutputString(input), pPunc);
                *retVal = IRV_PUNC;
                FcitxInstanceCleanInputWindow(instance);
                return true;
            } else
                return false;
        } else {
            if (pPunc)
                strcat(FcitxInputStateGetOutputString(input), pPunc);
            else {
                char buf[2] = { sym, 0 };
                strcat(FcitxInputStateGetOutputString(input), buf);
            }

            FcitxInstanceCleanInputWindow(instance);
            *retVal = IRV_PUNC;
            return true;
        }

        return false;
    }

    if (profile->bUseWidePunc) {
        if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)
                && puncState->cLastIsAutoConvert) {
            char *pPunc;

            FcitxInstanceForwardKey(puncState->owner, FcitxInstanceGetCurrentIC(instance), FCITX_PRESS_KEY, sym, state);
            pPunc = GetPunc(puncState, puncState->cLastIsAutoConvert);
            if (pPunc)
                FcitxInstanceCommitString(puncState->owner, FcitxInstanceGetCurrentIC(instance), pPunc);

            puncState->cLastIsAutoConvert = 0;
            *retVal = IRV_DO_NOTHING;
            return true;
        } else if (FcitxHotkeyIsHotKeySimple(sym, state)) {
            if (FcitxHotkeyIsHotKeyDigit(sym, state))
                puncState->bLastIsNumber = true;
            else {
                puncState->bLastIsNumber = false;
            }
        }
    }
    puncState->cLastIsAutoConvert = 0;
    return false;
}
Exemple #17
0
/**
 * @brief Process Key Input and return the status
 *
 * @param keycode keycode from XKeyEvent
 * @param state state from XKeyEvent
 * @param count count from XKeyEvent
 * @return INPUT_RETURN_VALUE
 **/
__EXPORT_API
INPUT_RETURN_VALUE FcitxChewingDoInput(void* arg, FcitxKeySym sym, unsigned int state)
{
    FcitxChewing* chewing = (FcitxChewing*) arg;
    FcitxInputState *input = FcitxInstanceGetInputState(chewing->owner);
    ChewingContext * c = chewing->context;

    if (FcitxCandidateWordGetListSize(FcitxInputStateGetCandidateList(input)) > 0
        && (FcitxHotkeyIsHotKeyDigit(sym, state) || FcitxHotkeyIsHotKey(sym, state, FCITX_RIGHT) || FcitxHotkeyIsHotKey(sym, state, FCITX_LEFT)))
        return IRV_TO_PROCESS;

    if (FcitxHotkeyIsHotKeySimple(sym, state)) {
        int scan_code = (int) sym & 0xff;
        chewing_handle_Default(c, scan_code);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) {
        chewing_handle_Backspace(c);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) {
        chewing_handle_Esc(c);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_DELETE)) {
        chewing_handle_Del(c);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) {
        chewing_handle_Space(c);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_UP)) {
        chewing_handle_Up(c);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_DOWN)) {
        chewing_handle_Down(c);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_PGUP)) {
        chewing_handle_PageDown(c);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_PGDN)) {
        chewing_handle_PageUp(c);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_RIGHT)) {
        chewing_handle_Right(c);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_LEFT)) {
        chewing_handle_Left(c);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)) {
        chewing_handle_Enter(c);
    } else if (state == FcitxKeyState_Ctrl && FcitxHotkeyIsHotKeyDigit(sym, FcitxKeyState_None)) {
        chewing_handle_CtrlNum(c, sym);
    } else {
        // to do: more chewing_handle
        return IRV_TO_PROCESS;
    }
    if (chewing_keystroke_CheckAbsorb(c)) {
        return IRV_DISPLAY_CANDWORDS;
    } else if (chewing_keystroke_CheckIgnore(c)) {
        return IRV_TO_PROCESS;
    } else if (chewing_commit_Check(c)) {
        char* str = chewing_commit_String(c);
        strcpy(FcitxInputStateGetOutputString(input), str);
        chewing_free(str);
        return IRV_COMMIT_STRING;
    } else
        return IRV_DISPLAY_CANDWORDS;
}
Exemple #18
0
/**
 * @brief Process Key Input and return the status
 *
 * @param keycode keycode from XKeyEvent
 * @param state state from XKeyEvent
 * @param count count from XKeyEvent
 * @return INPUT_RETURN_VALUE
 **/
__EXPORT_API
INPUT_RETURN_VALUE FcitxLibpinyinDoInput(void* arg, FcitxKeySym sym, unsigned int state)
{
    FcitxLibpinyin* libpinyin = (FcitxLibpinyin*) arg;
    FcitxLibpinyinConfig* config = &libpinyin->owner->config;
    FcitxInputState* input = FcitxInstanceGetInputState(libpinyin->owner->owner);

    if (FcitxHotkeyIsHotKeySimple(sym, state))
    {
        /* there is some special case that ';' is used */
        if (FcitxHotkeyIsHotKeyLAZ(sym, state)
            || sym == '\''
            || (FcitxHotkeyIsHotKey(sym, state, FCITX_SEMICOLON) && libpinyin->type == LPT_Shuangpin && (config->spScheme == FCITX_SHUANG_PIN_MS || config->spScheme == FCITX_SHUANG_PIN_ZIGUANG))
            || (libpinyin->type == LPT_Zhuyin && LibpinyinCheckZhuyinKey(sym, config->zhuyinLayout, config->useTone))
        )
        {
            if (strlen(libpinyin->buf) == 0 && (sym == '\'' || sym == ';'))
                return IRV_TO_PROCESS;

            if (strlen(libpinyin->buf) < MAX_PINYIN_INPUT)
            {
                size_t len = strlen(libpinyin->buf);
                if (libpinyin->buf[libpinyin->cursor_pos] != 0)
                {
                    memmove(libpinyin->buf + libpinyin->cursor_pos + 1, libpinyin->buf + libpinyin->cursor_pos, len - libpinyin->cursor_pos);
                }
                libpinyin->buf[len + 1] = 0;
                libpinyin->buf[libpinyin->cursor_pos] = (char) (sym & 0xff);
                libpinyin->cursor_pos ++;

                size_t parselen = FcitxLibpinyinParse(libpinyin, libpinyin->buf);

                if (parselen == 0 && strlen(libpinyin->buf) == 1 && libpinyin->type != LPT_Shuangpin
                    && !(libpinyin->type == LPT_Pinyin && !libpinyin->owner->config.incomplete)
                    && !(libpinyin->type == LPT_Zhuyin && !libpinyin->owner->config.chewingIncomplete))
                {
                    FcitxLibpinyinReset(libpinyin);
                    return IRV_TO_PROCESS;
                }
                return IRV_DISPLAY_CANDWORDS;
            }
            else
                return IRV_DO_NOTHING;
        }
    }

    if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)
        || (libpinyin->type == LPT_Zhuyin && FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)))
    {
        size_t len = strlen(libpinyin->buf);
        if (len == 0)
            return IRV_TO_PROCESS;

        return FcitxCandidateWordChooseByIndex(FcitxInputStateGetCandidateList(input), 0);
    }

    if (FcitxHotkeyIsHotKey(sym, state, FCITX_LIBPINYIN_SHIFT_ENTER)) {
        size_t len = strlen(libpinyin->buf);
        if (len == 0)
            return IRV_TO_PROCESS;

        strcpy(FcitxInputStateGetOutputString(input), libpinyin->buf);

        return IRV_COMMIT_STRING;
    }

    if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE) || FcitxHotkeyIsHotKey(sym, state, FCITX_DELETE))
    {
        if (strlen(libpinyin->buf) > 0)
        {
            int offset = LibpinyinGetOffset(libpinyin);
            if (offset != 0 && FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE))
            {
                g_array_remove_index_fast(libpinyin->fixed_string, libpinyin->fixed_string->len - 1);
                pinyin_clear_constraint(libpinyin->inst, LibpinyinGetOffset(libpinyin));
            }
            else
            {
                if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE))
                {
                    if (libpinyin->cursor_pos > 0)
                        libpinyin->cursor_pos -- ;
                    else
                        return IRV_DO_NOTHING;
                }
                size_t len = strlen(libpinyin->buf);
                if (libpinyin->cursor_pos == (int)len)
                    return IRV_DO_NOTHING;
                memmove(libpinyin->buf + libpinyin->cursor_pos, libpinyin->buf + libpinyin->cursor_pos + 1, len - libpinyin->cursor_pos - 1);
                libpinyin->buf[strlen(libpinyin->buf) - 1] = 0;
                if (libpinyin->buf[0] == '\0')
                    return IRV_CLEAN;
                else
                    FcitxLibpinyinParse(libpinyin, libpinyin->buf);
            }
            return IRV_DISPLAY_CANDWORDS;
        }
        else
            return IRV_TO_PROCESS;
    }
    else
    {
        if (strlen(libpinyin->buf) > 0)
        {
            if (FcitxHotkeyIsHotKey(sym, state, FCITX_LEFT))
            {
                if (libpinyin->cursor_pos > 0)
                {
                    if ( libpinyin->cursor_pos == LibpinyinGetPinyinOffset(libpinyin))
                    {
                        g_array_remove_index_fast(libpinyin->fixed_string, libpinyin->fixed_string->len - 1);
                        pinyin_clear_constraint(libpinyin->inst, LibpinyinGetOffset(libpinyin));
                        return IRV_DISPLAY_CANDWORDS;
                    }
                    else
                    {
                        libpinyin->cursor_pos--;
                        return IRV_DISPLAY_CANDWORDS;
                    }
                }

                return IRV_DO_NOTHING;
            }
            else if (FcitxHotkeyIsHotKey(sym, state, FCITX_RIGHT))
            {
                size_t len = strlen(libpinyin->buf);
                if (libpinyin->cursor_pos < (int) len)
                {
                    libpinyin->cursor_pos ++ ;
                    return IRV_DISPLAY_CANDWORDS;
                }
                return IRV_DO_NOTHING;
            }
            else if (FcitxHotkeyIsHotKey(sym, state, FCITX_HOME))
            {
                int offset = LibpinyinGetPinyinOffset(libpinyin);
                if ( libpinyin->cursor_pos != offset)
                {
                    libpinyin->cursor_pos = offset;
                    return IRV_DISPLAY_CANDWORDS;
                }
                return IRV_DO_NOTHING;
            }
            else if (FcitxHotkeyIsHotKey(sym, state, FCITX_END))
            {
                size_t len = strlen(libpinyin->buf);
                if (libpinyin->cursor_pos != (int) len)
                {
                    libpinyin->cursor_pos = len ;
                    return IRV_DISPLAY_CANDWORDS;
                }
                return IRV_DO_NOTHING;
            }
        }
        else {
            return IRV_TO_PROCESS;
        }
    }
    return IRV_TO_PROCESS;
}
Exemple #19
0
/**
 * @brief Process Key Input and return the status
 *
 * @param keycode keycode from XKeyEvent
 * @param state state from XKeyEvent
 * @param count count from XKeyEvent
 * @return INPUT_RETURN_VALUE
 **/
__EXPORT_API
INPUT_RETURN_VALUE FcitxChewingDoInput(void* arg, FcitxKeySym sym, unsigned int state)
{
    FcitxChewing* chewing = (FcitxChewing*) arg;
    FcitxInputState *input = FcitxInstanceGetInputState(chewing->owner);
    ChewingContext * ctx = chewing->context;
    int zuin_len;
    FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input);

    if (FcitxCandidateWordGetListSize(candList) > 0) {
        if (FcitxHotkeyIsHotKeyDigit(sym, state) || FcitxHotkeyIsHotKey(sym, state, FCITX_RIGHT) || FcitxHotkeyIsHotKey(sym, state, FCITX_LEFT))
            return IRV_TO_PROCESS;
        if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) {
            if (FcitxCandidateWordGoNextPage(candList))
                return IRV_DISPLAY_MESSAGE;
            else
                return IRV_DO_NOTHING;
        }
    }

    if (FcitxHotkeyIsHotKeySimple(sym, state)) {
        int scan_code = (int) sym & 0xff;
        chewing_handle_Default(ctx, scan_code);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) {
        char * zuin_str = chewing_zuin_String(ctx, &zuin_len);
        chewing_free(zuin_str);
        if (chewing_buffer_Len(ctx) + zuin_len == 0)
            return IRV_TO_PROCESS;
        chewing_handle_Backspace(ctx);
        if (chewing_buffer_Len(ctx) + zuin_len == 0)
            return IRV_CLEAN;
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) {
        chewing_handle_Esc(ctx);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_DELETE)) {
        char * zuin_str = chewing_zuin_String(ctx, &zuin_len);
        chewing_free(zuin_str);
        if (chewing_buffer_Len(ctx) + zuin_len == 0)
            return IRV_TO_PROCESS;
        chewing_handle_Del(ctx);
        if (chewing_buffer_Len(ctx) + zuin_len == 0)
            return IRV_CLEAN;
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) {
        chewing_handle_Space(ctx);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_UP)) {
        chewing_handle_Up(ctx);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_DOWN)) {
        chewing_handle_Down(ctx);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_PGUP)) {
        chewing_handle_PageDown(ctx);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_PGDN)) {
        chewing_handle_PageUp(ctx);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_RIGHT)) {
        chewing_handle_Right(ctx);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_LEFT)) {
        chewing_handle_Left(ctx);
    } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)) {
        chewing_handle_Enter(ctx);
    } else if (state == FcitxKeyState_Ctrl && FcitxHotkeyIsHotKeyDigit(sym, FcitxKeyState_None)) {
        chewing_handle_CtrlNum(ctx, sym);
    } else {
        // to do: more chewing_handle
        return IRV_TO_PROCESS;
    }
    if (chewing_keystroke_CheckAbsorb(ctx)) {
        return IRV_DISPLAY_CANDWORDS;
    } else if (chewing_keystroke_CheckIgnore(ctx)) {
        return IRV_TO_PROCESS;
    } else if (chewing_commit_Check(ctx)) {
        char* str = chewing_commit_String(ctx);
        FcitxInputContext* ic = FcitxInstanceGetCurrentIC(chewing->owner);
        FcitxInstanceCommitString(chewing->owner, ic, str);
        chewing_free(str);
        return IRV_DISPLAY_CANDWORDS;
    } else
        return IRV_DISPLAY_CANDWORDS;
}
Exemple #20
0
static boolean ProcessAutoEng(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->active) {
        FcitxKeySym keymain = FcitxHotkeyPadToMain(sym);
        if (FcitxHotkeyIsHotKeySimple(keymain, state)) {
            if (autoEngState->index < MAX_USER_INPUT) {
                autoEngState->buf[autoEngState->index] = keymain;
                autoEngState->index++;
                autoEngState->buf[autoEngState->index] = '\0';
                *retval = IRV_DISPLAY_MESSAGE;
            } else
                *retval = IRV_DO_NOTHING;
        } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) {
            autoEngState->index -- ;
            autoEngState->buf[autoEngState->index] = '\0';
            if (autoEngState->index == 0) {
                ResetAutoEng(autoEngState);
                *retval = IRV_CLEAN;
            } else
                *retval = IRV_DISPLAY_MESSAGE;
        } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)) {
            strcpy(FcitxInputStateGetOutputString(input), autoEngState->buf);
            ResetAutoEng(autoEngState);
            *retval = IRV_COMMIT_STRING;
        }
        ShowAutoEngMessage(autoEngState);
        return true;
    }
    if (FcitxHotkeyIsHotKeySimple(sym, state)) {
        if (FcitxInputStateGetRawInputBufferSize(input) == 0 && FcitxHotkeyIsHotKeyUAZ(sym, state)) {
            autoEngState->index = 1;
            autoEngState->buf[0] = sym;
            autoEngState->buf[1] = '\0';
            *retval = IRV_DISPLAY_MESSAGE;
            FcitxInputStateSetShowCursor(input, false);
            autoEngState->index = strlen(autoEngState->buf);
            autoEngState->active = true;
            ShowAutoEngMessage(autoEngState);
            return true;
        }

        strncpy(autoEngState->buf, FcitxInputStateGetRawInputBuffer(input), MAX_USER_INPUT);
        if (strlen(autoEngState->buf) >= MAX_USER_INPUT - 1)
            return false;

        autoEngState->index = strlen(autoEngState->buf);
        autoEngState->buf[autoEngState->index ++ ] = sym;
        autoEngState->buf[autoEngState->index] = '\0';

        if (SwitchToEng(autoEngState, autoEngState->buf)) {
            *retval = IRV_DISPLAY_MESSAGE;
            FcitxInputStateSetShowCursor(input, false);
            autoEngState->index = strlen(autoEngState->buf);
            autoEngState->active = true;
            ShowAutoEngMessage(autoEngState);
            return true;
        }
    }
    return false;
}
Exemple #21
0
FCITX_EXPORT_API
boolean FcitxHotkeyIsKey(FcitxKeySym sym, unsigned int state, FcitxKeySym symcmp, unsigned int statecmp)
{
    FcitxHotkey key[2] = { {0, symcmp, statecmp }, {0, 0, 0} };
    return FcitxHotkeyIsHotKey(sym ,state, key);
}
Exemple #22
0
boolean UnicodePreFilter(void* arg, FcitxKeySym sym, unsigned int state,
                         INPUT_RETURN_VALUE *r)
{
    INPUT_RETURN_VALUE retVal = IRV_TO_PROCESS;
    do {
        UnicodeModule *uni = arg;
        if (!uni->enable)
            break;
        FcitxInstance *instance = uni->owner;
        FcitxInputState *input = FcitxInstanceGetInputState(instance);
        FcitxGlobalConfig *fc = FcitxInstanceGetGlobalConfig(instance);
        FcitxCandidateWordList *candList;
        candList = FcitxInputStateGetCandidateList(input);

        FcitxCandidateWordSetPageSize(candList, 4);
        FcitxCandidateWordSetChooseAndModifier(candList, DIGIT_STR_CHOOSE,
                                               FcitxKeyState_Alt);
        if (FcitxHotkeyIsHotKey(sym, state,
                                FcitxConfigNextPageKey(instance, fc))) {
            if (FcitxCandidateWordGoPrevPage(candList))
                retVal = IRV_DISPLAY_MESSAGE;
            else
                retVal = IRV_DO_NOTHING;
        } else if (FcitxHotkeyIsHotKey(sym, state,
                                       FcitxConfigNextPageKey(instance, fc))) {
            if (FcitxCandidateWordGoNextPage(candList))
                retVal = IRV_DISPLAY_MESSAGE;
            else
                retVal = IRV_DO_NOTHING;
        } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) {
            size_t len = strlen(uni->buffer);
            if (len > 0)
                uni->buffer[--len] = '\0';
            if (len == 0) {
                retVal = IRV_CLEAN;
            } else {
                retVal = UnicodeGetCandWords(uni);
            }
        } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) {
            retVal = IRV_CLEAN;
        }

        if (retVal == IRV_TO_PROCESS) {
            int index = FcitxCandidateWordCheckChooseKey(candList, sym, state);
            if (index >= 0)
                retVal = FcitxCandidateWordChooseByIndex(candList, index);
        }

        FcitxKeySym keymain = FcitxHotkeyPadToMain(sym);
        if (retVal == IRV_TO_PROCESS && FcitxHotkeyIsHotKeySimple(keymain, state)) {
            char buf[2];
            buf[0] = keymain;
            buf[1] = '\0';
            if (strlen(uni->buffer) < MAX_USER_INPUT)
                strcat(uni->buffer, buf);
            retVal = UnicodeGetCandWords(uni);
        }
    } while(0);

    *r = retVal;
    if (retVal == IRV_TO_PROCESS)
        return false;
    return true;
}
Exemple #23
0
boolean QuickPhrasePreFilter(void* arg, FcitxKeySym sym,
                             unsigned int state,
                             INPUT_RETURN_VALUE *retval
                            )
{
    QuickPhraseState *qpstate = (QuickPhraseState*) arg;
    FcitxInputState *input = FcitxInstanceGetInputState(qpstate->owner);
    if (qpstate->enabled) {
        FcitxKeySym keymain = FcitxHotkeyPadToMain(sym);
        if (FcitxHotkeyIsHotKeySimple(keymain, state)) {
            *retval = QuickPhraseDoInput(qpstate, keymain, state);
            if (*retval == IRV_TO_PROCESS) {
                if (strlen(FcitxInputStateGetRawInputBuffer(input)) == 0
                    && (FcitxHotkeyIsHotKey(keymain, state, QuickPhraseTriggerKeys[qpstate->triggerKey]) || FcitxHotkeyIsHotKey(keymain, state, FCITX_SPACE))) {
                    char c[2] = { (char) (QuickPhraseTriggerKeys[qpstate->triggerKey][0].sym & 0xff), '\0'};
                    FcitxModuleFunctionArg farg;
                    FcitxKeySym s = QuickPhraseTriggerKeys[qpstate->triggerKey][0].sym;
                    farg.args[0] = &s;
                    char* strTemp = InvokeFunction(qpstate->owner, FCITX_PUNC, GETPUNC, farg);
                    strcpy(FcitxInputStateGetOutputString(input), strTemp ? strTemp : c);
                    *retval = IRV_COMMIT_STRING;
                } else {
                    char buf[2];
                    buf[0] = keymain;
                    buf[1] = '\0';
                    if (strlen(FcitxInputStateGetRawInputBuffer(input)) < MAX_USER_INPUT)
                        strcat(FcitxInputStateGetRawInputBuffer(input), buf);
                    ShowQuickPhraseMessage(qpstate);
                    *retval = QuickPhraseGetCandWords(qpstate);
                }
            } else
                return true;
        } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) {
            size_t len = strlen(FcitxInputStateGetRawInputBuffer(input));
            if (len > 0)
                FcitxInputStateGetRawInputBuffer(input)[--len] = '\0';
            if (len == 0) {
                *retval = IRV_CLEAN;
            } else {
                ShowQuickPhraseMessage(qpstate);
                *retval = QuickPhraseGetCandWords(qpstate);
            }
        } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)) {

            if (strlen(FcitxInputStateGetRawInputBuffer(input)) > 0) {
                strcpy(FcitxInputStateGetOutputString(input), FcitxInputStateGetRawInputBuffer(input));
                QuickPhraseReset(qpstate);
                *retval = IRV_COMMIT_STRING;
            } else {
                char c[2] = { (char) (QuickPhraseTriggerKeys[qpstate->triggerKey][0].sym & 0xff), '\0'};
                strcpy(FcitxInputStateGetOutputString(input), c);
                *retval = IRV_COMMIT_STRING;
            }
        } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) {
            *retval = IRV_CLEAN;
        } else
            *retval = IRV_DO_NOTHING;
        if (*retval == IRV_DISPLAY_MESSAGE) {
            FcitxMessagesSetMessageCount(FcitxInputStateGetAuxDown(input), 0);
            if (FcitxCandidateWordPageCount(FcitxInputStateGetCandidateList(input)) == 0)
                FcitxMessagesAddMessageAtLast(FcitxInputStateGetAuxDown(input), MSG_TIPS, "%s", _("Press Enter to input text"));
        }
        return true;
    }
    return false;
}