From 2ab6dd934478bfe63315034f1a2f365585d38242 Mon Sep 17 00:00:00 2001 From: Zi Ree Date: Wed, 3 Aug 2022 13:56:01 +0200 Subject: [PATCH] Linux SDL2 - make keyboard input work for the CEF plugin, still a couple funky keys left to deal with later --- indra/llwindow/llkeyboardsdl2.cpp | 26 ++++---- indra/media_plugins/cef/CMakeLists.txt | 13 ++++ indra/media_plugins/cef/media_plugin_cef.cpp | 66 +++++++++----------- 3 files changed, 58 insertions(+), 47 deletions(-) diff --git a/indra/llwindow/llkeyboardsdl2.cpp b/indra/llwindow/llkeyboardsdl2.cpp index d14c5b97a6..402feed1d5 100644 --- a/indra/llwindow/llkeyboardsdl2.cpp +++ b/indra/llwindow/llkeyboardsdl2.cpp @@ -565,22 +565,26 @@ U32 LLKeyboardSDL::mapSDL2toWin( U32 aSymbol ) mSDL2_to_Win[ SDLK_ESCAPE ] = (U32)WindowsVK::VK_ESCAPE; mSDL2_to_Win[ SDLK_DELETE ] = (U32)WindowsVK::VK_DELETE; - mSDL2_to_Win[ SDLK_KP_PERIOD ] = (U32)WindowsVK::VK_OEM_PERIOD; // VK_DECIMAL? mSDL2_to_Win[ SDLK_KP_DIVIDE ] = (U32)WindowsVK::VK_DIVIDE; mSDL2_to_Win[ SDLK_KP_MULTIPLY] = (U32)WindowsVK::VK_MULTIPLY; mSDL2_to_Win[ SDLK_KP_MINUS ] = (U32)WindowsVK::VK_OEM_MINUS; // VK_SUBSTRACT? mSDL2_to_Win[ SDLK_KP_PLUS ] = (U32)WindowsVK::VK_OEM_PLUS; // VK_ADD? mSDL2_to_Win[ SDLK_KP_ENTER ] = (U32)WindowsVK::VK_RETURN; - mSDL2_to_Win[ SDLK_KP_0 ] = (U32)WindowsVK::VK_NUMPAD0; - mSDL2_to_Win[ SDLK_KP_1 ] = (U32)WindowsVK::VK_NUMPAD1; - mSDL2_to_Win[ SDLK_KP_2 ] = (U32)WindowsVK::VK_NUMPAD2; - mSDL2_to_Win[ SDLK_KP_3 ] = (U32)WindowsVK::VK_NUMPAD3; - mSDL2_to_Win[ SDLK_KP_4 ] = (U32)WindowsVK::VK_NUMPAD4; - mSDL2_to_Win[ SDLK_KP_5 ] = (U32)WindowsVK::VK_NUMPAD5; - mSDL2_to_Win[ SDLK_KP_6 ] = (U32)WindowsVK::VK_NUMPAD6; - mSDL2_to_Win[ SDLK_KP_7 ] = (U32)WindowsVK::VK_NUMPAD7; - mSDL2_to_Win[ SDLK_KP_8 ] = (U32)WindowsVK::VK_NUMPAD8; - mSDL2_to_Win[ SDLK_KP_9 ] = (U32)WindowsVK::VK_NUMPAD9; + + // map numpad keys as best we can, mapping to VK_NUMPADx will break things + // for SDL2, so we use the actual functions + mSDL2_to_Win[ SDLK_KP_0 ] = (U32)WindowsVK::VK_INSERT; // VK_NUMPAD0 + mSDL2_to_Win[ SDLK_KP_1 ] = (U32)WindowsVK::VK_END; // VK_NUMPAD1 + mSDL2_to_Win[ SDLK_KP_2 ] = (U32)WindowsVK::VK_DOWN; // VK_NUMPAD2 + mSDL2_to_Win[ SDLK_KP_3 ] = (U32)WindowsVK::VK_NEXT; // VK_NUMPAD3 + mSDL2_to_Win[ SDLK_KP_4 ] = (U32)WindowsVK::VK_LEFT; // VK_NUMPAD4 + mSDL2_to_Win[ SDLK_KP_5 ] = (U32)WindowsVK::VK_NUMPAD5; // has no function + mSDL2_to_Win[ SDLK_KP_6 ] = (U32)WindowsVK::VK_RIGHT; // VK_NUMPAD6 + mSDL2_to_Win[ SDLK_KP_7 ] = (U32)WindowsVK::VK_HOME; // VK_NUMPAD7 + mSDL2_to_Win[ SDLK_KP_8 ] = (U32)WindowsVK::VK_UP; // VK_NUMPAD8 + mSDL2_to_Win[ SDLK_KP_9 ] = (U32)WindowsVK::VK_PRIOR; // VK_NUMPAD9 + + mSDL2_to_Win[ SDLK_KP_PERIOD ] = (U32)WindowsVK::VK_DELETE; // VK_OEM_PERIOD; // ? diff --git a/indra/media_plugins/cef/CMakeLists.txt b/indra/media_plugins/cef/CMakeLists.txt index c81a2f0385..d99884d8a2 100644 --- a/indra/media_plugins/cef/CMakeLists.txt +++ b/indra/media_plugins/cef/CMakeLists.txt @@ -87,6 +87,19 @@ add_library(media_plugin_cef # ${MEDIA_PLUGIN_BASE_LIBRARIES} #) +if (SDL_FOUND) + message("SDL_FOUND") + set_property(TARGET media_plugin_cef + PROPERTY COMPILE_DEFINITIONS LL_SDL=1 + ) +endif () +if (SDL2_FOUND) +message("SDL2_FOUND") +set_property(TARGET media_plugin_cef + PROPERTY COMPILE_DEFINITIONS LL_SDL2=1 LL_SDL=1 + ) +endif () + target_link_libraries(media_plugin_cef ${media_plugin_cef_LINK_LIBRARIES} ) diff --git a/indra/media_plugins/cef/media_plugin_cef.cpp b/indra/media_plugins/cef/media_plugin_cef.cpp index 465a571d6c..8f789279bc 100644 --- a/indra/media_plugins/cef/media_plugin_cef.cpp +++ b/indra/media_plugins/cef/media_plugin_cef.cpp @@ -1051,30 +1051,27 @@ void MediaPluginCEF::keyEvent(dullahan::EKeyEvent key_event, LLSD native_key_dat // Keyboard handling for Linux. #if LL_LINUX -#if SDL2USED && 0 - uint32_t native_key = (uint32_t)(native_key_data["virtual_key"].asInteger()); - uint32_t windows_virtual_key = (uint32_t)(native_key_data["virtual_key_win"].asInteger()); - uint32_t modifiers = (uint32_t)(native_key_data["modifiers"].asInteger()); - std::string inputtype = native_key_data["input_type"].asString(); +#if LL_SDL2 - if( native_key == '\n' ) - native_key = '\r'; - if(windows_virtual_key =='\n' ) - windows_virtual_key = '\r'; + uint32_t native_virtual_key = (uint32_t)(native_key_data["virtual_key"].asInteger()); // this is actually the SDL event.key.keysym.sym; + uint32_t native_virtual_key_win = (uint32_t)(native_key_data["virtual_key_win"].asInteger()); + uint32_t native_modifiers = (uint32_t)(native_key_data["modifiers"].asInteger()); - if( inputtype == "textinput" ) - key_event = dullahan::KE_KEY_CHAR; + // only for non-printable keysyms, the actual text input is done in unicodeInput() below + if (native_virtual_key <= 0x1b || native_virtual_key >= 0x7f) + { + // set keypad flag, not sure if this even does anything + bool keypad = false; + if (native_virtual_key_win >= 0x60 && native_virtual_key_win <= 0x6f) + { + keypad = true; + } - mCEFLib->nativeKeyboardEventSDL2(key_event, native_key, windows_virtual_key, modifiers, false ); - - // Slightly hacky :| To make CEF honor enter (eg to accept form input) we've to not only send KE_KEY_UP/KE_KEY_DOWN - // but also a KE_KEY_CHAR event. - // Note that we cannot blindly send a KE_CHAR for each KE_KEY_UP. Doing so will create bogus keyboard input (like % for cursor left). - // Adding this just in llwindowsdl does not seem to fire an appropriate unicodeInput event down below, thus repeat this check here again :( - if( dullahan::KE_KEY_UP == key_event && native_key == '\r' ) - mCEFLib->nativeKeyboardEventSDL2(dullahan::KE_KEY_CHAR, native_key, windows_virtual_key, modifiers, false ); - - #else + // yes, we send native_virtual_key_win twice because native_virtual_key breaks it + mCEFLib->nativeKeyboardEventSDL2(key_event, native_virtual_key_win, native_virtual_key_win, native_modifiers, keypad); + } + +#else uint32_t native_scan_code = (uint32_t)(native_key_data["sdl_sym"].asInteger()); uint32_t native_virtual_key = (uint32_t)(native_key_data["virtual_key"].asInteger()); @@ -1082,8 +1079,9 @@ void MediaPluginCEF::keyEvent(dullahan::EKeyEvent key_event, LLSD native_key_dat if( native_scan_code == '\n' ) native_scan_code = '\r'; mCEFLib->nativeKeyboardEvent(key_event, native_scan_code, native_virtual_key, native_modifiers); -#endif -#endif + +#endif // LL_SDL2 +#endif // LL_LINUX // }; @@ -1115,22 +1113,18 @@ void MediaPluginCEF::unicodeInput(std::string event, LLSD native_key_data = LLSD U64 lparam = ll_U32_from_sd(native_key_data["l_param"]); mCEFLib->nativeKeyboardEventWin(msg, wparam, lparam); #endif + #if LL_LINUX -#if SDL2USED && 0 - uint32_t native_key = (uint32_t)(native_key_data["virtual_key"].asInteger()); - uint32_t windows_virtual_key = (uint32_t)(native_key_data["virtual_key_win"].asInteger()); - uint32_t modifiers = (uint32_t)(native_key_data["modifiers"].asInteger()); - std::string inputtype = native_key_data["input_type"].asString(); +# if LL_SDL2 - if( native_key == '\n' ) - native_key = '\r'; - if(windows_virtual_key =='\n' ) - windows_virtual_key = '\r'; + uint32_t native_scan_code = (uint32_t)(native_key_data["sdl_sym"].asInteger()); + uint32_t native_virtual_key = (uint32_t)(native_key_data["virtual_key"].asInteger()); + uint32_t native_modifiers = (uint32_t)(native_key_data["modifiers"].asInteger()); - mCEFLib->nativeKeyboardEventSDL2(dullahan::KE_KEY_CHAR, native_key, windows_virtual_key, modifiers, false ); -#endif -#endif -// + mCEFLib->nativeKeyboardEvent(dullahan::KE_KEY_DOWN, native_scan_code, native_virtual_key, native_modifiers); + +#endif // LL_SDL2 +#endif // LL_LINUX }; ////////////////////////////////////////////////////////////////////////////////