예제 #1
0
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);
}
예제 #2
0
파일: xkbdbus.c 프로젝트: mylxiaoyi/fcitx
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;
}
예제 #3
0
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;
}
예제 #4
0
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;
}
예제 #5
0
void* SimpleUICreate(FcitxInstance* instance)
{
    FcitxSimpleUI* ui = fcitx_utils_new(FcitxSimpleUI);
    ui->owner = instance;
    FcitxSimpleUIAddFunctions(instance);
    return ui;
}
예제 #6
0
파일: thai.c 프로젝트: fcitx/fcitx-thai
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;
}
예제 #7
0
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;
}
예제 #8
0
파일: AutoEng.c 프로젝트: areslp/fcitx
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;
}
예제 #9
0
파일: clipboard.c 프로젝트: farseerfc/fcitx
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;
}
예제 #10
0
파일: unicode.c 프로젝트: HenryHu/fcitx
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;
}
예제 #11
0
파일: addon.c 프로젝트: rwdxll/fcitx5
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);
}
예제 #12
0
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;
}
예제 #13
0
파일: objpool.c 프로젝트: haulmy/fcitx-ng
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;
}
예제 #14
0
파일: objpool.c 프로젝트: adaptee/fcitx
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;
}
예제 #15
0
파일: punc.c 프로젝트: adaptee/fcitx
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;
}
예제 #16
0
파일: ime.c 프로젝트: fcitx/fcitx-ng
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);
}
예제 #17
0
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;
}
예제 #18
0
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;
}
예제 #19
0
파일: xim.c 프로젝트: adaptee/fcitx
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);
}
예제 #20
0
void*
SimpleFrontendCreate(FcitxInstance* instance, int frontendid)
{
    FcitxSimpleFrontend* simple = fcitx_utils_new(FcitxSimpleFrontend);
    simple->owner = instance;
    simple->frontendid = frontendid;
    FcitxSimpleFrontendAddFunctions(instance);
    return simple;
}
예제 #21
0
파일: rules.c 프로젝트: farseerfc/fcitx
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;
}
예제 #22
0
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;
}
예제 #23
0
파일: addon.c 프로젝트: rwdxll/fcitx5
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);
}
예제 #24
0
파일: ximhandler.c 프로젝트: adaptee/fcitx
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);
}
예제 #25
0
파일: keyboard.c 프로젝트: haulmy/fcitx-ng
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;
}
예제 #26
0
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;
}
예제 #27
0
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);
}
예제 #28
0
파일: classicui.c 프로젝트: adaptee/fcitx
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);
}
예제 #29
0
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);
}
예제 #30
0
파일: ximhandler.c 프로젝트: adaptee/fcitx
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);
}