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; }
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; }
static INPUT_RETURN_VALUE AutoEngCheckSelect(FcitxAutoEngState *autoEngState, FcitxKeySym sym, unsigned int state) { FcitxCandidateWordList *candList = FcitxInputStateGetCandidateList( FcitxInstanceGetInputState(autoEngState->owner)); int iKey = FcitxCandidateWordCheckChooseKey(candList, sym, state); if (iKey >= 0) return FcitxCandidateWordChooseByIndex(candList, iKey); return 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; }
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; }
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; }
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; }
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; }
/** * @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; }
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; }