Skip to content

Commit

Permalink
Merge pull request #222 from chewing/option-to-show-notification
Browse files Browse the repository at this point in the history
feat: Option to show notification about mode switches triggered by input
  • Loading branch information
kanru authored Aug 12, 2024
2 parents c55f1cb + 335c17b commit 4697363
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 26 deletions.
62 changes: 44 additions & 18 deletions po/ibus-chewing.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-22 17:50+0900\n"
"POT-Creation-Date: 2024-08-11 22:52+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -258,39 +258,49 @@ msgstr ""
msgid "The letter case without pressing the Shift key"
msgstr ""

#: src/setup/ibus-setup-chewing-window.ui:213
#: src/setup/ibus-setup-chewing-window.ui:211
msgid "Notify Mode Changes"
msgstr ""

#: src/setup/ibus-setup-chewing-window.ui:212
msgid ""
"Display a message when the Chinese/English or Fullwidth/Halfwidth mode "
"changes"
msgstr ""

#: src/setup/ibus-setup-chewing-window.ui:219
msgid "Selecting"
msgstr ""

#: src/setup/ibus-setup-chewing-window.ui:214
#: src/setup/ibus-setup-chewing-window.ui:220
msgid "Configure the candidate selection behavior"
msgstr ""

#: src/setup/ibus-setup-chewing-window.ui:225
#: src/setup/ibus-setup-chewing-window.ui:231
msgid "Candidates Per Page"
msgstr ""

#: src/setup/ibus-setup-chewing-window.ui:231
#: src/setup/ibus-setup-chewing-window.ui:237
msgid "Show Page Number"
msgstr ""

#: src/setup/ibus-setup-chewing-window.ui:237
#: src/setup/ibus-setup-chewing-window.ui:243
msgid "Choose Phrases Backwards"
msgstr ""

#: src/setup/ibus-setup-chewing-window.ui:238
#: src/setup/ibus-setup-chewing-window.ui:244
msgid "Open candidate list from the last character of a phrase"
msgstr ""

#: src/setup/ibus-setup-chewing-window.ui:244
#: src/setup/ibus-setup-chewing-window.ui:250
msgid "Use Space Key as Selection Key"
msgstr ""

#: src/setup/ibus-setup-chewing-window.ui:250
#: src/setup/ibus-setup-chewing-window.ui:256
msgid "Use Vertical Candidate Panel"
msgstr ""

#: src/setup/ibus-setup-chewing-window.ui:251
#: src/setup/ibus-setup-chewing-window.ui:257
msgid "Choose from vertical or horizontal panel"
msgstr ""

Expand All @@ -306,38 +316,54 @@ msgstr ""
msgid "_Chat"
msgstr ""

#: src/ibus-chewing-engine.c:411
#: src/ibus-chewing-engine.c:421
msgid "Switch to Alphanumeric Mode"
msgstr ""

#: src/ibus-chewing-engine.c:413
#: src/ibus-chewing-engine.c:423
msgid "Switch to Chinese Mode"
msgstr ""

#: src/ibus-chewing-engine.c:415
#: src/ibus-chewing-engine.c:425
msgid "Click to toggle Chinese/Alphanumeric Mode"
msgstr ""

#: src/ibus-chewing-engine.c:419
#: src/ibus-chewing-engine.c:429
msgid "Fullwidth Form"
msgstr ""

#: src/ibus-chewing-engine.c:421
#: src/ibus-chewing-engine.c:431
msgid "Halfwidth Form"
msgstr ""

#: src/ibus-chewing-engine.c:423
#: src/ibus-chewing-engine.c:433
msgid "Click to toggle Halfwidth/Fullwidth Form"
msgstr ""

#: src/ibus-chewing-engine.c:427
#: src/ibus-chewing-engine.c:437
msgid "IBus-Chewing Preferences"
msgstr ""

#: src/ibus-chewing-engine.c:429
#: src/ibus-chewing-engine.c:439
msgid "Click to configure IBus-Chewing"
msgstr ""

#: src/ibus-chewing-engine.c:956
msgid "Chinese Mode"
msgstr ""

#: src/ibus-chewing-engine.c:956
msgid "English Mode"
msgstr ""

#: src/ibus-chewing-engine.c:960
msgid "Fullwidth Mode"
msgstr ""

#: src/ibus-chewing-engine.c:960
msgid "Halfwidth Mode"
msgstr ""

