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 {
INPUT_RETURN_VALUE UnicodeGetCandWord(void* arg, FcitxCandidateWord* candWord) { UnicodeModule* uni = arg; FcitxInputState *input = FcitxInstanceGetInputState(uni->owner); strcpy(FcitxInputStateGetOutputString(input), candWord->strWord); return IRV_COMMIT_STRING; }
INPUT_RETURN_VALUE QuickPhraseGetCandWord(void* arg, FcitxCandidateWord* candWord) { QuickPhraseState *qpstate = (QuickPhraseState*) arg; QuickPhraseCand* qpcand = candWord->priv; FcitxInputState *input = FcitxInstanceGetInputState(qpstate->owner); strcpy(FcitxInputStateGetOutputString(input), qpcand->cand->strPhrase); return IRV_COMMIT_STRING; }
/** * @brief get the candidate word by index * * @param iIndex index of candidate word * @return the string of canidate word **/ __EXPORT_API INPUT_RETURN_VALUE FcitxLibpinyinGetCandWord (void* arg, FcitxCandidateWord* candWord) { FcitxLibpinyin* libpinyin = (FcitxLibpinyin* )arg; FcitxLibpinyinCandWord* pyCand = (FcitxLibpinyinCandWord*) candWord->priv; FcitxInstance* instance = libpinyin->owner->owner; FcitxInputState* input = FcitxInstanceGetInputState(instance); if (pyCand->ispunc) { strcpy(FcitxInputStateGetOutputString(input), candWord->strWord); return IRV_COMMIT_STRING; } else { if (!libpinyin->candidate || libpinyin->candidate->len <= pyCand->idx) return IRV_TO_PROCESS; lookup_candidate_t* cand = &g_array_index(libpinyin->candidate, lookup_candidate_t, pyCand->idx); pinyin_choose_candidate(libpinyin->inst, LibpinyinGetOffset(libpinyin), cand); FcitxLibpinyinFixed f; f.len = fcitx_utf8_strlen(cand->m_phrase_string); g_array_append_val(libpinyin->fixed_string, f); int offset = LibpinyinGetOffset(libpinyin); if (offset >= libpinyin->inst->m_pinyin_keys->len) { char* sentence = NULL; pinyin_guess_sentence(libpinyin->inst); sentence = LibpinyinGetSentence(libpinyin); if (sentence) { strcpy(FcitxInputStateGetOutputString(input), sentence); g_free(sentence); pinyin_train(libpinyin->inst); } else strcpy(FcitxInputStateGetOutputString(input), ""); return IRV_COMMIT_STRING; } int pyoffset = LibpinyinGetPinyinOffset(libpinyin); if (pyoffset > libpinyin->cursor_pos) libpinyin->cursor_pos = pyoffset; return IRV_DISPLAY_CANDWORDS; } return IRV_TO_PROCESS; }
INPUT_RETURN_VALUE QWGetCandWord(void *arg, FcitxCandidateWord* candWord) { FcitxQWState* qwstate = (FcitxQWState*) arg; FcitxInputState* input = FcitxInstanceGetInputState(qwstate->owner); strcpy(FcitxInputStateGetOutputString(input), candWord->strWord); return IRV_COMMIT_STRING; }
static INPUT_RETURN_VALUE LuaGetCandWord(void *arg, FcitxCandidateWord *candWord) { FCITX_UNUSED(arg); LuaModule *luamodule = (LuaModule*)candWord->owner; FcitxInputState *input = FcitxInstanceGetInputState(GetFcitx(luamodule)); strncpy(FcitxInputStateGetOutputString(input), candWord->strWord, MAX_USER_INPUT); return IRV_COMMIT_STRING; }
/** * @brief sunpinyin called this function while commit the string * * @param str committed string * @return void **/ void FcitxWindowHandler::commit(const TWCHAR* str) { FcitxInstance* instance = owner->owner; FcitxInputState* input = FcitxInstanceGetInputState(instance); char *buf_ = FcitxInputStateGetOutputString(input); memset(buf_, 0, MAX_USER_INPUT); WCSTOMBS(buf_, str, MAX_USER_INPUT); commit_flag = true; FcitxInputStateSetCursorPos(input, false); }
/** * @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; }
INPUT_RETURN_VALUE CloudPinyinGetCandWord(void* arg, FcitxCandidateWord* candWord) { FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg; CloudCandWord* cloudCand = candWord->priv; FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); if (cloudCand->filled) { char *py; char *string = GetCurrentString(cloudpinyin, &py); if (py) { *py = 0; snprintf(FcitxInputStateGetOutputString(input), MAX_USER_INPUT, "%s%s", string, candWord->strWord); FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); if (im) { char *output_string = FcitxInputStateGetOutputString(input); FCITX_DEF_MODULE_ARGS(args, output_string); if (strcmp(im->uniqueName, "sunpinyin") == 0) { FcitxSunPinyinInvokeAddWord(cloudpinyin->owner, args); } else if (strcmp(im->uniqueName, "shuangpin") == 0 || strcmp(im->uniqueName, "pinyin") == 0) { FcitxPinyinInvokeAddUserPhrase(cloudpinyin->owner, args); } else if (strcmp(im->uniqueName, "pinyin-libpinyin") == 0 || strcmp(im->uniqueName, "shuangpin-libpinyin") == 0) { FcitxLibPinyinInvokeAddWord(cloudpinyin->owner, args); } else if (strcmp(im->uniqueName, "sogou-pinyin") == 0) { FcitxSogouPinyinInvokeAddWord(cloudpinyin->owner, args); } } } if (string) free(string); return IRV_COMMIT_STRING; } else { return IRV_DO_NOTHING; } }
INPUT_RETURN_VALUE QuickPhraseGetLuaCandWord(void* arg, FcitxCandidateWord* candWord) { QuickPhraseState *qpstate = (QuickPhraseState*) arg; FcitxInputState *input = FcitxInstanceGetInputState(qpstate->owner); if (candWord->strExtra) { strcat(FcitxInputStateGetRawInputBuffer(input), candWord->strExtra); ShowQuickPhraseMessage(qpstate); return QuickPhraseGetCandWords(qpstate); } else { strcpy(FcitxInputStateGetOutputString(input), candWord->strWord); return IRV_COMMIT_STRING; } }
INPUT_RETURN_VALUE DoVKInput(FcitxVKState* vkstate, KeySym sym, int state) { char *pstr = NULL; FcitxInputState *input = FcitxInstanceGetInputState(vkstate->owner); if (FcitxHotkeyIsHotKeySimple(sym, state)) pstr = VKGetSymbol(vkstate, sym); if (!pstr) return IRV_TO_PROCESS; else { strcpy(FcitxInputStateGetOutputString(input), pstr); return IRV_COMMIT_STRING; } }
INPUT_RETURN_VALUE CloudPinyinGetCandWord(void* arg, FcitxCandidateWord* candWord) { FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg; CloudCandWord* cloudCand = candWord->priv; FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); if (cloudCand->filled) { char* string = GetCurrentString(cloudpinyin); char* py = SplitHZAndPY(string); if (py) { *py = 0; snprintf(FcitxInputStateGetOutputString(input), MAX_USER_INPUT, "%s%s", string, candWord->strWord); FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); FcitxModuleFunctionArg args; args.args[0] = FcitxInputStateGetOutputString(input); if (im) { if (strcmp(im->uniqueName, "sunpinyin") == 0) { //InvokeModuleFunctionWithName(cloudpinyin->owner, "fcitx-sunpinyin", 1, args); } else if (strcmp(im->uniqueName, "shuangpin") == 0 || strcmp(im->uniqueName, "pinyin") == 0) { FcitxModuleInvokeFunctionByName(cloudpinyin->owner, "fcitx-pinyin", 7, args); } } } if (string) free(string); return IRV_COMMIT_STRING; } else return IRV_DO_NOTHING; }
boolean FullWidthPostFilter(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE *retval ) { FcitxFullWidthChar* fwchar = (FcitxFullWidthChar*)arg; FcitxProfile* profile = FcitxInstanceGetProfile(fwchar->owner); if (*retval != IRV_TO_PROCESS) return false; if (profile->bUseFullWidthChar && FcitxHotkeyIsHotKeySimple(sym, state)) { sprintf(FcitxInputStateGetOutputString(FcitxInstanceGetInputState(fwchar->owner)), "%s", sCornerTrans[sym - 32]); *retval = IRV_COMMIT_STRING; return true; } return false; }
INPUT_RETURN_VALUE FcitxChewingGetCandWord(void* arg, FcitxCandidateWord* candWord) { FcitxChewing* chewing = (FcitxChewing*) candWord->owner; ChewingCandWord* w = (ChewingCandWord*) candWord->priv; FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(chewing->owner); FcitxInputState *input = FcitxInstanceGetInputState(chewing->owner); int page = w->index / config->iMaxCandWord; int off = w->index % config->iMaxCandWord; if (page < 0 || page >= chewing_cand_TotalPage(chewing->context)) return IRV_TO_PROCESS; int lastPage = chewing_cand_CurrentPage(chewing->context); while (page != chewing_cand_CurrentPage(chewing->context)) { if (page < chewing_cand_CurrentPage(chewing->context)) { chewing_handle_Left(chewing->context); } if (page > chewing_cand_CurrentPage(chewing->context)) { chewing_handle_Right(chewing->context); } /* though useless, but take care if there is a bug cause freeze */ if (lastPage == chewing_cand_CurrentPage(chewing->context)) { break; } lastPage = chewing_cand_CurrentPage(chewing->context); } chewing_handle_Default( chewing->context, selKey[off] ); if (chewing_keystroke_CheckAbsorb(chewing->context)) { return IRV_DISPLAY_CANDWORDS; } else if (chewing_keystroke_CheckIgnore(chewing->context)) { return IRV_TO_PROCESS; } else if (chewing_commit_Check(chewing->context)) { char* str = chewing_commit_String(chewing->context); strcpy(FcitxInputStateGetOutputString(input), str); chewing_free(str); return IRV_COMMIT_STRING; } else return IRV_DISPLAY_CANDWORDS; }
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; }
// This function is called from within fcitx. When the user selects a // candidate, this function copies the actual utf-8 string into the // output buffer fcitx uses to send to the client INPUT_RETURN_VALUE FcitxTabletGetCandWord(void* arg, FcitxCandidateWord* candWord) { FcitxTablet* tablet = (FcitxTablet*) candWord->owner; FcitxInputState *input = FcitxInstanceGetInputState(tablet->fcitx); strcpy(FcitxInputStateGetOutputString(input), candWord->strWord); return IRV_COMMIT_STRING; }
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 { strcpy(FcitxInputStateGetOutputString(input), qpstate->buffer); } QuickPhraseReset(qpstate); *retval = IRV_COMMIT_STRING; } else { 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);
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; }
/** * @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; }
static INPUT_RETURN_VALUE LuaGetCandWord(void* arg, FcitxCandidateWord* candWord) { LuaModule *luamodule = (LuaModule *)candWord->owner; FcitxInputState* input = FcitxInstanceGetInputState(GetFcitx(luamodule)); snprintf(FcitxInputStateGetOutputString(input), MAX_USER_INPUT, "%s", candWord->strWord); return IRV_COMMIT_STRING; }
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; }