void* IMSelectorCreate(FcitxInstance* instance) { IMSelector* imselector = fcitx_utils_malloc0(sizeof(IMSelector)); imselector->owner = instance; if (!LoadIMSelectorConfig(imselector)) { free(imselector); return NULL; } FcitxKeyFilterHook hk; hk.arg = imselector; hk.func = IMSelectorPreFilter; FcitxInstanceRegisterPreInputFilter(instance, hk); FcitxHotkeyHook hkhk; hkhk.arg = imselector; hkhk.hotkeyhandle = IMSelectorLocalTrigger; hkhk.hotkey = imselector->localKey; FcitxInstanceRegisterHotkeyFilter(instance, hkhk); hkhk.arg = imselector; hkhk.hotkeyhandle = IMSelectorGlobalTrigger; hkhk.hotkey = imselector->globalKey; FcitxInstanceRegisterHotkeyFilter(instance, hkhk); FcitxIMEventHook resethk; resethk.arg = imselector; resethk.func = IMSelectorReset; FcitxInstanceRegisterResetInputHook(instance, resethk); return imselector; }
void IMSelectorReload(void* arg) { IMSelector* imselector = arg; LoadIMSelectorConfig(imselector); }
void* IMSelectorCreate(FcitxInstance* instance) { IMSelector* imselector = fcitx_utils_malloc0(sizeof(IMSelector)); imselector->owner = instance; if (!LoadIMSelectorConfig(imselector)) { free(imselector); return NULL; } FcitxKeyFilterHook hk; hk.arg = imselector; hk.func = IMSelectorPreFilter; FcitxInstanceRegisterPreInputFilter(instance, hk); hk.arg = &imselector->triggered; hk.func = FcitxDummyReleaseInputHook; FcitxInstanceRegisterPreReleaseInputFilter(instance, hk); FcitxHotkeyHook hkhk; hkhk.arg = imselector; hkhk.hotkeyhandle = IMSelectorLocalTrigger; hkhk.hotkey = imselector->localKey; FcitxInstanceRegisterHotkeyFilter(instance, hkhk); hkhk.arg = imselector; hkhk.hotkeyhandle = IMSelectorGlobalTrigger; hkhk.hotkey = imselector->globalKey; FcitxInstanceRegisterHotkeyFilter(instance, hkhk); hkhk.arg = imselector; hkhk.hotkeyhandle = IMSelectorClearLocal; hkhk.hotkey = imselector->clearLocalKey; FcitxInstanceRegisterHotkeyFilter(instance, hkhk); /* this key is ignore the very first input method which is for inactive */ #define _ADD_HANDLE(X, ISGLOBAL) \ do { \ SelectorHandle* handle = &imselector->handle[ISGLOBAL][X - 1]; \ handle->global = ISGLOBAL; \ handle->idx = X; \ handle->imselector = imselector; \ hkhk.arg = handle; \ hkhk.hotkeyhandle = IMSelectorSelect; \ hkhk.hotkey = imselector->selectorKey[ISGLOBAL][X - 1]; \ FcitxInstanceRegisterHotkeyFilter(instance, hkhk); \ } while(0); _ADD_HANDLE(1, false); _ADD_HANDLE(2, false); _ADD_HANDLE(3, false); _ADD_HANDLE(4, false); _ADD_HANDLE(5, false); _ADD_HANDLE(6, false); _ADD_HANDLE(7, false); _ADD_HANDLE(8, false); _ADD_HANDLE(9, false); _ADD_HANDLE(1, true); _ADD_HANDLE(2, true); _ADD_HANDLE(3, true); _ADD_HANDLE(4, true); _ADD_HANDLE(5, true); _ADD_HANDLE(6, true); _ADD_HANDLE(7, true); _ADD_HANDLE(8, true); _ADD_HANDLE(9, true); FcitxIMEventHook resethk; resethk.arg = imselector; resethk.func = IMSelectorReset; FcitxInstanceRegisterResetInputHook(instance, resethk); return imselector; }