FCITX_EXPORT_API FcitxConfiguration* fcitx_configuration_new(const char* name) { FcitxConfiguration* config = fcitx_utils_new(FcitxConfiguration); fcitx_utils_string_swap(&config->name, name); return fcitx_configuration_ref(config); }
void* FcitxXkbDBusCreate(FcitxInstance* instance) { FcitxXkbDBus* xkbdbus = fcitx_utils_new(FcitxXkbDBus); xkbdbus->owner = instance; do { FcitxModuleFunctionArg arg; DBusConnection* conn = InvokeFunction(instance, FCITX_DBUS, GETCONNECTION, arg); if (conn == NULL) { FcitxLog(ERROR, "DBus Not initialized"); break; } DBusObjectPathVTable fcitxIPCVTable = {NULL, &FcitxXkbDBusEventHandler, NULL, NULL, NULL, NULL }; if (!dbus_connection_register_object_path(conn, FCITX_XKB_PATH, &fcitxIPCVTable, xkbdbus)) { FcitxLog(ERROR, "No memory"); break; } FcitxModuleFunctionArg args; FcitxXkbRules* rules = InvokeFunction(instance, FCITX_XKB, GETRULES, args); if (!rules) break; xkbdbus->rules = rules; xkbdbus->isocodes = FcitxXkbReadIsoCodes(ISOCODES_ISO639_XML, ISOCODES_ISO3166_XML); return xkbdbus; } while(0); free(xkbdbus); return NULL; }
CharSelectData* CharSelectDataCreate() { CharSelectData* charselect = fcitx_utils_new(CharSelectData); do { FILE* fp = FcitxXDGGetFileWithPrefix("data", "charselectdata", "r", NULL); if (!fp) break; fseek(fp, 0, SEEK_END); long int size = ftell(fp); fseek(fp, 0, SEEK_SET); charselect->size = size; charselect->dataFile = fcitx_utils_malloc0(size); fread(charselect->dataFile, 1, size, fp); fclose(fp); CharSelectDataCreateIndex(charselect); return charselect; } while(0); free(charselect); return NULL; }
static void* PinyinEnhanceCreate(FcitxInstance *instance) { PinyinEnhance *pyenhance = fcitx_utils_new(PinyinEnhance); pyenhance->owner = instance; if (!PinyinEnhanceLoadConfig(&pyenhance->config)) { free(pyenhance); return NULL; } PinyinEnhanceSymInit(pyenhance); FcitxIMEventHook event_hook = { .arg = pyenhance, .func = PinyinEnhanceAddCandidateWord, }; FcitxInstanceRegisterUpdateCandidateWordHook(instance, event_hook); event_hook.func = PinyinEnhanceResetHook; FcitxInstanceRegisterResetInputHook(instance, event_hook); FcitxKeyFilterHook key_hook = { .arg = pyenhance, .func = PinyinEnhancePostInput }; FcitxInstanceRegisterPostInputFilter(pyenhance->owner, key_hook); key_hook.func = PinyinEnhancePreInput; FcitxInstanceRegisterPreInputFilter(pyenhance->owner, key_hook); FcitxPinyinEnhanceAddFunctions(instance); return pyenhance; }
void* SimpleUICreate(FcitxInstance* instance) { FcitxSimpleUI* ui = fcitx_utils_new(FcitxSimpleUI); ui->owner = instance; FcitxSimpleUIAddFunctions(instance); return ui; }
static void* FcitxThaiCreate(FcitxInstance* instance) { FcitxThai* thai = fcitx_utils_new(FcitxThai); bindtextdomain("fcitx-thai", LOCALEDIR); thai->owner = instance; if (!ThaiLoadConfig(&thai->config)) { free(thai); return NULL; } FcitxIMIFace iface; memset(&iface, 0, sizeof(FcitxIMIFace)); iface.DoInput = FcitxThaiDoInput; iface.GetCandWords = FcitxThaiGetCandWords; iface.Init = FcitxThaiInit; iface.Save = FcitxThaiSave; iface.ResetIM = FcitxThaiResetIM; FcitxInstanceRegisterIMv2( instance, thai, "thai", _("Thai"), "thai", iface, 10, "th" ); FcitxThaiAddFunctions(instance); return thai; }
FcitxInputContext* fcitx_input_context_manager_create_ic(FcitxInputContextManager* manager, FcitxInputContextFillDataCallback callback, void* userData) { FcitxInputContext* ic = NULL; if (manager->freeList) { ic = manager->freeList; manager->freeList = ic->hh.next; } else { uint32_t newid; while ((newid = ++manager->icid) != 0); HASH_FIND(hh, manager->ics, &newid, sizeof(uint32_t), ic); if (ic) { return NULL; } ic = fcitx_utils_new(FcitxInputContext); ic->id = newid; ic->manager = manager; } if (callback) { callback(ic, userData); } return ic; }
void *AutoEngCreate(FcitxInstance *instance) { FcitxAutoEngState* autoEngState = fcitx_utils_new(FcitxAutoEngState); autoEngState->owner = instance; LoadAutoEng(autoEngState); FcitxKeyFilterHook khk; khk.arg = autoEngState; khk.func = PreInputProcessAutoEng; FcitxInstanceRegisterPreInputFilter(instance, khk); khk.func = PostInputProcessAutoEng; FcitxInstanceRegisterPostInputFilter(instance, khk); FcitxIMEventHook rhk; rhk.arg = autoEngState; rhk.func = ResetAutoEng; FcitxInstanceRegisterResetInputHook(instance, rhk); FcitxInstanceRegisterWatchableContext(instance, CONTEXT_DISABLE_AUTOENG, FCT_Boolean, FCF_ResetOnInputMethodChange); ResetAutoEng(autoEngState); return autoEngState; }
static void* ClipboardCreate(FcitxInstance *instance) { FcitxClipboard *clipboard = fcitx_utils_new(FcitxClipboard); clipboard->owner = instance; if (!FcitxClipboardLoadConfig(&clipboard->config)) { ClipboardDestroy(clipboard); return NULL; } ClipboardInitReadHistory(clipboard); /* #ifdef ENABLE_X11 */ ClipboardInitX11(clipboard); /* #endif */ ApplyClipboardConfig(clipboard); FcitxKeyFilterHook key_hook = { .arg = clipboard, .func = ClipboardPreHook }; FcitxInstanceRegisterPreInputFilter(instance, key_hook); key_hook.func = ClipboardPostHook; FcitxInstanceRegisterPostInputFilter(instance, key_hook); FcitxIMEventHook reset_hook = { .arg = clipboard, .func = ClipboardReset }; FcitxInstanceRegisterResetInputHook(instance, reset_hook); FcitxAddon *self = FcitxClipboardGetAddon(instance); FcitxModuleAddFunction(self, ClipboardGetPrimary); FcitxModuleAddFunction(self, ClipboardGetClipboard); return clipboard; }
void* UnicodeCreate(FcitxInstance* instance) { UnicodeModule* uni = fcitx_utils_new(UnicodeModule); uni->owner = instance; if (!UnicodeLoadConfig(uni)) { free(uni); return NULL; } FcitxIMEventHook imhk; imhk.arg = uni; imhk.func = UnicodeReset; FcitxInstanceRegisterResetInputHook(instance, imhk); FcitxKeyFilterHook kfhk; kfhk.arg = uni; kfhk.func = UnicodePreFilter; FcitxInstanceRegisterPreInputFilter(instance, kfhk); kfhk.arg = &uni->enable; kfhk.func = FcitxDummyReleaseInputHook; FcitxInstanceRegisterPreReleaseInputFilter(instance, kfhk); FcitxHotkeyHook hkhk; hkhk.arg = uni; hkhk.hotkey = uni->key; hkhk.hotkeyhandle = UnicodeHotkey; FcitxInstanceRegisterHotkeyFilter(instance, hkhk); return uni; }
FCITX_EXPORT_API void fcitx_addon_manager_register_resolver(FcitxAddonManager* manager, const char* name, FcitxAddonResolver* resolver) { FcitxAddonResolver* copiedResolver = fcitx_utils_new(FcitxAddonResolver); memcpy(copiedResolver, resolver, sizeof(FcitxAddonResolver)); fcitx_dict_insert_by_str(manager->resolvers, name, copiedResolver, false); }
void *QuickPhraseCreate(FcitxInstance *instance) { QuickPhraseState *qpstate = fcitx_utils_new(QuickPhraseState); qpstate->owner = instance; qpstate->enabled = false; if (!LoadQuickPhraseConfig(&qpstate->config)) { free(qpstate); return NULL; } LoadQuickPhrase(qpstate); FcitxKeyFilterHook hk; hk.arg = qpstate; hk.func = QuickPhrasePostFilter; FcitxInstanceRegisterPostInputFilter(instance, hk); hk.func = QuickPhrasePreFilter; FcitxInstanceRegisterPreInputFilter(instance, hk); FcitxIMEventHook resethk; resethk.arg = qpstate; resethk.func = QuickPhraseReset; FcitxInstanceRegisterResetInputHook(instance, resethk); FcitxInstanceRegisterWatchableContext(instance, CONTEXT_DISABLE_QUICKPHRASE, FCT_Boolean, FCF_ResetOnInputMethodChange); FcitxQuickPhraseAddFunctions(instance); return qpstate; }
FCITX_EXPORT_API FcitxObjPool* fcitx_obj_pool_new_with_prealloc(size_t size, size_t prealloc) { FcitxObjPool *pool = fcitx_utils_new(FcitxObjPool); fcitx_obj_pool_init_with_prealloc(pool, size, prealloc); return pool; }
FCITX_EXPORT_API FcitxObjPool* fcitx_obj_pool_new(size_t size) { FcitxObjPool *pool = fcitx_utils_new(FcitxObjPool); fcitx_obj_pool_init(pool, size); return pool; }
void* PuncWhichAlloc(void* arg) { FcitxPunc* puncState = arg; PuncWhich* which = fcitx_utils_new(PuncWhich); which->lastPunc = puncState->curPunc; which->bitset = fcitx_bitset_new(256); return which; }
FCITX_EXPORT_API FcitxInputMethodManager* fcitx_input_method_manager_new(FcitxAddonManager* addonManager) { FcitxInputMethodManager* self = fcitx_utils_new(FcitxInputMethodManager); self->addonManager = addonManager; self->groups = fcitx_ptr_array_new((FcitxDestroyNotify) fcitx_input_method_group_free); self->ims = fcitx_dict_new(NULL); return fcitx_input_method_manager_ref(self); }
FCITX_EXPORT_API FcitxStringMap* fcitx_string_map_new(const char* str, char delim) { FcitxStringMap* map = fcitx_utils_new(FcitxStringMap); if (str) { fcitx_string_map_from_string(map, str, delim); } return map; }
FCITX_EXPORT_API FcitxHandlerTable* fcitx_handler_table_new(size_t obj_size, FcitxFreeContentFunc free_func) { FcitxHandlerTable *table = fcitx_utils_new(FcitxHandlerTable); table->obj_size = obj_size; table->free_func = free_func; table->objs = fcitx_obj_pool_new(obj_size + sizeof(FcitxHandlerObj)); return table; }
void XimCloseIM(void* arg, FcitxInputContext* ic) { FcitxXimFrontend* xim = (FcitxXimFrontend*) arg; IMChangeFocusStruct* call_data = fcitx_utils_new(IMChangeFocusStruct); FcitxXimIC* ximic = (FcitxXimIC*) ic->privateic; call_data->connect_id = ximic->connect_id; call_data->icid = ximic->id; XimPendingCall(xim, XCT_PREEDIT_END, (XPointer) call_data); }
void* SimpleFrontendCreate(FcitxInstance* instance, int frontendid) { FcitxSimpleFrontend* simple = fcitx_utils_new(FcitxSimpleFrontend); simple->owner = instance; simple->frontendid = frontendid; FcitxSimpleFrontendAddFunctions(instance); return simple; }
FcitxXkbRules* FcitxXkbReadRules(const char* file) { xmlSAXHandler handle; memset(&handle, 0, sizeof(xmlSAXHandler)); handle.startElement = RulesHandlerStartElement; handle.endElement = RulesHandlerEndElement; handle.characters = RulesHandlerCharacters; xmlInitParser(); FcitxXkbRules* rules = fcitx_utils_new(FcitxXkbRules); utarray_new(rules->layoutInfos, &layout_icd); utarray_new(rules->modelInfos, &model_icd); utarray_new(rules->optionGroupInfos, &option_group_icd); FcitxXkbRulesHandler ruleshandler; ruleshandler.rules = rules; ruleshandler.path = fcitx_utils_new_string_list(); ruleshandler.fromExtra = false; xmlSAXUserParseFile(&handle, &ruleshandler, file); utarray_free(ruleshandler.path); size_t extra_len = strlen(file) - strlen(".xml"); if (strcmp(file + extra_len, ".xml") == 0) { char extrafile[extra_len + strlen(".extras.xml") + 1]; memcpy(extrafile, file, extra_len); memcpy(extrafile + extra_len, ".extras.xml", sizeof(".extras.xml")); FcitxXkbRules *rulesextra = fcitx_utils_new(FcitxXkbRules); utarray_new(rulesextra->layoutInfos, &layout_icd); utarray_new(rulesextra->modelInfos, &model_icd); utarray_new(rulesextra->optionGroupInfos, &option_group_icd); ruleshandler.rules = rulesextra; ruleshandler.path = fcitx_utils_new_string_list(); xmlSAXUserParseFile(&handle, &ruleshandler, extrafile); utarray_free(ruleshandler.path); MergeRules(rules, rulesextra); } xmlCleanupParser(); return rules; }
SpellCustomDict* SpellCustomNewDict(FcitxSpell *spell, const char *lang) { SpellCustomDict *dict = fcitx_utils_new(SpellCustomDict); if (!SpellCustomInitDict(spell, dict, lang)) { SpellCustomFreeDict(spell, dict); return NULL; } return dict; }
FCITX_EXPORT_API FcitxAddonManager* fcitx_addon_manager_new(FcitxStandardPath* standardPath) { FcitxAddonManager* manager = fcitx_utils_new(FcitxAddonManager); manager->resolvers = fcitx_dict_new(fcitx_addon_resolver_free); manager->standardPath = fcitx_standard_path_ref(standardPath); manager->addons = fcitx_dict_new((FcitxDestroyNotify) fcitx_addon_free); manager->loadedAddons = fcitx_ptr_array_new(NULL); manager->properties = fcitx_dict_new(NULL); return fcitx_addon_manager_ref(manager); }
void XimPreeditCallbackDone(FcitxXimFrontend *xim, const FcitxXimIC* ic) { IMPreeditCBStruct* pcb = fcitx_utils_new(IMPreeditCBStruct); pcb->major_code = XIM_PREEDIT_DONE; pcb->minor_code = 0; pcb->connect_id = ic->connect_id; pcb->icid = ic->id; pcb->todo.return_value = 0; XimPendingCall(xim, XCT_CALLCALLBACK, (XPointer) pcb); }
void* fcitx_keyboard_init(FcitxAddonManager* manager, const FcitxAddonConfig* config) { FCITX_UNUSED(manager); FCITX_UNUSED(config); FcitxKeyboard* keyboard = fcitx_utils_new(FcitxKeyboard); char* localepath = fcitx_utils_get_fcitx_path("localedir"); bindtextdomain("xkeyboard-config", localepath); bind_textdomain_codeset("xkeyboard-config", "UTF-8"); free(localepath); return keyboard; }
void* ZinniaCreate(FcitxTabletConfig* cfg) { Zinnia* zn = fcitx_utils_new(Zinnia); zn->recog = zinnia_recognizer_new(); // create the engine if (!zinnia_recognizer_open(zn->recog, cfg->ZinniaModel)) { FcitxLog(ERROR, "Could not create Zinnia engine: %s", zinnia_recognizer_strerror(zn->recog)); return NULL; } zn->result = NULL; // The output string. 30 chars should be plenty. zn->candidates = (char*) malloc(30 * sizeof(char)); return zn; }
FcitxComposeTable* _fcitx_compose_table_alloc(const char* locale) { FcitxComposeTable* table = fcitx_utils_new(FcitxComposeTable); table->localeToTable = fcitx_dict_new(free); table->composeTable = utarray_new(&composeElementIcd); table->locale = locale ? strdup(locale) : strdup(_get_locale()); char* p = table->locale; while(*p) { *p = fcitx_utils_toupper(*p); p++; } return fcitx_compose_table_ref(table); }
static void ClassicUIRegisterStatus(void *arg, FcitxUIStatus* status) { FcitxClassicUI* classicui = (FcitxClassicUI*) arg; FcitxSkin* sc = &classicui->skin; status->uipriv[classicui->isfallback] = fcitx_utils_new(FcitxClassicUIStatus); char *name; fcitx_utils_alloc_cat_str(name, status->name, "_active.png"); LoadImage(sc, name, false); free(name); fcitx_utils_alloc_cat_str(name, status->name, "_inactive.png"); LoadImage(sc, name, false); free(name); }
FCITX_EXPORT_API FcitxStandardPath* fcitx_standard_path_new() { FcitxStandardPath* path = fcitx_utils_new(FcitxStandardPath); // initialize user directory path->configHome = fcitx_standard_default_path_construct("XDG_CONFIG_HOME", ".config"); path->configDirs = fcitx_standard_default_paths_construct("XDG_CONFIG_DIRS", "/etc/xdg", NULL); path->dataHome = fcitx_standard_default_path_construct("XDG_DATA_HOME", ".local/share"); path->dataDirs = fcitx_standard_default_paths_construct("XDG_DATA_DIRS", "/usr/local/share:/usr/share", "datadir"); path->cacheHome = fcitx_standard_default_path_construct("XDG_CACHE_HOME", ".cache"); const char* tmpdir = getenv("TMPDIR"); path->runtimeDir = fcitx_standard_default_path_construct("XDG_RUNTIME_DIR", !tmpdir || !tmpdir[0] ? "/tmp" : tmpdir); path->addonDirs = fcitx_standard_default_paths_construct("FCITX_ADDON_DIRS", FCITX_INSTALL_ADDONDIR, NULL); return fcitx_standard_path_ref(path); }
void XimForwardKeyInternal(FcitxXimFrontend *xim, FcitxXimIC* ic, XEvent* xEvent ) { IMForwardEventStruct* forwardEvent = fcitx_utils_new(IMForwardEventStruct); forwardEvent->connect_id = ic->connect_id; forwardEvent->icid = ic->id; forwardEvent->major_code = XIM_FORWARD_EVENT; forwardEvent->sync_bit = 0; forwardEvent->serial_number = xim->currentSerialNumberCallData; memcpy(&(forwardEvent->event), xEvent, sizeof(XEvent)); XimPendingCall(xim, XCT_FORWARD, (XPointer)forwardEvent); }