From e977975008efe6d8df8d31f6f046d37b5d73d9ae Mon Sep 17 00:00:00 2001 From: Zi Ree Date: Sun, 2 Oct 2022 15:54:26 +0200 Subject: [PATCH] FIRE-32123 - Attempt to fix Right-ALT cam on non AltGr keyboards while still keeping AltGr on AltGr keyboards working --- indra/llwindow/llkeyboardsdl2.cpp | 6 ++--- indra/llwindow/llwindowsdl2.cpp | 37 +++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/indra/llwindow/llkeyboardsdl2.cpp b/indra/llwindow/llkeyboardsdl2.cpp index 402feed1d5..594818869e 100644 --- a/indra/llwindow/llkeyboardsdl2.cpp +++ b/indra/llwindow/llkeyboardsdl2.cpp @@ -148,7 +148,7 @@ void LLKeyboardSDL::resetMaskKeys() mKeyLevel[KEY_CONTROL] = TRUE; } - if(mask & KMOD_LALT) + if(mask & KMOD_ALT) { mKeyLevel[KEY_ALT] = TRUE; } @@ -170,7 +170,7 @@ MASK LLKeyboardSDL::updateModifiers(const U32 mask) out_mask |= MASK_CONTROL; } - if(mask & KMOD_LALT) + if(mask & KMOD_ALT) { out_mask |= MASK_ALT; } @@ -252,7 +252,7 @@ MASK LLKeyboardSDL::currentMask(BOOL for_mouse_event) result |= MASK_SHIFT; if (mask & KMOD_CTRL) result |= MASK_CONTROL; - if (mask & KMOD_LALT) + if (mask & KMOD_ALT) result |= MASK_ALT; // For keyboard events, consider Meta keys equivalent to Control diff --git a/indra/llwindow/llwindowsdl2.cpp b/indra/llwindow/llwindowsdl2.cpp index c1f99e39f9..cd5d3b362e 100644 --- a/indra/llwindow/llwindowsdl2.cpp +++ b/indra/llwindow/llwindowsdl2.cpp @@ -1779,11 +1779,40 @@ void LLWindowSDL::gatherInput() static U64 previousTextinputTime = 0; SDL_Event event; + // mask to apply to the keyup/keydown modifiers to handle AltGr keys correctly + static U32 altGrMask = 0x00; + // Handle all outstanding SDL events while (SDL_PollEvent(&event)) { switch (event.type) { + case SDL_SYSWMEVENT: + { + XEvent e = event.syswm.msg->msg.x11.event; + if (e.type == KeyPress || e.type == KeyRelease) + { + // XLookupKeysym doesn't work here because of the weird way the "index" is + // tied to the e->state and we don't get the necessary information at this + // point, so we use the more expensive XLookupString which apparently knows + // all of the secrets inside XKeyEvent. -Zi + + KeySym ks; + static char str[256+1]; + XLookupString((XKeyEvent *) &e, str, 256, &ks, nullptr); + + if (ks == XK_ISO_Level3_Shift) + { + altGrMask = KMOD_RALT; + } + else if (ks == XK_Alt_R) + { + altGrMask = 0x00; + } + } + break; + } + case SDL_MOUSEWHEEL: if( event.wheel.y != 0 ) mCallbacks->handleScrollWheel(this, -event.wheel.y); @@ -1803,6 +1832,10 @@ void LLWindowSDL::gatherInput() { auto string = utf8str_to_utf16str( event.text.text ); mKeyModifiers = gKeyboard->currentMask( FALSE ); + if (altGrMask) + { + mKeyModifiers &= ~MASK_ALT; + } mInputType = "textinput"; for( auto key: string ) { @@ -1821,7 +1854,7 @@ void LLWindowSDL::gatherInput() case SDL_KEYDOWN: mKeyVirtualKey = event.key.keysym.sym; - mKeyModifiers = event.key.keysym.mod; + mKeyModifiers = event.key.keysym.mod & (~altGrMask); mInputType = "keydown"; // treat all possible Enter/Return keys the same @@ -1863,7 +1896,7 @@ void LLWindowSDL::gatherInput() case SDL_KEYUP: mKeyVirtualKey = event.key.keysym.sym; - mKeyModifiers = event.key.keysym.mod; + mKeyModifiers = event.key.keysym.mod & (~altGrMask); mInputType = "keyup"; // treat all possible Enter/Return keys the same