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 * EcoreInputModifierToEcoreIMFLock function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Locks enums.
173 * @param[in] modifier the Ecore_Event_Modifier input.
174 * @return the Ecore_IMF_Keyboard_Locks output.
176 Ecore_IMF_Keyboard_Locks EcoreInputModifierToEcoreIMFLock( unsigned int modifier )
178 unsigned int lock( ECORE_IMF_KEYBOARD_LOCK_NONE ); // If no other matches, returns NONE.
180 if( modifier & ECORE_EVENT_LOCK_NUM )
182 lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.
185 if( modifier & ECORE_EVENT_LOCK_CAPS )
187 lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.
190 if( modifier & ECORE_EVENT_LOCK_SCROLL )
192 lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.
195 return static_cast<Ecore_IMF_Keyboard_Locks>( lock );
199 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
200 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
201 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
202 * @return the Ecore_IMF_Keyboard_Modifiers output.
204 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
206 unsigned int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
209 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
211 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
214 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
216 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
219 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
221 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
224 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
226 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
229 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
231 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
234 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
238 // Copied from x server
239 static unsigned int GetCurrentMilliSeconds(void)
244 static clockid_t clockid;
248 #ifdef CLOCK_MONOTONIC_COARSE
249 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
250 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
252 clockid = CLOCK_MONOTONIC_COARSE;
256 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
258 clockid = CLOCK_MONOTONIC;
265 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
267 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
270 gettimeofday(&tv, NULL);
271 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
274 #ifndef DALI_PROFILE_UBUNTU
275 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
276 #endif // DALI_PROFILE_UBUNTU
279 * Get the device name from the provided ecore key event
281 void GetDeviceName( Ecore_Event_Key* keyEvent, std::string& result )
283 const char* ecoreDeviceName = ecore_device_name_get( keyEvent->dev );
285 if ( ecoreDeviceName )
287 result = ecoreDeviceName;
292 * Get the device class from the provided ecore event
294 void GetDeviceClass( Ecore_Device_Class ecoreDeviceClass, Device::Class::Type& deviceClass )
296 switch( ecoreDeviceClass )
298 case ECORE_DEVICE_CLASS_SEAT:
300 deviceClass = Device::Class::USER;
303 case ECORE_DEVICE_CLASS_KEYBOARD:
305 deviceClass = Device::Class::KEYBOARD;
308 case ECORE_DEVICE_CLASS_MOUSE:
310 deviceClass = Device::Class::MOUSE;
313 case ECORE_DEVICE_CLASS_TOUCH:
315 deviceClass = Device::Class::TOUCH;
318 case ECORE_DEVICE_CLASS_PEN:
320 deviceClass = Device::Class::PEN;
323 case ECORE_DEVICE_CLASS_POINTER:
325 deviceClass = Device::Class::POINTER;
328 case ECORE_DEVICE_CLASS_GAMEPAD:
330 deviceClass = Device::Class::GAMEPAD;
335 deviceClass = Device::Class::NONE;
341 void GetDeviceSubclass( Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subclass::Type& deviceSubclass )
343 switch( ecoreDeviceSubclass )
345 case ECORE_DEVICE_SUBCLASS_FINGER:
347 deviceSubclass = Device::Subclass::FINGER;
350 case ECORE_DEVICE_SUBCLASS_FINGERNAIL:
352 deviceSubclass = Device::Subclass::FINGERNAIL;
355 case ECORE_DEVICE_SUBCLASS_KNUCKLE:
357 deviceSubclass = Device::Subclass::KNUCKLE;
360 case ECORE_DEVICE_SUBCLASS_PALM:
362 deviceSubclass = Device::Subclass::PALM;
365 case ECORE_DEVICE_SUBCLASS_HAND_SIZE:
367 deviceSubclass = Device::Subclass::HAND_SIDE;
370 case ECORE_DEVICE_SUBCLASS_HAND_FLAT:
372 deviceSubclass = Device::Subclass::HAND_FLAT;
375 case ECORE_DEVICE_SUBCLASS_PEN_TIP:
377 deviceSubclass = Device::Subclass::PEN_TIP;
380 case ECORE_DEVICE_SUBCLASS_TRACKPAD:
382 deviceSubclass = Device::Subclass::TRACKPAD;
385 case ECORE_DEVICE_SUBCLASS_TRACKPOINT:
387 deviceSubclass = Device::Subclass::TRACKPOINT;
390 case ECORE_DEVICE_SUBCLASS_TRACKBALL:
392 deviceSubclass = Device::Subclass::TRACKBALL;
395 #ifdef OVER_TIZEN_VERSION_4
396 case ECORE_DEVICE_SUBCLASS_REMOCON:
398 deviceSubclass = Device::Subclass::REMOCON;
401 case ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD:
403 deviceSubclass = Device::Subclass::VIRTUAL_KEYBOARD;
409 deviceSubclass = Device::Subclass::NONE;
415 } // unnamed namespace
417 // Impl to hide EFL implementation.
418 struct EventHandler::Impl
420 // Construction & Destruction
425 Impl( EventHandler* handler, Ecore_Wl_Window* window )
426 : mHandler( handler ),
427 mEcoreEventHandler(),
432 #ifdef DALI_ELDBUS_AVAILABLE
433 , mSystemConnection( NULL )
434 #endif // DALI_ELDBUS_AVAILABLE
436 // Only register for touch and key events if we have a window
439 // Register Touch events
440 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
441 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
442 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
443 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, handler ) );
445 // Register Mouse wheel events
446 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
448 // Register Focus events
449 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
450 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
452 // Register Key events
453 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
454 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
456 // Register Selection event - clipboard selection
457 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
458 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
460 // Register Rotate event
461 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
463 // Register Detent event
464 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
466 #ifndef DALI_PROFILE_UBUNTU
467 // Register Vconf notify - font name and size
468 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
469 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
470 #endif // DALI_PROFILE_UBUNTU
472 #ifdef DALI_ELDBUS_AVAILABLE
473 // Initialize ElDBus.
474 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
477 EcoreElDBusInitialisation( handler );
479 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
480 #endif // DALI_ELDBUS_AVAILABLE
489 #ifndef DALI_PROFILE_UBUNTU
490 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
491 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
492 #endif // DALI_PROFILE_UBUNTU
494 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
496 ecore_event_handler_del( *iter );
499 #ifdef DALI_ELDBUS_AVAILABLE
500 // Close down ElDBus connections.
501 if( mSystemConnection )
503 eldbus_connection_unref( mSystemConnection );
505 #endif // DALI_ELDBUS_AVAILABLE
510 /////////////////////////////////////////////////////////////////////////////////////////////////
512 /////////////////////////////////////////////////////////////////////////////////////////////////
515 * Called when a touch down is received.
517 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
519 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
520 EventHandler* handler( (EventHandler*)data );
522 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
524 PointState::Type state ( PointState::DOWN );
526 // Check if the buttons field is set and ensure it's the primary touch button.
527 // If this event was triggered by buttons other than the primary button (used for touch), then
528 // just send an interrupted event to Core.
529 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
531 state = PointState::INTERRUPTED;
534 Device::Class::Type deviceClass;
535 Device::Subclass::Type deviceSubclass;
537 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
538 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
540 Integration::Point point;
541 point.SetDeviceId( touchEvent->multi.device );
542 point.SetState( state );
543 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
544 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
545 point.SetPressure( touchEvent->multi.pressure );
546 point.SetAngle( Degree( touchEvent->multi.angle ) );
547 point.SetDeviceClass( deviceClass );
548 point.SetDeviceSubclass( deviceSubclass );
550 handler->SendEvent( point, touchEvent->timestamp );
553 return ECORE_CALLBACK_PASS_ON;
557 * Called when a touch up is received.
559 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
561 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
562 EventHandler* handler( (EventHandler*)data );
564 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
566 Device::Class::Type deviceClass;
567 Device::Subclass::Type deviceSubclass;
569 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
570 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
572 Integration::Point point;
573 point.SetDeviceId( touchEvent->multi.device );
574 point.SetState( PointState::UP );
575 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
576 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
577 point.SetPressure( touchEvent->multi.pressure );
578 point.SetAngle( Degree( touchEvent->multi.angle ) );
579 point.SetDeviceClass( deviceClass );
580 point.SetDeviceSubclass( deviceSubclass );
582 handler->SendEvent( point, touchEvent->timestamp );
585 return ECORE_CALLBACK_PASS_ON;
589 * Called when a touch motion is received.
591 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
593 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
594 EventHandler* handler( (EventHandler*)data );
596 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
598 Device::Class::Type deviceClass;
599 Device::Subclass::Type deviceSubclass;
601 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
602 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
604 Integration::Point point;
605 point.SetDeviceId( touchEvent->multi.device );
606 point.SetState( PointState::MOTION );
607 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
608 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
609 point.SetPressure( touchEvent->multi.pressure );
610 point.SetAngle( Degree( touchEvent->multi.angle ) );
611 point.SetDeviceClass( deviceClass );
612 point.SetDeviceSubclass( deviceSubclass );
614 handler->SendEvent( point, touchEvent->timestamp );
617 return ECORE_CALLBACK_PASS_ON;
621 * Called when a touch is canceled.
623 static Eina_Bool EcoreEventMouseButtonCancel( void* data, int type, void* event )
625 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
626 EventHandler* handler( (EventHandler*)data );
628 if( touchEvent->window == (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
630 Integration::Point point;
631 point.SetState( PointState::INTERRUPTED );
632 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
633 handler->SendEvent( point, touchEvent->timestamp );
635 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventMouseButtonCancel\n" );
638 return ECORE_CALLBACK_PASS_ON;
642 * Called when a mouse wheel is received.
644 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
646 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
648 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);
650 EventHandler* handler( (EventHandler*)data );
651 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
653 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
654 handler->SendWheelEvent( wheelEvent );
656 return ECORE_CALLBACK_PASS_ON;
659 /////////////////////////////////////////////////////////////////////////////////////////////////
661 /////////////////////////////////////////////////////////////////////////////////////////////////
664 * Called when a key down is received.
666 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
668 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
670 EventHandler* handler( (EventHandler*)data );
671 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
672 bool eventHandled( false );
674 // If a device key then skip ecore_imf_context_filter_event.
675 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
677 Ecore_IMF_Context* imfContext = NULL;
678 Dali::ImfManager imfManager( ImfManager::Get() );
681 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
686 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
687 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
688 ecoreKeyDownEvent.keyname = keyEvent->keyname;
689 ecoreKeyDownEvent.key = keyEvent->key;
690 ecoreKeyDownEvent.string = keyEvent->string;
691 ecoreKeyDownEvent.compose = keyEvent->compose;
692 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
693 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
694 ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent->modifiers );
695 ecoreKeyDownEvent.dev_name = ecore_device_name_get( keyEvent->dev );
696 ecoreKeyDownEvent.dev_class = static_cast<Ecore_IMF_Device_Class>( ecore_device_class_get( keyEvent->dev ) );
697 ecoreKeyDownEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass>( ecore_device_subclass_get( keyEvent->dev ) );
699 std::string checkDevice;
700 GetDeviceName( keyEvent, checkDevice );
702 // 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.
703 if( ( checkDevice == "ime" ) && ( ( !strncmp( keyEvent->keyname, "Left", 4 ) ) ||
704 ( !strncmp( keyEvent->keyname, "Right", 5 ) ) ||
705 ( !strncmp( keyEvent->keyname, "Up", 2 ) ) ||
706 ( !strncmp( keyEvent->keyname, "Down", 4 ) ) ) )
712 eventHandled = ecore_imf_context_filter_event( imfContext,
713 ECORE_IMF_EVENT_KEY_DOWN,
714 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
717 // If the event has not been handled by IMF then check if we should reset our IMF context
720 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
721 !strcmp( keyEvent->keyname, "Return" ) ||
722 !strcmp( keyEvent->keyname, "KP_Enter" ) ||
723 !strcmp( keyEvent->keyname, "XF86Exit" ) )
725 ecore_imf_context_reset( imfContext );
731 // If the event wasn't handled then we should send a key event.
734 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
736 std::string keyName( keyEvent->keyname );
737 std::string keyString( "" );
738 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
739 keyCode = (keyCode == -1) ? 0 : keyCode;
740 int modifier( keyEvent->modifiers );
741 unsigned long time = keyEvent->timestamp;
742 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
743 keyCode = atoi(keyEvent->keyname + 8);
745 // Ensure key event string is not NULL as keys like SHIFT have a null string.
746 if ( keyEvent->string )
748 keyString = keyEvent->string;
751 std::string deviceName;
752 Device::Class::Type deviceClass;
753 Device::Subclass::Type deviceSubclass;
755 GetDeviceName( keyEvent, deviceName );
756 GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
757 GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
759 DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s) deviceClass(%d)\n", deviceName.c_str(), deviceClass );
761 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, deviceName, deviceClass, deviceSubclass );
762 handler->SendEvent( keyEvent );
766 return ECORE_CALLBACK_PASS_ON;
770 * Called when a key up is received.
772 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
774 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
776 EventHandler* handler( (EventHandler*)data );
777 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
778 bool eventHandled( false );
780 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
781 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
783 Ecore_IMF_Context* imfContext = NULL;
784 Dali::ImfManager imfManager( ImfManager::Get() );
787 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
792 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
793 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
794 ecoreKeyUpEvent.keyname = keyEvent->keyname;
795 ecoreKeyUpEvent.key = keyEvent->key;
796 ecoreKeyUpEvent.string = keyEvent->string;
797 ecoreKeyUpEvent.compose = keyEvent->compose;
798 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
799 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
800 ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent->modifiers );
801 ecoreKeyUpEvent.dev_name = ecore_device_name_get( keyEvent->dev );
802 ecoreKeyUpEvent.dev_class = static_cast<Ecore_IMF_Device_Class>( ecore_device_class_get( keyEvent->dev ) );
803 ecoreKeyUpEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass>( ecore_device_subclass_get( keyEvent->dev ) );
805 eventHandled = ecore_imf_context_filter_event( imfContext,
806 ECORE_IMF_EVENT_KEY_UP,
807 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
811 // If the event wasn't handled then we should send a key event.
814 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
816 std::string keyName( keyEvent->keyname );
817 std::string keyString( "" );
818 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
819 keyCode = (keyCode == -1) ? 0 : keyCode;
820 int modifier( keyEvent->modifiers );
821 unsigned long time = keyEvent->timestamp;
822 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
823 keyCode = atoi(keyEvent->keyname + 8);
825 // Ensure key event string is not NULL as keys like SHIFT have a null string.
826 if ( keyEvent->string )
828 keyString = keyEvent->string;
831 std::string deviceName;
832 Device::Class::Type deviceClass;
833 Device::Subclass::Type deviceSubclass;
835 GetDeviceName( keyEvent, deviceName );
836 GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
837 GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
839 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, deviceName, deviceClass, deviceSubclass );
840 handler->SendEvent( keyEvent );
844 return ECORE_CALLBACK_PASS_ON;
847 /////////////////////////////////////////////////////////////////////////////////////////////////
849 /////////////////////////////////////////////////////////////////////////////////////////////////
852 * Called when the window gains focus.
854 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
856 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
857 EventHandler* handler( (EventHandler*)data );
859 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
861 // If the window gains focus and we hid the keyboard then show it again.
862 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
864 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
866 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
868 Dali::ImfManager imfManager( ImfManager::Get() );
871 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
872 if( imfManagerImpl.RestoreAfterFocusLost() )
874 imfManagerImpl.Activate();
878 Dali::Clipboard clipboard = Clipboard::Get();
879 clipboard.HideClipboard();
882 return ECORE_CALLBACK_PASS_ON;
886 * Called when the window loses focus.
888 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
890 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
891 EventHandler* handler( (EventHandler*)data );
893 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
895 // If the window loses focus then hide the keyboard.
896 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
898 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
900 Dali::ImfManager imfManager( ImfManager::Get() );
903 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
904 if( imfManagerImpl.RestoreAfterFocusLost() )
906 imfManagerImpl.Deactivate();
911 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
912 Dali::Clipboard clipboard = Clipboard::Get();
915 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
916 clipBoardImpl.HideClipboard(true);
920 return ECORE_CALLBACK_PASS_ON;
924 * Called when the window is damaged.
926 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
928 return ECORE_CALLBACK_PASS_ON;
932 * Called when the window properties are changed.
933 * We are only interested in the font change.
937 /////////////////////////////////////////////////////////////////////////////////////////////////
938 // Drag & Drop Callbacks
939 /////////////////////////////////////////////////////////////////////////////////////////////////
942 * Called when a dragged item enters our window's bounds.
943 * This is when items are dragged INTO our window.
945 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
947 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
949 return ECORE_CALLBACK_PASS_ON;
953 * Called when a dragged item is moved within our window.
954 * This is when items are dragged INTO our window.
956 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
958 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
960 return ECORE_CALLBACK_PASS_ON;
964 * Called when a dragged item leaves our window's bounds.
965 * This is when items are dragged INTO our window.
967 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
969 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
971 return ECORE_CALLBACK_PASS_ON;
975 * Called when the dragged item is dropped within our window's bounds.
976 * This is when items are dragged INTO our window.
978 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
980 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
982 return ECORE_CALLBACK_PASS_ON;
986 * Called when a dragged item is moved from our window and the target window has done processing it.
987 * This is when items are dragged FROM our window.
989 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
991 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
992 return ECORE_CALLBACK_PASS_ON;
996 * Called when a dragged item is moved from our window and the target window has sent us a status.
997 * This is when items are dragged FROM our window.
999 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
1001 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
1002 return ECORE_CALLBACK_PASS_ON;
1006 * Called when the client messages (i.e. the accessibility events) are received.
1008 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
1010 return ECORE_CALLBACK_PASS_ON;
1014 /////////////////////////////////////////////////////////////////////////////////////////////////
1015 // ElDBus Accessibility Callbacks
1016 /////////////////////////////////////////////////////////////////////////////////////////////////
1018 #ifdef DALI_ELDBUS_AVAILABLE
1019 // Callback for Ecore ElDBus accessibility events.
1020 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
1022 EventHandler* handler = static_cast< EventHandler* >( context );
1023 // Ignore any accessibility events when paused.
1024 if( handler->mPaused )
1029 if( !handler->mAccessibilityAdaptor )
1031 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
1035 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1036 if( !accessibilityAdaptor )
1038 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
1044 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
1047 // The string defines the arg-list's respective types.
1048 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
1050 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1053 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
1055 // Create a touch point object.
1056 TouchPoint::State touchPointState( TouchPoint::Down );
1059 touchPointState = TouchPoint::Down; // Mouse down.
1061 else if( state == 1 )
1063 touchPointState = TouchPoint::Motion; // Mouse move.
1065 else if( state == 2 )
1067 touchPointState = TouchPoint::Up; // Mouse up.
1071 touchPointState = TouchPoint::Interrupted; // Error.
1074 // Send touch event to accessibility adaptor.
1075 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1077 // Perform actions based on received gestures.
1078 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
1079 switch( gestureValue )
1081 case 0: // OneFingerHover
1084 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1087 case 1: // TwoFingersHover
1089 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1090 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1093 case 2: // ThreeFingersHover
1095 // Read from top item on screen continuously.
1096 accessibilityAdaptor->HandleActionReadFromTopEvent();
1099 case 3: // OneFingerFlickLeft
1101 // Move to previous item.
1102 accessibilityAdaptor->HandleActionReadPreviousEvent();
1105 case 4: // OneFingerFlickRight
1107 // Move to next item.
1108 accessibilityAdaptor->HandleActionReadNextEvent();
1111 case 5: // OneFingerFlickUp
1113 // Move to previous item.
1114 accessibilityAdaptor->HandleActionPreviousEvent();
1117 case 6: // OneFingerFlickDown
1119 // Move to next item.
1120 accessibilityAdaptor->HandleActionNextEvent();
1123 case 7: // TwoFingersFlickUp
1125 // Scroll up the list.
1126 accessibilityAdaptor->HandleActionScrollUpEvent();
1129 case 8: // TwoFingersFlickDown
1131 // Scroll down the list.
1132 accessibilityAdaptor->HandleActionScrollDownEvent();
1135 case 9: // TwoFingersFlickLeft
1137 // Scroll left to the previous page
1138 accessibilityAdaptor->HandleActionPageLeftEvent();
1141 case 10: // TwoFingersFlickRight
1143 // Scroll right to the next page
1144 accessibilityAdaptor->HandleActionPageRightEvent();
1147 case 11: // ThreeFingersFlickLeft
1152 case 12: // ThreeFingersFlickRight
1157 case 13: // ThreeFingersFlickUp
1162 case 14: // ThreeFingersFlickDown
1167 case 15: // OneFingerSingleTap
1170 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1173 case 16: // OneFingerDoubleTap
1175 // Activate selected item / active edit mode.
1176 accessibilityAdaptor->HandleActionActivateEvent();
1179 case 17: // OneFingerTripleTap
1182 accessibilityAdaptor->HandleActionZoomEvent();
1185 case 18: // TwoFingersSingleTap
1187 // Pause/Resume current speech
1188 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1191 case 19: // TwoFingersDoubleTap
1193 // Start/Stop current action
1194 accessibilityAdaptor->HandleActionStartStopEvent();
1197 case 20: // TwoFingersTripleTap
1199 // Read information from indicator
1200 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1203 case 21: // ThreeFingersSingleTap
1205 // Read from top item on screen continuously.
1206 accessibilityAdaptor->HandleActionReadFromTopEvent();
1209 case 22: // ThreeFingersDoubleTap
1211 // Read from next item continuously.
1212 accessibilityAdaptor->HandleActionReadFromNextEvent();
1215 case 23: // ThreeFingersTripleTap
1220 case 24: // OneFingerFlickLeftReturn
1222 // Scroll up to the previous page
1223 accessibilityAdaptor->HandleActionPageUpEvent();
1226 case 25: // OneFingerFlickRightReturn
1228 // Scroll down to the next page
1229 accessibilityAdaptor->HandleActionPageDownEvent();
1232 case 26: // OneFingerFlickUpReturn
1234 // Move to the first item on screen
1235 accessibilityAdaptor->HandleActionMoveToFirstEvent();
1238 case 27: // OneFingerFlickDownReturn
1240 // Move to the last item on screen
1241 accessibilityAdaptor->HandleActionMoveToLastEvent();
1244 case 28: // TwoFingersFlickLeftReturn
1249 case 29: // TwoFingersFlickRightReturn
1254 case 30: // TwoFingersFlickUpReturn
1259 case 31: // TwoFingersFlickDownReturn
1264 case 32: // ThreeFingersFlickLeftReturn
1269 case 33: // ThreeFingersFlickRightReturn
1274 case 34: // ThreeFingersFlickUpReturn
1279 case 35: // ThreeFingersFlickDownReturn
1287 void EcoreElDBusInitialisation( void *handle )
1289 Eldbus_Object *object;
1290 Eldbus_Proxy *manager;
1292 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1294 DALI_LOG_ERROR( "Unable to get system bus\n" );
1297 object = eldbus_object_get( mSystemConnection, BUS, PATH );
1300 DALI_LOG_ERROR( "Getting object failed\n" );
1304 manager = eldbus_proxy_get( object, INTERFACE );
1307 DALI_LOG_ERROR( "Getting proxy failed\n" );
1311 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1313 DALI_LOG_ERROR( "No signal handler returned\n" );
1316 #endif // DALI_ELDBUS_AVAILABLE
1319 * Called when the source window notifies us the content in clipboard is selected.
1321 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1323 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1324 return ECORE_CALLBACK_PASS_ON;
1328 * Called when the source window sends us about the selected content.
1329 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1331 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1333 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1334 return ECORE_CALLBACK_PASS_ON;
1338 * Called when the source window notifies us the content in clipboard is selected.
1340 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1342 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1344 Dali::Clipboard clipboard = Clipboard::Get();
1347 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1348 clipBoardImpl.ExcuteBuffered( true, event );
1350 return ECORE_CALLBACK_PASS_ON;
1354 * Called when the source window sends us about the selected content.
1355 * For example, when item is selected in the clipboard.
1357 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1359 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1361 EventHandler* handler( (EventHandler*)data );
1362 Dali::Clipboard clipboard = Clipboard::Get();
1363 char *selectionData = NULL;
1366 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1367 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1369 if ( selectionData && handler->mClipboardEventNotifier )
1371 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1372 std::string content( selectionData, strlen(selectionData) );
1374 clipboardEventNotifier.SetContent( content );
1375 clipboardEventNotifier.EmitContentSelectedSignal();
1377 return ECORE_CALLBACK_PASS_ON;
1381 * Called when rotate event is recevied
1383 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1385 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1387 EventHandler* handler( (EventHandler*)data );
1388 Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1390 if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1392 return ECORE_CALLBACK_PASS_ON;
1395 RotationEvent rotationEvent;
1396 rotationEvent.angle = ev->angle;
1397 rotationEvent.winResize = 0;
1399 if( ev->angle == 0 || ev->angle == 180 )
1401 rotationEvent.width = ev->w;
1402 rotationEvent.height = ev->h;
1406 rotationEvent.width = ev->h;
1407 rotationEvent.height = ev->w;
1410 handler->SendRotationPrepareEvent( rotationEvent );
1412 return ECORE_CALLBACK_PASS_ON;
1416 * Called when detent event is recevied
1418 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1420 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1421 EventHandler* handler( (EventHandler*)data );
1422 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1423 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1424 int timeStamp = e->timestamp;
1426 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1427 handler->SendWheelEvent( wheelEvent );
1428 return ECORE_CALLBACK_PASS_ON;
1431 /////////////////////////////////////////////////////////////////////////////////////////////////
1433 /////////////////////////////////////////////////////////////////////////////////////////////////
1435 * Called when a font name is changed.
1437 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1439 EventHandler* handler = static_cast<EventHandler*>( data );
1440 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1444 * Called when a font size is changed.
1446 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1448 EventHandler* handler = static_cast<EventHandler*>( data );
1449 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1452 void ConvertTouchPosition( Integration::Point& point )
1454 Vector2 position = point.GetScreenPosition();
1455 Vector2 convertedPosition;
1457 switch( mRotationAngle )
1461 convertedPosition.x = mWindowWidth - position.y;
1462 convertedPosition.y = position.x;
1467 convertedPosition.x = mWindowWidth - position.x;
1468 convertedPosition.y = mWindowHeight - position.y;
1473 convertedPosition.x = position.y;
1474 convertedPosition.y = mWindowHeight - position.x;
1479 convertedPosition = position;
1484 point.SetScreenPosition( convertedPosition );
1488 EventHandler* mHandler;
1489 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1490 Ecore_Wl_Window* mWindow;
1494 #ifdef DALI_ELDBUS_AVAILABLE
1495 Eldbus_Connection* mSystemConnection;
1496 #endif // DALI_ELDBUS_AVAILABLE
1499 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1500 : mCoreEventInterface( coreEventInterface ),
1501 mGestureManager( gestureManager ),
1502 mStyleMonitor( StyleMonitor::Get() ),
1503 mDamageObserver( damageObserver ),
1504 mRotationObserver( NULL ),
1505 mDragAndDropDetector( dndDetector ),
1506 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1507 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1508 mClipboard( Clipboard::Get() ),
1512 Ecore_Wl_Window* window = 0;
1514 // this code only works with the Ecore RenderSurface so need to downcast
1515 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1518 window = ecoreSurface->GetWlWindow();
1521 mImpl = new Impl(this, window);
1524 EventHandler::~EventHandler()
1531 mGestureManager.Stop();
1534 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1538 timeStamp = GetCurrentMilliSeconds();
1541 mImpl->ConvertTouchPosition( point );
1543 Integration::TouchEvent touchEvent;
1544 Integration::HoverEvent hoverEvent;
1545 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1546 if(type != Integration::TouchEventCombiner::DispatchNone )
1548 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);
1550 // First the touch and/or hover event & related gesture events are queued
1551 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1553 mCoreEventInterface.QueueCoreEvent( touchEvent );
1554 mGestureManager.SendEvent(touchEvent);
1557 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1559 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1562 // Next the events are processed with a single call into Core
1563 mCoreEventInterface.ProcessCoreEvents();
1567 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1569 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1570 if ( physicalKeyboard )
1572 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1574 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1578 // Create send KeyEvent to Core.
1579 mCoreEventInterface.QueueCoreEvent( keyEvent );
1580 mCoreEventInterface.ProcessCoreEvents();
1583 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1585 // Create WheelEvent and send to Core.
1586 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1587 mCoreEventInterface.QueueCoreEvent( event );
1588 mCoreEventInterface.ProcessCoreEvents();
1591 void EventHandler::SendEvent( StyleChange::Type styleChange )
1593 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1594 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1597 void EventHandler::SendEvent( const DamageArea& area )
1599 mDamageObserver.OnDamaged( area );
1602 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1604 if( mRotationObserver != NULL )
1606 mImpl->mRotationAngle = event.angle;
1607 mImpl->mWindowWidth = event.width;
1608 mImpl->mWindowHeight = event.height;
1610 mRotationObserver->OnRotationPrepare( event );
1611 mRotationObserver->OnRotationRequest();
1615 void EventHandler::SendRotationRequestEvent( )
1617 // No need to separate event into prepare and request in wayland
1620 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1622 Integration::Point convertedPoint( point );
1623 SendEvent(convertedPoint, timeStamp);
1626 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1628 SendWheelEvent( wheelEvent );
1631 void EventHandler::FeedKeyEvent( KeyEvent& event )
1633 Integration::KeyEvent convertedEvent( event );
1634 SendEvent( convertedEvent );
1637 void EventHandler::FeedEvent( Integration::Event& event )
1639 mCoreEventInterface.QueueCoreEvent( event );
1640 mCoreEventInterface.ProcessCoreEvents();
1643 void EventHandler::Reset()
1647 // Any touch listeners should be told of the interruption.
1648 Integration::TouchEvent event;
1649 Integration::Point point;
1650 point.SetState( PointState::INTERRUPTED );
1651 event.AddPoint( point );
1653 // First the touch event & related gesture events are queued
1654 mCoreEventInterface.QueueCoreEvent( event );
1655 mGestureManager.SendEvent( event );
1657 // Next the events are processed with a single call into Core
1658 mCoreEventInterface.ProcessCoreEvents();
1661 void EventHandler::Pause()
1667 void EventHandler::Resume()
1673 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1675 mDragAndDropDetector = detector;
1678 void EventHandler::SetRotationObserver( RotationObserver* observer )
1680 mRotationObserver = observer;
1683 } // namespace Adaptor
1685 } // namespace Internal
1689 #pragma GCC diagnostic pop