From d188f5f7358c7e3682766647d63949d909764ae8 Mon Sep 17 00:00:00 2001 From: Wonsik Jung Date: Mon, 2 Dec 2019 15:54:30 +0900 Subject: [PATCH] [Tizen] Support to get KeyCode dynamically using xkbcommon API This reverts commit dda9b4a35ae448a0a23da50594719fc31dc71390. --- .../ecore-wl2/window-base-ecore-wl2.cpp | 86 +++++++++++++++++++++- .../ecore-wl2/window-base-ecore-wl2.h | 1 + 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp index e57dcb2..cbc31ab 100755 --- a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp +++ b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp @@ -63,6 +63,13 @@ const char* BUS = "org.enlightenment.wm-screen-reader"; const char* INTERFACE = "org.tizen.GestureNavigation"; const char* PATH = "/org/tizen/GestureNavigation"; +struct KeyCodeMap +{ + xkb_keysym_t keySym; + xkb_keycode_t keyCode; + bool isKeyCode; +}; + /** * Get the device name from the provided ecore key event */ @@ -198,6 +205,67 @@ void GetDeviceSubclass( Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subcl } } +static void FindKeyCode( struct xkb_keymap* keyMap, xkb_keycode_t key, void* data ) +{ + KeyCodeMap* foundKeyCode = static_cast< KeyCodeMap* >( data ); + if( foundKeyCode->isKeyCode ) + { + return; + } + + xkb_keysym_t keySym = foundKeyCode->keySym; + int nsyms = 0; + const xkb_keysym_t* symsOut = NULL; + + nsyms = xkb_keymap_key_get_syms_by_level( keyMap, key, 0, 0, &symsOut ); + + if( nsyms && symsOut ) + { + if( *symsOut == keySym ) + { + foundKeyCode->keyCode = key; + foundKeyCode->isKeyCode = true; + } + } +} + +static void GetKeyCode( std::string keyName, int32_t& keyCode ) +{ + xkb_keymap* keyMap = NULL; + xkb_keysym_t sym = XKB_KEY_NoSymbol; + KeyCodeMap foundKeyCode; + + Ecore_Wl2_Input* ecoreWlInput = NULL; + + Ecore_Wl2_Display* display = ecore_wl2_connected_display_get( NULL ); + ecoreWlInput = ecore_wl2_input_default_input_get( display ); + + if( !ecoreWlInput ) + { + DALI_LOG_ERROR( "Failed to get Ecore_Wl2_Input in WindowBaseEcoreWl2\n" ); + return; + } + + keyMap = ecore_wl2_input_keymap_get( ecoreWlInput ); + if( !keyMap ) + { + DALI_LOG_ERROR( "Failed to get keymap in WindowBaseEcoreWl2\n" ); + return; + } + + sym = xkb_keysym_from_name( keyName.c_str(), XKB_KEYSYM_NO_FLAGS ); + if( sym == XKB_KEY_NoSymbol ) + { + DALI_LOG_ERROR( "Failed to get keysym in WindowBaseEcoreWl2\n" ); + return; + } + + foundKeyCode.keySym = sym; + foundKeyCode.isKeyCode = false; + xkb_keymap_key_for_each( keyMap, FindKeyCode, &foundKeyCode ); + keyCode = static_cast< int32_t >( foundKeyCode.keyCode ); +} + ///////////////////////////////////////////////////////////////////////////////////////////////// // Window Callbacks ///////////////////////////////////////////////////////////////////////////////////////////////// @@ -1079,7 +1147,14 @@ void WindowBaseEcoreWl2::OnKeyDown( void* data, int type, void* event ) logicalKey = keyEvent->key; } - int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname ); + int keyCode = 0; + GetKeyCode( keyName, keyCode ); + + if( keyCode == 0 ) + { + keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname ); + } + keyCode = ( keyCode == -1 ) ? 0 : keyCode; int modifier( keyEvent->modifiers ); unsigned long time = keyEvent->timestamp; @@ -1133,7 +1208,14 @@ void WindowBaseEcoreWl2::OnKeyUp( void* data, int type, void* event ) logicalKey = keyEvent->key; } - int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname ); + int keyCode = 0; + GetKeyCode( keyName, keyCode ); + + if( keyCode == 0 ) + { + keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname ); + } + keyCode = ( keyCode == -1 ) ? 0 : keyCode; int modifier( keyEvent->modifiers ); unsigned long time = keyEvent->timestamp; diff --git a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h index 8aaa4eb..54e2dbd 100644 --- a/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h +++ b/dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h @@ -26,6 +26,7 @@ #include #include #include +#include #ifdef DALI_ELDBUS_AVAILABLE #include -- 2.7.4