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; }
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; }