2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <events/event-handler.h>
23 #include <Ecore_Input.h>
24 #include <ecore-wl-render-surface.h>
29 #ifndef DALI_PROFILE_UBUNTU
31 #include <vconf-keys.h>
32 #endif // DALI_PROFILE_UBUNTU
34 #ifdef DALI_ELDBUS_AVAILABLE
36 #endif // DALI_ELDBUS_AVAILABLE
38 #include <dali/public-api/common/vector-wrapper.h>
39 #include <dali/public-api/events/touch-point.h>
40 #include <dali/public-api/events/key-event.h>
41 #include <dali/public-api/events/wheel-event.h>
42 #include <dali/integration-api/debug.h>
43 #include <dali/integration-api/events/key-event-integ.h>
44 #include <dali/integration-api/events/touch-event-integ.h>
45 #include <dali/integration-api/events/hover-event-integ.h>
46 #include <dali/integration-api/events/wheel-event-integ.h>
49 #include <events/gesture-manager.h>
50 #include <window-render-surface.h>
51 #include <clipboard-impl.h>
53 #include <physical-keyboard-impl.h>
54 #include <style-monitor-impl.h>
55 #include <base/core-event-interface.h>
56 #include <virtual-keyboard.h>
67 #if defined(DEBUG_ENABLED)
70 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
71 Integration::Log::Filter* gClientMessageLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_CLIENT_MESSAGE");
72 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
73 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
74 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
75 } // unnamed namespace
83 const char* BUS = "org.enlightenment.wm-screen-reader";
84 const char* INTERFACE = "org.tizen.GestureNavigation";
85 const char* PATH = "/org/tizen/GestureNavigation";
87 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
89 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
91 #ifdef DALI_ELDBUS_AVAILABLE
92 // DBus gesture string matching lists.
93 // TODO: This needs moving to its own module.
94 const char * ElDBusAccessibilityFingerCountStrings[] =
100 const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
105 GESTURE_TYPE_SINGLE_TAP,
106 GESTURE_TYPE_DOUBLE_TAP,
107 GESTURE_TYPE_TRIPLE_TAP
109 struct GestureTypeTable
112 const GestureType type;
114 GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
116 { "Hover", GESTURE_TYPE_HOVER },
117 { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
118 { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
119 { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
121 const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
124 SUB_GESTURE_TYPE_NONE,
125 SUB_GESTURE_TYPE_FLICK
127 struct SubGestureTypeTable
130 const SubGestureType type;
132 SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
134 { "Flick", SUB_GESTURE_TYPE_FLICK }
136 const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
137 enum GestureDirection
139 GESTURE_DIRECTION_NONE,
140 GESTURE_DIRECTION_UP,
141 GESTURE_DIRECTION_DOWN,
142 GESTURE_DIRECTION_LEFT,
143 GESTURE_DIRECTION_RIGHT,
144 GESTURE_DIRECTION_UP_RETURN,
145 GESTURE_DIRECTION_DOWN_RETURN,
146 GESTURE_DIRECTION_LEFT_RETURN,
147 GESTURE_DIRECTION_RIGHT_RETURN
149 struct GestureDirectionTable
152 const GestureDirection direction;
154 GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
156 { "Up", GESTURE_DIRECTION_UP },
157 { "Down", GESTURE_DIRECTION_DOWN },
158 { "Left", GESTURE_DIRECTION_LEFT },
159 { "Right", GESTURE_DIRECTION_RIGHT },
160 { "UpReturn", GESTURE_DIRECTION_UP_RETURN },
161 { "DownReturn", GESTURE_DIRECTION_DOWN_RETURN },
162 { "LeftReturn", GESTURE_DIRECTION_LEFT_RETURN },
163 { "RightReturn", GESTURE_DIRECTION_RIGHT_RETURN }
165 const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
166 #endif // DALI_ELDBUS_AVAILABLE
169 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
170 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
171 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
172 * @return the Ecore_IMF_Keyboard_Modifiers output.
174 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
176 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
179 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
181 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
184 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
186 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
189 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
191 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
194 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
196 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
199 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
201 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
204 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
208 // Copied from x server
209 static unsigned int GetCurrentMilliSeconds(void)
214 static clockid_t clockid;
218 #ifdef CLOCK_MONOTONIC_COARSE
219 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
220 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
222 clockid = CLOCK_MONOTONIC_COARSE;
226 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
228 clockid = CLOCK_MONOTONIC;
235 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
237 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
240 gettimeofday(&tv, NULL);
241 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
244 #ifndef DALI_PROFILE_UBUNTU
245 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
246 #endif // DALI_PROFILE_UBUNTU
248 } // unnamed namespace
250 // Impl to hide EFL implementation.
251 struct EventHandler::Impl
253 // Construction & Destruction
258 Impl( EventHandler* handler, Ecore_Wl_Window* window )
259 : mHandler( handler ),
260 mEcoreEventHandler(),
262 #ifdef DALI_ELDBUS_AVAILABLE
263 , mSystemConnection( NULL )
264 #endif // DALI_ELDBUS_AVAILABLE
266 // Only register for touch and key events if we have a window
269 // Register Touch events
270 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
271 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
272 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
273 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
275 // Register Mouse wheel events
276 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
278 // Register Focus events
279 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
280 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
282 // Register Key events
283 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
284 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
286 // Register Selection event - clipboard selection
287 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
288 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
290 // Register Rotate event
291 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
293 // Register Detent event
294 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
296 #ifndef DALI_PROFILE_UBUNTU
297 // Register Vconf notify - font name and size
298 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
299 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
300 #endif // DALI_PROFILE_UBUNTU
302 #ifdef DALI_ELDBUS_AVAILABLE
303 // Initialize ElDBus.
304 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
307 EcoreElDBusInitialisation( handler );
309 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
310 #endif // DALI_ELDBUS_AVAILABLE
319 #ifndef DALI_PROFILE_UBUNTU
320 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
321 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
322 #endif // DALI_PROFILE_UBUNTU
324 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
326 ecore_event_handler_del( *iter );
329 #ifdef DALI_ELDBUS_AVAILABLE
330 // Close down ElDBus connections.
331 if( mSystemConnection )
333 eldbus_connection_unref( mSystemConnection );
335 #endif // DALI_ELDBUS_AVAILABLE
340 /////////////////////////////////////////////////////////////////////////////////////////////////
342 /////////////////////////////////////////////////////////////////////////////////////////////////
345 * Called when a touch down is received.
347 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
349 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
350 EventHandler* handler( (EventHandler*)data );
352 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
354 PointState::Type state ( PointState::DOWN );
356 // Check if the buttons field is set and ensure it's the primary touch button.
357 // If this event was triggered by buttons other than the primary button (used for touch), then
358 // just send an interrupted event to Core.
359 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
361 state = PointState::INTERRUPTED;
364 Integration::Point point;
365 point.SetDeviceId( touchEvent->multi.device );
366 point.SetState( state );
367 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
368 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
369 point.SetPressure( touchEvent->multi.pressure );
370 point.SetAngle( Degree( touchEvent->multi.angle ) );
371 handler->SendEvent( point, touchEvent->timestamp );
374 return ECORE_CALLBACK_PASS_ON;
378 * Called when a touch up is received.
380 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
382 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
383 EventHandler* handler( (EventHandler*)data );
385 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
387 Integration::Point point;
388 point.SetDeviceId( touchEvent->multi.device );
389 point.SetState( PointState::UP );
390 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
391 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
392 point.SetPressure( touchEvent->multi.pressure );
393 point.SetAngle( Degree( touchEvent->multi.angle ) );
394 handler->SendEvent( point, touchEvent->timestamp );
397 return ECORE_CALLBACK_PASS_ON;
401 * Called when a touch up is received.
403 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
405 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
407 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT Ecore_Event_Mouse_Wheel: direction: %d, modifiers: %d, x: %d, y: %d, z: %d\n", mouseWheelEvent->direction, mouseWheelEvent->modifiers, mouseWheelEvent->x, mouseWheelEvent->y, mouseWheelEvent->z);
409 EventHandler* handler( (EventHandler*)data );
410 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
412 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
413 handler->SendWheelEvent( wheelEvent );
415 return ECORE_CALLBACK_PASS_ON;
419 * Called when a touch motion is received.
421 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
423 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
424 EventHandler* handler( (EventHandler*)data );
426 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
428 Integration::Point point;
429 point.SetDeviceId( touchEvent->multi.device );
430 point.SetState( PointState::MOTION );
431 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
432 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
433 point.SetPressure( touchEvent->multi.pressure );
434 point.SetAngle( Degree( touchEvent->multi.angle ) );
435 handler->SendEvent( point, touchEvent->timestamp );
438 return ECORE_CALLBACK_PASS_ON;
441 /////////////////////////////////////////////////////////////////////////////////////////////////
443 /////////////////////////////////////////////////////////////////////////////////////////////////
446 * Called when a key down is received.
448 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
450 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
452 EventHandler* handler( (EventHandler*)data );
453 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
454 bool eventHandled( false );
456 // If a device key then skip ecore_imf_context_filter_event.
457 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
459 Ecore_IMF_Context* imfContext = NULL;
460 Dali::ImfManager imfManager( ImfManager::Get() );
463 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
468 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
469 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
470 ecoreKeyDownEvent.keyname = keyEvent->keyname;
471 ecoreKeyDownEvent.key = keyEvent->key;
472 ecoreKeyDownEvent.string = keyEvent->string;
473 ecoreKeyDownEvent.compose = keyEvent->compose;
474 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
475 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
476 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
477 #ifdef ECORE_IMF_1_13
478 ecoreKeyDownEvent.dev_name = "";
479 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
480 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
481 #endif // ECORE_IMF_1_13
483 eventHandled = ecore_imf_context_filter_event( imfContext,
484 ECORE_IMF_EVENT_KEY_DOWN,
485 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
487 // If the event has not been handled by IMF then check if we should reset our IMF context
490 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
491 !strcmp( keyEvent->keyname, "Return" ) ||
492 !strcmp( keyEvent->keyname, "KP_Enter" ) )
494 ecore_imf_context_reset( imfContext );
500 // If the event wasn't handled then we should send a key event.
503 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
505 std::string keyName( keyEvent->keyname );
506 std::string keyString( "" );
507 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
508 keyCode = (keyCode == -1) ? 0 : keyCode;
509 int modifier( keyEvent->modifiers );
510 unsigned long time = keyEvent->timestamp;
511 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
512 keyCode = atoi(keyEvent->keyname + 8);
514 // Ensure key event string is not NULL as keys like SHIFT have a null string.
515 if ( keyEvent->string )
517 keyString = keyEvent->string;
520 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Down);
521 handler->SendEvent( keyEvent );
525 return ECORE_CALLBACK_PASS_ON;
529 * Called when a key up is received.
531 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
533 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
535 EventHandler* handler( (EventHandler*)data );
536 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
537 bool eventHandled( false );
539 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
540 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
542 Ecore_IMF_Context* imfContext = NULL;
543 Dali::ImfManager imfManager( ImfManager::Get() );
546 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
551 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
552 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
553 ecoreKeyUpEvent.keyname = keyEvent->keyname;
554 ecoreKeyUpEvent.key = keyEvent->key;
555 ecoreKeyUpEvent.string = keyEvent->string;
556 ecoreKeyUpEvent.compose = keyEvent->compose;
557 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
558 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
559 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
561 eventHandled = ecore_imf_context_filter_event( imfContext,
562 ECORE_IMF_EVENT_KEY_UP,
563 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
567 // If the event wasn't handled then we should send a key event.
570 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
572 std::string keyName( keyEvent->keyname );
573 std::string keyString( "" );
574 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
575 keyCode = (keyCode == -1) ? 0 : keyCode;
576 int modifier( keyEvent->modifiers );
577 unsigned long time = keyEvent->timestamp;
578 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
579 keyCode = atoi(keyEvent->keyname + 8);
581 // Ensure key event string is not NULL as keys like SHIFT have a null string.
582 if ( keyEvent->string )
584 keyString = keyEvent->string;
587 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
588 handler->SendEvent( keyEvent );
592 return ECORE_CALLBACK_PASS_ON;
595 /////////////////////////////////////////////////////////////////////////////////////////////////
597 /////////////////////////////////////////////////////////////////////////////////////////////////
600 * Called when the window gains focus.
602 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
604 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
605 EventHandler* handler( (EventHandler*)data );
607 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
609 // If the window gains focus and we hid the keyboard then show it again.
610 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
612 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
614 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
616 Dali::ImfManager imfManager( ImfManager::Get() );
619 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
620 if( imfManagerImpl.RestoreAfterFocusLost() )
622 imfManagerImpl.Activate();
626 Dali::Clipboard clipboard = Clipboard::Get();
627 clipboard.HideClipboard();
630 return ECORE_CALLBACK_PASS_ON;
634 * Called when the window loses focus.
636 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
638 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
639 EventHandler* handler( (EventHandler*)data );
641 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
643 // If the window loses focus then hide the keyboard.
644 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
646 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
648 Dali::ImfManager imfManager( ImfManager::Get() );
651 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
652 if( imfManagerImpl.RestoreAfterFocusLost() )
654 imfManagerImpl.Deactivate();
659 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
660 Dali::Clipboard clipboard = Clipboard::Get();
663 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
664 clipBoardImpl.HideClipboard(true);
668 return ECORE_CALLBACK_PASS_ON;
672 * Called when the window is damaged.
674 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
676 return ECORE_CALLBACK_PASS_ON;
680 * Called when the window properties are changed.
681 * We are only interested in the font change.
685 /////////////////////////////////////////////////////////////////////////////////////////////////
686 // Drag & Drop Callbacks
687 /////////////////////////////////////////////////////////////////////////////////////////////////
690 * Called when a dragged item enters our window's bounds.
691 * This is when items are dragged INTO our window.
693 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
695 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
697 return ECORE_CALLBACK_PASS_ON;
701 * Called when a dragged item is moved within our window.
702 * This is when items are dragged INTO our window.
704 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
706 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
708 return ECORE_CALLBACK_PASS_ON;
712 * Called when a dragged item leaves our window's bounds.
713 * This is when items are dragged INTO our window.
715 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
717 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
719 return ECORE_CALLBACK_PASS_ON;
723 * Called when the dragged item is dropped within our window's bounds.
724 * This is when items are dragged INTO our window.
726 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
728 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
730 return ECORE_CALLBACK_PASS_ON;
734 * Called when a dragged item is moved from our window and the target window has done processing it.
735 * This is when items are dragged FROM our window.
737 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
739 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
740 return ECORE_CALLBACK_PASS_ON;
744 * Called when a dragged item is moved from our window and the target window has sent us a status.
745 * This is when items are dragged FROM our window.
747 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
749 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
750 return ECORE_CALLBACK_PASS_ON;
754 * Called when the client messages (i.e. the accessibility events) are received.
756 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
758 return ECORE_CALLBACK_PASS_ON;
762 /////////////////////////////////////////////////////////////////////////////////////////////////
763 // ElDBus Accessibility Callbacks
764 /////////////////////////////////////////////////////////////////////////////////////////////////
766 #ifdef DALI_ELDBUS_AVAILABLE
767 // Callback for Ecore ElDBus accessibility events.
768 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
770 EventHandler* handler = static_cast< EventHandler* >( context );
771 // Ignore any accessibility events when paused.
772 if( handler->mPaused )
777 if( !handler->mAccessibilityAdaptor )
779 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
783 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
784 if( !accessibilityAdaptor )
786 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
792 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
795 // The string defines the arg-list's respective types.
796 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
798 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
801 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
803 // Create a touch point object.
804 TouchPoint::State touchPointState( TouchPoint::Down );
807 touchPointState = TouchPoint::Down; // Mouse down.
809 else if( state == 1 )
811 touchPointState = TouchPoint::Motion; // Mouse move.
813 else if( state == 2 )
815 touchPointState = TouchPoint::Up; // Mouse up.
819 touchPointState = TouchPoint::Interrupted; // Error.
822 // Send touch event to accessibility adaptor.
823 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
825 // Perform actions based on received gestures.
826 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
827 switch( gestureValue )
829 case 0: // OneFingerHover
832 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
835 case 1: // TwoFingersHover
837 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
838 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
841 case 2: // ThreeFingersHover
843 // Read from top item on screen continuously.
844 accessibilityAdaptor->HandleActionReadFromTopEvent();
847 case 3: // OneFingerFlickLeft
849 // Move to previous item.
850 accessibilityAdaptor->HandleActionReadPreviousEvent();
853 case 4: // OneFingerFlickRight
855 // Move to next item.
856 accessibilityAdaptor->HandleActionReadNextEvent();
859 case 5: // OneFingerFlickUp
861 // Move to previous item.
862 accessibilityAdaptor->HandleActionPreviousEvent();
865 case 6: // OneFingerFlickDown
867 // Move to next item.
868 accessibilityAdaptor->HandleActionNextEvent();
871 case 7: // TwoFingersFlickUp
873 // Scroll up the list.
874 accessibilityAdaptor->HandleActionScrollUpEvent();
877 case 8: // TwoFingersFlickDown
879 // Scroll down the list.
880 accessibilityAdaptor->HandleActionScrollDownEvent();
883 case 9: // TwoFingersFlickLeft
885 // Scroll left to the previous page
886 accessibilityAdaptor->HandleActionPageLeftEvent();
889 case 10: // TwoFingersFlickRight
891 // Scroll right to the next page
892 accessibilityAdaptor->HandleActionPageRightEvent();
895 case 11: // ThreeFingersFlickLeft
900 case 12: // ThreeFingersFlickRight
905 case 13: // ThreeFingersFlickUp
910 case 14: // ThreeFingersFlickDown
915 case 15: // OneFingerSingleTap
918 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
921 case 16: // OneFingerDoubleTap
923 // Activate selected item / active edit mode.
924 accessibilityAdaptor->HandleActionActivateEvent();
927 case 17: // OneFingerTripleTap
930 accessibilityAdaptor->HandleActionZoomEvent();
933 case 18: // TwoFingersSingleTap
935 // Pause/Resume current speech
936 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
939 case 19: // TwoFingersDoubleTap
941 // Start/Stop current action
942 accessibilityAdaptor->HandleActionStartStopEvent();
945 case 20: // TwoFingersTripleTap
947 // Read information from indicator
948 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
951 case 21: // ThreeFingersSingleTap
953 // Read from top item on screen continuously.
954 accessibilityAdaptor->HandleActionReadFromTopEvent();
957 case 22: // ThreeFingersDoubleTap
959 // Read from next item continuously.
960 accessibilityAdaptor->HandleActionReadFromNextEvent();
963 case 23: // ThreeFingersTripleTap
968 case 24: // OneFingerFlickLeftReturn
970 // Scroll up to the previous page
971 accessibilityAdaptor->HandleActionPageUpEvent();
974 case 25: // OneFingerFlickRightReturn
976 // Scroll down to the next page
977 accessibilityAdaptor->HandleActionPageDownEvent();
980 case 26: // OneFingerFlickUpReturn
982 // Move to the first item on screen
983 accessibilityAdaptor->HandleActionMoveToFirstEvent();
986 case 27: // OneFingerFlickDownReturn
988 // Move to the last item on screen
989 accessibilityAdaptor->HandleActionMoveToLastEvent();
992 case 28: // TwoFingersFlickLeftReturn
997 case 29: // TwoFingersFlickRightReturn
1002 case 30: // TwoFingersFlickUpReturn
1007 case 31: // TwoFingersFlickDownReturn
1012 case 32: // ThreeFingersFlickLeftReturn
1017 case 33: // ThreeFingersFlickRightReturn
1022 case 34: // ThreeFingersFlickUpReturn
1027 case 35: // ThreeFingersFlickDownReturn
1035 void EcoreElDBusInitialisation( void *handle )
1037 Eldbus_Object *object;
1038 Eldbus_Proxy *manager;
1040 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1042 DALI_LOG_ERROR( "Unable to get system bus\n" );
1045 object = eldbus_object_get( mSystemConnection, BUS, PATH );
1048 DALI_LOG_ERROR( "Getting object failed\n" );
1052 manager = eldbus_proxy_get( object, INTERFACE );
1055 DALI_LOG_ERROR( "Getting proxy failed\n" );
1059 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1061 DALI_LOG_ERROR( "No signal handler returned\n" );
1064 #endif // DALI_ELDBUS_AVAILABLE
1067 * Called when the source window notifies us the content in clipboard is selected.
1069 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1071 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1072 return ECORE_CALLBACK_PASS_ON;
1076 * Called when the source window sends us about the selected content.
1077 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1079 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1081 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1082 return ECORE_CALLBACK_PASS_ON;
1086 * Called when the source window notifies us the content in clipboard is selected.
1088 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1090 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1092 Dali::Clipboard clipboard = Clipboard::Get();
1095 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1096 clipBoardImpl.ExcuteBuffered( true, event );
1098 return ECORE_CALLBACK_PASS_ON;
1102 * Called when the source window sends us about the selected content.
1103 * For example, when item is selected in the clipboard.
1105 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1107 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1109 EventHandler* handler( (EventHandler*)data );
1110 Dali::Clipboard clipboard = Clipboard::Get();
1111 char *selectionData = NULL;
1114 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1115 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1117 if ( selectionData && handler->mClipboardEventNotifier )
1119 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1120 std::string content( selectionData, strlen(selectionData) );
1122 clipboardEventNotifier.SetContent( content );
1123 clipboardEventNotifier.EmitContentSelectedSignal();
1125 return ECORE_CALLBACK_PASS_ON;
1129 * Called when rotate event is recevied
1131 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1133 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1135 EventHandler* handler( (EventHandler*)data );
1136 Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1138 if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1140 return ECORE_CALLBACK_PASS_ON;
1143 RotationEvent rotationEvent;
1144 rotationEvent.angle = ev->angle;
1145 rotationEvent.winResize = 0;
1146 rotationEvent.width = ev->w;
1147 rotationEvent.height = ev->h;
1148 handler->SendRotationPrepareEvent( rotationEvent );
1150 return ECORE_CALLBACK_PASS_ON;
1154 * Called when detent event is recevied
1156 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1158 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1159 EventHandler* handler( (EventHandler*)data );
1160 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1161 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1162 int timeStamp = e->timestamp;
1164 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1165 handler->SendWheelEvent( wheelEvent );
1166 return ECORE_CALLBACK_PASS_ON;
1169 /////////////////////////////////////////////////////////////////////////////////////////////////
1171 /////////////////////////////////////////////////////////////////////////////////////////////////
1173 * Called when a font name is changed.
1175 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1177 EventHandler* handler = static_cast<EventHandler*>( data );
1178 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1182 * Called when a font size is changed.
1184 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1186 EventHandler* handler = static_cast<EventHandler*>( data );
1187 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1191 EventHandler* mHandler;
1192 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1193 Ecore_Wl_Window* mWindow;
1194 #ifdef DALI_ELDBUS_AVAILABLE
1195 Eldbus_Connection* mSystemConnection;
1196 #endif // DALI_ELDBUS_AVAILABLE
1199 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1200 : mCoreEventInterface( coreEventInterface ),
1201 mGestureManager( gestureManager ),
1202 mStyleMonitor( StyleMonitor::Get() ),
1203 mDamageObserver( damageObserver ),
1204 mRotationObserver( NULL ),
1205 mDragAndDropDetector( dndDetector ),
1206 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1207 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1208 mClipboard( Clipboard::Get() ),
1212 Ecore_Wl_Window* window = 0;
1214 // this code only works with the Ecore RenderSurface so need to downcast
1215 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1218 window = ecoreSurface->GetWlWindow();
1221 mImpl = new Impl(this, window);
1224 EventHandler::~EventHandler()
1231 mGestureManager.Stop();
1234 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1238 timeStamp = GetCurrentMilliSeconds();
1241 Integration::TouchEvent touchEvent;
1242 Integration::HoverEvent hoverEvent;
1243 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1244 if(type != Integration::TouchEventCombiner::DispatchNone )
1246 DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.deviceId, point.state, point.local.x, point.local.y);
1248 // First the touch and/or hover event & related gesture events are queued
1249 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1251 mCoreEventInterface.QueueCoreEvent( touchEvent );
1252 mGestureManager.SendEvent(touchEvent);
1255 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1257 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1260 // Next the events are processed with a single call into Core
1261 mCoreEventInterface.ProcessCoreEvents();
1265 void EventHandler::SendEvent(KeyEvent& keyEvent)
1267 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1268 if ( physicalKeyboard )
1270 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
1272 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1276 // Create KeyEvent and send to Core.
1277 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
1278 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
1279 mCoreEventInterface.QueueCoreEvent( event );
1280 mCoreEventInterface.ProcessCoreEvents();
1283 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1285 // Create WheelEvent and send to Core.
1286 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1287 mCoreEventInterface.QueueCoreEvent( event );
1288 mCoreEventInterface.ProcessCoreEvents();
1291 void EventHandler::SendEvent( StyleChange::Type styleChange )
1293 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1294 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1297 void EventHandler::SendEvent( const DamageArea& area )
1299 mDamageObserver.OnDamaged( area );
1302 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1304 if( mRotationObserver != NULL )
1306 mRotationObserver->OnRotationPrepare( event );
1307 mRotationObserver->OnRotationRequest();
1311 void EventHandler::SendRotationRequestEvent( )
1313 // No need to separate event into prepare and request in wayland
1316 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1318 Integration::Point convertedPoint( point );
1319 SendEvent(convertedPoint, timeStamp);
1322 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1324 SendWheelEvent( wheelEvent );
1327 void EventHandler::FeedKeyEvent( KeyEvent& event )
1332 void EventHandler::FeedEvent( Integration::Event& event )
1334 mCoreEventInterface.QueueCoreEvent( event );
1335 mCoreEventInterface.ProcessCoreEvents();
1338 void EventHandler::Reset()
1342 // Any touch listeners should be told of the interruption.
1343 Integration::TouchEvent event;
1344 Integration::Point point;
1345 point.SetState( PointState::INTERRUPTED );
1346 event.AddPoint( point );
1348 // First the touch event & related gesture events are queued
1349 mCoreEventInterface.QueueCoreEvent( event );
1350 mGestureManager.SendEvent( event );
1352 // Next the events are processed with a single call into Core
1353 mCoreEventInterface.ProcessCoreEvents();
1356 void EventHandler::Pause()
1362 void EventHandler::Resume()
1368 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1370 mDragAndDropDetector = detector;
1373 void EventHandler::SetRotationObserver( RotationObserver* observer )
1375 mRotationObserver = observer;
1378 } // namespace Adaptor
1380 } // namespace Internal