From 590bb3a8993b029a4b4e46e05c2bfed7d200a8b4 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Wed, 15 Apr 2009 07:48:06 +0800 Subject: [PATCH] Add IBUS_IGNORED_MASK and IBUS_HANDLED_MASK. --- client/gtk2/ibusimcontext.c | 40 ++++++++++++++++++++++++++++--------- src/ibusenumtypes.c | 2 ++ src/ibusinputcontext.c | 5 ++++- src/ibustypes.h | 6 ++++-- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c index feb4c236..168e45a8 100644 --- a/client/gtk2/ibusimcontext.c +++ b/client/gtk2/ibusimcontext.c @@ -190,33 +190,44 @@ _key_snooper_cb (GtkWidget *widget, IBusIMContext *ibusimcontext; ibusimcontext = (IBusIMContext *) _focus_im_context; - if (!_use_key_snooper) + if (G_UNLIKELY (!_use_key_snooper)) return retval; if (ibusimcontext == NULL) - return retval; + return FALSE; - if (ibusimcontext->ibuscontext == NULL || ibusimcontext->has_focus == FALSE) - return retval; + if (G_UNLIKELY (ibusimcontext->ibuscontext == NULL || ibusimcontext->has_focus == FALSE)) + return FALSE; + + if (G_UNLIKELY (event->state & IBUS_HANDLED_MASK)) + return TRUE; + + if (G_UNLIKELY (event->state & IBUS_IGNORED_MASK)) + return FALSE; switch (event->type) { case GDK_KEY_RELEASE: retval = ibus_input_context_process_key_event (ibusimcontext->ibuscontext, event->keyval, event->state | IBUS_RELEASE_MASK); - event->state |= IBUS_FORWARD_MASK; break; case GDK_KEY_PRESS: retval = ibus_input_context_process_key_event (ibusimcontext->ibuscontext, event->keyval, event->state); - event->state |= IBUS_FORWARD_MASK; break; default: retval = FALSE; break; } + if (retval) { + event->state |= IBUS_HANDLED_MASK; + } + else { + event->state |= IBUS_IGNORED_MASK; + } + return retval; } @@ -386,11 +397,18 @@ ibus_im_context_filter_keypress (GtkIMContext *context, IBusIMContext *ibusimcontext = (IBusIMContext *) context; - if (ibusimcontext->ibuscontext && ibusimcontext->has_focus) { + if (G_LIKELY (ibusimcontext->ibuscontext && ibusimcontext->has_focus)) { /* If context does not have focus, ibus will process key event in sync mode. * It is a workaround for increase search in treeview. */ - gboolean retval; + gboolean retval = FALSE; + + if (event->state & IBUS_HANDLED_MASK) + return TRUE; + + if (event->state & IBUS_IGNORED_MASK) + return gtk_im_context_filter_keypress (ibusimcontext->slave, event); + switch (event->type) { case GDK_KEY_RELEASE: retval = ibus_input_context_process_key_event (ibusimcontext->ibuscontext, @@ -407,9 +425,13 @@ ibus_im_context_filter_keypress (GtkIMContext *context, } if (retval) { + event->state |= IBUS_HANDLED_MASK; return TRUE; } - return gtk_im_context_filter_keypress (ibusimcontext->slave, event); + else { + event->state |= IBUS_IGNORED_MASK; + return gtk_im_context_filter_keypress (ibusimcontext->slave, event); + } } else { return gtk_im_context_filter_keypress (ibusimcontext->slave, event); diff --git a/src/ibusenumtypes.c b/src/ibusenumtypes.c index 591b3f0d..69a90259 100644 --- a/src/ibusenumtypes.c +++ b/src/ibusenumtypes.c @@ -110,7 +110,9 @@ ibus_modifier_type_get_type (void) { IBUS_BUTTON3_MASK, "IBUS_BUTTON3_MASK", "button3-mask" }, { IBUS_BUTTON4_MASK, "IBUS_BUTTON4_MASK", "button4-mask" }, { IBUS_BUTTON5_MASK, "IBUS_BUTTON5_MASK", "button5-mask" }, + { IBUS_HANDLED_MASK, "IBUS_HANDLED_MASK", "handled-mask" }, { IBUS_FORWARD_MASK, "IBUS_FORWARD_MASK", "forward-mask" }, + { IBUS_IGNORED_MASK, "IBUS_IGNORED_MASK", "ignored-mask" }, { IBUS_SUPER_MASK, "IBUS_SUPER_MASK", "super-mask" }, { IBUS_HYPER_MASK, "IBUS_HYPER_MASK", "hyper-mask" }, { IBUS_META_MASK, "IBUS_META_MASK", "meta-mask" }, diff --git a/src/ibusinputcontext.c b/src/ibusinputcontext.c index 95754cfd..52547ff9 100644 --- a/src/ibusinputcontext.c +++ b/src/ibusinputcontext.c @@ -553,7 +553,10 @@ ibus_input_context_process_key_event (IBusInputContext *context, IBusError *error = NULL; gboolean retval; - if (state & IBUS_FORWARD_MASK) + if (state & IBUS_HANDLED_MASK) + return TRUE; + + if (state & IBUS_IGNORED_MASK) return FALSE; retval = ibus_proxy_call_with_reply ((IBusProxy *) context, diff --git a/src/ibustypes.h b/src/ibustypes.h index d2f15bad..2f7c0bfe 100644 --- a/src/ibustypes.h +++ b/src/ibustypes.h @@ -69,11 +69,13 @@ typedef enum IBUS_BUTTON5_MASK = 1 << 12, /* The next few modifiers are used by XKB, so we skip to the end. - * Bits 15 - 24 are currently unused. Bit 29 is used internally. + * Bits 15 - 23 are currently unused. Bit 29 is used internally. */ - /* forward mask */ + /* ibus mask */ + IBUS_HANDLED_MASK = 1 << 24, IBUS_FORWARD_MASK = 1 << 25, + IBUS_IGNORED_MASK = IBUS_FORWARD_MASK, IBUS_SUPER_MASK = 1 << 26, IBUS_HYPER_MASK = 1 << 27,