Merge "Add cancel event flag in Key up event" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl2 / window-base-ecore-wl2.cpp
index 40e27c3..a258f6c 100755 (executable)
@@ -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,31 @@ void GetDeviceSubclass( Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subcl
   }
 }
 
+
+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;
+    }
+  }
+}
+
 /////////////////////////////////////////////////////////////////////////////////////////////////
 // Window Callbacks
 /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -473,6 +505,38 @@ static Eina_Bool EcoreEventEffectEnd(void *data, int type, void *event)
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
+// Keyboard Repeat Settings Changed Callbacks
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+static Eina_Bool EcoreEventSeatKeyboardRepeatChanged(void *data, int type, void *event)
+{
+   Ecore_Wl2_Event_Seat_Keyboard_Repeat_Changed *keyboardRepeat = static_cast<Ecore_Wl2_Event_Seat_Keyboard_Repeat_Changed*>( event );
+   WindowBaseEcoreWl2* windowBase = static_cast< WindowBaseEcoreWl2* >( data );
+   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::EcoreEventSeatKeyboardRepeatChanged, id[ %d ]\n", keyboardRepeat->id );
+   if( windowBase )
+   {
+     windowBase->OnKeyboardRepeatSettingsChanged();
+   }
+
+  return ECORE_CALLBACK_RENEW;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+// Keymap Changed Callbacks
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+static Eina_Bool EcoreEventSeatKeymapChanged(void *data, int type, void *event)
+{
+  WindowBaseEcoreWl2* windowBase = static_cast< WindowBaseEcoreWl2* >( data );
+  if( windowBase )
+  {
+    windowBase->KeymapChanged( data, type, event );
+  }
+
+  return ECORE_CALLBACK_RENEW;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
 // Font Callbacks
 /////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -629,6 +693,7 @@ WindowBaseEcoreWl2::WindowBaseEcoreWl2( Dali::PositionSize positionSize, Any sur
   mEventQueue( NULL ),
   mTizenPolicy( NULL ),
   mTizenDisplayPolicy( NULL ),
+  mKeyMap( NULL ),
   mSupportedAuxiliaryHints(),
   mAuxiliaryHints(),
   mNotificationLevel( -1 ),
@@ -640,6 +705,8 @@ WindowBaseEcoreWl2::WindowBaseEcoreWl2( Dali::PositionSize positionSize, Any sur
   mBrightness( 0 ),
   mBrightnessChangeState( 0 ),
   mBrightnessChangeDone( true ),
+  mVisible( true ),
+  mWindowPositionSize( positionSize ),
   mOwnSurface( false ),
   mMoveResizeSerial( 0 ),
   mLastSubmittedMoveResizeSerial( 0 )
@@ -713,41 +780,44 @@ void WindowBaseEcoreWl2::Initialize( PositionSize positionSize, Any surface, boo
 
   SetTransparency( isTransparent );
 
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this ) );
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_FOCUS_IN,                    EcoreEventWindowFocusIn,             this ) );
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_FOCUS_OUT,                   EcoreEventWindowFocusOut,            this ) );
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_OUTPUT_TRANSFORM,            EcoreEventOutputTransform,           this ) );
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_IGNORE_OUTPUT_TRANSFORM,     EcoreEventIgnoreOutputTransform,     this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_WINDOW_ICONIFY_STATE_CHANGE,  EcoreEventWindowIconifyStateChanged, this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_FOCUS_IN,                     EcoreEventWindowFocusIn,             this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_FOCUS_OUT,                    EcoreEventWindowFocusOut,            this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_OUTPUT_TRANSFORM,             EcoreEventOutputTransform,           this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_IGNORE_OUTPUT_TRANSFORM,      EcoreEventIgnoreOutputTransform,     this ) );
 
   // Register Rotate event
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_WINDOW_ROTATE,               EcoreEventRotate,                    this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_WINDOW_ROTATE,                EcoreEventRotate,                    this ) );
 
   // Register Configure event
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_WINDOW_CONFIGURE,            EcoreEventConfigure,                 this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_WINDOW_CONFIGURE,             EcoreEventConfigure,                 this ) );
 
   // Register Touch events
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN,               EcoreEventMouseButtonDown,           this ) );
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP,                 EcoreEventMouseButtonUp,             this ) );
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE,                      EcoreEventMouseButtonMove,           this ) );
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL,             EcoreEventMouseButtonCancel,         this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN,                EcoreEventMouseButtonDown,           this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP,                  EcoreEventMouseButtonUp,             this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE,                       EcoreEventMouseButtonMove,           this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL,              EcoreEventMouseButtonCancel,         this ) );
 
   // Register Mouse wheel events
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL,                     EcoreEventMouseWheel,                this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL,                      EcoreEventMouseWheel,                this ) );
 
   // Register Detent event
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE,                   EcoreEventDetentRotation,            this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE,                    EcoreEventDetentRotation,            this ) );
 
   // Register Key events
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN,                        EcoreEventKeyDown,                   this ) );
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_KEY_UP,                          EcoreEventKeyUp,                     this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN,                         EcoreEventKeyDown,                   this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_KEY_UP,                           EcoreEventKeyUp,                     this ) );
 
   // Register Selection event - clipboard selection
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_DATA_SOURCE_SEND,            EcoreEventDataSend,                  this ) );
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_SELECTION_DATA_READY,        EcoreEventDataReceive,               this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_DATA_SOURCE_SEND,             EcoreEventDataSend,                  this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_SELECTION_DATA_READY,         EcoreEventDataReceive,               this ) );
 
   // Register Effect Start/End event
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_EFFECT_START,                EcoreEventEffectStart,               this ) );
-  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_EFFECT_END,                  EcoreEventEffectEnd,                 this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_EFFECT_START,                 EcoreEventEffectStart,               this ) );
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_EFFECT_END,                   EcoreEventEffectEnd,                 this ) );
+
+  // Register Keyboard repeat event
+  mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_SEAT_KEYBOARD_REPEAT_CHANGED, EcoreEventSeatKeyboardRepeatChanged, this ) );
 
   // Register Vconf notify - font name and size
   vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, this );
@@ -776,6 +846,15 @@ void WindowBaseEcoreWl2::Initialize( PositionSize positionSize, Any surface, boo
     }
   }
 
+  Ecore_Wl2_Input* ecoreWlInput = ecore_wl2_input_default_input_get( display );
+
+  if( ecoreWlInput )
+  {
+    mKeyMap = ecore_wl2_input_keymap_get( ecoreWlInput );
+
+    mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL2_EVENT_SEAT_KEYMAP_CHANGED, EcoreEventSeatKeymapChanged, this ) );
+  }
+
   // get auxiliary hint
   Eina_List* hints = ecore_wl2_window_aux_hints_supported_get( mEcoreWindow );
   if( hints )
@@ -892,6 +971,9 @@ void WindowBaseEcoreWl2::OnRotation( void* data, int type, void* event )
       rotationEvent.height = ev->w;
     }
 
+    mWindowPositionSize.width = rotationEvent.width;
+    mWindowPositionSize.height = rotationEvent.height;
+
     mRotationSignal.Emit( rotationEvent );
   }
 }
@@ -1041,7 +1123,7 @@ void WindowBaseEcoreWl2::OnDetentRotation( void* data, int type, void* event )
   int direction = ( detentEvent->direction == ECORE_DETENT_DIRECTION_CLOCKWISE ) ? 1 : -1;
   int timeStamp = detentEvent->timestamp;
 
-  WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2( 0.0f, 0.0f ), direction, timeStamp );
+  WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, direction, 0, Vector2( 0.0f, 0.0f ), 0, timeStamp );
 
   mWheelEventSignal.Emit( wheelEvent );
 }