#: src/main.c:63
msgid "Cannot connect to IBus!"
msgstr ""
Expand Down
3 changes: 3 additions & 0 deletions src/IBusChewingPreEdit.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ EventResponse self_handle_shift_left(IBusChewingPreEdit *self, KSym kSym,
}

ibus_chewing_pre_edit_toggle_chi_eng_mode(self);
ibus_chewing_engine_notify_chinese_english_mode_change(IBUS_CHEWING_ENGINE(self->engine));
return EVENT_RESPONSE_IGNORE;
}

Expand Down Expand Up @@ -408,6 +409,7 @@ EventResponse self_handle_shift_right(IBusChewingPreEdit *self, KSym kSym,
}

ibus_chewing_pre_edit_toggle_chi_eng_mode(self);
ibus_chewing_engine_notify_chinese_english_mode_change(IBUS_CHEWING_ENGINE(self->engine));
return EVENT_RESPONSE_IGNORE;
}

Expand Down Expand Up @@ -462,6 +464,7 @@ EventResponse self_handle_space(IBusChewingPreEdit *self, KSym kSym, KeyModifier
if (is_shift_only) {
handle_log("Shift+Space");
chewing_handle_ShiftSpace(self->context);
ibus_chewing_engine_notify_fullwidth_mode_change(IBUS_CHEWING_ENGINE(self->engine));
return EVENT_RESPONSE_PROCESS;
}

Expand Down
3 changes: 3 additions & 0 deletions src/ibus-chewing-engine-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ struct _IBusChewingEngine {

EngineFlag statusFlags;
IBusCapabilite capabilite;
gboolean pending_notify_chinese_english_mode;
gboolean pending_notify_fullwidth_mode;

char *prop_kb_type;
char *prop_sel_keys;
Expand All @@ -64,6 +66,7 @@ struct _IBusChewingEngine {
gboolean prop_show_page_number;
char *prop_conversion_engine;
gboolean prop_ibus_use_system_layout;
gboolean prop_notify_mode_change;

IBusText *InputMode_label_chi;
IBusText *InputMode_label_eng;
Expand Down
32 changes: 30 additions & 2 deletions src/ibus-chewing-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ typedef enum {
PROP_SHOW_PAGE_NUMBER,
PROP_CONVERSION_ENGINE,
PROP_IBUS_USE_SYSTEM_LAYOUT,
PROP_NOTIFY_MODE_CHANGE,
N_PROPERTIES
} IBusChewingEngineProperty;

Expand All @@ -122,6 +123,7 @@ static void ibus_chewing_engine_property_hide(IBusEngine *engine, const gchar *p

#define is_password(self) ibus_chewing_engine_has_status_flag(self, ENGINE_FLAG_IS_PASSWORD)
#define is_chinese_mode(self) ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit)
#define is_fullwidth_mode(self) ibus_chewing_pre_edit_get_full_half_mode(self->icPreEdit)

#define ibus_text_is_empty(iText) ((iText == NULL) || STRING_IS_EMPTY(iText->text))

Expand Down Expand Up @@ -256,6 +258,9 @@ static void ibus_chewing_engine_set_property(GObject *object, guint property_id,
case PROP_IBUS_USE_SYSTEM_LAYOUT:
self->prop_ibus_use_system_layout = g_value_get_boolean(value);
break;
case PROP_NOTIFY_MODE_CHANGE:
self->prop_notify_mode_change = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
Expand Down Expand Up @@ -326,6 +331,9 @@ static void ibus_chewing_engine_get_property(GObject *object, guint property_id,
case PROP_IBUS_USE_SYSTEM_LAYOUT:
g_value_set_boolean(value, self->prop_ibus_use_system_layout);
break;
case PROP_NOTIFY_MODE_CHANGE:
g_value_set_boolean(value, self->prop_notify_mode_change);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
Expand Down Expand Up @@ -400,6 +408,8 @@ static void ibus_chewing_engine_class_init(IBusChewingEngineClass *klass) {
g_param_spec_string("conversion-engine", NULL, NULL, NULL, G_PARAM_READWRITE);
obj_properties[PROP_IBUS_USE_SYSTEM_LAYOUT] =
g_param_spec_boolean("use-system-keyboard-layout", NULL, NULL, FALSE, G_PARAM_READWRITE);
obj_properties[PROP_NOTIFY_MODE_CHANGE] =
g_param_spec_boolean("notify-mode-change", NULL, NULL, TRUE, G_PARAM_READWRITE);

g_object_class_install_properties(object_class, N_PROPERTIES, obj_properties);
}
Expand Down Expand Up @@ -435,6 +445,8 @@ static void ibus_chewing_engine_init(IBusChewingEngine *self) {
self->outgoingText = NULL;
self->statusFlags = 0;
self->capabilite = 0;
self->pending_notify_chinese_english_mode = FALSE;
self->pending_notify_fullwidth_mode = FALSE;
self->InputMode = g_object_ref_sink(
ibus_property_new("InputMode", PROP_TYPE_NORMAL, self->InputMode_label_chi, NULL,
self->InputMode_tooltip, TRUE, TRUE, PROP_STATE_UNCHECKED, NULL));
Expand Down Expand Up @@ -488,6 +500,7 @@ static void ibus_chewing_engine_init(IBusChewingEngine *self) {
bind_settings("sync-caps-lock");
bind_settings("show-page-number");
bind_settings("conversion-engine");
bind_settings("notify-mode-change");

g_settings_bind(ibus_settings, "use-system-keyboard-layout", self, "use-system-keyboard-layout",
G_SETTINGS_BIND_DEFAULT);
Expand Down Expand Up @@ -938,6 +951,14 @@ void refresh_aux_text(IBusChewingEngine *self) {
IBUS_CHEWING_LOG(INFO, "update_aux_text() auxStr=%s", auxStr);
self->auxText = g_object_ref_sink(ibus_text_new_from_string(auxStr));
g_free(auxStr);
} else if (self->prop_notify_mode_change && self->pending_notify_chinese_english_mode) {
self->pending_notify_chinese_english_mode = FALSE;
char *auxStr = is_chinese_mode(self) ? _("Chinese Mode") : _("English Mode");
self->auxText = g_object_ref_sink(ibus_text_new_from_static_string(auxStr));
} else if (self->prop_notify_mode_change && self->pending_notify_fullwidth_mode) {
self->pending_notify_fullwidth_mode = FALSE;
char *auxStr = is_fullwidth_mode(self) ? _("Fullwidth Mode") : _("Halfwidth Mode");
self->auxText = g_object_ref_sink(ibus_text_new_from_static_string(auxStr));
} else if (showPageNumber && (chewing_cand_TotalPage(self->icPreEdit->context) > 0)) {
int TotalPage = chewing_cand_TotalPage(self->icPreEdit->context);
int currentPage = chewing_cand_CurrentPage(self->icPreEdit->context) + 1;
Expand Down Expand Up @@ -1071,8 +1092,8 @@ void ibus_chewing_engine_property_activate(IBusEngine *engine, const gchar *prop
ibus_chewing_engine_refresh_property(self, prop_name);
} else if (STRING_EQUALS(prop_name, "AlnumSize")) {
/* Toggle Full <-> Half */
chewing_set_ShapeMode(self->icPreEdit->context,
!chewing_get_ShapeMode(self->icPreEdit->context));
ibus_chewing_pre_edit_toggle_full_half_mode(self->icPreEdit);
IBUS_CHEWING_LOG(INFO, "property_activate fullwidth=%d", is_fullwidth_mode(self));
ibus_chewing_engine_refresh_property(self, prop_name);
} else if (STRING_EQUALS(prop_name, "setup_prop")) {
/* open preferences window */
Expand Down Expand Up @@ -1104,4 +1125,11 @@ gboolean ibus_chewing_engine_use_vertical_lookup_table(IBusChewingEngine *self)

gboolean ibus_chewing_engine_use_system_layout(IBusChewingEngine *self) {
return self->prop_ibus_use_system_layout;
}

void ibus_chewing_engine_notify_chinese_english_mode_change(IBusChewingEngine *self) {
self->pending_notify_chinese_english_mode = TRUE;
}
void ibus_chewing_engine_notify_fullwidth_mode_change(IBusChewingEngine *self) {
self->pending_notify_fullwidth_mode = TRUE;
}
12 changes: 6 additions & 6 deletions src/ibus-chewing-engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ GType engine_flag_get_type(void) G_GNUC_CONST;
G_DEFINE_AUTOPTR_CLEANUP_FUNC(IBusEngine, g_object_unref)

#define IBUS_TYPE_CHEWING_ENGINE ibus_chewing_engine_get_type()
G_DECLARE_FINAL_TYPE(IBusChewingEngine, ibus_chewing_engine, IBUS,
CHEWING_ENGINE, IBusEngine)
G_DECLARE_FINAL_TYPE(IBusChewingEngine, ibus_chewing_engine, IBUS, CHEWING_ENGINE, IBusEngine)

void ibus_chewing_engine_refresh_property_list(IBusChewingEngine *self);
void ibus_chewing_engine_hide_property_list(IBusChewingEngine *self);
Expand All @@ -55,13 +54,14 @@ void ibus_chewing_engine_enable(IBusEngine *self);
void ibus_chewing_engine_disable(IBusEngine *self);
void ibus_chewing_engine_focus_in(IBusEngine *self);
void ibus_chewing_engine_focus_out(IBusEngine *self);
gboolean ibus_chewing_engine_process_key_event(IBusEngine *self, guint key_sym,
guint keycode, guint modifiers);
gboolean ibus_chewing_engine_process_key_event(IBusEngine *self, guint key_sym, guint keycode,
guint modifiers);

char ibus_chewing_engine_get_default_english_case(IBusChewingEngine *self);
char ibus_chewing_engine_get_chinese_english_toggle_key(
IBusChewingEngine *self);
char ibus_chewing_engine_get_chinese_english_toggle_key(IBusChewingEngine *self);
gboolean ibus_chewing_engine_use_vertical_lookup_table(IBusChewingEngine *self);
gboolean ibus_chewing_engine_use_system_layout(IBusChewingEngine *self);
void ibus_chewing_engine_notify_chinese_english_mode_change(IBusChewingEngine *self);
void ibus_chewing_engine_notify_fullwidth_mode_change(IBusChewingEngine *self);

G_END_DECLS
4 changes: 4 additions & 0 deletions src/setup/ibus-setup-chewing-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct _IbusSetupChewingWindow {
AdwSwitchRow *phrase_choice_from_last;
AdwSwitchRow *space_as_selection;
AdwSwitchRow *vertical_lookup_table;
AdwSwitchRow *notify_mode_change;
};

G_DEFINE_FINAL_TYPE(IbusSetupChewingWindow, ibus_setup_chewing_window, ADW_TYPE_APPLICATION_WINDOW)
Expand Down Expand Up @@ -82,6 +83,7 @@ static void ibus_setup_chewing_window_class_init(IbusSetupChewingWindowClass *kl
bind_child(phrase_choice_from_last);
bind_child(space_as_selection);
bind_child(vertical_lookup_table);
bind_child(notify_mode_change);

gtk_widget_class_install_action(widget_class, "about", NULL, action_adaptor_show_about);
gtk_widget_class_add_binding_action(widget_class, GDK_KEY_Escape, 0, "window.close", NULL);
Expand Down Expand Up @@ -220,4 +222,6 @@ static void ibus_setup_chewing_window_init(IbusSetupChewingWindow *self) {
G_SETTINGS_BIND_DEFAULT);
g_settings_bind(settings, "vertical-lookup-table", self->vertical_lookup_table, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind(settings, "notify-mode-change", self->notify_mode_change, "active",
G_SETTINGS_BIND_DEFAULT);
}
6 changes: 6 additions & 0 deletions src/setup/ibus-setup-chewing-window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@
<property name="subtitle" translatable="yes">The letter case without pressing the Shift key</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="notify_mode_change">
<property name="title" translatable="yes">Notify Mode Changes</property>
<property name="subtitle" translatable="yes">Display a message when the Chinese/English or Fullwidth/Halfwidth mode changes</property>
</object>
</child>
</object>
</child>
<child>
Expand Down
7 changes: 7 additions & 0 deletions src/setup/org.freedesktop.IBus.Chewing.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@
"IM": Keyboard status follows IM status
</description>
</key>
<key name="notify-mode-change" type="b">
<default>true</default>
<summary>Notify when Chinese/English or Fullwidth/Halfwidth mode changes</summary>
<description>
Display a simple notification when an input mode change is triggered by user input.
</description>
</key>
<key name="plain-zhuyin" type="b">
<default>false</default>
<summary>Plain Zhuyin mode (deprecated)</summary>
Expand Down

0 comments on commit 4697363

Please sign in to comment.