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

Add prefilter flag #1

wants to merge 2 commits into from

Conversation

ermshiperete
Copy link
Collaborator

This PR adds a new IBUS_PREFILTER_MASK flag which the engine can set on the state. This allows engines to prefilter events and use that to control the order of the output even if some syntethic key events get interspersed between the input.

A scenario where this is necessary is in ibus-engine-keyman for applications that don't support surrounding text like Chrome/Chromium and gnome-terminal. For example with the IPA (SIL) keyboard, the users presses the 'n' key which produces 'n' output. Then the user presses ';'. The expected result is that the 'n' gets replaced by 'ŋ'. For applications that don't support surrounding text the engine has to forward a Backspace key event, followed by committing the new text 'ŋ'. However, since the key event gets processed asynchronously, it can happen that the new text gets committed before the Backspace key is processed, leading to the deletion of 'ŋ' instead of 'n'.

The IBUS_PREFILTER_MASK flag allows to solve this problem: when the engine receives a key press, it calls ibus_engine_forward_key_event() for the same key with the IBUS_PREFILTER_MASK flag set. Only when
it receives a key press with the IBUS_PREFILTER_MASK already set it will process the key. When it generates the Backspace key event it will forward it to ibus with the IBUS_PREFILTER_MASK flag already set. When it comes back to the engine it will be in the correct order.

Since IBUS_PREFILTER_MASK is a flag that will only ever get set by the engine it shouldn't break any existing engines.

This PR also adds IBUS_CAP_PREFILTER to IBusCapabilite. This allows engines to detect whether they are dealing with an ibus
version that was compiled with prefilter support.

This change adds a new `IBUS_PREFILTER_MASK` flag which the engine
can set on the state. This allows engines to prefilter events and
use that to control the order of the output even if some syntethic
key events get interspersed between the input.

A scenario where this is necessary is in ibus-engine-keyman for
applications that don't support surrounding text like Chrome/Chromium
and gnome-terminal. For example with the _IPA (SIL)_ keyboard, the
users presses the 'n' key which produces 'n' output. Then the user
presses ';'. The expected result is that the 'n' gets replaced by
'ŋ'. For applications that don't support surrounding text the
engine has to forward a Backspace key event, followed by committing
the new text 'ŋ'. However, since the key event gets processed
asynchronously, it can happen that the new text gets committed before
the Backspace key is processed, leading to the deletion of 'ŋ'
instead of 'n'.

The `IBUS_PREFILTER_MASK` flag allows to solve this problem: when the
engine receives a key press, it calls `ibus_engine_forward_key_event()`
for the same key with the `IBUS_PREFILTER_MASK` flag set. Only when
it receives a key press with the `IBUS_PREFILTER_MASK` already set it
will process the key. When it generates the Backspace key event it will
forward it to ibus with the `IBUS_PREFILTER_MASK` flag already set.
When it comes back to the engine it will be in the correct order.

Since `IBUS_PREFILTER_MASK` is a flag that will only ever get set by
the engine it shouldn't break any existing engines.
This allows engines to detect whether they are dealing with an ibus
version that was compiled with prefilter support.
Copy link
Member

@mcdurdin mcdurdin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ermshiperete
Copy link
Collaborator Author

Opened in ibus repo as ibus#2440.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants