Browse Source

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
pull/19/head
jean-pierre charras 3 months ago
parent
commit
11cc86e586
  1. 37
      common/tool/tool_dispatcher.cpp
  2. 8
      common/widgets/lib_tree.cpp
  3. 10
      common/widgets/widget_hotkey_list.cpp
  4. 8
      eeschema/widgets/hierarchy_pane.cpp
  5. 35
      include/tool/tool_dispatcher.h

37
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()
{

8
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;

10
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;

8
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;

35
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

Loading…
Cancel
Save