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>
47 #include <dali/devel-api/events/key-event-devel.h>
50 #include <events/gesture-manager.h>
51 #include <window-render-surface.h>
52 #include <clipboard-impl.h>
54 #include <physical-keyboard-impl.h>
55 #include <style-monitor-impl.h>
56 #include <base/core-event-interface.h>
57 #include <virtual-keyboard.h>
68 #if defined(DEBUG_ENABLED)
71 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
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;
92 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
93 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
94 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
95 * @return the Ecore_IMF_Keyboard_Modifiers output.
97 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
99 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
102 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
104 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
107 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
109 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
112 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
114 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
117 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
119 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
122 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
124 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
127 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
131 // Copied from x server
132 static unsigned int GetCurrentMilliSeconds(void)
137 static clockid_t clockid;
141 #ifdef CLOCK_MONOTONIC_COARSE
142 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
143 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
145 clockid = CLOCK_MONOTONIC_COARSE;
149 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
151 clockid = CLOCK_MONOTONIC;
158 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
160 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
163 gettimeofday(&tv, NULL);
164 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
167 #ifndef DALI_PROFILE_UBUNTU
168 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
169 #endif // DALI_PROFILE_UBUNTU
172 * Get the device name from the provided ecore key event
174 void GetDeviceName( Ecore_Event_Key* keyEvent, std::string& result )
176 const char* ecoreDeviceName = ecore_device_name_get( keyEvent->dev );
178 if ( ecoreDeviceName )
180 result = ecoreDeviceName;
185 * Get the device class from the provided ecore key event
187 void GetDeviceClass( Ecore_Event_Key* keyEvent, DevelKeyEvent::DeviceClass::Type& deviceClass )
189 Ecore_Device_Class ecoreDeviceClass = ecore_device_class_get( keyEvent->dev );
191 switch( ecoreDeviceClass )
193 case ECORE_DEVICE_CLASS_SEAT:
195 deviceClass = DevelKeyEvent::DeviceClass::USER;
198 case ECORE_DEVICE_CLASS_KEYBOARD:
200 deviceClass = DevelKeyEvent::DeviceClass::KEYBOARD;
203 case ECORE_DEVICE_CLASS_MOUSE:
205 deviceClass = DevelKeyEvent::DeviceClass::MOUSE;
208 case ECORE_DEVICE_CLASS_TOUCH:
210 deviceClass = DevelKeyEvent::DeviceClass::TOUCH;
213 case ECORE_DEVICE_CLASS_PEN:
215 deviceClass = DevelKeyEvent::DeviceClass::PEN;
218 case ECORE_DEVICE_CLASS_POINTER:
220 deviceClass = DevelKeyEvent::DeviceClass::POINTER;
223 case ECORE_DEVICE_CLASS_GAMEPAD:
225 deviceClass = DevelKeyEvent::DeviceClass::GAMEPAD;
230 deviceClass = DevelKeyEvent::DeviceClass::NONE;
236 } // unnamed namespace
238 // Impl to hide EFL implementation.
239 struct EventHandler::Impl
241 // Construction & Destruction
246 Impl( EventHandler* handler, Ecore_Wl_Window* window )
247 : mHandler( handler ),
248 mEcoreEventHandler(),
250 #ifdef DALI_ELDBUS_AVAILABLE
251 , mSystemConnection( NULL )
252 #endif // DALI_ELDBUS_AVAILABLE
254 // Only register for touch and key events if we have a window
257 // Register Touch events
258 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
259 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
260 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
261 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
262 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, handler ) );
264 // Register Mouse wheel events
265 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
267 // Register Focus events
268 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
269 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
271 // Register Key events
272 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
273 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
275 // Register Selection event - clipboard selection
276 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
277 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
279 // Register Rotate event
280 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
282 // Register Detent event
283 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
285 #ifndef DALI_PROFILE_UBUNTU
286 // Register Vconf notify - font name and size
287 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
288 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
289 #endif // DALI_PROFILE_UBUNTU
291 #ifdef DALI_ELDBUS_AVAILABLE
292 // Initialize ElDBus.
293 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
296 EcoreElDBusInitialisation( handler );
298 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
299 #endif // DALI_ELDBUS_AVAILABLE
308 #ifndef DALI_PROFILE_UBUNTU
309 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
310 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
311 #endif // DALI_PROFILE_UBUNTU
313 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
315 ecore_event_handler_del( *iter );
318 #ifdef DALI_ELDBUS_AVAILABLE
319 // Close down ElDBus connections.
320 if( mSystemConnection )
322 eldbus_connection_unref( mSystemConnection );
324 #endif // DALI_ELDBUS_AVAILABLE
329 /////////////////////////////////////////////////////////////////////////////////////////////////
331 /////////////////////////////////////////////////////////////////////////////////////////////////
334 * Called when a touch down is received.
336 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
338 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
339 EventHandler* handler( (EventHandler*)data );
341 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
343 PointState::Type state ( PointState::DOWN );
345 // Check if the buttons field is set and ensure it's the primary touch button.
346 // If this event was triggered by buttons other than the primary button (used for touch), then
347 // just send an interrupted event to Core.
348 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
350 state = PointState::INTERRUPTED;
353 Integration::Point point;
354 point.SetDeviceId( touchEvent->multi.device );
355 point.SetState( state );
356 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
357 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
358 point.SetPressure( touchEvent->multi.pressure );
359 point.SetAngle( Degree( touchEvent->multi.angle ) );
360 handler->SendEvent( point, touchEvent->timestamp );
363 return ECORE_CALLBACK_PASS_ON;
367 * Called when a touch up is received.
369 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
371 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
372 EventHandler* handler( (EventHandler*)data );
374 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
376 Integration::Point point;
377 point.SetDeviceId( touchEvent->multi.device );
378 point.SetState( PointState::UP );
379 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
380 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
381 point.SetPressure( touchEvent->multi.pressure );
382 point.SetAngle( Degree( touchEvent->multi.angle ) );
383 handler->SendEvent( point, touchEvent->timestamp );
386 return ECORE_CALLBACK_PASS_ON;
390 * Called when a touch motion is received.
392 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
394 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
395 EventHandler* handler( (EventHandler*)data );
397 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
399 Integration::Point point;
400 point.SetDeviceId( touchEvent->multi.device );
401 point.SetState( PointState::MOTION );
402 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
403 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
404 point.SetPressure( touchEvent->multi.pressure );
405 point.SetAngle( Degree( touchEvent->multi.angle ) );
406 handler->SendEvent( point, touchEvent->timestamp );
409 return ECORE_CALLBACK_PASS_ON;
413 * Called when a touch is canceled.
415 static Eina_Bool EcoreEventMouseButtonCancel( void* data, int type, void* event )
417 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
418 EventHandler* handler( (EventHandler*)data );
420 if( touchEvent->window == (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
422 Integration::Point point;
423 point.SetDeviceId( touchEvent->multi.device );
424 point.SetState( PointState::INTERRUPTED );
425 point.SetScreenPosition( Vector2( 0.0f, 0.0f ) );
426 handler->SendEvent( point, touchEvent->timestamp );
428 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventMouseButtonCancel\n" );
431 return ECORE_CALLBACK_PASS_ON;
435 * Called when a mouse wheel is received.
437 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
439 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
441 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);
443 EventHandler* handler( (EventHandler*)data );
444 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
446 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
447 handler->SendWheelEvent( wheelEvent );
449 return ECORE_CALLBACK_PASS_ON;
452 /////////////////////////////////////////////////////////////////////////////////////////////////
454 /////////////////////////////////////////////////////////////////////////////////////////////////
457 * Called when a key down is received.
459 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
461 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
463 EventHandler* handler( (EventHandler*)data );
464 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
465 bool eventHandled( false );
467 // If a device key then skip ecore_imf_context_filter_event.
468 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
470 Ecore_IMF_Context* imfContext = NULL;
471 Dali::ImfManager imfManager( ImfManager::Get() );
474 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
479 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
480 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
481 ecoreKeyDownEvent.keyname = keyEvent->keyname;
482 ecoreKeyDownEvent.key = keyEvent->key;
483 ecoreKeyDownEvent.string = keyEvent->string;
484 ecoreKeyDownEvent.compose = keyEvent->compose;
485 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
486 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
487 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
488 #ifdef ECORE_IMF_1_13
489 ecoreKeyDownEvent.dev_name = "";
490 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
491 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
492 #endif // ECORE_IMF_1_13
494 eventHandled = ecore_imf_context_filter_event( imfContext,
495 ECORE_IMF_EVENT_KEY_DOWN,
496 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
498 // If the event has not been handled by IMF then check if we should reset our IMF context
501 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
502 !strcmp( keyEvent->keyname, "Return" ) ||
503 !strcmp( keyEvent->keyname, "KP_Enter" ) )
505 ecore_imf_context_reset( imfContext );
511 // If the event wasn't handled then we should send a key event.
514 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
516 std::string keyName( keyEvent->keyname );
517 std::string keyString( "" );
518 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
519 keyCode = (keyCode == -1) ? 0 : keyCode;
520 int modifier( keyEvent->modifiers );
521 unsigned long time = keyEvent->timestamp;
522 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
523 keyCode = atoi(keyEvent->keyname + 8);
525 // Ensure key event string is not NULL as keys like SHIFT have a null string.
526 if ( keyEvent->string )
528 keyString = keyEvent->string;
531 std::string deviceName;
532 DevelKeyEvent::DeviceClass::Type deviceClass;
534 GetDeviceName( keyEvent, deviceName );
535 GetDeviceClass( keyEvent, deviceClass );
537 DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s) deviceClass(%d)\n", deviceName.c_str(), deviceClass );
539 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, deviceName, deviceClass );
540 handler->SendEvent( keyEvent );
544 return ECORE_CALLBACK_PASS_ON;
548 * Called when a key up is received.
550 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
552 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
554 EventHandler* handler( (EventHandler*)data );
555 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
556 bool eventHandled( false );
558 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
559 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
561 Ecore_IMF_Context* imfContext = NULL;
562 Dali::ImfManager imfManager( ImfManager::Get() );
565 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
570 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
571 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
572 ecoreKeyUpEvent.keyname = keyEvent->keyname;
573 ecoreKeyUpEvent.key = keyEvent->key;
574 ecoreKeyUpEvent.string = keyEvent->string;
575 ecoreKeyUpEvent.compose = keyEvent->compose;
576 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
577 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
578 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
579 #ifdef ECORE_IMF_1_13
580 ecoreKeyUpEvent.dev_name = "";
581 ecoreKeyUpEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
582 ecoreKeyUpEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
583 #endif // ECORE_IMF_1_13
585 eventHandled = ecore_imf_context_filter_event( imfContext,
586 ECORE_IMF_EVENT_KEY_UP,
587 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
591 // If the event wasn't handled then we should send a key event.
594 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
596 std::string keyName( keyEvent->keyname );
597 std::string keyString( "" );
598 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
599 keyCode = (keyCode == -1) ? 0 : keyCode;
600 int modifier( keyEvent->modifiers );
601 unsigned long time = keyEvent->timestamp;
602 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
603 keyCode = atoi(keyEvent->keyname + 8);
605 // Ensure key event string is not NULL as keys like SHIFT have a null string.
606 if ( keyEvent->string )
608 keyString = keyEvent->string;
611 std::string deviceName;
612 DevelKeyEvent::DeviceClass::Type deviceClass;
614 GetDeviceName( keyEvent, deviceName );
615 GetDeviceClass( keyEvent, deviceClass );
617 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, deviceName, deviceClass );
618 handler->SendEvent( keyEvent );
622 return ECORE_CALLBACK_PASS_ON;
625 /////////////////////////////////////////////////////////////////////////////////////////////////
627 /////////////////////////////////////////////////////////////////////////////////////////////////
630 * Called when the window gains focus.
632 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
634 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
635 EventHandler* handler( (EventHandler*)data );
637 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
639 // If the window gains focus and we hid the keyboard then show it again.
640 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
642 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
644 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
646 Dali::ImfManager imfManager( ImfManager::Get() );
649 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
650 if( imfManagerImpl.RestoreAfterFocusLost() )
652 imfManagerImpl.Activate();
656 Dali::Clipboard clipboard = Clipboard::Get();
657 clipboard.HideClipboard();
660 return ECORE_CALLBACK_PASS_ON;
664 * Called when the window loses focus.
666 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
668 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
669 EventHandler* handler( (EventHandler*)data );
671 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
673 // If the window loses focus then hide the keyboard.
674 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
676 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
678 Dali::ImfManager imfManager( ImfManager::Get() );
681 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
682 if( imfManagerImpl.RestoreAfterFocusLost() )
684 imfManagerImpl.Deactivate();
689 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
690 Dali::Clipboard clipboard = Clipboard::Get();
693 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
694 clipBoardImpl.HideClipboard(true);
698 return ECORE_CALLBACK_PASS_ON;
702 * Called when the window is damaged.
704 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
706 return ECORE_CALLBACK_PASS_ON;
710 * Called when the window properties are changed.
711 * We are only interested in the font change.
715 /////////////////////////////////////////////////////////////////////////////////////////////////
716 // Drag & Drop Callbacks
717 /////////////////////////////////////////////////////////////////////////////////////////////////
720 * Called when a dragged item enters our window's bounds.
721 * This is when items are dragged INTO our window.
723 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
725 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
727 return ECORE_CALLBACK_PASS_ON;
731 * Called when a dragged item is moved within our window.
732 * This is when items are dragged INTO our window.
734 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
736 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
738 return ECORE_CALLBACK_PASS_ON;
742 * Called when a dragged item leaves our window's bounds.
743 * This is when items are dragged INTO our window.
745 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
747 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
749 return ECORE_CALLBACK_PASS_ON;
753 * Called when the dragged item is dropped within our window's bounds.
754 * This is when items are dragged INTO our window.
756 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
758 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
760 return ECORE_CALLBACK_PASS_ON;
764 * Called when a dragged item is moved from our window and the target window has done processing it.
765 * This is when items are dragged FROM our window.
767 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
769 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
770 return ECORE_CALLBACK_PASS_ON;
774 * Called when a dragged item is moved from our window and the target window has sent us a status.
775 * This is when items are dragged FROM our window.
777 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
779 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
780 return ECORE_CALLBACK_PASS_ON;
784 * Called when the client messages (i.e. the accessibility events) are received.
786 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
788 return ECORE_CALLBACK_PASS_ON;
792 /////////////////////////////////////////////////////////////////////////////////////////////////
793 // ElDBus Accessibility Callbacks
794 /////////////////////////////////////////////////////////////////////////////////////////////////
796 #ifdef DALI_ELDBUS_AVAILABLE
797 // Callback for Ecore ElDBus accessibility events.
798 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
800 EventHandler* handler = static_cast< EventHandler* >( context );
801 // Ignore any accessibility events when paused.
802 if( handler->mPaused )
807 if( !handler->mAccessibilityAdaptor )
809 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
813 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
814 if( !accessibilityAdaptor )
816 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
822 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
825 // The string defines the arg-list's respective types.
826 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
828 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
831 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
833 // Create a touch point object.
834 TouchPoint::State touchPointState( TouchPoint::Down );
837 touchPointState = TouchPoint::Down; // Mouse down.
839 else if( state == 1 )
841 touchPointState = TouchPoint::Motion; // Mouse move.
843 else if( state == 2 )
845 touchPointState = TouchPoint::Up; // Mouse up.
849 touchPointState = TouchPoint::Interrupted; // Error.
852 // Send touch event to accessibility adaptor.
853 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
855 // Perform actions based on received gestures.
856 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
857 switch( gestureValue )
859 case 0: // OneFingerHover
862 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
865 case 1: // TwoFingersHover
867 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
868 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
871 case 2: // ThreeFingersHover
873 // Read from top item on screen continuously.
874 accessibilityAdaptor->HandleActionReadFromTopEvent();
877 case 3: // OneFingerFlickLeft
879 // Move to previous item.
880 accessibilityAdaptor->HandleActionReadPreviousEvent();
883 case 4: // OneFingerFlickRight
885 // Move to next item.
886 accessibilityAdaptor->HandleActionReadNextEvent();
889 case 5: // OneFingerFlickUp
891 // Move to previous item.
892 accessibilityAdaptor->HandleActionPreviousEvent();
895 case 6: // OneFingerFlickDown
897 // Move to next item.
898 accessibilityAdaptor->HandleActionNextEvent();
901 case 7: // TwoFingersFlickUp
903 // Scroll up the list.
904 accessibilityAdaptor->HandleActionScrollUpEvent();
907 case 8: // TwoFingersFlickDown
909 // Scroll down the list.
910 accessibilityAdaptor->HandleActionScrollDownEvent();
913 case 9: // TwoFingersFlickLeft
915 // Scroll left to the previous page
916 accessibilityAdaptor->HandleActionPageLeftEvent();
919 case 10: // TwoFingersFlickRight
921 // Scroll right to the next page
922 accessibilityAdaptor->HandleActionPageRightEvent();
925 case 11: // ThreeFingersFlickLeft
930 case 12: // ThreeFingersFlickRight
935 case 13: // ThreeFingersFlickUp
940 case 14: // ThreeFingersFlickDown
945 case 15: // OneFingerSingleTap
948 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
951 case 16: // OneFingerDoubleTap
953 // Activate selected item / active edit mode.
954 accessibilityAdaptor->HandleActionActivateEvent();
957 case 17: // OneFingerTripleTap
960 accessibilityAdaptor->HandleActionZoomEvent();
963 case 18: // TwoFingersSingleTap
965 // Pause/Resume current speech
966 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
969 case 19: // TwoFingersDoubleTap
971 // Start/Stop current action
972 accessibilityAdaptor->HandleActionStartStopEvent();
975 case 20: // TwoFingersTripleTap
977 // Read information from indicator
978 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
981 case 21: // ThreeFingersSingleTap
983 // Read from top item on screen continuously.
984 accessibilityAdaptor->HandleActionReadFromTopEvent();
987 case 22: // ThreeFingersDoubleTap
989 // Read from next item continuously.
990 accessibilityAdaptor->HandleActionReadFromNextEvent();
993 case 23: // ThreeFingersTripleTap
998 case 24: // OneFingerFlickLeftReturn
1000 // Scroll up to the previous page
1001 accessibilityAdaptor->HandleActionPageUpEvent();
1004 case 25: // OneFingerFlickRightReturn
1006 // Scroll down to the next page
1007 accessibilityAdaptor->HandleActionPageDownEvent();
1010 case 26: // OneFingerFlickUpReturn
1012 // Move to the first item on screen
1013 accessibilityAdaptor->HandleActionMoveToFirstEvent();
1016 case 27: // OneFingerFlickDownReturn
1018 // Move to the last item on screen
1019 accessibilityAdaptor->HandleActionMoveToLastEvent();
1022 case 28: // TwoFingersFlickLeftReturn
1027 case 29: // TwoFingersFlickRightReturn
1032 case 30: // TwoFingersFlickUpReturn
1037 case 31: // TwoFingersFlickDownReturn
1042 case 32: // ThreeFingersFlickLeftReturn
1047 case 33: // ThreeFingersFlickRightReturn
1052 case 34: // ThreeFingersFlickUpReturn
1057 case 35: // ThreeFingersFlickDownReturn
1065 void EcoreElDBusInitialisation( void *handle )
1067 Eldbus_Object *object;
1068 Eldbus_Proxy *manager;
1070 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1072 DALI_LOG_ERROR( "Unable to get system bus\n" );
1075 object = eldbus_object_get( mSystemConnection, BUS, PATH );
1078 DALI_LOG_ERROR( "Getting object failed\n" );
1082 manager = eldbus_proxy_get( object, INTERFACE );
1085 DALI_LOG_ERROR( "Getting proxy failed\n" );
1089 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1091 DALI_LOG_ERROR( "No signal handler returned\n" );
1094 #endif // DALI_ELDBUS_AVAILABLE
1097 * Called when the source window notifies us the content in clipboard is selected.
1099 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1101 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1102 return ECORE_CALLBACK_PASS_ON;
1106 * Called when the source window sends us about the selected content.
1107 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1109 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1111 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1112 return ECORE_CALLBACK_PASS_ON;
1116 * Called when the source window notifies us the content in clipboard is selected.
1118 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1120 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1122 Dali::Clipboard clipboard = Clipboard::Get();
1125 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1126 clipBoardImpl.ExcuteBuffered( true, event );
1128 return ECORE_CALLBACK_PASS_ON;
1132 * Called when the source window sends us about the selected content.
1133 * For example, when item is selected in the clipboard.
1135 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1137 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1139 EventHandler* handler( (EventHandler*)data );
1140 Dali::Clipboard clipboard = Clipboard::Get();
1141 char *selectionData = NULL;
1144 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1145 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1147 if ( selectionData && handler->mClipboardEventNotifier )
1149 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1150 std::string content( selectionData, strlen(selectionData) );
1152 clipboardEventNotifier.SetContent( content );
1153 clipboardEventNotifier.EmitContentSelectedSignal();
1155 return ECORE_CALLBACK_PASS_ON;
1159 * Called when rotate event is recevied
1161 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1163 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1165 EventHandler* handler( (EventHandler*)data );
1166 Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1168 if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1170 return ECORE_CALLBACK_PASS_ON;
1173 RotationEvent rotationEvent;
1174 rotationEvent.angle = ev->angle;
1175 rotationEvent.winResize = 0;
1176 rotationEvent.width = ev->w;
1177 rotationEvent.height = ev->h;
1178 handler->SendRotationPrepareEvent( rotationEvent );
1180 return ECORE_CALLBACK_PASS_ON;
1184 * Called when detent event is recevied
1186 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1188 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1189 EventHandler* handler( (EventHandler*)data );
1190 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1191 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1192 int timeStamp = e->timestamp;
1194 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1195 handler->SendWheelEvent( wheelEvent );
1196 return ECORE_CALLBACK_PASS_ON;
1199 /////////////////////////////////////////////////////////////////////////////////////////////////
1201 /////////////////////////////////////////////////////////////////////////////////////////////////
1203 * Called when a font name is changed.
1205 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1207 EventHandler* handler = static_cast<EventHandler*>( data );
1208 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1212 * Called when a font size is changed.
1214 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1216 EventHandler* handler = static_cast<EventHandler*>( data );
1217 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1221 EventHandler* mHandler;
1222 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1223 Ecore_Wl_Window* mWindow;
1224 #ifdef DALI_ELDBUS_AVAILABLE
1225 Eldbus_Connection* mSystemConnection;
1226 #endif // DALI_ELDBUS_AVAILABLE
1229 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1230 : mCoreEventInterface( coreEventInterface ),
1231 mGestureManager( gestureManager ),
1232 mStyleMonitor( StyleMonitor::Get() ),
1233 mDamageObserver( damageObserver ),
1234 mRotationObserver( NULL ),
1235 mDragAndDropDetector( dndDetector ),
1236 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1237 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1238 mClipboard( Clipboard::Get() ),
1242 Ecore_Wl_Window* window = 0;
1244 // this code only works with the Ecore RenderSurface so need to downcast
1245 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1248 window = ecoreSurface->GetWlWindow();
1251 mImpl = new Impl(this, window);
1254 EventHandler::~EventHandler()
1261 mGestureManager.Stop();
1264 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1268 timeStamp = GetCurrentMilliSeconds();
1271 Integration::TouchEvent touchEvent;
1272 Integration::HoverEvent hoverEvent;
1273 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1274 if(type != Integration::TouchEventCombiner::DispatchNone )
1276 DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.GetDeviceId(), point.GetState(), point.GetLocalPosition().x, point.GetLocalPosition().y);
1278 // First the touch and/or hover event & related gesture events are queued
1279 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1281 mCoreEventInterface.QueueCoreEvent( touchEvent );
1282 mGestureManager.SendEvent(touchEvent);
1285 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1287 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1290 // Next the events are processed with a single call into Core
1291 mCoreEventInterface.ProcessCoreEvents();
1295 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1297 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1298 if ( physicalKeyboard )
1300 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1302 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1306 // Create send KeyEvent to Core.
1307 mCoreEventInterface.QueueCoreEvent( keyEvent );
1308 mCoreEventInterface.ProcessCoreEvents();
1311 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1313 // Create WheelEvent and send to Core.
1314 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1315 mCoreEventInterface.QueueCoreEvent( event );
1316 mCoreEventInterface.ProcessCoreEvents();
1319 void EventHandler::SendEvent( StyleChange::Type styleChange )
1321 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1322 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1325 void EventHandler::SendEvent( const DamageArea& area )
1327 mDamageObserver.OnDamaged( area );
1330 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1332 if( mRotationObserver != NULL )
1334 mRotationObserver->OnRotationPrepare( event );
1335 mRotationObserver->OnRotationRequest();
1339 void EventHandler::SendRotationRequestEvent( )
1341 // No need to separate event into prepare and request in wayland
1344 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1346 Integration::Point convertedPoint( point );
1347 SendEvent(convertedPoint, timeStamp);
1350 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1352 SendWheelEvent( wheelEvent );
1355 void EventHandler::FeedKeyEvent( KeyEvent& event )
1357 Integration::KeyEvent convertedEvent( event );
1358 SendEvent( convertedEvent );
1361 void EventHandler::FeedEvent( Integration::Event& event )
1363 mCoreEventInterface.QueueCoreEvent( event );
1364 mCoreEventInterface.ProcessCoreEvents();
1367 void EventHandler::Reset()
1371 // Any touch listeners should be told of the interruption.
1372 Integration::TouchEvent event;
1373 Integration::Point point;
1374 point.SetState( PointState::INTERRUPTED );
1375 event.AddPoint( point );
1377 // First the touch event & related gesture events are queued
1378 mCoreEventInterface.QueueCoreEvent( event );
1379 mGestureManager.SendEvent( event );
1381 // Next the events are processed with a single call into Core
1382 mCoreEventInterface.ProcessCoreEvents();
1385 void EventHandler::Pause()
1391 void EventHandler::Resume()
1397 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1399 mDragAndDropDetector = detector;
1402 void EventHandler::SetRotationObserver( RotationObserver* observer )
1404 mRotationObserver = observer;
1407 } // namespace Adaptor
1409 } // namespace Internal