Skip to content

fix(linux): fix context after typing Bksp with Wayland#15820

Open
ermshiperete wants to merge 8 commits intomasterfrom
fix/linux/context
Open

fix(linux): fix context after typing Bksp with Wayland#15820
ermshiperete wants to merge 8 commits intomasterfrom
fix/linux/context

Conversation

@ermshiperete
Copy link
Copy Markdown
Contributor

@ermshiperete ermshiperete commented Apr 7, 2026

This fixes a problem with the context after typing Backspace when using Wayland. Wayland uses double-buffering for the text, so we always have to commit after making changes.

This is only a partial fix, so we can't really test this.

Part-of: #15676
Test-bot: skip

This fixes a problem with the context after typing Backspace when
using Wayland. Wayland uses double-buffering for the text, so we always
have to commit after making changes.

Fixes: #15676
@ermshiperete ermshiperete requested a review from mcdurdin April 7, 2026 12:45
@github-project-automation github-project-automation bot moved this to Todo in Keyman Apr 7, 2026
@keymanapp-test-bot keymanapp-test-bot bot added the user-test-missing User tests have not yet been defined for the PR label Apr 7, 2026
@keymanapp-test-bot
Copy link
Copy Markdown

keymanapp-test-bot bot commented Apr 7, 2026

User Test Results

Test specification and instructions

User tests are not required

@keymanapp-test-bot keymanapp-test-bot bot added this to the A19S26 milestone Apr 7, 2026
g_autofree gchar *debug = NULL;
g_message("DAR: %s - %s", __FUNCTION__, debug = debug_utf8_with_codepoints(string));
text = ibus_text_new_from_static_string (string);
text = ibus_text_new_from_string(string);
Copy link
Copy Markdown
Contributor Author

@ermshiperete ermshiperete Apr 7, 2026

Choose a reason for hiding this comment

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

Devin.ai:

Change from ibus_text_new_from_static_string to ibus_text_new_from_string is a correct fix

The old code on line 639 used ibus_text_new_from_static_string(string), which assumes the passed string has static lifetime (it does NOT copy the string). However, all three callers of commit_string pass dynamically-allocated strings: ibus_keyman_set_text passes D-Bus text, process_output_action passes g_ucs4_to_utf8 output, and commit_current_queue_item passes char_buffer. The change to ibus_text_new_from_string (which copies the string) is strictly safer. The old code likely worked in practice because ibus_engine_commit_text serializes the text over D-Bus before returning, but it was technically incorrect.

Copy link
Copy Markdown
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.

I think this LGTM. Might be good to add a comment on the purpose of is_dirty

Comment thread linux/ibus-keyman/src/engine.c Outdated
Comment on lines +249 to +254
// This is not always reliable: IBus detects whether the client supports
// surrounding text by emitting the retrieve-surrounding signal. As part
// of that signal handler, the client is expected to call
// gtk_im_context_set_surrounding_with_selection which ends calling
// set_context_if_needed at a time when IBus is still in the middle of
// determining whether the client supports surrounding text.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels a little bit like a TODO item. Is there some way we can make this reliable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've no idea how we could improve this on the keyman side.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like re-entrancy is the main problem? I am not 100% clear if you are saying that when we call this, that process may not have completed, or something else?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Things are complicated. I tried to add a document that shows the sequence of events, but that doesn't give the full picture either. I thought we could use engine->enabled to know if IBus has the correct values, but that's still too early. When we get a keydown we can rely on the value from client_supports_surrounding_text , but before that we might get a wrong value.

Anyway, what I'm trying to say with this code comment is that client_supports_surrounding_text is not always 100% reliable and getting a wrong value is expected and hasn't caused problems IIRC.

Copy link
Copy Markdown
Contributor Author

@ermshiperete ermshiperete Apr 16, 2026

Choose a reason for hiding this comment

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

(see also the sequence diagram which I added to this PR.)

Comment thread linux/ibus-keyman/src/engine.c Outdated
ermshiperete and others added 2 commits April 8, 2026 18:08
Co-authored-by: Marc Durdin <marc@durdin.net>
@keymanapp-test-bot keymanapp-test-bot bot removed the user-test-missing User tests have not yet been defined for the PR label Apr 8, 2026
@keyman-server keyman-server modified the milestones: A19S26, A19S27 Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants