Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
[anthy] make use of new ShowCurrentIMInfo function to show input mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Feb 22, 2016
1 parent c7c3772 commit bc2d949
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -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()
Expand Down
46 changes: 45 additions & 1 deletion src/factory.cpp
Expand Up @@ -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,
Expand Down Expand Up @@ -84,6 +86,7 @@ void* FcitxAnthyCreate(FcitxInstance* instance)
iface.ReloadConfig = FcitxAnthyReloadConfig;
iface.Save = FcitxAnthySave;
iface.OnClose = FcitxAnthyOnClose;
iface.GetSubModeName = FcitxAnthyGetSubModeName;

FcitxInstanceRegisterIMv2(
instance,
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -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)
Expand All @@ -204,4 +249,3 @@ void ConfigAnthy(AnthyInstance* anthy) {
anthy->configure();
anthy->update_ui();
}

1 change: 1 addition & 0 deletions src/factory.h
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/fcitx-anthy.desc
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/imengine.cpp
Expand Up @@ -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) \
{ \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/imengine.h
Expand Up @@ -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);
Expand Down

0 comments on commit bc2d949

Please sign in to comment.