TextBox is processing already handled events on Linux
Describe the bug
Under Linux OS, when explicitly handing a keydown event, in some cases the TextBox still processes the TextInput event.
Note that the repro example is handling the keydown event as handled, however the TextBox is still processing that input:
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.KeyModifiers.HasFlag(KeyModifiers.Control))
{
mLogTextBox.Text += "Pressed Ctrl+" + e.Key + Environment.NewLine;
e.Handled = true;
}
}
To Reproduce Steps to reproduce the behavior:
- Clone the following minimal example: https://github.com/danipen/LinuxHandleKeyDown
- Run the example.
- Hit Ctrl + 1 (or any other key combination that reproduces the issue).
- See that the textbox writes a 1 in the text and shouldn't.
Expected behavior
-
macOS and Windows OS are working as expected (when the
KeyDownevent is marked ase.Handled = true, theTextBoxdoesn't process thatTextInput. See the following video. https://user-images.githubusercontent.com/501613/196429137-dcc6ebb2-dcb5-414c-8f4b-836865ad23be.mov -
Only Linux OS reproduces the wrong behavior. See the following video. https://user-images.githubusercontent.com/501613/196429240-a2fee008-b8c0-47e0-bdf2-0d78b0f08514.mov
Screenshots

Desktop (please complete the following information):
- OS: Linux Ubuntu 20.04.
- Version 11.0.0-preview2
Additional context Note that there are several key combinations that reproduce the issue: Ctrl + + Ctrl + - Ctrl + 1 Ctrl + 9 Ctrl + / Ctrl + * Ctrl + < etc...
Note also that other similar key combinations doesn't repro the issue, such as Ctrl + 5
I encountered same problem while developed #8539 The problem in x11 is there: https://github.com/AvaloniaUI/Avalonia/blob/9a9339527791b84dac478e1142b033b9ba42e84e/src/Avalonia.X11/X11Window.Ime.cs#L95-L114
https://github.com/AvaloniaUI/Avalonia/blob/9a9339527791b84dac478e1142b033b9ba42e84e/src/Avalonia.X11/X11Window.Ime.cs#L159-L169
https://github.com/AvaloniaUI/Avalonia/blob/ae7298bf50df80f463ab9260535b39434fc5ebcc/src/Avalonia.X11/X11Window.Ime.cs#L116-L123
https://github.com/AvaloniaUI/Avalonia/blob/ae7298bf50df80f463ab9260535b39434fc5ebcc/src/Avalonia.X11/X11Window.cs#L749-L757
it is not possible to know if the event was handled by sendinput before call TriggerClassicTextInputEvent