@@ -1071,7 +1153,15 @@ void WindowBaseEcoreWl2::OnKeyDown( void* data, int type, void* event )
       logicalKey = keyEvent->key;
     }
 
-    int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname );
+    int keyCode = 0;
+    GetKeyCode( keyName, keyCode ); // Get key code dynamically.
+
+    if( keyCode == 0 )
+    {
+      // Get a specific key code from dali key look up table.
+      keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname );
+    }
+
     keyCode = ( keyCode == -1 ) ? 0 : keyCode;
     int modifier( keyEvent->modifiers );
     unsigned long time = keyEvent->timestamp;
@@ -1108,6 +1198,15 @@ void WindowBaseEcoreWl2::OnKeyUp( void* data, int type, void* event )
   {
     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnKeyUp\n" );
 
+#if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR) && (ECORE_VERSION_MINOR >= 23)
+    // Cancel processing flag is sent because this key event will combine with the previous key. So, the event should not actually perform anything.
+    if( keyEvent->event_flags & ECORE_EVENT_FLAG_CANCEL )
+    {
+      DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnKeyUp: This event flag indicates the event is canceled. \n" );
+      return;
+    }
+#endif // Since ecore 1.23 version
+
     std::string keyName( keyEvent->keyname );
     std::string logicalKey( "" );
     std::string keyString( "" );
@@ -1125,7 +1224,15 @@ void WindowBaseEcoreWl2::OnKeyUp( void* data, int type, void* event )
       logicalKey = keyEvent->key;
     }
 
-    int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname );
+    int keyCode = 0;
+    GetKeyCode( keyName, keyCode ); // Get key code dynamically.
+
+    if( keyCode == 0 )
+    {
+      // Get a specific key code from dali key look up table.
+      keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname );
+    }
+
     keyCode = ( keyCode == -1 ) ? 0 : keyCode;
     int modifier( keyEvent->modifiers );
     unsigned long time = keyEvent->timestamp;
@@ -1194,6 +1301,22 @@ void WindowBaseEcoreWl2::OnTransitionEffectEvent( DevelWindow::EffectState state
   mTransitionEffectEventSignal.Emit( state, type );
 }
 
