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