AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.12k stars 2.26k forks source link

On Linux, KeyEventArgs.KeySymbol is null in KeyDown event for symbols on the number keys #14727

Open PermanentNovice opened 9 months ago

PermanentNovice commented 9 months ago

Describe the bug

The code:

textBox.KeyDown+=(s,e)=>
{
 if (e.KeySymbol==null)
 {
  Console.WriteLine("null");
 }
 else
 {
  Console.WriteLine(e.KeySymbol);
 }
};

To reproduce

Type '@' in the text box. On Windows, the console prints '@' as expected. On Linux, it prints 'null'.

The same is true for all the symbols on the keys from 1 to 0.

Expected behavior

Consistent behavior on Windows and Linux.

Environment

maxkatz6 commented 9 months ago

I am not a X11 expert, but it might be null, when XKeysymToString returns empty buffer: https://github.com/AvaloniaUI/Avalonia/blob/d2023a94e8410f9a88314e3404158c9e311fef3c/src/Avalonia.X11/X11Window.Ime.cs#L233-L237

If there is no better X11 API, we might not have much room to improve here.