+void WindowBaseEcoreWl2::OnKeyboardRepeatSettingsChanged()
+{
+  mKeyboardRepeatSettingsChangedSignal.Emit();
+}
+
+void WindowBaseEcoreWl2::KeymapChanged(void *data, int type, void *event)
+{
+  Ecore_Wl2_Event_Seat_Keymap_Changed *changed = static_cast<Ecore_Wl2_Event_Seat_Keymap_Changed*>( event );
+  DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::KeymapChanged, keymap id[ %d ]\n", changed->id );
+  Ecore_Wl2_Input* ecoreWlInput = ecore_wl2_input_default_input_get( changed->display );
+  if( ecoreWlInput )
+  {
+    mKeyMap = ecore_wl2_input_keymap_get( ecoreWlInput );
+  }
+}
+
 void WindowBaseEcoreWl2::RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
 {
   if( strcmp( interface, tizen_policy_interface.name ) == 0 )
@@ -1259,6 +1382,24 @@ void WindowBaseEcoreWl2::DisplayPolicyBrightnessChangeDone( void* data, struct t
   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
 }
 
+void WindowBaseEcoreWl2::GetKeyCode( std::string keyName, int32_t& keyCode )
+{
+  xkb_keysym_t sym = XKB_KEY_NoSymbol;
+  KeyCodeMap foundKeyCode;
+
+  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( mKeyMap, FindKeyCode, &foundKeyCode );
+  keyCode = static_cast< int32_t >( foundKeyCode.keyCode );
+}
+
 Any WindowBaseEcoreWl2::GetNativeWindow()
 {
   return mEcoreWindow;
@@ -1419,16 +1560,19 @@ bool WindowBaseEcoreWl2::IsEglWindowRotationSupported()
 
 void WindowBaseEcoreWl2::Move( PositionSize positionSize )
 {
+  mWindowPositionSize = positionSize;
   ecore_wl2_window_position_set( mEcoreWindow, positionSize.x, positionSize.y );
 }
 
 void WindowBaseEcoreWl2::Resize( PositionSize positionSize )
 {
+  mWindowPositionSize = positionSize;
   ecore_wl2_window_geometry_set( mEcoreWindow, positionSize.x, positionSize.y, positionSize.width, positionSize.height );
 }
 
 void WindowBaseEcoreWl2::MoveResize( PositionSize positionSize )
 {
+  mWindowPositionSize = positionSize;
   ecore_wl2_window_sync_geometry_set( mEcoreWindow, ++mMoveResizeSerial, positionSize.x, positionSize.y, positionSize.width, positionSize.height );
 }
 
@@ -1457,7 +1601,7 @@ void WindowBaseEcoreWl2::Activate()
 void WindowBaseEcoreWl2::SetAvailableAnlges( const std::vector< int >& angles )
 {
   int rotations[4] = { 0 };
-  DALI_LOG_RELEASE_INFO( "WindowBaseEcoreWl2::SetAvailableAnlges, angle's count: %d\n", angles.size() );
+  DALI_LOG_RELEASE_INFO( "WindowBaseEcoreWl2::SetAvailableAnlges, angle's count: %d, angles\n", angles.size() );
   for( std::size_t i = 0; i < angles.size(); ++i )
   {
     rotations[i] = static_cast< int >( angles[i] );
@@ -1468,7 +1612,6 @@ void WindowBaseEcoreWl2::SetAvailableAnlges( const std::vector< int >& angles )
 
 void WindowBaseEcoreWl2::SetPreferredAngle( int angle )
 {
-  DALI_LOG_RELEASE_INFO( "WindowBaseEcoreWl2::SetPreferredAngle, angle: %d\n", angle );
   ecore_wl2_window_preferred_rotation_set( mEcoreWindow, angle );
 }
 
@@ -1479,11 +1622,18 @@ void WindowBaseEcoreWl2::SetAcceptFocus( bool accept )
 
 void WindowBaseEcoreWl2::Show()
 {
+  if( !mVisible )
+  {
+    ecore_wl2_window_geometry_set( mEcoreWindow, mWindowPositionSize.x, mWindowPositionSize.y, mWindowPositionSize.width, mWindowPositionSize.height );
+  }
+  mVisible = true;
+
   ecore_wl2_window_show( mEcoreWindow );
 }
 
 void WindowBaseEcoreWl2::Hide()
 {
+  mVisible = false;
   ecore_wl2_window_hide( mEcoreWindow );
 }
 
@@ -2229,6 +2379,8 @@ void WindowBaseEcoreWl2::CreateWindow( PositionSize positionSize )
     DALI_ASSERT_ALWAYS( 0 && "Failed to get display" );
   }
 
+  ecore_wl2_display_sync( display );
+
   mEcoreWindow = ecore_wl2_window_new( display, NULL, positionSize.x, positionSize.y, positionSize.width, positionSize.height );
 
   if ( mEcoreWindow == 0 )
@@ -2251,6 +2403,16 @@ void WindowBaseEcoreWl2::SetParent( WindowBase* parentWinBase )
   ecore_wl2_window_parent_set( mEcoreWindow, ecoreParent );
 }
 
+int WindowBaseEcoreWl2::CreateFrameRenderedSyncFence()
+{
+  return wl_egl_window_tizen_create_commit_sync_fd( mEglWindow );
+}
+
+int WindowBaseEcoreWl2::CreateFramePresentedSyncFence()
+{
+  return wl_egl_window_tizen_create_presentation_sync_fd( mEglWindow );
+}
+
 } // namespace Adaptor
 
 } // namespace Internal