Skip to content

Commit

Permalink
feat: Add option to dissable Shift+Space as fullwidth toggle key
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Jul 20, 2024
1 parent 35354ed commit 110b5af
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/IBusChewingApplier.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ gboolean escCleanAllBuf_apply_callback(PropertyContext *ctx, gpointer) {
return TRUE;
}

gboolean enable_fullwidth_toggle_key_apply_callback(PropertyContext *ctx,
gpointer) {
GValue *value = &(ctx->value);
IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *)ctx->parent;

chewing_config_set_int(icPreEdit->context,
"chewing.enable_fullwidth_toggle_key",
g_value_get_boolean(value));
return TRUE;
}

/* Additional symbol buffer length */
gboolean maxChiSymbolLen_apply_callback(PropertyContext *ctx, gpointer) {
GValue *value = &(ctx->value);
Expand Down
2 changes: 1 addition & 1 deletion src/IBusChewingPreEdit.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ EventResponse self_handle_space(IBusChewingPreEdit *self, KSym kSym,
handle_log("space");

if (is_shift_only) {
ibus_chewing_pre_edit_toggle_full_half_mode(self);
chewing_handle_ShiftSpace(self->context);

Check warning on line 492 in src/IBusChewingPreEdit.c

View check run for this annotation

Codecov / codecov/patch

src/IBusChewingPreEdit.c#L492

Added line #L492 was not covered by tests
return EVENT_RESPONSE_PROCESS;
}

Expand Down
4 changes: 4 additions & 0 deletions src/IBusChewingProperties.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ MkdgPropertySpec propSpecs[] = {
N_("Esc clean all buffer"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "0", NULL,
NULL, 0, 1, escCleanAllBuf_apply_callback, 0,
N_("Escape key cleans the text in pre-edit-buffer"), NULL},
{G_TYPE_BOOLEAN, "enable-fullwidth-toggle-key", PAGE_EDITING,
N_("Enable fullwidth toggle key"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "0",
NULL, NULL, 0, 1, enable_fullwidth_toggle_key_apply_callback, 0,
N_("Escape key cleans the text in pre-edit-buffer"), NULL},
{G_TYPE_INT, "max-chi-symbol-len", PAGE_EDITING,
N_("Maximum Chinese characters"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "20",
NULL, NULL, 0, 39, maxChiSymbolLen_apply_callback, 0,
Expand Down
3 changes: 3 additions & 0 deletions src/IBusChewingProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ gboolean easySymbolInput_apply_callback(PropertyContext *ctx,

gboolean escCleanAllBuf_apply_callback(PropertyContext *ctx, gpointer userData);

gboolean enable_fullwidth_toggle_key_apply_callback(PropertyContext *ctx,
gpointer userData);

gboolean maxChiSymbolLen_apply_callback(PropertyContext *ctx,
gpointer userData);

Expand Down
3 changes: 3 additions & 0 deletions src/setup/ibus-setup-chewing-about.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ static char *generate_debug_info(void) {
g_string_append_printf(
string, "- esc-clean-all-buf: %d\n",
g_settings_get_boolean(settings, "esc-clean-all-buf"));
g_string_append_printf(
string, "- enable-fullwidth-toggle-key: %d\n",
g_settings_get_boolean(settings, "enable-fullwidth-toggle-key"));
g_string_append_printf(
string, "- max-chi-symbol-len: %d\n",
g_settings_get_int(settings, "max-chi-symbol-len"));
Expand Down
5 changes: 5 additions & 0 deletions src/setup/ibus-setup-chewing-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct _IbusSetupChewingWindow {
AdwSwitchRow *clean_buffer_focus_out;
AdwSwitchRow *easy_symbol_input;
AdwSwitchRow *esc_clean_all_buf;
AdwSwitchRow *enable_fullwidth_toggle_key;
AdwSpinRow *max_chi_symbol_len;
AdwComboRow *chi_eng_mode_toggle;
AdwComboRow *sync_caps_lock;
Expand Down Expand Up @@ -74,6 +75,7 @@ ibus_setup_chewing_window_class_init(IbusSetupChewingWindowClass *klass) {
bind_child(clean_buffer_focus_out);
bind_child(easy_symbol_input);
bind_child(esc_clean_all_buf);
bind_child(enable_fullwidth_toggle_key);
bind_child(max_chi_symbol_len);
bind_child(chi_eng_mode_toggle);
bind_child(sync_caps_lock);
Expand Down Expand Up @@ -206,6 +208,9 @@ static void ibus_setup_chewing_window_init(IbusSetupChewingWindow *self) {
"active", G_SETTINGS_BIND_DEFAULT);
g_settings_bind(settings, "esc-clean-all-buf", self->esc_clean_all_buf,
"active", G_SETTINGS_BIND_DEFAULT);
g_settings_bind(settings, "enable-fullwidth-toggle-key",
self->enable_fullwidth_toggle_key, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind(settings, "max-chi-symbol-len", self->max_chi_symbol_len,
"value", G_SETTINGS_BIND_DEFAULT);
g_settings_bind_with_mapping(settings, "chi-eng-mode-toggle",
Expand Down
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 @@ -134,6 +134,12 @@
<property name="subtitle" translatable="yes">Escape key discards all uncommitted texts</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="enable_fullwidth_toggle_key">
<property name="title" translatable="yes">Enable Fullwidth Toggle Key (Shift+Space)</property>
<property name="subtitle" translatable="yes">Use Shift+Space to switch between fullwdith and halfwidth symbols input</property>
</object>
</child>
<child>
<object class="AdwSpinRow" id="max_chi_symbol_len">
<property name="adjustment">
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 @@ -91,6 +91,13 @@
Escape key cleans the text in pre-edit-buffer
</description>
</key>
<key name="enable-fullwidth-toggle-key" type="b">
<default>true</default>
<summary>Enable fullwidth toggle key</summary>
<description>
Enable fullwidth/halfwidth toggle key (Shift+Space)
</description>
</key>
<key name="max-chi-symbol-len" type="i">
<range min="0" max="39"/>
<default>20</default>
Expand Down

0 comments on commit 110b5af

Please sign in to comment.