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

Add prefilter flag #1

Closed
wants to merge 2 commits into from
Closed
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
18 changes: 13 additions & 5 deletions client/gtk2/ibusimcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,11 @@ _process_key_event_done (GObject *object,
gdk_event_get_device (event),
gdk_event_get_time (event),
gdk_key_event_get_keycode (event),
gdk_event_get_modifier_state (event) | IBUS_IGNORED_MASK,
(gdk_event_get_modifier_state (event) | IBUS_IGNORED_MASK) & ~IBUS_PREFILTER_MASK,
0);
#else
((GdkEventKey *)event)->state |= IBUS_IGNORED_MASK;
((GdkEventKey *)event)->state &= ~IBUS_PREFILTER_MASK;
gdk_event_put (event);
#endif
}
Expand Down Expand Up @@ -646,8 +647,10 @@ _key_snooper_cb (GtkWidget *widget,
if (G_UNLIKELY (event->state & IBUS_HANDLED_MASK))
return TRUE;

if (G_UNLIKELY (event->state & IBUS_IGNORED_MASK))
return FALSE;
if (!(event->state & IBUS_PREFILTER_MASK)) {
if (G_UNLIKELY(event->state & IBUS_IGNORED_MASK))
return FALSE;
}

do {
if (_fake_context != ibuscontext)
Expand Down Expand Up @@ -984,6 +987,11 @@ ibus_im_context_init (GObject *obj)
#else
ibusimcontext->caps = IBUS_CAP_PREEDIT_TEXT | IBUS_CAP_FOCUS;
#endif

#ifdef ENABLE_PREFILTER
ibusimcontext->caps |= IBUS_CAP_PREFILTER;
#endif

if (_use_sync_mode != 1)
ibusimcontext->caps |= IBUS_CAP_SYNC_PROCESS_KEY;

Expand Down Expand Up @@ -1142,7 +1150,7 @@ ibus_im_context_filter_keypress (GtkIMContext *context,
GdkModifierType state = gdk_event_get_modifier_state (event);
if (state & IBUS_HANDLED_MASK)
return TRUE;
if (state & IBUS_IGNORED_MASK)
if (state & IBUS_IGNORED_MASK && !(state & IBUS_PREFILTER_MASK))
return ibus_im_context_commit_event (ibusimcontext, event);
}
#else
Expand All @@ -1152,7 +1160,7 @@ ibus_im_context_filter_keypress (GtkIMContext *context,
/* Do not call gtk_im_context_filter_keypress() because
* gtk_im_context_simple_filter_keypress() binds Ctrl-Shift-u
*/
if (event->state & IBUS_IGNORED_MASK)
if (event->state & IBUS_IGNORED_MASK && !(event->state & IBUS_PREFILTER_MASK))
return ibus_im_context_commit_event (ibusimcontext, event);

/* XXX it is a workaround for some applications do not set client
Expand Down
13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,18 @@ else
enable_surrounding_text="no (disabled, use --enable-surrounding-text to enable)"
fi

# --disable-prefilter option
AC_ARG_ENABLE(prefilter,
AS_HELP_STRING([--disable-prefilter],
[Disable prefilter support]),
[enable_prefilter=$enableval],
[enable_prefilter=yes]
)
if test x"$enable_prefilter" = x"yes"; then
AC_DEFINE(ENABLE_PREFILTER, TRUE, [Enable prefilter support])
enable_prefilter="yes (enabled, use --disable-prefilter to disable)"
fi

# --disable-ui
AC_ARG_ENABLE(ui,
AS_HELP_STRING([--disable-ui],
Expand Down Expand Up @@ -886,6 +898,7 @@ Build options:
No snooper regexes "$NO_SNOOPER_APPS"
Panel icon "$IBUS_ICON_KEYBOARD"
Enable surrounding-text $enable_surrounding_text
Enable prefilter $enable_prefilter
Enable libnotify $enable_libnotify
Enable Emoji dict $enable_emoji_dict
Unicode Emoji directory $UNICODE_EMOJI_DIR
Expand Down
10 changes: 7 additions & 3 deletions src/ibustypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* @IBUS_BUTTON3_MASK: Mouse button 3 (right) is activated.
* @IBUS_BUTTON4_MASK: Mouse button 4 (scroll up) is activated.
* @IBUS_BUTTON5_MASK: Mouse button 5 (scroll down) is activated.
* @IBUS_PREFILTER_MASK: Prefilter mask indicates the event has been prefiltered by the engine.
* @IBUS_HANDLED_MASK: Handled mask indicates the event has been handled by ibus.
* @IBUS_FORWARD_MASK: Forward mask indicates the event has been forward from ibus.
* @IBUS_IGNORED_MASK: It is an alias of IBUS_FORWARD_MASK.
Expand All @@ -63,7 +64,7 @@
* @IBUS_MODIFIER_MASK: Modifier mask for the all the masks above.
*
* Handles key modifier such as control, shift and alt and release event.
* Note that nits 15 - 25 are currently unused, while bit 29 is used internally.
* Note that bits 15 - 22 are currently unused, while bit 29 is used internally.
*/
typedef enum
{
Expand All @@ -82,10 +83,11 @@ typedef enum
IBUS_BUTTON5_MASK = 1 << 12,

/* The next few modifiers are used by XKB, so we skip to the end.
* Bits 15 - 23 are currently unused. Bit 29 is used internally.
* Bits 15 - 22 are currently unused. Bit 29 is used internally.
*/

/* ibus mask */
IBUS_PREFILTER_MASK= 1 << 23,
IBUS_HANDLED_MASK = 1 << 24,
IBUS_FORWARD_MASK = 1 << 25,
IBUS_IGNORED_MASK = IBUS_FORWARD_MASK,
Expand All @@ -96,7 +98,7 @@ typedef enum

IBUS_RELEASE_MASK = 1 << 30,

IBUS_MODIFIER_MASK = 0x5f001fff
IBUS_MODIFIER_MASK = 0x5f801fff
} IBusModifierType;

/**
Expand All @@ -112,6 +114,7 @@ typedef enum
* @IBUS_CAP_SYNC_PROCESS_KEY: Asynchronous process key events are not
* supported and the ibus_engine_forward_key_event() should not be
* used for the return value of #IBusEngine::process_key_event().
* @IBUS_CAP_PREFILTER: ibus is compiled with prefilter support.
*
* Capability flags of UI.
*/
Expand All @@ -124,6 +127,7 @@ typedef enum {
IBUS_CAP_SURROUNDING_TEXT = 1 << 5,
IBUS_CAP_OSK = 1 << 6,
IBUS_CAP_SYNC_PROCESS_KEY = 1 << 7,
IBUS_CAP_PREFILTER = 1 << 8,
} IBusCapabilite;

/**
Expand Down