From 769bddb9e3c01f1d3fe1f36bf87ecdbdb25e7095 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 10 May 2025 15:54:55 +0200 Subject: [PATCH] Do generate wxEVT_CHAR for Ctrl-Letter even in non US layouts Use the key translated to the US layout by XKB and not the actual character produced by the key in the current layout when determining whether to generate wxEVT_CHAR for key presses with Ctrl or not. This ensures that we produce the expected events for Ctrl-Latter in all layouts and not just the ones using Latin letters. See #25384, #25385. (cherry picked from commit 57c33bb9edb226648bbde1b4425ccaa932cf46a7) --- docs/changes.txt | 1 + src/gtk/window.cpp | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 824dda5a7f..bf2e679c63 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -267,6 +267,7 @@ wxGTK: - Fix handling total window size with GNOME with X11 (#25348). - Fix height of read-only wxBitmapComboBox (#25468). - Fix wxGLCanvas scale when using EGL/Wayland in high DPI (Popax21, #23733). +- Fix missing wxEVT_CHAR for Ctrl-Letter in non-US layouts (#25384). - Show system default window buttons under Wayland (#25562). wxMSW diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 6a71e39d2d..171dddddf8 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -1388,20 +1388,21 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), // etc). if ( eventChar.ControlDown() ) { - if ( uniChar >= 'a' && uniChar <= 'z' ) - uniChar = toupper(uniChar); + // We should already have the corresponding key in US layout, + // translated from GTK using XKB, in the event. + long keyCode = event.m_keyCode; - if ( (uniChar >= 'A' && uniChar <= 'Z') || - uniChar == '[' || - uniChar == '\\' || - uniChar == ']' || - uniChar == '^' || - uniChar == '_' ) + if ( (keyCode >= 'A' && keyCode <= 'Z') || + keyCode == '[' || + keyCode == '\\' || + keyCode == ']' || + keyCode == '^' || + keyCode == '_' ) { // Convert to ASCII control character. - uniChar &= 0x1f; + keyCode &= 0x1f; } - else if ( uniChar != ' ' ) + else if ( keyCode != ' ' ) { // For the printable characters other than Space (for which // we still do generate CHAR event, for compatibility with @@ -1413,9 +1414,9 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), break; } - eventChar.m_keyCode = uniChar; + eventChar.m_keyCode = keyCode; #if wxUSE_UNICODE - eventChar.m_uniChar = uniChar; + eventChar.m_uniChar = keyCode; #endif // wxUSE_UNICODE } else // Not a control character.