From bc2d949bbd20cf30e4a508c4383fac0ae0cc6d45 Mon Sep 17 00:00:00 2001 From: Weng Xuetian Date: Mon, 22 Feb 2016 09:46:45 -0800 Subject: [PATCH] [anthy] make use of new ShowCurrentIMInfo function to show input mode See fcitx/fcitx#245 --- CMakeLists.txt | 2 +- src/factory.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++- src/factory.h | 1 + src/fcitx-anthy.desc | 5 +++++ src/imengine.cpp | 9 +++++++++ src/imengine.h | 2 ++ 6 files changed, 63 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d8034c..0e5c8e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(fcitx-anthy) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) -FIND_PACKAGE(Fcitx 4.2.8 REQUIRED) +FIND_PACKAGE(Fcitx 4.2.9.2 REQUIRED) FIND_PACKAGE(Anthy REQUIRED) _fcitx_add_uninstall_target() diff --git a/src/factory.cpp b/src/factory.cpp index 919c8d0..d786da7 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -46,8 +46,10 @@ static INPUT_RETURN_VALUE FcitxAnthyDoReleaseInput(void* arg, FcitxKeySym sym, u static void FcitxAnthyReloadConfig(void* arg); static void FcitxAnthySave(void* arg); static void FcitxAnthyReset(void* arg); +static void FcitxAnthyFocusIn(void* arg); static void FcitxAnthyResetIM(void* arg); static void FcitxAnthyOnClose(void* arg, FcitxIMCloseEventType event); +static const char * FcitxAnthyGetSubModeName(void* arg); FCITX_DEFINE_PLUGIN(fcitx_anthy, ime2, FcitxIMClass2) = { FcitxAnthyCreate, @@ -84,6 +86,7 @@ void* FcitxAnthyCreate(FcitxInstance* instance) iface.ReloadConfig = FcitxAnthyReloadConfig; iface.Save = FcitxAnthySave; iface.OnClose = FcitxAnthyOnClose; + iface.GetSubModeName = FcitxAnthyGetSubModeName; FcitxInstanceRegisterIMv2( instance, @@ -100,6 +103,8 @@ void* FcitxAnthyCreate(FcitxInstance* instance) hk.arg = anthy; hk.func = FcitxAnthyReset; FcitxInstanceRegisterResetInputHook(instance, hk); + hk.func = FcitxAnthyFocusIn; + FcitxInstanceRegisterInputFocusHook(instance, hk); return anthy; } @@ -134,6 +139,40 @@ void FcitxAnthyReset(void* arg) anthy->update_ui(); } +void FcitxAnthyShowIMInfo(void* arg) +{ + AnthyInstance* anthy = (AnthyInstance*) arg; + static FcitxInputContext* ic; + + // don't show the info again if ic is not changed, this is annoying + // when cursor jumps within same application. + FcitxInputContext* newic = FcitxInstanceGetCurrentIC(anthy->get_owner()); + if (newic == ic) { + return; + } + + ic = newic; + if (!ic) { + return; + } + + FcitxIM* im = FcitxInstanceGetCurrentIM(anthy->get_owner()); + if (im && strcmp(im->uniqueName, "anthy") == 0) { + FcitxInstanceShowCurrentIMInfo(anthy->get_owner()); + } +} + +void FcitxAnthyFocusIn(void* arg) +{ + AnthyInstance* anthy = (AnthyInstance*) arg; + FcitxInstance* instance = anthy->get_owner(); + + if (anthy->get_config()->m_show_input_mode_on_focus && + !FcitxInstanceCheckTimeoutByFunc(instance, FcitxAnthyShowIMInfo)) { + FcitxInstanceAddTimeout(instance, 100, FcitxAnthyShowIMInfo, anthy); + } +} + void FcitxAnthySave(void* arg) { } @@ -186,6 +225,12 @@ void FcitxAnthyOnClose(void* arg, FcitxIMCloseEventType event) anthy->auto_commit(event); } +const char * FcitxAnthyGetSubModeName(void *arg) +{ + AnthyInstance* anthy = (AnthyInstance*) arg; + return anthy->get_input_mode_name(); +} + void SaveAnthyConfig(AnthyInstance* anthy) @@ -204,4 +249,3 @@ void ConfigAnthy(AnthyInstance* anthy) { anthy->configure(); anthy->update_ui(); } - diff --git a/src/factory.h b/src/factory.h index 8a5e7b2..96a3019 100644 --- a/src/factory.h +++ b/src/factory.h @@ -186,6 +186,7 @@ struct FcitxAnthyConfig { boolean m_show_add_word_label; boolean m_use_direct_key_on_predict; boolean m_show_candidates_label; + boolean m_show_input_mode_on_focus; boolean m_romaji_allow_split; int m_nicola_time; diff --git a/src/fcitx-anthy.desc b/src/fcitx-anthy.desc index 3ef350e..93e9919 100644 --- a/src/fcitx-anthy.desc +++ b/src/fcitx-anthy.desc @@ -94,6 +94,11 @@ Type=Boolean Description=Show candidates label DefaultValue=True +[General/ShowInputMode] +Type=Boolean +Description=Show input mode in input window when focus changes +DefaultValue=True + [Interface/ShowInputMode] Type=Boolean Description=Show input mode diff --git a/src/imengine.cpp b/src/imengine.cpp index 9326bc8..4ff2a70 100644 --- a/src/imengine.cpp +++ b/src/imengine.cpp @@ -690,6 +690,12 @@ const char* AnthyInstance::get_symbol_style_icon() return symbol_style_status[m_config.m_symbol_style].icon; } +const char * AnthyInstance::get_input_mode_name() +{ + return _(input_mode_status[m_config.m_input_mode].description); +} + + #define DEFINE_MENU_ACTION(NAME, TYPE, FUNC) \ void Update##NAME##Menu(struct _FcitxUIMenu *menu) \ { \ @@ -827,6 +833,8 @@ AnthyInstance::set_input_mode (InputMode mode) "anthy-input-mode", _(input_mode_status[mode].label), _(input_mode_status[mode].description)); + + FcitxInstanceShowCurrentIMInfo(m_owner); } void @@ -2105,6 +2113,7 @@ CONFIG_BINDING_REGISTER("General", "AllowSplit", m_romaji_allow_split) CONFIG_BINDING_REGISTER("General", "UseDirectKeyOnPredict", m_use_direct_key_on_predict) CONFIG_BINDING_REGISTER("General", "NTriggersToShowCandWin", m_n_triggers_to_show_cand_win) CONFIG_BINDING_REGISTER("General", "ShowCandidatesLabel", m_show_candidates_label) +CONFIG_BINDING_REGISTER("General", "ShowInputMode", m_show_input_mode_on_focus) CONFIG_BINDING_REGISTER("Interface", "ShowInputMode", m_show_input_mode_label) CONFIG_BINDING_REGISTER("Interface", "ShowTypingMethod", m_show_typing_method_label) diff --git a/src/imengine.h b/src/imengine.h index e7d038e..ec7fbba 100644 --- a/src/imengine.h +++ b/src/imengine.h @@ -159,6 +159,8 @@ class AnthyInstance const char* get_period_style_icon(); const char* get_symbol_style_icon(); + const char* get_input_mode_name(); + bool action_select_candidate (unsigned int i); void reset_cursor(int cursor); void auto_commit(FcitxIMCloseEventType type);