INPUT_RETURN_VALUE UnicodeGetCandWords(UnicodeModule* uni) { FcitxInputState *input = FcitxInstanceGetInputState(uni->owner); FcitxInstanceCleanInputWindow(uni->owner); FcitxMessagesAddMessageStringsAtLast(FcitxInputStateGetPreedit(input), MSG_INPUT, uni->buffer); FcitxInputStateSetShowCursor(input, true); FcitxInputStateSetCursorPos(input, strlen(uni->buffer)); FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input); FcitxCandidateWordSetLayoutHint(candList, CLH_Vertical); UT_array* result = CharSelectDataFind(uni->charselectdata, uni->buffer); utarray_foreach(c, result, uint32_t) { char* s = fcitx_utils_malloc0(sizeof(char) * (UTF8_MAX_LENGTH + 1)); fcitx_ucs4_to_utf8(*c, s); FcitxCandidateWord candWord; candWord.callback = UnicodeGetCandWord; candWord.owner = uni; candWord.priv = NULL; candWord.extraType = MSG_OTHER; candWord.wordType = MSG_CODE; candWord.strWord = s; char* name = CharSelectDataName(uni->charselectdata, *c); fcitx_utils_alloc_cat_str(candWord.strExtra, " ", name); free(name); FcitxCandidateWordAppend(candList, &candWord); }
void IMSelectorGetCands(IMSelector* imselector) { FcitxInstance* instance = imselector->owner; FcitxInputState *input = FcitxInstanceGetInputState(instance); UT_array* imes = FcitxInstanceGetIMEs(instance); FcitxInstanceCleanInputWindow(instance); FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input); FcitxCandidateWordSetPageSize(candList, 10); FcitxCandidateWordSetChoose(candList, DIGIT_STR_CHOOSE); FcitxInputStateSetShowCursor(input, false); FcitxCandidateWordSetOverrideDefaultHighlight(candList, false); FcitxCandidateWordSetLayoutHint(candList, CLH_Vertical); FcitxIM* im = FcitxInstanceGetCurrentIM(instance); FcitxInputContext* ic = FcitxInstanceGetCurrentIC(instance); FcitxInputContext2* ic2 = (FcitxInputContext2*) ic; if (!ic) return; FcitxMessages *aux_up = FcitxInputStateGetAuxUp(input); FcitxMessagesAddMessageStringsAtLast(aux_up, MSG_TIPS, imselector->global ? _("Select global input method: ") : _("Select local input method: ")); if (ic2->imname) { int idx = FcitxInstanceGetIMIndexByName(instance, ic2->imname); FcitxIM *im = fcitx_array_eltptr(imes, idx); if (im) { FcitxMessagesAddMessageStringsAtLast(aux_up, MSG_TIPS, _("Current local input method is "), im->strName); } } else { FcitxMessagesAddMessageStringsAtLast(aux_up, MSG_TIPS, _("No local input method")); } utarray_foreach(pim, imes, FcitxIM) { FcitxCandidateWord candWord; candWord.callback = IMSelectorGetCand; candWord.owner = imselector; candWord.strExtra = NULL; if (ic2->imname && strcmp(ic2->imname, pim->uniqueName) == 0) { candWord.priv = NULL; candWord.strWord = strdup(_("Clear local input method")); } else { candWord.priv = strdup(pim->uniqueName); candWord.strWord = strdup(pim->strName); } if (im && strcmp(im->uniqueName, pim->uniqueName) == 0) { candWord.wordType = MSG_CANDIATE_CURSOR; } else { candWord.wordType = MSG_OTHER; } FcitxCandidateWordAppend(candList, &candWord); }
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; }
INPUT_RETURN_VALUE FcitxKkcGetCandWords(void* arg) { FcitxKkc *kkc = (FcitxKkc*)arg; FcitxInputState* input = FcitxInstanceGetInputState(kkc->owner); FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input); FcitxMessages* clientPreedit = FcitxInputStateGetClientPreedit(input); FcitxMessages* preedit = FcitxInputStateGetPreedit(input); FcitxInstanceCleanInputWindow(kkc->owner); FcitxMessages* message = FcitxInstanceICSupportPreedit(kkc->owner, FcitxInstanceGetCurrentIC(kkc->owner)) ? clientPreedit : preedit; FcitxCandidateWordSetChoose(candList, DIGIT_STR_CHOOSE); FcitxCandidateWordSetPageSize(candList, kkc->config.pageSize); FcitxCandidateWordSetLayoutHint(candList, kkc->config.candidateLayout); FcitxInputStateSetShowCursor(input, true); KkcSegmentList* segments = kkc_context_get_segments(kkc->context); if (kkc_segment_list_get_cursor_pos(segments) >= 0) { int i = 0; int offset = 0; for (i = 0; i < kkc_segment_list_get_size(segments); i ++) { KkcSegment* segment = kkc_segment_list_get(segments, i); const gchar* str = kkc_segment_get_output(segment); FcitxMessageType messageType = MSG_INPUT; if (i < kkc_segment_list_get_cursor_pos(segments)) { offset += strlen(str); } if (i == kkc_segment_list_get_cursor_pos(segments)) { messageType = (FcitxMessageType) (MSG_HIGHLIGHT | MSG_OTHER); } FcitxMessagesAddMessageAtLast(message, messageType, "%s", str); } if (message == clientPreedit) { FcitxInputStateSetClientCursorPos(input, offset); } else { FcitxInputStateSetCursorPos(input, offset); } } else { gchar* str = kkc_context_get_input(kkc->context); if (str && str[0]) { FcitxMessagesAddMessageAtLast(message, MSG_INPUT, "%s", str); if (message == clientPreedit) { FcitxInputStateSetClientCursorPos(input, strlen(str)); } else { FcitxInputStateSetCursorPos(input, strlen(str)); } } g_free(str); } KkcCandidateList* kkcCandidates = kkc_context_get_candidates(kkc->context); if (kkc_candidate_list_get_page_visible(kkcCandidates)) { int i, j; guint size = kkc_candidate_list_get_size(kkcCandidates); gint cursor_pos = kkc_candidate_list_get_cursor_pos(kkcCandidates); guint page_start = kkc_candidate_list_get_page_start(kkcCandidates); guint page_size = kkc_candidate_list_get_page_size(kkcCandidates); for (i = kkc_candidate_list_get_page_start(kkcCandidates), j = 0; i < size; i ++, j++) { FcitxCandidateWord word; word.callback = FcitxKkcGetCandWord; word.extraType = MSG_OTHER; word.owner = kkc; int* id = fcitx_utils_new(int); *id = j; word.priv = id; word.strExtra = NULL; word.strExtra = MSG_TIPS; KkcCandidate* kkcCandidate = kkc_candidate_list_get(kkcCandidates, i); if (kkc->config.showAnnotation && kkc_candidate_get_annotation(kkcCandidate)) { fcitx_utils_alloc_cat_str(word.strExtra, " [", kkc_candidate_get_annotation(kkcCandidate), "]"); } word.strWord = strdup(kkc_candidate_get_text(kkcCandidate)); if (i == cursor_pos) { word.wordType = MSG_CANDIATE_CURSOR; } else { word.wordType = MSG_OTHER; } FcitxCandidateWordAppend(candList, &word); } FcitxCandidateWordSetFocus(candList, cursor_pos - page_start); FcitxCandidateWordSetOverridePaging(candList, (cursor_pos - page_start) >= page_size, (size - page_start) / page_size != (cursor_pos - page_start) / page_size, FcitxKkcPaging, kkc, NULL); } if (kkc_context_has_output(kkc->context)) { gchar* str = kkc_context_poll_output(kkc->context); FcitxInstanceCommitString(kkc->owner, FcitxInstanceGetCurrentIC(kkc->owner), str); g_free(str); } return IRV_DISPLAY_CANDWORDS; }