Linux SDL2 - make keyboard input work for the CEF plugin, still a couple funky keys left to deal with later

master
Zi Ree 2022-08-03 13:56:01 +02:00
parent 2b6427e1ba
commit 2ab6dd9344
3 changed files with 58 additions and 47 deletions

View File

@ -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;
// ?

View File

@ -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}
)

View File

@ -1051,30 +1051,27 @@ void MediaPluginCEF::keyEvent(dullahan::EKeyEvent key_event, LLSD native_key_dat
// <FS:ND> 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 );
// <ND> 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
// </FS:ND>
};
@ -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
// </FS:ND>
mCEFLib->nativeKeyboardEvent(dullahan::KE_KEY_DOWN, native_scan_code, native_virtual_key, native_modifiers);
#endif // LL_SDL2
#endif // LL_LINUX
};
////////////////////////////////////////////////////////////////////////////////