INPUT_RETURN_VALUE QWGetCandWords(void *arg) { FcitxQWState* qwstate = (FcitxQWState*) arg; FcitxInputState* input = FcitxInstanceGetInputState(qwstate->owner); int iQu, iWei; int i; FcitxCandidateWordSetPageSize(FcitxInputStateGetCandidateList(input), 10); FcitxCandidateWordSetChoose(FcitxInputStateGetCandidateList(input), DIGIT_STR_CHOOSE); if (FcitxInputStateGetRawInputBufferSize(input) == 3) { iQu = (FcitxInputStateGetRawInputBuffer(input)[0] - '0') * 10 + FcitxInputStateGetRawInputBuffer(input)[1] - '0'; iWei = (FcitxInputStateGetRawInputBuffer(input)[2] - '0') * 10; for (i = 0; i < 10; i++) { FcitxCandidateWord candWord; candWord.callback = QWGetCandWord; candWord.owner = qwstate; candWord.priv = NULL; candWord.strExtra = NULL; candWord.strWord = strdup(GetQuWei(qwstate, iQu, iWei + i + 1)); candWord.wordType = MSG_OTHER; FcitxCandidateWordAppend(FcitxInputStateGetCandidateList(input), &candWord); } } FcitxInputStateSetCursorPos(input, FcitxInputStateGetRawInputBufferSize(input)); FcitxMessagesSetMessageCount(FcitxInputStateGetPreedit(input), 0); FcitxMessagesAddMessageAtLast(FcitxInputStateGetPreedit(input), MSG_INPUT, "%s", FcitxInputStateGetRawInputBuffer(input)); return IRV_DISPLAY_CANDWORDS; }
void CloudPinyinAddCandidateWord(void* arg) { FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg; FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner); FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner); if (cloudpinyin->initialized == false) return; /* check whether the current im is pinyin */ if (CHECK_VALID_IM) { /* there is something pending input */ if (FcitxInputStateGetRawInputBufferSize(input) >= cloudpinyin->config.iMinimumPinyinLength) { char* strToFree = NULL, *inputString; strToFree = GetCurrentString(cloudpinyin); inputString = SplitHZAndPY(strToFree); if (inputString) { CloudPinyinCache* cacheEntry = CloudPinyinCacheLookup(cloudpinyin, inputString); FcitxLog(LOGLEVEL, "%s", inputString); if (cacheEntry == NULL) CloudPinyinAddInputRequest(cloudpinyin, inputString); _CloudPinyinAddCandidateWord(cloudpinyin, inputString); } if (strToFree) free(strToFree); } } return; }
boolean PostInputProcessAutoEng(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; if (FcitxHotkeyIsHotKeyUAZ(sym, state) && (FcitxInputStateGetRawInputBufferSize(input) != 0 || (FcitxInputStateGetKeyState(input) & FcitxKeyState_CapsLock) == 0) && AutoEngCheckPreedit(autoEngState)) { AutoEngSetBuff(autoEngState, FcitxInputStateGetRawInputBuffer(input), FcitxHotkeyPadToMain(sym)); AutoEngActivate(autoEngState, input, retval); return true; } return false; }
void ShowAutoEngMessage(FcitxAutoEngState* autoEngState) { FcitxInputState* input = FcitxInstanceGetInputState(autoEngState->owner); FcitxInstanceCleanInputWindow(autoEngState->owner); if (autoEngState->buf[0] == '\0') return; FcitxMessagesAddMessageAtLast(FcitxInputStateGetPreedit(input), MSG_INPUT, "%s", autoEngState->buf); strcpy(FcitxInputStateGetRawInputBuffer(input), autoEngState->buf); FcitxInputStateSetRawInputBufferSize(input, strlen(autoEngState->buf)); FcitxInputStateSetCursorPos(input, FcitxInputStateGetRawInputBufferSize(input)); FcitxInputStateSetShowCursor(input, true); FcitxMessagesAddMessageAtLast(FcitxInputStateGetAuxDown(input), MSG_TIPS, _("Press Enter to input text")); }
boolean PostInputProcessAutoEng(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 (FcitxHotkeyIsHotKeyUAZ(sym, state) && (FcitxInputStateGetRawInputBufferSize(input) != 0 || (FcitxInputStateGetKeyState(input) & FcitxKeyState_CapsLock) == 0) && AutoEngCheckPreedit(autoEngState)) { *retval = IRV_DISPLAY_MESSAGE; FcitxInputStateSetShowCursor(input, false); AutoEngSetBuff(autoEngState, FcitxInputStateGetRawInputBuffer(input), FcitxHotkeyPadToMain(sym)); autoEngState->active = true; ShowAutoEngMessage(autoEngState, retval); return true; } return false; }
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; }
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; }
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; }
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; }