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
263 // Register Mouse wheel events
264 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
266 // Register Focus events
267 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
268 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
270 // Register Key events
271 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
272 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
274 // Register Selection event - clipboard selection
275 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
276 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
278 // Register Rotate event
279 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
281 // Register Detent event
282 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
284 #ifndef DALI_PROFILE_UBUNTU
285 // Register Vconf notify - font name and size
286 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
287 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
288 #endif // DALI_PROFILE_UBUNTU
290 #ifdef DALI_ELDBUS_AVAILABLE
291 // Initialize ElDBus.
292 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
295 EcoreElDBusInitialisation( handler );
297 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
298 #endif // DALI_ELDBUS_AVAILABLE
307 #ifndef DALI_PROFILE_UBUNTU
308 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
309 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
310 #endif // DALI_PROFILE_UBUNTU
312 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
314 ecore_event_handler_del( *iter );
317 #ifdef DALI_ELDBUS_AVAILABLE
318 // Close down ElDBus connections.
319 if( mSystemConnection )
321 eldbus_connection_unref( mSystemConnection );
323 #endif // DALI_ELDBUS_AVAILABLE
328 /////////////////////////////////////////////////////////////////////////////////////////////////
330 /////////////////////////////////////////////////////////////////////////////////////////////////
333 * Called when a touch down is received.
335 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
337 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
338 EventHandler* handler( (EventHandler*)data );
340 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
342 PointState::Type state ( PointState::DOWN );
344 // Check if the buttons field is set and ensure it's the primary touch button.
345 // If this event was triggered by buttons other than the primary button (used for touch), then
346 // just send an interrupted event to Core.
347 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
349 state = PointState::INTERRUPTED;
352 Integration::Point point;
353 point.SetDeviceId( touchEvent->multi.device );
354 point.SetState( state );
355 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
356 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
357 point.SetPressure( touchEvent->multi.pressure );
358 point.SetAngle( Degree( touchEvent->multi.angle ) );
359 handler->SendEvent( point, touchEvent->timestamp );
362 return ECORE_CALLBACK_PASS_ON;
366 * Called when a touch up is received.
368 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
370 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
371 EventHandler* handler( (EventHandler*)data );
373 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
375 Integration::Point point;
376 point.SetDeviceId( touchEvent->multi.device );
377 point.SetState( PointState::UP );
378 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
379 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
380 point.SetPressure( touchEvent->multi.pressure );
381 point.SetAngle( Degree( touchEvent->multi.angle ) );
382 handler->SendEvent( point, touchEvent->timestamp );
385 return ECORE_CALLBACK_PASS_ON;
389 * Called when a touch up is received.
391 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
393 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
395 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);
397 EventHandler* handler( (EventHandler*)data );
398 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
400 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
401 handler->SendWheelEvent( wheelEvent );
403 return ECORE_CALLBACK_PASS_ON;
407 * Called when a touch motion is received.
409 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
411 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
412 EventHandler* handler( (EventHandler*)data );
414 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
416 Integration::Point point;
417 point.SetDeviceId( touchEvent->multi.device );
418 point.SetState( PointState::MOTION );
419 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
420 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
421 point.SetPressure( touchEvent->multi.pressure );
422 point.SetAngle( Degree( touchEvent->multi.angle ) );
423 handler->SendEvent( point, touchEvent->timestamp );
426 return ECORE_CALLBACK_PASS_ON;
429 /////////////////////////////////////////////////////////////////////////////////////////////////
431 /////////////////////////////////////////////////////////////////////////////////////////////////
434 * Called when a key down is received.
436 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
438 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
440 EventHandler* handler( (EventHandler*)data );
441 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
442 bool eventHandled( false );
444 // If a device key then skip ecore_imf_context_filter_event.
445 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
447 Ecore_IMF_Context* imfContext = NULL;
448 Dali::ImfManager imfManager( ImfManager::Get() );
451 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
456 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
457 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
458 ecoreKeyDownEvent.keyname = keyEvent->keyname;
459 ecoreKeyDownEvent.key = keyEvent->key;
460 ecoreKeyDownEvent.string = keyEvent->string;
461 ecoreKeyDownEvent.compose = keyEvent->compose;
462 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
463 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
464 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
465 #ifdef ECORE_IMF_1_13
466 ecoreKeyDownEvent.dev_name = "";
467 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
468 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
469 #endif // ECORE_IMF_1_13
471 eventHandled = ecore_imf_context_filter_event( imfContext,
472 ECORE_IMF_EVENT_KEY_DOWN,
473 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
475 // If the event has not been handled by IMF then check if we should reset our IMF context
478 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
479 !strcmp( keyEvent->keyname, "Return" ) ||
480 !strcmp( keyEvent->keyname, "KP_Enter" ) )
482 ecore_imf_context_reset( imfContext );
488 // If the event wasn't handled then we should send a key event.
491 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
493 std::string keyName( keyEvent->keyname );
494 std::string keyString( "" );
495 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
496 keyCode = (keyCode == -1) ? 0 : keyCode;
497 int modifier( keyEvent->modifiers );
498 unsigned long time = keyEvent->timestamp;
499 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
500 keyCode = atoi(keyEvent->keyname + 8);
502 // Ensure key event string is not NULL as keys like SHIFT have a null string.
503 if ( keyEvent->string )
505 keyString = keyEvent->string;
508 std::string deviceName;
509 DevelKeyEvent::DeviceClass::Type deviceClass;
511 GetDeviceName( keyEvent, deviceName );
512 GetDeviceClass( keyEvent, deviceClass );
514 DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s) deviceClass(%d)\n", deviceName.c_str(), deviceClass );
516 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, deviceName, deviceClass );
517 handler->SendEvent( keyEvent );
521 return ECORE_CALLBACK_PASS_ON;
525 * Called when a key up is received.
527 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
529 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
531 EventHandler* handler( (EventHandler*)data );
532 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
533 bool eventHandled( false );
535 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
536 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
538 Ecore_IMF_Context* imfContext = NULL;
539 Dali::ImfManager imfManager( ImfManager::Get() );
542 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
547 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
548 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
549 ecoreKeyUpEvent.keyname = keyEvent->keyname;
550 ecoreKeyUpEvent.key = keyEvent->key;
551 ecoreKeyUpEvent.string = keyEvent->string;
552 ecoreKeyUpEvent.compose = keyEvent->compose;
553 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
554 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
555 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
556 #ifdef ECORE_IMF_1_13
557 ecoreKeyUpEvent.dev_name = "";
558 ecoreKeyUpEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
559 ecoreKeyUpEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
560 #endif // ECORE_IMF_1_13
562 eventHandled = ecore_imf_context_filter_event( imfContext,
563 ECORE_IMF_EVENT_KEY_UP,
564 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
568 // If the event wasn't handled then we should send a key event.
571 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
573 std::string keyName( keyEvent->keyname );
574 std::string keyString( "" );
575 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
576 keyCode = (keyCode == -1) ? 0 : keyCode;
577 int modifier( keyEvent->modifiers );
578 unsigned long time = keyEvent->timestamp;
579 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
580 keyCode = atoi(keyEvent->keyname + 8);
582 // Ensure key event string is not NULL as keys like SHIFT have a null string.
583 if ( keyEvent->string )
585 keyString = keyEvent->string;
588 std::string deviceName;
589 DevelKeyEvent::DeviceClass::Type deviceClass;
591 GetDeviceName( keyEvent, deviceName );
592 GetDeviceClass( keyEvent, deviceClass );
594 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, deviceName, deviceClass );
595 handler->SendEvent( keyEvent );
599 return ECORE_CALLBACK_PASS_ON;
602 /////////////////////////////////////////////////////////////////////////////////////////////////
604 /////////////////////////////////////////////////////////////////////////////////////////////////
607 * Called when the window gains focus.
609 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
611 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
612 EventHandler* handler( (EventHandler*)data );
614 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
616 // If the window gains focus and we hid the keyboard then show it again.
617 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
619 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
621 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
623 Dali::ImfManager imfManager( ImfManager::Get() );
626 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
627 if( imfManagerImpl.RestoreAfterFocusLost() )
629 imfManagerImpl.Activate();
633 Dali::Clipboard clipboard = Clipboard::Get();
634 clipboard.HideClipboard();
637 return ECORE_CALLBACK_PASS_ON;
641 * Called when the window loses focus.
643 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
645 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
646 EventHandler* handler( (EventHandler*)data );
648 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
650 // If the window loses focus then hide the keyboard.
651 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
653 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
655 Dali::ImfManager imfManager( ImfManager::Get() );
658 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
659 if( imfManagerImpl.RestoreAfterFocusLost() )
661 imfManagerImpl.Deactivate();
666 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
667 Dali::Clipboard clipboard = Clipboard::Get();
670 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
671 clipBoardImpl.HideClipboard(true);
675 return ECORE_CALLBACK_PASS_ON;
679 * Called when the window is damaged.
681 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
683 return ECORE_CALLBACK_PASS_ON;
687 * Called when the window properties are changed.
688 * We are only interested in the font change.
692 /////////////////////////////////////////////////////////////////////////////////////////////////
693 // Drag & Drop Callbacks
694 /////////////////////////////////////////////////////////////////////////////////////////////////
697 * Called when a dragged item enters our window's bounds.
698 * This is when items are dragged INTO our window.
700 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
702 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
704 return ECORE_CALLBACK_PASS_ON;
708 * Called when a dragged item is moved within our window.
709 * This is when items are dragged INTO our window.
711 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
713 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
715 return ECORE_CALLBACK_PASS_ON;
719 * Called when a dragged item leaves our window's bounds.
720 * This is when items are dragged INTO our window.
722 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
724 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
726 return ECORE_CALLBACK_PASS_ON;
730 * Called when the dragged item is dropped within our window's bounds.
731 * This is when items are dragged INTO our window.
733 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
735 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
737 return ECORE_CALLBACK_PASS_ON;
741 * Called when a dragged item is moved from our window and the target window has done processing it.
742 * This is when items are dragged FROM our window.
744 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
746 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
747 return ECORE_CALLBACK_PASS_ON;
751 * Called when a dragged item is moved from our window and the target window has sent us a status.
752 * This is when items are dragged FROM our window.
754 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
756 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
757 return ECORE_CALLBACK_PASS_ON;
761 * Called when the client messages (i.e. the accessibility events) are received.
763 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
765 return ECORE_CALLBACK_PASS_ON;
769 /////////////////////////////////////////////////////////////////////////////////////////////////
770 // ElDBus Accessibility Callbacks
771 /////////////////////////////////////////////////////////////////////////////////////////////////
773 #ifdef DALI_ELDBUS_AVAILABLE
774 // Callback for Ecore ElDBus accessibility events.
775 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
777 EventHandler* handler = static_cast< EventHandler* >( context );
778 // Ignore any accessibility events when paused.
779 if( handler->mPaused )
784 if( !handler->mAccessibilityAdaptor )
786 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
790 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
791 if( !accessibilityAdaptor )
793 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
799 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
802 // The string defines the arg-list's respective types.
803 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
805 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
808 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
810 // Create a touch point object.
811 TouchPoint::State touchPointState( TouchPoint::Down );
814 touchPointState = TouchPoint::Down; // Mouse down.
816 else if( state == 1 )
818 touchPointState = TouchPoint::Motion; // Mouse move.
820 else if( state == 2 )
822 touchPointState = TouchPoint::Up; // Mouse up.
826 touchPointState = TouchPoint::Interrupted; // Error.
829 // Send touch event to accessibility adaptor.
830 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
832 // Perform actions based on received gestures.
833 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
834 switch( gestureValue )
836 case 0: // OneFingerHover
839 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
842 case 1: // TwoFingersHover
844 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
845 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
848 case 2: // ThreeFingersHover
850 // Read from top item on screen continuously.
851 accessibilityAdaptor->HandleActionReadFromTopEvent();
854 case 3: // OneFingerFlickLeft
856 // Move to previous item.
857 accessibilityAdaptor->HandleActionReadPreviousEvent();
860 case 4: // OneFingerFlickRight
862 // Move to next item.
863 accessibilityAdaptor->HandleActionReadNextEvent();
866 case 5: // OneFingerFlickUp
868 // Move to previous item.
869 accessibilityAdaptor->HandleActionPreviousEvent();
872 case 6: // OneFingerFlickDown
874 // Move to next item.
875 accessibilityAdaptor->HandleActionNextEvent();
878 case 7: // TwoFingersFlickUp
880 // Scroll up the list.
881 accessibilityAdaptor->HandleActionScrollUpEvent();
884 case 8: // TwoFingersFlickDown
886 // Scroll down the list.
887 accessibilityAdaptor->HandleActionScrollDownEvent();
890 case 9: // TwoFingersFlickLeft
892 // Scroll left to the previous page
893 accessibilityAdaptor->HandleActionPageLeftEvent();
896 case 10: // TwoFingersFlickRight
898 // Scroll right to the next page
899 accessibilityAdaptor->HandleActionPageRightEvent();
902 case 11: // ThreeFingersFlickLeft
907 case 12: // ThreeFingersFlickRight
912 case 13: // ThreeFingersFlickUp
917 case 14: // ThreeFingersFlickDown
922 case 15: // OneFingerSingleTap
925 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
928 case 16: // OneFingerDoubleTap
930 // Activate selected item / active edit mode.
931 accessibilityAdaptor->HandleActionActivateEvent();
934 case 17: // OneFingerTripleTap
937 accessibilityAdaptor->HandleActionZoomEvent();
940 case 18: // TwoFingersSingleTap
942 // Pause/Resume current speech
943 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
946 case 19: // TwoFingersDoubleTap
948 // Start/Stop current action
949 accessibilityAdaptor->HandleActionStartStopEvent();
952 case 20: // TwoFingersTripleTap
954 // Read information from indicator
955 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
958 case 21: // ThreeFingersSingleTap
960 // Read from top item on screen continuously.
961 accessibilityAdaptor->HandleActionReadFromTopEvent();
964 case 22: // ThreeFingersDoubleTap
966 // Read from next item continuously.
967 accessibilityAdaptor->HandleActionReadFromNextEvent();
970 case 23: // ThreeFingersTripleTap
975 case 24: // OneFingerFlickLeftReturn
977 // Scroll up to the previous page
978 accessibilityAdaptor->HandleActionPageUpEvent();
981 case 25: // OneFingerFlickRightReturn
983 // Scroll down to the next page
984 accessibilityAdaptor->HandleActionPageDownEvent();
987 case 26: // OneFingerFlickUpReturn
989 // Move to the first item on screen
990 accessibilityAdaptor->HandleActionMoveToFirstEvent();
993 case 27: // OneFingerFlickDownReturn
995 // Move to the last item on screen
996 accessibilityAdaptor->HandleActionMoveToLastEvent();
999 case 28: // TwoFingersFlickLeftReturn
1004 case 29: // TwoFingersFlickRightReturn
1009 case 30: // TwoFingersFlickUpReturn
1014 case 31: // TwoFingersFlickDownReturn
1019 case 32: // ThreeFingersFlickLeftReturn
1024 case 33: // ThreeFingersFlickRightReturn
1029 case 34: // ThreeFingersFlickUpReturn
1034 case 35: // ThreeFingersFlickDownReturn
1042 void EcoreElDBusInitialisation( void *handle )
1044 Eldbus_Object *object;
1045 Eldbus_Proxy *manager;
1047 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1049 DALI_LOG_ERROR( "Unable to get system bus\n" );
1052 object = eldbus_object_get( mSystemConnection, BUS, PATH );
1055 DALI_LOG_ERROR( "Getting object failed\n" );
1059 manager = eldbus_proxy_get( object, INTERFACE );
1062 DALI_LOG_ERROR( "Getting proxy failed\n" );
1066 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1068 DALI_LOG_ERROR( "No signal handler returned\n" );
1071 #endif // DALI_ELDBUS_AVAILABLE
1074 * Called when the source window notifies us the content in clipboard is selected.
1076 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1078 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1079 return ECORE_CALLBACK_PASS_ON;
1083 * Called when the source window sends us about the selected content.
1084 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1086 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1088 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1089 return ECORE_CALLBACK_PASS_ON;
1093 * Called when the source window notifies us the content in clipboard is selected.
1095 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1097 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1099 Dali::Clipboard clipboard = Clipboard::Get();
1102 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1103 clipBoardImpl.ExcuteBuffered( true, event );
1105 return ECORE_CALLBACK_PASS_ON;
1109 * Called when the source window sends us about the selected content.
1110 * For example, when item is selected in the clipboard.
1112 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1114 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1116 EventHandler* handler( (EventHandler*)data );
1117 Dali::Clipboard clipboard = Clipboard::Get();
1118 char *selectionData = NULL;
1121 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1122 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1124 if ( selectionData && handler->mClipboardEventNotifier )
1126 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1127 std::string content( selectionData, strlen(selectionData) );
1129 clipboardEventNotifier.SetContent( content );
1130 clipboardEventNotifier.EmitContentSelectedSignal();
1132 return ECORE_CALLBACK_PASS_ON;
1136 * Called when rotate event is recevied
1138 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1140 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1142 EventHandler* handler( (EventHandler*)data );
1143 Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1145 if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1147 return ECORE_CALLBACK_PASS_ON;
1150 RotationEvent rotationEvent;
1151 rotationEvent.angle = ev->angle;
1152 rotationEvent.winResize = 0;
1153 rotationEvent.width = ev->w;
1154 rotationEvent.height = ev->h;
1155 handler->SendRotationPrepareEvent( rotationEvent );
1157 return ECORE_CALLBACK_PASS_ON;
1161 * Called when detent event is recevied
1163 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1165 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1166 EventHandler* handler( (EventHandler*)data );
1167 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1168 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1169 int timeStamp = e->timestamp;
1171 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1172 handler->SendWheelEvent( wheelEvent );
1173 return ECORE_CALLBACK_PASS_ON;
1176 /////////////////////////////////////////////////////////////////////////////////////////////////
1178 /////////////////////////////////////////////////////////////////////////////////////////////////
1180 * Called when a font name is changed.
1182 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1184 EventHandler* handler = static_cast<EventHandler*>( data );
1185 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1189 * Called when a font size is changed.
1191 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1193 EventHandler* handler = static_cast<EventHandler*>( data );
1194 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1198 EventHandler* mHandler;
1199 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1200 Ecore_Wl_Window* mWindow;
1201 #ifdef DALI_ELDBUS_AVAILABLE
1202 Eldbus_Connection* mSystemConnection;
1203 #endif // DALI_ELDBUS_AVAILABLE
1206 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1207 : mCoreEventInterface( coreEventInterface ),
1208 mGestureManager( gestureManager ),
1209 mStyleMonitor( StyleMonitor::Get() ),
1210 mDamageObserver( damageObserver ),
1211 mRotationObserver( NULL ),
1212 mDragAndDropDetector( dndDetector ),
1213 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1214 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1215 mClipboard( Clipboard::Get() ),
1219 Ecore_Wl_Window* window = 0;
1221 // this code only works with the Ecore RenderSurface so need to downcast
1222 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1225 window = ecoreSurface->GetWlWindow();
1228 mImpl = new Impl(this, window);
1231 EventHandler::~EventHandler()
1238 mGestureManager.Stop();
1241 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1245 timeStamp = GetCurrentMilliSeconds();
1248 Integration::TouchEvent touchEvent;
1249 Integration::HoverEvent hoverEvent;
1250 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1251 if(type != Integration::TouchEventCombiner::DispatchNone )
1253 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);
1255 // First the touch and/or hover event & related gesture events are queued
1256 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1258 mCoreEventInterface.QueueCoreEvent( touchEvent );
1259 mGestureManager.SendEvent(touchEvent);
1262 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1264 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1267 // Next the events are processed with a single call into Core
1268 mCoreEventInterface.ProcessCoreEvents();
1272 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1274 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1275 if ( physicalKeyboard )
1277 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1279 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1283 // Create send KeyEvent to Core.
1284 mCoreEventInterface.QueueCoreEvent( keyEvent );
1285 mCoreEventInterface.ProcessCoreEvents();
1288 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1290 // Create WheelEvent and send to Core.
1291 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1292 mCoreEventInterface.QueueCoreEvent( event );
1293 mCoreEventInterface.ProcessCoreEvents();
1296 void EventHandler::SendEvent( StyleChange::Type styleChange )
1298 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1299 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1302 void EventHandler::SendEvent( const DamageArea& area )
1304 mDamageObserver.OnDamaged( area );
1307 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1309 if( mRotationObserver != NULL )
1311 mRotationObserver->OnRotationPrepare( event );
1312 mRotationObserver->OnRotationRequest();
1316 void EventHandler::SendRotationRequestEvent( )
1318 // No need to separate event into prepare and request in wayland
1321 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1323 Integration::Point convertedPoint( point );
1324 SendEvent(convertedPoint, timeStamp);
1327 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1329 SendWheelEvent( wheelEvent );
1332 void EventHandler::FeedKeyEvent( KeyEvent& event )
1334 Integration::KeyEvent convertedEvent( event );
1335 SendEvent( convertedEvent );
1338 void EventHandler::FeedEvent( Integration::Event& event )
1340 mCoreEventInterface.QueueCoreEvent( event );
1341 mCoreEventInterface.ProcessCoreEvents();
1344 void EventHandler::Reset()
1348 // Any touch listeners should be told of the interruption.
1349 Integration::TouchEvent event;
1350 Integration::Point point;
1351 point.SetState( PointState::INTERRUPTED );
1352 event.AddPoint( point );
1354 // First the touch event & related gesture events are queued
1355 mCoreEventInterface.QueueCoreEvent( event );
1356 mGestureManager.SendEvent( event );
1358 // Next the events are processed with a single call into Core
1359 mCoreEventInterface.ProcessCoreEvents();
1362 void EventHandler::Pause()
1368 void EventHandler::Resume()
1374 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1376 mDragAndDropDetector = detector;
1379 void EventHandler::SetRotationObserver( RotationObserver* observer )
1381 mRotationObserver = observer;
1384 } // namespace Adaptor
1386 } // namespace Internal