2 * Copyright (c) 2017 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>
22 // Ecore is littered with C style cast
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wold-style-cast"
26 #include <Ecore_Input.h>
27 #include <ecore-wl-render-surface.h>
32 #ifndef DALI_PROFILE_UBUNTU
34 #include <vconf-keys.h>
35 #endif // DALI_PROFILE_UBUNTU
37 #ifdef DALI_ELDBUS_AVAILABLE
39 #endif // DALI_ELDBUS_AVAILABLE
41 #include <dali/public-api/common/vector-wrapper.h>
42 #include <dali/public-api/events/device.h>
43 #include <dali/public-api/events/touch-point.h>
44 #include <dali/public-api/events/key-event.h>
45 #include <dali/public-api/events/wheel-event.h>
46 #include <dali/integration-api/debug.h>
47 #include <dali/integration-api/events/key-event-integ.h>
48 #include <dali/integration-api/events/touch-event-integ.h>
49 #include <dali/integration-api/events/hover-event-integ.h>
50 #include <dali/integration-api/events/wheel-event-integ.h>
53 #include <events/gesture-manager.h>
54 #include <window-render-surface.h>
55 #include <clipboard-impl.h>
57 #include <physical-keyboard-impl.h>
58 #include <style-monitor-impl.h>
59 #include <base/core-event-interface.h>
60 #include <virtual-keyboard.h>
71 #if defined(DEBUG_ENABLED)
74 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
75 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
76 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
77 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
78 } // unnamed namespace
86 const char* BUS = "org.enlightenment.wm-screen-reader";
87 const char* INTERFACE = "org.tizen.GestureNavigation";
88 const char* PATH = "/org/tizen/GestureNavigation";
90 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
92 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
94 #ifdef DALI_ELDBUS_AVAILABLE
95 // DBus gesture string matching lists.
96 // TODO: This needs moving to its own module.
97 const char * ElDBusAccessibilityFingerCountStrings[] =
103 const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
108 GESTURE_TYPE_SINGLE_TAP,
109 GESTURE_TYPE_DOUBLE_TAP,
110 GESTURE_TYPE_TRIPLE_TAP
112 struct GestureTypeTable
115 const GestureType type;
117 GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
119 { "Hover", GESTURE_TYPE_HOVER },
120 { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
121 { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
122 { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
124 const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
127 SUB_GESTURE_TYPE_NONE,
128 SUB_GESTURE_TYPE_FLICK
130 struct SubGestureTypeTable
133 const SubGestureType type;
135 SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
137 { "Flick", SUB_GESTURE_TYPE_FLICK }
139 const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
140 enum GestureDirection
142 GESTURE_DIRECTION_NONE,
143 GESTURE_DIRECTION_UP,
144 GESTURE_DIRECTION_DOWN,
145 GESTURE_DIRECTION_LEFT,
146 GESTURE_DIRECTION_RIGHT,
147 GESTURE_DIRECTION_UP_RETURN,
148 GESTURE_DIRECTION_DOWN_RETURN,
149 GESTURE_DIRECTION_LEFT_RETURN,
150 GESTURE_DIRECTION_RIGHT_RETURN
152 struct GestureDirectionTable
155 const GestureDirection direction;
157 GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
159 { "Up", GESTURE_DIRECTION_UP },
160 { "Down", GESTURE_DIRECTION_DOWN },
161 { "Left", GESTURE_DIRECTION_LEFT },
162 { "Right", GESTURE_DIRECTION_RIGHT },
163 { "UpReturn", GESTURE_DIRECTION_UP_RETURN },
164 { "DownReturn", GESTURE_DIRECTION_DOWN_RETURN },
165 { "LeftReturn", GESTURE_DIRECTION_LEFT_RETURN },
166 { "RightReturn", GESTURE_DIRECTION_RIGHT_RETURN }
168 const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
169 #endif // DALI_ELDBUS_AVAILABLE
172 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
173 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
174 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
175 * @return the Ecore_IMF_Keyboard_Modifiers output.
177 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
179 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
182 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
184 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
187 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
189 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
192 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
194 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
197 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
199 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
202 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
204 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
207 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
211 // Copied from x server
212 static unsigned int GetCurrentMilliSeconds(void)
217 static clockid_t clockid;
221 #ifdef CLOCK_MONOTONIC_COARSE
222 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
223 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
225 clockid = CLOCK_MONOTONIC_COARSE;
229 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
231 clockid = CLOCK_MONOTONIC;
238 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
240 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
243 gettimeofday(&tv, NULL);
244 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
247 #ifndef DALI_PROFILE_UBUNTU
248 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
249 #endif // DALI_PROFILE_UBUNTU
252 * Get the device name from the provided ecore key event
254 void GetDeviceName( Ecore_Event_Key* keyEvent, std::string& result )
256 const char* ecoreDeviceName = ecore_device_name_get( keyEvent->dev );
258 if ( ecoreDeviceName )
260 result = ecoreDeviceName;
265 * Get the device class from the provided ecore event
267 void GetDeviceClass( Ecore_Device_Class ecoreDeviceClass, Device::Class::Type& deviceClass )
269 switch( ecoreDeviceClass )
271 case ECORE_DEVICE_CLASS_SEAT:
273 deviceClass = Device::Class::USER;
276 case ECORE_DEVICE_CLASS_KEYBOARD:
278 deviceClass = Device::Class::KEYBOARD;
281 case ECORE_DEVICE_CLASS_MOUSE:
283 deviceClass = Device::Class::MOUSE;
286 case ECORE_DEVICE_CLASS_TOUCH:
288 deviceClass = Device::Class::TOUCH;
291 case ECORE_DEVICE_CLASS_PEN:
293 deviceClass = Device::Class::PEN;
296 case ECORE_DEVICE_CLASS_POINTER:
298 deviceClass = Device::Class::POINTER;
301 case ECORE_DEVICE_CLASS_GAMEPAD:
303 deviceClass = Device::Class::GAMEPAD;
308 deviceClass = Device::Class::NONE;
314 void GetDeviceSubclass( Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subclass::Type& deviceSubclass )
316 switch( ecoreDeviceSubclass )
318 case ECORE_DEVICE_SUBCLASS_FINGER:
320 deviceSubclass = Device::Subclass::FINGER;
323 case ECORE_DEVICE_SUBCLASS_FINGERNAIL:
325 deviceSubclass = Device::Subclass::FINGERNAIL;
328 case ECORE_DEVICE_SUBCLASS_KNUCKLE:
330 deviceSubclass = Device::Subclass::KNUCKLE;
333 case ECORE_DEVICE_SUBCLASS_PALM:
335 deviceSubclass = Device::Subclass::PALM;
338 case ECORE_DEVICE_SUBCLASS_HAND_SIZE:
340 deviceSubclass = Device::Subclass::HAND_SIDE;
343 case ECORE_DEVICE_SUBCLASS_HAND_FLAT:
345 deviceSubclass = Device::Subclass::HAND_FLAT;
348 case ECORE_DEVICE_SUBCLASS_PEN_TIP:
350 deviceSubclass = Device::Subclass::PEN_TIP;
353 case ECORE_DEVICE_SUBCLASS_TRACKPAD:
355 deviceSubclass = Device::Subclass::TRACKPAD;
358 case ECORE_DEVICE_SUBCLASS_TRACKPOINT:
360 deviceSubclass = Device::Subclass::TRACKPOINT;
363 case ECORE_DEVICE_SUBCLASS_TRACKBALL:
365 deviceSubclass = Device::Subclass::TRACKBALL;
368 #ifdef OVER_TIZEN_VERSION_4
369 case ECORE_DEVICE_SUBCLASS_REMOCON:
371 deviceSubclass = Device::Subclass::REMOCON;
374 case ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD:
376 deviceSubclass = Device::Subclass::VIRTUAL_KEYBOARD;
382 deviceSubclass = Device::Subclass::NONE;
388 } // unnamed namespace
390 // Impl to hide EFL implementation.
391 struct EventHandler::Impl
393 // Construction & Destruction
398 Impl( EventHandler* handler, Ecore_Wl_Window* window )
399 : mHandler( handler ),
400 mEcoreEventHandler(),
405 #ifdef DALI_ELDBUS_AVAILABLE
406 , mSystemConnection( NULL )
407 #endif // DALI_ELDBUS_AVAILABLE
409 // Only register for touch and key events if we have a window
412 // Register Touch events
413 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
414 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
415 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
416 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, handler ) );
418 // Register Mouse wheel events
419 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
421 // Register Focus events
422 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
423 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
425 // Register Key events
426 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
427 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
429 // Register Selection event - clipboard selection
430 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
431 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
433 // Register Rotate event
434 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
436 // Register Detent event
437 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
439 #ifndef DALI_PROFILE_UBUNTU
440 // Register Vconf notify - font name and size
441 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
442 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
443 #endif // DALI_PROFILE_UBUNTU
445 #ifdef DALI_ELDBUS_AVAILABLE
446 // Initialize ElDBus.
447 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
450 EcoreElDBusInitialisation( handler );
452 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
453 #endif // DALI_ELDBUS_AVAILABLE
462 #ifndef DALI_PROFILE_UBUNTU
463 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
464 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
465 #endif // DALI_PROFILE_UBUNTU
467 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
469 ecore_event_handler_del( *iter );
472 #ifdef DALI_ELDBUS_AVAILABLE
473 // Close down ElDBus connections.
474 if( mSystemConnection )
476 eldbus_connection_unref( mSystemConnection );
478 #endif // DALI_ELDBUS_AVAILABLE
483 /////////////////////////////////////////////////////////////////////////////////////////////////
485 /////////////////////////////////////////////////////////////////////////////////////////////////
488 * Called when a touch down is received.
490 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
492 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
493 EventHandler* handler( (EventHandler*)data );
495 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
497 PointState::Type state ( PointState::DOWN );
499 // Check if the buttons field is set and ensure it's the primary touch button.
500 // If this event was triggered by buttons other than the primary button (used for touch), then
501 // just send an interrupted event to Core.
502 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
504 state = PointState::INTERRUPTED;
507 Device::Class::Type deviceClass;
508 Device::Subclass::Type deviceSubclass;
510 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
511 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
513 Integration::Point point;
514 point.SetDeviceId( touchEvent->multi.device );
515 point.SetState( state );
516 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
517 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
518 point.SetPressure( touchEvent->multi.pressure );
519 point.SetAngle( Degree( touchEvent->multi.angle ) );
520 point.SetDeviceClass( deviceClass );
521 point.SetDeviceSubclass( deviceSubclass );
523 handler->SendEvent( point, touchEvent->timestamp );
526 return ECORE_CALLBACK_PASS_ON;
530 * Called when a touch up is received.
532 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
534 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
535 EventHandler* handler( (EventHandler*)data );
537 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
539 Device::Class::Type deviceClass;
540 Device::Subclass::Type deviceSubclass;
542 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
543 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
545 Integration::Point point;
546 point.SetDeviceId( touchEvent->multi.device );
547 point.SetState( PointState::UP );
548 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
549 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
550 point.SetPressure( touchEvent->multi.pressure );
551 point.SetAngle( Degree( touchEvent->multi.angle ) );
552 point.SetDeviceClass( deviceClass );
553 point.SetDeviceSubclass( deviceSubclass );
555 handler->SendEvent( point, touchEvent->timestamp );
558 return ECORE_CALLBACK_PASS_ON;
562 * Called when a touch motion is received.
564 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
566 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
567 EventHandler* handler( (EventHandler*)data );
569 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
571 Device::Class::Type deviceClass;
572 Device::Subclass::Type deviceSubclass;
574 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
575 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
577 Integration::Point point;
578 point.SetDeviceId( touchEvent->multi.device );
579 point.SetState( PointState::MOTION );
580 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
581 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
582 point.SetPressure( touchEvent->multi.pressure );
583 point.SetAngle( Degree( touchEvent->multi.angle ) );
584 point.SetDeviceClass( deviceClass );
585 point.SetDeviceSubclass( deviceSubclass );
587 handler->SendEvent( point, touchEvent->timestamp );
590 return ECORE_CALLBACK_PASS_ON;
594 * Called when a touch is canceled.
596 static Eina_Bool EcoreEventMouseButtonCancel( void* data, int type, void* event )
598 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
599 EventHandler* handler( (EventHandler*)data );
601 if( touchEvent->window == (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
603 Integration::Point point;
604 point.SetState( PointState::INTERRUPTED );
605 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
606 handler->SendEvent( point, touchEvent->timestamp );
608 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventMouseButtonCancel\n" );
611 return ECORE_CALLBACK_PASS_ON;
615 * Called when a mouse wheel is received.
617 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
619 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
621 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);
623 EventHandler* handler( (EventHandler*)data );
624 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
626 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
627 handler->SendWheelEvent( wheelEvent );
629 return ECORE_CALLBACK_PASS_ON;
632 /////////////////////////////////////////////////////////////////////////////////////////////////
634 /////////////////////////////////////////////////////////////////////////////////////////////////
637 * Called when a key down is received.
639 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
641 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
643 EventHandler* handler( (EventHandler*)data );
644 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
645 bool eventHandled( false );
647 // If a device key then skip ecore_imf_context_filter_event.
648 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
650 Ecore_IMF_Context* imfContext = NULL;
651 Dali::ImfManager imfManager( ImfManager::Get() );
654 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
659 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
660 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
661 ecoreKeyDownEvent.keyname = keyEvent->keyname;
662 ecoreKeyDownEvent.key = keyEvent->key;
663 ecoreKeyDownEvent.string = keyEvent->string;
664 ecoreKeyDownEvent.compose = keyEvent->compose;
665 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
666 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
667 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
668 ecoreKeyDownEvent.dev_name = "";
669 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
670 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
672 std::string checkDevice;
673 GetDeviceName( keyEvent, checkDevice );
675 // If the device is IME and the focused key is the direction keys, then we should send a key event to move a key cursor.
676 if( ( checkDevice == "ime" ) && ( ( !strncmp( keyEvent->keyname, "Left", 4 ) ) ||
677 ( !strncmp( keyEvent->keyname, "Right", 5 ) ) ||
678 ( !strncmp( keyEvent->keyname, "Up", 2 ) ) ||
679 ( !strncmp( keyEvent->keyname, "Down", 4 ) ) ) )
685 eventHandled = ecore_imf_context_filter_event( imfContext,
686 ECORE_IMF_EVENT_KEY_DOWN,
687 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
690 // If the event has not been handled by IMF then check if we should reset our IMF context
693 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
694 !strcmp( keyEvent->keyname, "Return" ) ||
695 !strcmp( keyEvent->keyname, "KP_Enter" ) )
697 ecore_imf_context_reset( imfContext );
703 // If the event wasn't handled then we should send a key event.
706 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
708 std::string keyName( keyEvent->keyname );
709 std::string keyString( "" );
710 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
711 keyCode = (keyCode == -1) ? 0 : keyCode;
712 int modifier( keyEvent->modifiers );
713 unsigned long time = keyEvent->timestamp;
714 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
715 keyCode = atoi(keyEvent->keyname + 8);
717 // Ensure key event string is not NULL as keys like SHIFT have a null string.
718 if ( keyEvent->string )
720 keyString = keyEvent->string;
723 std::string deviceName;
724 Device::Class::Type deviceClass;
725 Device::Subclass::Type deviceSubclass;
727 GetDeviceName( keyEvent, deviceName );
728 GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
729 GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
731 DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s) deviceClass(%d)\n", deviceName.c_str(), deviceClass );
733 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, deviceName, deviceClass, deviceSubclass );
734 handler->SendEvent( keyEvent );
738 return ECORE_CALLBACK_PASS_ON;
742 * Called when a key up is received.
744 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
746 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
748 EventHandler* handler( (EventHandler*)data );
749 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
750 bool eventHandled( false );
752 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
753 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
755 Ecore_IMF_Context* imfContext = NULL;
756 Dali::ImfManager imfManager( ImfManager::Get() );
759 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
764 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
765 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
766 ecoreKeyUpEvent.keyname = keyEvent->keyname;
767 ecoreKeyUpEvent.key = keyEvent->key;
768 ecoreKeyUpEvent.string = keyEvent->string;
769 ecoreKeyUpEvent.compose = keyEvent->compose;
770 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
771 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
772 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
773 ecoreKeyUpEvent.dev_name = "";
774 ecoreKeyUpEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
775 ecoreKeyUpEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
777 eventHandled = ecore_imf_context_filter_event( imfContext,
778 ECORE_IMF_EVENT_KEY_UP,
779 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
783 // If the event wasn't handled then we should send a key event.
786 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
788 std::string keyName( keyEvent->keyname );
789 std::string keyString( "" );
790 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
791 keyCode = (keyCode == -1) ? 0 : keyCode;
792 int modifier( keyEvent->modifiers );
793 unsigned long time = keyEvent->timestamp;
794 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
795 keyCode = atoi(keyEvent->keyname + 8);
797 // Ensure key event string is not NULL as keys like SHIFT have a null string.
798 if ( keyEvent->string )
800 keyString = keyEvent->string;
803 std::string deviceName;
804 Device::Class::Type deviceClass;
805 Device::Subclass::Type deviceSubclass;
807 GetDeviceName( keyEvent, deviceName );
808 GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
809 GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
811 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, deviceName, deviceClass, deviceSubclass );
812 handler->SendEvent( keyEvent );
816 return ECORE_CALLBACK_PASS_ON;
819 /////////////////////////////////////////////////////////////////////////////////////////////////
821 /////////////////////////////////////////////////////////////////////////////////////////////////
824 * Called when the window gains focus.
826 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
828 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
829 EventHandler* handler( (EventHandler*)data );
831 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
833 // If the window gains focus and we hid the keyboard then show it again.
834 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
836 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
838 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
840 Dali::ImfManager imfManager( ImfManager::Get() );
843 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
844 if( imfManagerImpl.RestoreAfterFocusLost() )
846 imfManagerImpl.Activate();
850 Dali::Clipboard clipboard = Clipboard::Get();
851 clipboard.HideClipboard();
854 return ECORE_CALLBACK_PASS_ON;
858 * Called when the window loses focus.
860 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
862 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
863 EventHandler* handler( (EventHandler*)data );
865 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
867 // If the window loses focus then hide the keyboard.
868 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
870 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
872 Dali::ImfManager imfManager( ImfManager::Get() );
875 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
876 if( imfManagerImpl.RestoreAfterFocusLost() )
878 imfManagerImpl.Deactivate();
883 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
884 Dali::Clipboard clipboard = Clipboard::Get();
887 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
888 clipBoardImpl.HideClipboard(true);
892 return ECORE_CALLBACK_PASS_ON;
896 * Called when the window is damaged.
898 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
900 return ECORE_CALLBACK_PASS_ON;
904 * Called when the window properties are changed.
905 * We are only interested in the font change.
909 /////////////////////////////////////////////////////////////////////////////////////////////////
910 // Drag & Drop Callbacks
911 /////////////////////////////////////////////////////////////////////////////////////////////////
914 * Called when a dragged item enters our window's bounds.
915 * This is when items are dragged INTO our window.
917 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
919 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
921 return ECORE_CALLBACK_PASS_ON;
925 * Called when a dragged item is moved within our window.
926 * This is when items are dragged INTO our window.
928 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
930 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
932 return ECORE_CALLBACK_PASS_ON;
936 * Called when a dragged item leaves our window's bounds.
937 * This is when items are dragged INTO our window.
939 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
941 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
943 return ECORE_CALLBACK_PASS_ON;
947 * Called when the dragged item is dropped within our window's bounds.
948 * This is when items are dragged INTO our window.
950 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
952 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
954 return ECORE_CALLBACK_PASS_ON;
958 * Called when a dragged item is moved from our window and the target window has done processing it.
959 * This is when items are dragged FROM our window.
961 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
963 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
964 return ECORE_CALLBACK_PASS_ON;
968 * Called when a dragged item is moved from our window and the target window has sent us a status.
969 * This is when items are dragged FROM our window.
971 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
973 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
974 return ECORE_CALLBACK_PASS_ON;
978 * Called when the client messages (i.e. the accessibility events) are received.
980 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
982 return ECORE_CALLBACK_PASS_ON;
986 /////////////////////////////////////////////////////////////////////////////////////////////////
987 // ElDBus Accessibility Callbacks
988 /////////////////////////////////////////////////////////////////////////////////////////////////
990 #ifdef DALI_ELDBUS_AVAILABLE
991 // Callback for Ecore ElDBus accessibility events.
992 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
994 EventHandler* handler = static_cast< EventHandler* >( context );
995 // Ignore any accessibility events when paused.
996 if( handler->mPaused )
1001 if( !handler->mAccessibilityAdaptor )
1003 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
1007 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1008 if( !accessibilityAdaptor )
1010 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
1016 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
1019 // The string defines the arg-list's respective types.
1020 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
1022 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1025 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
1027 // Create a touch point object.
1028 TouchPoint::State touchPointState( TouchPoint::Down );
1031 touchPointState = TouchPoint::Down; // Mouse down.
1033 else if( state == 1 )
1035 touchPointState = TouchPoint::Motion; // Mouse move.
1037 else if( state == 2 )
1039 touchPointState = TouchPoint::Up; // Mouse up.
1043 touchPointState = TouchPoint::Interrupted; // Error.
1046 // Send touch event to accessibility adaptor.
1047 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1049 // Perform actions based on received gestures.
1050 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
1051 switch( gestureValue )
1053 case 0: // OneFingerHover
1056 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1059 case 1: // TwoFingersHover
1061 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1062 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1065 case 2: // ThreeFingersHover
1067 // Read from top item on screen continuously.
1068 accessibilityAdaptor->HandleActionReadFromTopEvent();
1071 case 3: // OneFingerFlickLeft
1073 // Move to previous item.
1074 accessibilityAdaptor->HandleActionReadPreviousEvent();
1077 case 4: // OneFingerFlickRight
1079 // Move to next item.
1080 accessibilityAdaptor->HandleActionReadNextEvent();
1083 case 5: // OneFingerFlickUp
1085 // Move to previous item.
1086 accessibilityAdaptor->HandleActionPreviousEvent();
1089 case 6: // OneFingerFlickDown
1091 // Move to next item.
1092 accessibilityAdaptor->HandleActionNextEvent();
1095 case 7: // TwoFingersFlickUp
1097 // Scroll up the list.
1098 accessibilityAdaptor->HandleActionScrollUpEvent();
1101 case 8: // TwoFingersFlickDown
1103 // Scroll down the list.
1104 accessibilityAdaptor->HandleActionScrollDownEvent();
1107 case 9: // TwoFingersFlickLeft
1109 // Scroll left to the previous page
1110 accessibilityAdaptor->HandleActionPageLeftEvent();
1113 case 10: // TwoFingersFlickRight
1115 // Scroll right to the next page
1116 accessibilityAdaptor->HandleActionPageRightEvent();
1119 case 11: // ThreeFingersFlickLeft
1124 case 12: // ThreeFingersFlickRight
1129 case 13: // ThreeFingersFlickUp
1134 case 14: // ThreeFingersFlickDown
1139 case 15: // OneFingerSingleTap
1142 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1145 case 16: // OneFingerDoubleTap
1147 // Activate selected item / active edit mode.
1148 accessibilityAdaptor->HandleActionActivateEvent();
1151 case 17: // OneFingerTripleTap
1154 accessibilityAdaptor->HandleActionZoomEvent();
1157 case 18: // TwoFingersSingleTap
1159 // Pause/Resume current speech
1160 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1163 case 19: // TwoFingersDoubleTap
1165 // Start/Stop current action
1166 accessibilityAdaptor->HandleActionStartStopEvent();
1169 case 20: // TwoFingersTripleTap
1171 // Read information from indicator
1172 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1175 case 21: // ThreeFingersSingleTap
1177 // Read from top item on screen continuously.
1178 accessibilityAdaptor->HandleActionReadFromTopEvent();
1181 case 22: // ThreeFingersDoubleTap
1183 // Read from next item continuously.
1184 accessibilityAdaptor->HandleActionReadFromNextEvent();
1187 case 23: // ThreeFingersTripleTap
1192 case 24: // OneFingerFlickLeftReturn
1194 // Scroll up to the previous page
1195 accessibilityAdaptor->HandleActionPageUpEvent();
1198 case 25: // OneFingerFlickRightReturn
1200 // Scroll down to the next page
1201 accessibilityAdaptor->HandleActionPageDownEvent();
1204 case 26: // OneFingerFlickUpReturn
1206 // Move to the first item on screen
1207 accessibilityAdaptor->HandleActionMoveToFirstEvent();
1210 case 27: // OneFingerFlickDownReturn
1212 // Move to the last item on screen
1213 accessibilityAdaptor->HandleActionMoveToLastEvent();
1216 case 28: // TwoFingersFlickLeftReturn
1221 case 29: // TwoFingersFlickRightReturn
1226 case 30: // TwoFingersFlickUpReturn
1231 case 31: // TwoFingersFlickDownReturn
1236 case 32: // ThreeFingersFlickLeftReturn
1241 case 33: // ThreeFingersFlickRightReturn
1246 case 34: // ThreeFingersFlickUpReturn
1251 case 35: // ThreeFingersFlickDownReturn
1259 void EcoreElDBusInitialisation( void *handle )
1261 Eldbus_Object *object;
1262 Eldbus_Proxy *manager;
1264 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1266 DALI_LOG_ERROR( "Unable to get system bus\n" );
1269 object = eldbus_object_get( mSystemConnection, BUS, PATH );
1272 DALI_LOG_ERROR( "Getting object failed\n" );
1276 manager = eldbus_proxy_get( object, INTERFACE );
1279 DALI_LOG_ERROR( "Getting proxy failed\n" );
1283 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1285 DALI_LOG_ERROR( "No signal handler returned\n" );
1288 #endif // DALI_ELDBUS_AVAILABLE
1291 * Called when the source window notifies us the content in clipboard is selected.
1293 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1295 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1296 return ECORE_CALLBACK_PASS_ON;
1300 * Called when the source window sends us about the selected content.
1301 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1303 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1305 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1306 return ECORE_CALLBACK_PASS_ON;
1310 * Called when the source window notifies us the content in clipboard is selected.
1312 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1314 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1316 Dali::Clipboard clipboard = Clipboard::Get();
1319 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1320 clipBoardImpl.ExcuteBuffered( true, event );
1322 return ECORE_CALLBACK_PASS_ON;
1326 * Called when the source window sends us about the selected content.
1327 * For example, when item is selected in the clipboard.
1329 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1331 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1333 EventHandler* handler( (EventHandler*)data );
1334 Dali::Clipboard clipboard = Clipboard::Get();
1335 char *selectionData = NULL;
1338 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1339 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1341 if ( selectionData && handler->mClipboardEventNotifier )
1343 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1344 std::string content( selectionData, strlen(selectionData) );
1346 clipboardEventNotifier.SetContent( content );
1347 clipboardEventNotifier.EmitContentSelectedSignal();
1349 return ECORE_CALLBACK_PASS_ON;
1353 * Called when rotate event is recevied
1355 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1357 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1359 EventHandler* handler( (EventHandler*)data );
1360 Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1362 if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1364 return ECORE_CALLBACK_PASS_ON;
1367 RotationEvent rotationEvent;
1368 rotationEvent.angle = ev->angle;
1369 rotationEvent.winResize = 0;
1371 if( ev->angle == 0 || ev->angle == 180 )
1373 rotationEvent.width = ev->w;
1374 rotationEvent.height = ev->h;
1378 rotationEvent.width = ev->h;
1379 rotationEvent.height = ev->w;
1382 handler->SendRotationPrepareEvent( rotationEvent );
1384 return ECORE_CALLBACK_PASS_ON;
1388 * Called when detent event is recevied
1390 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1392 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1393 EventHandler* handler( (EventHandler*)data );
1394 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1395 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1396 int timeStamp = e->timestamp;
1398 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1399 handler->SendWheelEvent( wheelEvent );
1400 return ECORE_CALLBACK_PASS_ON;
1403 /////////////////////////////////////////////////////////////////////////////////////////////////
1405 /////////////////////////////////////////////////////////////////////////////////////////////////
1407 * Called when a font name is changed.
1409 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1411 EventHandler* handler = static_cast<EventHandler*>( data );
1412 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1416 * Called when a font size is changed.
1418 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1420 EventHandler* handler = static_cast<EventHandler*>( data );
1421 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1424 void ConvertTouchPosition( Integration::Point& point )
1426 Vector2 position = point.GetScreenPosition();
1427 Vector2 convertedPosition;
1429 switch( mRotationAngle )
1433 convertedPosition.x = mWindowWidth - position.y;
1434 convertedPosition.y = position.x;
1439 convertedPosition.x = mWindowWidth - position.x;
1440 convertedPosition.y = mWindowHeight - position.y;
1445 convertedPosition.x = position.y;
1446 convertedPosition.y = mWindowHeight - position.x;
1451 convertedPosition = position;
1456 point.SetScreenPosition( convertedPosition );
1460 EventHandler* mHandler;
1461 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1462 Ecore_Wl_Window* mWindow;
1466 #ifdef DALI_ELDBUS_AVAILABLE
1467 Eldbus_Connection* mSystemConnection;
1468 #endif // DALI_ELDBUS_AVAILABLE
1471 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1472 : mCoreEventInterface( coreEventInterface ),
1473 mGestureManager( gestureManager ),
1474 mStyleMonitor( StyleMonitor::Get() ),
1475 mDamageObserver( damageObserver ),
1476 mRotationObserver( NULL ),
1477 mDragAndDropDetector( dndDetector ),
1478 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1479 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1480 mClipboard( Clipboard::Get() ),
1484 Ecore_Wl_Window* window = 0;
1486 // this code only works with the Ecore RenderSurface so need to downcast
1487 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1490 window = ecoreSurface->GetWlWindow();
1493 mImpl = new Impl(this, window);
1496 EventHandler::~EventHandler()
1503 mGestureManager.Stop();
1506 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1510 timeStamp = GetCurrentMilliSeconds();
1513 mImpl->ConvertTouchPosition( point );
1515 Integration::TouchEvent touchEvent;
1516 Integration::HoverEvent hoverEvent;
1517 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1518 if(type != Integration::TouchEventCombiner::DispatchNone )
1520 DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.GetDeviceId(), point.GetState(), point.GetScreenPosition().x, point.GetScreenPosition().y);
1522 // First the touch and/or hover event & related gesture events are queued
1523 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1525 mCoreEventInterface.QueueCoreEvent( touchEvent );
1526 mGestureManager.SendEvent(touchEvent);
1529 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1531 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1534 // Next the events are processed with a single call into Core
1535 mCoreEventInterface.ProcessCoreEvents();
1539 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1541 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1542 if ( physicalKeyboard )
1544 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1546 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1550 // Create send KeyEvent to Core.
1551 mCoreEventInterface.QueueCoreEvent( keyEvent );
1552 mCoreEventInterface.ProcessCoreEvents();
1555 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1557 // Create WheelEvent and send to Core.
1558 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1559 mCoreEventInterface.QueueCoreEvent( event );
1560 mCoreEventInterface.ProcessCoreEvents();
1563 void EventHandler::SendEvent( StyleChange::Type styleChange )
1565 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1566 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1569 void EventHandler::SendEvent( const DamageArea& area )
1571 mDamageObserver.OnDamaged( area );
1574 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1576 if( mRotationObserver != NULL )
1578 mImpl->mRotationAngle = event.angle;
1579 mImpl->mWindowWidth = event.width;
1580 mImpl->mWindowHeight = event.height;
1582 mRotationObserver->OnRotationPrepare( event );
1583 mRotationObserver->OnRotationRequest();
1587 void EventHandler::SendRotationRequestEvent( )
1589 // No need to separate event into prepare and request in wayland
1592 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1594 Integration::Point convertedPoint( point );
1595 SendEvent(convertedPoint, timeStamp);
1598 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1600 SendWheelEvent( wheelEvent );
1603 void EventHandler::FeedKeyEvent( KeyEvent& event )
1605 Integration::KeyEvent convertedEvent( event );
1606 SendEvent( convertedEvent );
1609 void EventHandler::FeedEvent( Integration::Event& event )
1611 mCoreEventInterface.QueueCoreEvent( event );
1612 mCoreEventInterface.ProcessCoreEvents();
1615 void EventHandler::Reset()
1619 // Any touch listeners should be told of the interruption.
1620 Integration::TouchEvent event;
1621 Integration::Point point;
1622 point.SetState( PointState::INTERRUPTED );
1623 event.AddPoint( point );
1625 // First the touch event & related gesture events are queued
1626 mCoreEventInterface.QueueCoreEvent( event );
1627 mGestureManager.SendEvent( event );
1629 // Next the events are processed with a single call into Core
1630 mCoreEventInterface.ProcessCoreEvents();
1633 void EventHandler::Pause()
1639 void EventHandler::Resume()
1645 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1647 mDragAndDropDetector = detector;
1650 void EventHandler::SetRotationObserver( RotationObserver* observer )
1652 mRotationObserver = observer;
1655 } // namespace Adaptor
1657 } // namespace Internal
1661 #pragma GCC diagnostic pop