Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix caps sync mode #232

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions src/IBusChewingPreEdit-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
#define bpmf_check ibus_chewing_bopomofo_check(self->context)
#define table_is_showing ibus_chewing_pre_edit_has_flag(self, FLAG_TABLE_SHOW)

#define is_capslock (umaskedMod == IBUS_LOCK_MASK)
#define is_capslock (unmaskedMod & IBUS_LOCK_MASK)
#define is_shift_only (maskedMod == IBUS_SHIFT_MASK)
#define is_shift (unmaskedMod & IBUS_SHIFT_MASK)
#define is_ctrl_only (maskedMod == IBUS_CONTROL_MASK)
#define buffer_is_empty (ibus_chewing_pre_edit_is_empty(self))

/*== Event processing ==*/
/* We only recognize the combination of shift, control and alt */
#define modifiers_mask(unmaskedMod) \
#define modifiers_mask(unmaskedMod) \
unmaskedMod &(IBUS_SHIFT_MASK | IBUS_CONTROL_MASK | IBUS_MOD1_MASK)

/**
Expand All @@ -53,39 +53,36 @@
* allowed. allowed=IBUS_SHIFT_MASK means both keysym without modifier or shift
* are allowed.
*/
#define filter_modifiers(allowed) \
KeyModifiers maskedMod = modifiers_mask(unmaskedMod); \
if ((maskedMod) & (~(allowed))) { \
return EVENT_RESPONSE_IGNORE; \
#define filter_modifiers(allowed) \
KeyModifiers maskedMod = modifiers_mask(unmaskedMod); \
if ((maskedMod) & (~(allowed))) { \
return EVENT_RESPONSE_IGNORE; \
}
#define absorb_when_release \
if (event_is_released(unmaskedMod)) { \
return EVENT_RESPONSE_ABSORB; \
#define absorb_when_release \
if (event_is_released(unmaskedMod)) { \
return EVENT_RESPONSE_ABSORB; \
}
#define ignore_when_release \
if (event_is_released(unmaskedMod)) { \
return EVENT_RESPONSE_IGNORE; \
#define ignore_when_release \
if (event_is_released(unmaskedMod)) { \
return EVENT_RESPONSE_IGNORE; \
}
#define ignore_when_buffer_is_empty \
if (buffer_is_empty) { \
return EVENT_RESPONSE_IGNORE; \
#define ignore_when_buffer_is_empty \
if (buffer_is_empty) { \
return EVENT_RESPONSE_IGNORE; \
}
#define ignore_when_buffer_is_empty_and_table_not_showing \
if (buffer_is_empty && !table_is_showing) { \
return EVENT_RESPONSE_IGNORE; \
#define ignore_when_buffer_is_empty_and_table_not_showing \
if (buffer_is_empty && !table_is_showing) { \
return EVENT_RESPONSE_IGNORE; \
}

#define event_is_released(unmaskedMod) ((unmaskedMod & IBUS_RELEASE_MASK) != 0)
#define event_process_or_ignore(cond) \
(cond) ? EVENT_RESPONSE_PROCESS : EVENT_RESPONSE_IGNORE
#define event_process_or_ignore(cond) (cond) ? EVENT_RESPONSE_PROCESS : EVENT_RESPONSE_IGNORE

#define handle_log(funcName) \
IBUS_CHEWING_LOG(INFO, "* self_handle_%s(-,%x(%s),%x(%s))", funcName, \
kSym, key_sym_get_name(kSym), unmaskedMod, \
modifiers_to_string(unmaskedMod));
#define handle_log(funcName) \
IBUS_CHEWING_LOG(INFO, "* self_handle_%s(-,%x(%s),%x(%s))", funcName, kSym, \
key_sym_get_name(kSym), unmaskedMod, modifiers_to_string(unmaskedMod));

KSym self_key_sym_fix(IBusChewingPreEdit *self, KSym kSym,
KeyModifiers unmaskedMod);
KSym self_key_sym_fix(IBusChewingPreEdit *self, KSym kSym, KeyModifiers unmaskedMod);

EventResponse self_handle_key_sym_default(IBusChewingPreEdit *self, KSym kSym,
KeyModifiers unmaskedMod);
Expand Down
3 changes: 2 additions & 1 deletion src/IBusChewingPreEdit.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ EventResponse self_handle_num_keypad(IBusChewingPreEdit *self, KSym kSym,
}

EventResponse self_handle_caps_lock(IBusChewingPreEdit *self, KSym kSym, KeyModifiers unmaskedMod) {
filter_modifiers(0);
filter_modifiers(IBUS_LOCK_MASK);

IBusChewingEngine *engine = IBUS_CHEWING_ENGINE(self->engine);
gchar toggleChinese = ibus_chewing_engine_get_chinese_english_toggle_key(engine);
Expand Down Expand Up @@ -781,6 +781,7 @@ gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit *self, KSym kSym,

if (!is_full_shape && !is_chinese &&
!(kSym == IBUS_KEY_space && unmaskedMod == IBUS_SHIFT_MASK) &&
!(kSym == IBUS_KEY_Caps_Lock && is_capslock) &&
!is_shift_toggle(self->keyLast, kSym, unmaskedMod)) {
/* Users treat English Sub-mode as IM Disabled,
* So key strokes should be passed to client directly. Github 144.
Expand Down
2 changes: 1 addition & 1 deletion src/ibus-chewing-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ static void ibus_chewing_engine_init(IBusChewingEngine *self) {
void ibus_chewing_engine_restore_mode(IBusChewingEngine *self) {
g_return_if_fail(self != NULL);
g_return_if_fail(IBUS_IS_CHEWING_ENGINE(self));
{
if (ibus_chewing_engine_get_chinese_english_toggle_key(self) == 'c') {
IBUS_CHEWING_LOG(DEBUG, "restore_mode() statusFlags=%x", self->statusFlags);
GdkDisplay *display = gdk_display_get_default();

Expand Down
Loading