From 11cc86e586441f02e79af0b88c2576cb82670257 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 10 Sep 2025 18:10:43 +0200 Subject: [PATCH] Hotkey handling: disable usage of keyboard modifier flag wxMOD_ALTGR. The flag wxMOD_ALTGR is defined in wxWidgets as wxMOD_CONTROL|wxMOD_ALT So AltGr key cannot used as modifier key because it is the same as Alt key + Ctrl key that is already handled. So the previous code did not work with modifiers Alt key, Ctrl key and Altgr key Fixes https://gitlab.com/kicad/code/kicad/-/issues/21696 --- common/tool/tool_dispatcher.cpp | 37 +++++++++++++++++++++++++++ common/widgets/lib_tree.cpp | 8 ++++-- common/widgets/widget_hotkey_list.cpp | 10 +++++--- eeschema/widgets/hierarchy_pane.cpp | 8 ++++-- include/tool/tool_dispatcher.h | 35 +++---------------------- 5 files changed, 59 insertions(+), 39 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 5c1030ccd3..98b08d9944 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -158,6 +158,43 @@ TOOL_DISPATCHER::~TOOL_DISPATCHER() delete st; } +int TOOL_DISPATCHER::decodeModifiers( const wxKeyboardState* aState ) +{ + int mods = 0; + int wxmods = aState->GetModifiers(); + + // Returns the state of key modifiers (Alt, Ctrl and so on). Be carefull: + // the flag wxMOD_ALTGR is defined in wxWidgets as wxMOD_CONTROL|wxMOD_ALT + // So AltGr key cannot used as modifier key because it is the same as Alt key + Ctrl key. +#if CAN_USE_ALTGR_KEY + if( wxmods & wxMOD_ALTGR ) + mods |= MD_ALTGR; + else +#endif + { + if( wxmods & wxMOD_CONTROL ) + mods |= MD_CTRL; + + if( wxmods & wxMOD_ALT ) + mods |= MD_ALT; + } + + if( wxmods & wxMOD_SHIFT ) + mods |= MD_SHIFT; + +#ifdef wxMOD_META + if( wxmods & wxMOD_META ) + mods |= MD_META; +#endif + +#ifdef wxMOD_WIN + if( wxmods & wxMOD_WIN ) + mods |= MD_SUPER; +#endif + + return mods; +} + void TOOL_DISPATCHER::ResetState() { diff --git a/common/widgets/lib_tree.cpp b/common/widgets/lib_tree.cpp index e2c94c9be3..79a2d54b1f 100644 --- a/common/widgets/lib_tree.cpp +++ b/common/widgets/lib_tree.cpp @@ -642,9 +642,13 @@ void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke ) int mods = aKeyStroke.GetModifiers(); - if( mods & wxMOD_ALTGR ) - hotkey += MD_ALTGR; + // the flag wxMOD_ALTGR is defined in wxWidgets as wxMOD_CONTROL|wxMOD_ALT + // So AltGr key cannot used as modifier key because it is the same as Alt key + Ctrl key. +#if CAN_USE_ALTGR_KEY + if( wxmods & wxMOD_ALTGR ) + mods |= MD_ALTGR; else +#endif { if( mods & wxMOD_CONTROL ) hotkey += MD_CTRL; diff --git a/common/widgets/widget_hotkey_list.cpp b/common/widgets/widget_hotkey_list.cpp index 58da3318c3..c2dfdf08fd 100644 --- a/common/widgets/widget_hotkey_list.cpp +++ b/common/widgets/widget_hotkey_list.cpp @@ -670,7 +670,7 @@ long WIDGET_HOTKEY_LIST::MapKeypressToKeycode( const wxKeyEvent& aEvent ) { long key = aEvent.GetKeyCode(); bool is_tab = aEvent.IsKeyInCategory( WXK_CATEGORY_TAB ); - +printf("key %lX mod %X\n", key, aEvent.GetModifiers()); if( key == WXK_ESCAPE ) { return 0; @@ -698,9 +698,13 @@ long WIDGET_HOTKEY_LIST::MapKeypressToKeycode( const wxKeyEvent& aEvent ) if( ( mods & wxMOD_SHIFT ) && ( keyIsLetter || key > 256 || key == 9 || key == 32 ) ) key |= MD_SHIFT; - if( mods & wxMOD_ALTGR ) - key |= MD_ALTGR; + // the flag wxMOD_ALTGR is defined in wxWidgets as wxMOD_CONTROL|wxMOD_ALT + // So AltGr key cannot used as modifier key because it is the same as Alt key + Ctrl key. + #if CAN_USE_ALTGR_KEY + if( wxmods & wxMOD_ALTGR ) + mods |= MD_ALTGR; else + #endif { if( mods & wxMOD_CONTROL ) key |= MD_CTRL; diff --git a/eeschema/widgets/hierarchy_pane.cpp b/eeschema/widgets/hierarchy_pane.cpp index 8d2f483092..d3d1461aa4 100644 --- a/eeschema/widgets/hierarchy_pane.cpp +++ b/eeschema/widgets/hierarchy_pane.cpp @@ -548,9 +548,13 @@ void HIERARCHY_PANE::onCharHook( wxKeyEvent& aKeyStroke ) int mods = aKeyStroke.GetModifiers(); - if( mods & wxMOD_ALTGR ) - hotkey += MD_ALTGR; + // the flag wxMOD_ALTGR is defined in wxWidgets as wxMOD_CONTROL|wxMOD_ALT + // So AltGr key cannot used as modifier key because it is the same as Alt key + Ctrl key. +#if CAN_USE_ALTGR_KEY + if( wxmods & wxMOD_ALTGR ) + mods |= MD_ALTGR; else +#endif { if( mods & wxMOD_CONTROL ) hotkey += MD_CTRL; diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index d2fc758ee6..9307890ef6 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -84,38 +84,9 @@ private: /// Returns the instance of VIEW, used by the application. KIGFX::VIEW* getView(); - /// Saves the state of key modifiers (Alt, Ctrl and so on). - static int decodeModifiers( const wxKeyboardState* aState ) - { - int mods = 0; - int wxmods = aState->GetModifiers(); - - if( wxmods & wxMOD_ALTGR ) - mods |= MD_ALTGR; - else - { - if( wxmods & wxMOD_CONTROL ) - mods |= MD_CTRL; - - if( wxmods & wxMOD_ALT ) - mods |= MD_ALT; - } - - if( wxmods & wxMOD_SHIFT ) - mods |= MD_SHIFT; - -#ifdef wxMOD_META - if( wxmods & wxMOD_META ) - mods |= MD_META; -#endif - -#ifdef wxMOD_WIN - if( wxmods & wxMOD_WIN ) - mods |= MD_SUPER; -#endif - - return mods; - } + /// Returns the state of key modifiers (Alt, Ctrl and so on) as OR'ed list + /// of bits (MD_CTRL, MD_ALT ...) + static int decodeModifiers( const wxKeyboardState* aState ); private: /// The time threshold for a mouse button press that distinguishes between a single mouse