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 <dali/internal/window-system/common/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_IMF.h>
28 #include <dali/integration-api/wayland/ecore-wl-render-surface.h>
29 //#include <dali/window-system/tizen-wayland/window-render-surface-ecore-wl.h>
34 #ifndef DALI_PROFILE_UBUNTU
36 #include <vconf-keys.h>
37 #endif // DALI_PROFILE_UBUNTU
39 #ifdef DALI_ELDBUS_AVAILABLE
41 #endif // DALI_ELDBUS_AVAILABLE
43 #include <dali/public-api/common/vector-wrapper.h>
44 #include <dali/public-api/events/device.h>
45 #include <dali/public-api/events/touch-point.h>
46 #include <dali/public-api/events/key-event.h>
47 #include <dali/public-api/events/wheel-event.h>
48 #include <dali/integration-api/debug.h>
49 #include <dali/integration-api/events/key-event-integ.h>
50 #include <dali/integration-api/events/touch-event-integ.h>
51 #include <dali/integration-api/events/hover-event-integ.h>
52 #include <dali/integration-api/events/wheel-event-integ.h>
55 #include <dali/internal/input/common/gesture-manager.h>
56 #include <dali/internal/window-system/tizen-wayland/window-render-surface-ecore-wl.h>
57 #include <dali/internal/clipboard/common/clipboard-impl.h>
58 #include <dali/internal/input/common/key-impl.h>
59 #include <dali/internal/input/common/physical-keyboard-impl.h>
60 #include <dali/internal/styling/common/style-monitor-impl.h>
61 #include <dali/internal/system/common/core-event-interface.h>
62 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
73 #if defined(DEBUG_ENABLED)
76 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
77 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
78 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
79 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
80 } // unnamed namespace
88 const char* BUS = "org.enlightenment.wm-screen-reader";
89 const char* INTERFACE = "org.tizen.GestureNavigation";
90 const char* PATH = "/org/tizen/GestureNavigation";
92 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
94 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
96 #ifdef DALI_ELDBUS_AVAILABLE
97 // DBus gesture string matching lists.
98 // TODO: This needs moving to its own module.
99 const char * ElDBusAccessibilityFingerCountStrings[] =
105 const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
110 GESTURE_TYPE_SINGLE_TAP,
111 GESTURE_TYPE_DOUBLE_TAP,
112 GESTURE_TYPE_TRIPLE_TAP
114 struct GestureTypeTable
117 const GestureType type;
119 GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
121 { "Hover", GESTURE_TYPE_HOVER },
122 { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
123 { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
124 { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
126 const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
129 SUB_GESTURE_TYPE_NONE,
130 SUB_GESTURE_TYPE_FLICK
132 struct SubGestureTypeTable
135 const SubGestureType type;
137 SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
139 { "Flick", SUB_GESTURE_TYPE_FLICK }
141 const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
142 enum GestureDirection
144 GESTURE_DIRECTION_NONE,
145 GESTURE_DIRECTION_UP,
146 GESTURE_DIRECTION_DOWN,
147 GESTURE_DIRECTION_LEFT,
148 GESTURE_DIRECTION_RIGHT,
149 GESTURE_DIRECTION_UP_RETURN,
150 GESTURE_DIRECTION_DOWN_RETURN,
151 GESTURE_DIRECTION_LEFT_RETURN,
152 GESTURE_DIRECTION_RIGHT_RETURN
154 struct GestureDirectionTable
157 const GestureDirection direction;
159 GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
161 { "Up", GESTURE_DIRECTION_UP },
162 { "Down", GESTURE_DIRECTION_DOWN },
163 { "Left", GESTURE_DIRECTION_LEFT },
164 { "Right", GESTURE_DIRECTION_RIGHT },
165 { "UpReturn", GESTURE_DIRECTION_UP_RETURN },
166 { "DownReturn", GESTURE_DIRECTION_DOWN_RETURN },
167 { "LeftReturn", GESTURE_DIRECTION_LEFT_RETURN },
168 { "RightReturn", GESTURE_DIRECTION_RIGHT_RETURN }
170 const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
171 #endif // DALI_ELDBUS_AVAILABLE
174 * EcoreInputModifierToEcoreIMFLock function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Locks enums.
175 * @param[in] modifier the Ecore_Event_Modifier input.
176 * @return the Ecore_IMF_Keyboard_Locks output.
178 Ecore_IMF_Keyboard_Locks EcoreInputModifierToEcoreIMFLock( unsigned int modifier )
180 unsigned int lock( ECORE_IMF_KEYBOARD_LOCK_NONE ); // If no other matches, returns NONE.
182 if( modifier & ECORE_EVENT_LOCK_NUM )
184 lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.
187 if( modifier & ECORE_EVENT_LOCK_CAPS )
189 lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.
192 if( modifier & ECORE_EVENT_LOCK_SCROLL )
194 lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.
197 return static_cast<Ecore_IMF_Keyboard_Locks>( lock );
201 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
202 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
203 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
204 * @return the Ecore_IMF_Keyboard_Modifiers output.
206 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
208 unsigned int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
211 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
213 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
216 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
218 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
221 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
223 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
226 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
228 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
231 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
233 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
236 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
240 // Copied from x server
241 static unsigned int GetCurrentMilliSeconds(void)
246 static clockid_t clockid;
250 #ifdef CLOCK_MONOTONIC_COARSE
251 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
252 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
254 clockid = CLOCK_MONOTONIC_COARSE;
258 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
260 clockid = CLOCK_MONOTONIC;
267 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
269 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
272 gettimeofday(&tv, NULL);
273 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
276 #ifndef DALI_PROFILE_UBUNTU
277 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
278 #endif // DALI_PROFILE_UBUNTU
281 * Get the device name from the provided ecore key event
283 void GetDeviceName( Ecore_Event_Key* keyEvent, std::string& result )
285 const char* ecoreDeviceName = ecore_device_name_get( keyEvent->dev );
287 if ( ecoreDeviceName )
289 result = ecoreDeviceName;
294 * Get the device class from the provided ecore event
296 void GetDeviceClass( Ecore_Device_Class ecoreDeviceClass, Device::Class::Type& deviceClass )
298 switch( ecoreDeviceClass )
300 case ECORE_DEVICE_CLASS_SEAT:
302 deviceClass = Device::Class::USER;
305 case ECORE_DEVICE_CLASS_KEYBOARD:
307 deviceClass = Device::Class::KEYBOARD;
310 case ECORE_DEVICE_CLASS_MOUSE:
312 deviceClass = Device::Class::MOUSE;
315 case ECORE_DEVICE_CLASS_TOUCH:
317 deviceClass = Device::Class::TOUCH;
320 case ECORE_DEVICE_CLASS_PEN:
322 deviceClass = Device::Class::PEN;
325 case ECORE_DEVICE_CLASS_POINTER:
327 deviceClass = Device::Class::POINTER;
330 case ECORE_DEVICE_CLASS_GAMEPAD:
332 deviceClass = Device::Class::GAMEPAD;
337 deviceClass = Device::Class::NONE;
343 void GetDeviceSubclass( Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subclass::Type& deviceSubclass )
345 switch( ecoreDeviceSubclass )
347 case ECORE_DEVICE_SUBCLASS_FINGER:
349 deviceSubclass = Device::Subclass::FINGER;
352 case ECORE_DEVICE_SUBCLASS_FINGERNAIL:
354 deviceSubclass = Device::Subclass::FINGERNAIL;
357 case ECORE_DEVICE_SUBCLASS_KNUCKLE:
359 deviceSubclass = Device::Subclass::KNUCKLE;
362 case ECORE_DEVICE_SUBCLASS_PALM:
364 deviceSubclass = Device::Subclass::PALM;
367 case ECORE_DEVICE_SUBCLASS_HAND_SIZE:
369 deviceSubclass = Device::Subclass::HAND_SIDE;
372 case ECORE_DEVICE_SUBCLASS_HAND_FLAT:
374 deviceSubclass = Device::Subclass::HAND_FLAT;
377 case ECORE_DEVICE_SUBCLASS_PEN_TIP:
379 deviceSubclass = Device::Subclass::PEN_TIP;
382 case ECORE_DEVICE_SUBCLASS_TRACKPAD:
384 deviceSubclass = Device::Subclass::TRACKPAD;
387 case ECORE_DEVICE_SUBCLASS_TRACKPOINT:
389 deviceSubclass = Device::Subclass::TRACKPOINT;
392 case ECORE_DEVICE_SUBCLASS_TRACKBALL:
394 deviceSubclass = Device::Subclass::TRACKBALL;
397 #ifdef OVER_TIZEN_VERSION_4
398 case ECORE_DEVICE_SUBCLASS_REMOCON:
400 deviceSubclass = Device::Subclass::REMOCON;
403 case ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD:
405 deviceSubclass = Device::Subclass::VIRTUAL_KEYBOARD;
411 deviceSubclass = Device::Subclass::NONE;
417 } // unnamed namespace
419 // Impl to hide EFL implementation.
420 struct EventHandler::Impl
422 // Construction & Destruction
427 Impl( EventHandler* handler, Ecore_Wl_Window* window )
428 : mHandler( handler ),
429 mEcoreEventHandler(),
434 #ifdef DALI_ELDBUS_AVAILABLE
435 , mSystemConnection( NULL )
436 #endif // DALI_ELDBUS_AVAILABLE
438 // Only register for touch and key events if we have a window
441 // Register Touch events
442 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
443 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
444 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
445 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, handler ) );
447 // Register Mouse wheel events
448 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
450 // Register Focus events
451 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
452 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
454 // Register Key events
455 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
456 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
458 // Register Selection event - clipboard selection
459 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
460 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
462 // Register Rotate event
463 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
465 // Register Detent event
466 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
468 #ifndef DALI_PROFILE_UBUNTU
469 // Register Vconf notify - font name and size
470 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
471 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
472 #endif // DALI_PROFILE_UBUNTU
474 #ifdef DALI_ELDBUS_AVAILABLE
475 // Initialize ElDBus.
476 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
479 EcoreElDBusInitialisation( handler );
481 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
482 #endif // DALI_ELDBUS_AVAILABLE
491 #ifndef DALI_PROFILE_UBUNTU
492 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
493 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
494 #endif // DALI_PROFILE_UBUNTU
496 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
498 ecore_event_handler_del( *iter );
501 #ifdef DALI_ELDBUS_AVAILABLE
502 // Close down ElDBus connections.
503 if( mSystemConnection )
505 eldbus_connection_unref( mSystemConnection );
507 #endif // DALI_ELDBUS_AVAILABLE
512 /////////////////////////////////////////////////////////////////////////////////////////////////
514 /////////////////////////////////////////////////////////////////////////////////////////////////
517 * Called when a touch down is received.
519 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
521 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
522 EventHandler* handler( (EventHandler*)data );
524 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
526 PointState::Type state ( PointState::DOWN );
528 // Check if the buttons field is set and ensure it's the primary touch button.
529 // If this event was triggered by buttons other than the primary button (used for touch), then
530 // just send an interrupted event to Core.
531 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
533 state = PointState::INTERRUPTED;
536 Device::Class::Type deviceClass;
537 Device::Subclass::Type deviceSubclass;
539 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
540 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
542 Integration::Point point;
543 point.SetDeviceId( touchEvent->multi.device );
544 point.SetState( state );
545 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
546 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
547 point.SetPressure( touchEvent->multi.pressure );
548 point.SetAngle( Degree( touchEvent->multi.angle ) );
549 point.SetDeviceClass( deviceClass );
550 point.SetDeviceSubclass( deviceSubclass );
552 handler->SendEvent( point, touchEvent->timestamp );
555 return ECORE_CALLBACK_PASS_ON;
559 * Called when a touch up is received.
561 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
563 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
564 EventHandler* handler( (EventHandler*)data );
566 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
568 Device::Class::Type deviceClass;
569 Device::Subclass::Type deviceSubclass;
571 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
572 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
574 Integration::Point point;
575 point.SetDeviceId( touchEvent->multi.device );
576 point.SetState( PointState::UP );
577 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
578 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
579 point.SetPressure( touchEvent->multi.pressure );
580 point.SetAngle( Degree( touchEvent->multi.angle ) );
581 point.SetDeviceClass( deviceClass );
582 point.SetDeviceSubclass( deviceSubclass );
584 handler->SendEvent( point, touchEvent->timestamp );
587 return ECORE_CALLBACK_PASS_ON;
591 * Called when a touch motion is received.
593 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
595 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
596 EventHandler* handler( (EventHandler*)data );
598 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
600 Device::Class::Type deviceClass;
601 Device::Subclass::Type deviceSubclass;
603 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
604 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
606 Integration::Point point;
607 point.SetDeviceId( touchEvent->multi.device );
608 point.SetState( PointState::MOTION );
609 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
610 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
611 point.SetPressure( touchEvent->multi.pressure );
612 point.SetAngle( Degree( touchEvent->multi.angle ) );
613 point.SetDeviceClass( deviceClass );
614 point.SetDeviceSubclass( deviceSubclass );
616 handler->SendEvent( point, touchEvent->timestamp );
619 return ECORE_CALLBACK_PASS_ON;
623 * Called when a touch is canceled.
625 static Eina_Bool EcoreEventMouseButtonCancel( void* data, int type, void* event )
627 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
628 EventHandler* handler( (EventHandler*)data );
630 if( touchEvent->window == (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
632 Integration::Point point;
633 point.SetDeviceId( touchEvent->multi.device );
634 point.SetState( PointState::INTERRUPTED );
635 point.SetScreenPosition( Vector2( 0.0f, 0.0f ) );
636 handler->SendEvent( point, touchEvent->timestamp );
638 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventMouseButtonCancel\n" );
641 return ECORE_CALLBACK_PASS_ON;
645 * Called when a mouse wheel is received.
647 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
649 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
651 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);
653 EventHandler* handler( (EventHandler*)data );
654 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
656 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
657 handler->SendWheelEvent( wheelEvent );
659 return ECORE_CALLBACK_PASS_ON;
662 /////////////////////////////////////////////////////////////////////////////////////////////////
664 /////////////////////////////////////////////////////////////////////////////////////////////////
667 * Called when a key down is received.
669 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
671 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
673 EventHandler* handler( (EventHandler*)data );
674 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
675 bool eventHandled( false );
677 // If a device key then skip ecore_imf_context_filter_event.
678 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
680 Ecore_IMF_Context* imfContext = NULL;
681 Dali::ImfManager imfManager( ImfManager::Get() );
684 imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
689 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
690 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
691 ecoreKeyDownEvent.keyname = keyEvent->keyname;
692 ecoreKeyDownEvent.key = keyEvent->key;
693 ecoreKeyDownEvent.string = keyEvent->string;
694 ecoreKeyDownEvent.compose = keyEvent->compose;
695 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
696 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
697 ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent->modifiers );
698 ecoreKeyDownEvent.dev_name = ecore_device_name_get( keyEvent->dev );
699 ecoreKeyDownEvent.dev_class = static_cast<Ecore_IMF_Device_Class>( ecore_device_class_get( keyEvent->dev ) );
700 ecoreKeyDownEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass>( ecore_device_subclass_get( keyEvent->dev ) );
702 std::string checkDevice;
703 GetDeviceName( keyEvent, checkDevice );
705 // 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.
706 if( ( checkDevice == "ime" ) && ( ( !strncmp( keyEvent->keyname, "Left", 4 ) ) ||
707 ( !strncmp( keyEvent->keyname, "Right", 5 ) ) ||
708 ( !strncmp( keyEvent->keyname, "Up", 2 ) ) ||
709 ( !strncmp( keyEvent->keyname, "Down", 4 ) ) ) )
715 eventHandled = ecore_imf_context_filter_event( imfContext,
716 ECORE_IMF_EVENT_KEY_DOWN,
717 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
720 // If the event has not been handled by IMF then check if we should reset our IMF context
723 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
724 !strcmp( keyEvent->keyname, "Return" ) ||
725 !strcmp( keyEvent->keyname, "KP_Enter" ) )
727 ecore_imf_context_reset( imfContext );
733 // If the event wasn't handled then we should send a key event.
736 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
738 std::string keyName( keyEvent->keyname );
739 std::string keyString( "" );
740 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
741 keyCode = (keyCode == -1) ? 0 : keyCode;
742 int modifier( keyEvent->modifiers );
743 unsigned long time = keyEvent->timestamp;
744 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
745 keyCode = atoi(keyEvent->keyname + 8);
747 // Ensure key event string is not NULL as keys like SHIFT have a null string.
748 if ( keyEvent->string )
750 keyString = keyEvent->string;
753 std::string deviceName;
754 Device::Class::Type deviceClass;
755 Device::Subclass::Type deviceSubclass;
757 GetDeviceName( keyEvent, deviceName );
758 GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
759 GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
761 DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s) deviceClass(%d)\n", deviceName.c_str(), deviceClass );
763 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, deviceName, deviceClass, deviceSubclass );
764 handler->SendEvent( keyEvent );
768 return ECORE_CALLBACK_PASS_ON;
772 * Called when a key up is received.
774 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
776 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
778 EventHandler* handler( (EventHandler*)data );
779 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
780 bool eventHandled( false );
782 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
783 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
785 Ecore_IMF_Context* imfContext = NULL;
786 Dali::ImfManager imfManager( ImfManager::Get() );
789 imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
794 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
795 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
796 ecoreKeyUpEvent.keyname = keyEvent->keyname;
797 ecoreKeyUpEvent.key = keyEvent->key;
798 ecoreKeyUpEvent.string = keyEvent->string;
799 ecoreKeyUpEvent.compose = keyEvent->compose;
800 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
801 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
802 ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent->modifiers );
803 ecoreKeyUpEvent.dev_name = ecore_device_name_get( keyEvent->dev );
804 ecoreKeyUpEvent.dev_class = static_cast<Ecore_IMF_Device_Class>( ecore_device_class_get( keyEvent->dev ) );
805 ecoreKeyUpEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass>( ecore_device_subclass_get( keyEvent->dev ) );
807 eventHandled = ecore_imf_context_filter_event( imfContext,
808 ECORE_IMF_EVENT_KEY_UP,
809 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
813 // If the event wasn't handled then we should send a key event.
816 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
818 std::string keyName( keyEvent->keyname );
819 std::string keyString( "" );
820 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
821 keyCode = (keyCode == -1) ? 0 : keyCode;
822 int modifier( keyEvent->modifiers );
823 unsigned long time = keyEvent->timestamp;
824 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
825 keyCode = atoi(keyEvent->keyname + 8);
827 // Ensure key event string is not NULL as keys like SHIFT have a null string.
828 if ( keyEvent->string )
830 keyString = keyEvent->string;
833 std::string deviceName;
834 Device::Class::Type deviceClass;
835 Device::Subclass::Type deviceSubclass;
837 GetDeviceName( keyEvent, deviceName );
838 GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
839 GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
841 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, deviceName, deviceClass, deviceSubclass );
842 handler->SendEvent( keyEvent );
846 return ECORE_CALLBACK_PASS_ON;
849 /////////////////////////////////////////////////////////////////////////////////////////////////
851 /////////////////////////////////////////////////////////////////////////////////////////////////
854 * Called when the window gains focus.
856 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
858 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
859 EventHandler* handler( (EventHandler*)data );
861 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
863 // If the window gains focus and we hid the keyboard then show it again.
864 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
866 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
868 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
870 Dali::ImfManager imfManager( ImfManager::Get() );
873 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
874 if( imfManagerImpl.RestoreAfterFocusLost() )
876 imfManagerImpl.Activate();
880 Dali::Clipboard clipboard = Clipboard::Get();
881 clipboard.HideClipboard();
884 return ECORE_CALLBACK_PASS_ON;
888 * Called when the window loses focus.
890 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
892 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
893 EventHandler* handler( (EventHandler*)data );
895 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
897 // If the window loses focus then hide the keyboard.
898 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
900 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
902 Dali::ImfManager imfManager( ImfManager::Get() );
905 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
906 if( imfManagerImpl.RestoreAfterFocusLost() )
908 imfManagerImpl.Deactivate();
913 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
914 Dali::Clipboard clipboard = Clipboard::Get();
917 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
918 clipBoardImpl.HideClipboard(true);
922 return ECORE_CALLBACK_PASS_ON;
926 * Called when the window is damaged.
928 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
930 return ECORE_CALLBACK_PASS_ON;
934 * Called when the window properties are changed.
935 * We are only interested in the font change.
939 /////////////////////////////////////////////////////////////////////////////////////////////////
940 // Drag & Drop Callbacks
941 /////////////////////////////////////////////////////////////////////////////////////////////////
944 * Called when a dragged item enters our window's bounds.
945 * This is when items are dragged INTO our window.
947 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
949 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
951 return ECORE_CALLBACK_PASS_ON;
955 * Called when a dragged item is moved within our window.
956 * This is when items are dragged INTO our window.
958 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
960 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
962 return ECORE_CALLBACK_PASS_ON;
966 * Called when a dragged item leaves our window's bounds.
967 * This is when items are dragged INTO our window.
969 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
971 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
973 return ECORE_CALLBACK_PASS_ON;
977 * Called when the dragged item is dropped within our window's bounds.
978 * This is when items are dragged INTO our window.
980 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
982 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
984 return ECORE_CALLBACK_PASS_ON;
988 * Called when a dragged item is moved from our window and the target window has done processing it.
989 * This is when items are dragged FROM our window.
991 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
993 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
994 return ECORE_CALLBACK_PASS_ON;
998 * Called when a dragged item is moved from our window and the target window has sent us a status.
999 * This is when items are dragged FROM our window.
1001 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
1003 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
1004 return ECORE_CALLBACK_PASS_ON;
1008 * Called when the client messages (i.e. the accessibility events) are received.
1010 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
1012 return ECORE_CALLBACK_PASS_ON;
1016 /////////////////////////////////////////////////////////////////////////////////////////////////
1017 // ElDBus Accessibility Callbacks
1018 /////////////////////////////////////////////////////////////////////////////////////////////////
1020 #ifdef DALI_ELDBUS_AVAILABLE
1021 // Callback for Ecore ElDBus accessibility events.
1022 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
1024 EventHandler* handler = static_cast< EventHandler* >( context );
1025 // Ignore any accessibility events when paused.
1026 if( handler->mPaused )
1031 if( !handler->mAccessibilityAdaptor )
1033 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
1037 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1038 if( !accessibilityAdaptor )
1040 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
1046 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
1049 // The string defines the arg-list's respective types.
1050 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
1052 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1055 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
1057 // Create a touch point object.
1058 TouchPoint::State touchPointState( TouchPoint::Down );
1061 touchPointState = TouchPoint::Down; // Mouse down.
1063 else if( state == 1 )
1065 touchPointState = TouchPoint::Motion; // Mouse move.
1067 else if( state == 2 )
1069 touchPointState = TouchPoint::Up; // Mouse up.
1073 touchPointState = TouchPoint::Interrupted; // Error.
1076 // Send touch event to accessibility adaptor.
1077 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1079 // Perform actions based on received gestures.
1080 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
1081 switch( gestureValue )
1083 case 0: // OneFingerHover
1086 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1089 case 1: // TwoFingersHover
1091 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1092 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1095 case 2: // ThreeFingersHover
1097 // Read from top item on screen continuously.
1098 accessibilityAdaptor->HandleActionReadFromTopEvent();
1101 case 3: // OneFingerFlickLeft
1103 // Move to previous item.
1104 accessibilityAdaptor->HandleActionReadPreviousEvent();
1107 case 4: // OneFingerFlickRight
1109 // Move to next item.
1110 accessibilityAdaptor->HandleActionReadNextEvent();
1113 case 5: // OneFingerFlickUp
1115 // Move to previous item.
1116 accessibilityAdaptor->HandleActionPreviousEvent();
1119 case 6: // OneFingerFlickDown
1121 // Move to next item.
1122 accessibilityAdaptor->HandleActionNextEvent();
1125 case 7: // TwoFingersFlickUp
1127 // Scroll up the list.
1128 accessibilityAdaptor->HandleActionScrollUpEvent();
1131 case 8: // TwoFingersFlickDown
1133 // Scroll down the list.
1134 accessibilityAdaptor->HandleActionScrollDownEvent();
1137 case 9: // TwoFingersFlickLeft
1139 // Scroll left to the previous page
1140 accessibilityAdaptor->HandleActionPageLeftEvent();
1143 case 10: // TwoFingersFlickRight
1145 // Scroll right to the next page
1146 accessibilityAdaptor->HandleActionPageRightEvent();
1149 case 11: // ThreeFingersFlickLeft
1154 case 12: // ThreeFingersFlickRight
1159 case 13: // ThreeFingersFlickUp
1164 case 14: // ThreeFingersFlickDown
1169 case 15: // OneFingerSingleTap
1172 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1175 case 16: // OneFingerDoubleTap
1177 // Activate selected item / active edit mode.
1178 accessibilityAdaptor->HandleActionActivateEvent();
1181 case 17: // OneFingerTripleTap
1184 accessibilityAdaptor->HandleActionZoomEvent();
1187 case 18: // TwoFingersSingleTap
1189 // Pause/Resume current speech
1190 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1193 case 19: // TwoFingersDoubleTap
1195 // Start/Stop current action
1196 accessibilityAdaptor->HandleActionStartStopEvent();
1199 case 20: // TwoFingersTripleTap
1201 // Read information from indicator
1202 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1205 case 21: // ThreeFingersSingleTap
1207 // Read from top item on screen continuously.
1208 accessibilityAdaptor->HandleActionReadFromTopEvent();
1211 case 22: // ThreeFingersDoubleTap
1213 // Read from next item continuously.
1214 accessibilityAdaptor->HandleActionReadFromNextEvent();
1217 case 23: // ThreeFingersTripleTap
1222 case 24: // OneFingerFlickLeftReturn
1224 // Scroll up to the previous page
1225 accessibilityAdaptor->HandleActionPageUpEvent();
1228 case 25: // OneFingerFlickRightReturn
1230 // Scroll down to the next page
1231 accessibilityAdaptor->HandleActionPageDownEvent();
1234 case 26: // OneFingerFlickUpReturn
1236 // Move to the first item on screen
1237 accessibilityAdaptor->HandleActionMoveToFirstEvent();
1240 case 27: // OneFingerFlickDownReturn
1242 // Move to the last item on screen
1243 accessibilityAdaptor->HandleActionMoveToLastEvent();
1246 case 28: // TwoFingersFlickLeftReturn
1251 case 29: // TwoFingersFlickRightReturn
1256 case 30: // TwoFingersFlickUpReturn
1261 case 31: // TwoFingersFlickDownReturn
1266 case 32: // ThreeFingersFlickLeftReturn
1271 case 33: // ThreeFingersFlickRightReturn
1276 case 34: // ThreeFingersFlickUpReturn
1281 case 35: // ThreeFingersFlickDownReturn
1289 void EcoreElDBusInitialisation( void *handle )
1291 Eldbus_Object *object;
1292 Eldbus_Proxy *manager;
1294 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1296 DALI_LOG_ERROR( "Unable to get system bus\n" );
1299 object = eldbus_object_get( mSystemConnection, BUS, PATH );
1302 DALI_LOG_ERROR( "Getting object failed\n" );
1306 manager = eldbus_proxy_get( object, INTERFACE );
1309 DALI_LOG_ERROR( "Getting proxy failed\n" );
1313 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1315 DALI_LOG_ERROR( "No signal handler returned\n" );
1318 #endif // DALI_ELDBUS_AVAILABLE
1321 * Called when the source window notifies us the content in clipboard is selected.
1323 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1325 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1326 return ECORE_CALLBACK_PASS_ON;
1330 * Called when the source window sends us about the selected content.
1331 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1333 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1335 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1336 return ECORE_CALLBACK_PASS_ON;
1340 * Called when the source window notifies us the content in clipboard is selected.
1342 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1344 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1346 Dali::Clipboard clipboard = Clipboard::Get();
1349 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1350 clipBoardImpl.ExcuteBuffered( true, event );
1352 return ECORE_CALLBACK_PASS_ON;
1356 * Called when the source window sends us about the selected content.
1357 * For example, when item is selected in the clipboard.
1359 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1361 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1363 EventHandler* handler( (EventHandler*)data );
1364 Dali::Clipboard clipboard = Clipboard::Get();
1365 char *selectionData = NULL;
1368 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1369 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1371 if ( selectionData && handler->mClipboardEventNotifier )
1373 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1374 std::string content( selectionData, strlen(selectionData) );
1376 clipboardEventNotifier.SetContent( content );
1377 clipboardEventNotifier.EmitContentSelectedSignal();
1379 return ECORE_CALLBACK_PASS_ON;
1383 * Called when rotate event is recevied
1385 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1387 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1389 EventHandler* handler( (EventHandler*)data );
1390 Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1392 if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1394 return ECORE_CALLBACK_PASS_ON;
1397 RotationEvent rotationEvent;
1398 rotationEvent.angle = ev->angle;
1399 rotationEvent.winResize = 0;
1401 if( ev->angle == 0 || ev->angle == 180 )
1403 rotationEvent.width = ev->w;
1404 rotationEvent.height = ev->h;
1408 rotationEvent.width = ev->h;
1409 rotationEvent.height = ev->w;
1412 handler->SendRotationPrepareEvent( rotationEvent );
1414 return ECORE_CALLBACK_PASS_ON;
1418 * Called when detent event is recevied
1420 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1422 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1423 EventHandler* handler( (EventHandler*)data );
1424 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1425 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1426 int timeStamp = e->timestamp;
1428 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1429 handler->SendWheelEvent( wheelEvent );
1430 return ECORE_CALLBACK_PASS_ON;
1433 /////////////////////////////////////////////////////////////////////////////////////////////////
1435 /////////////////////////////////////////////////////////////////////////////////////////////////
1437 * Called when a font name is changed.
1439 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1441 EventHandler* handler = static_cast<EventHandler*>( data );
1442 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1446 * Called when a font size is changed.
1448 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1450 EventHandler* handler = static_cast<EventHandler*>( data );
1451 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1454 void ConvertTouchPosition( Integration::Point& point )
1456 Vector2 position = point.GetScreenPosition();
1457 Vector2 convertedPosition;
1459 switch( mRotationAngle )
1463 convertedPosition.x = mWindowWidth - position.y;
1464 convertedPosition.y = position.x;
1469 convertedPosition.x = mWindowWidth - position.x;
1470 convertedPosition.y = mWindowHeight - position.y;
1475 convertedPosition.x = position.y;
1476 convertedPosition.y = mWindowHeight - position.x;
1481 convertedPosition = position;
1486 point.SetScreenPosition( convertedPosition );
1490 EventHandler* mHandler;
1491 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1492 Ecore_Wl_Window* mWindow;
1496 #ifdef DALI_ELDBUS_AVAILABLE
1497 Eldbus_Connection* mSystemConnection;
1498 #endif // DALI_ELDBUS_AVAILABLE
1501 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1502 : mCoreEventInterface( coreEventInterface ),
1503 mGestureManager( gestureManager ),
1504 mStyleMonitor( StyleMonitor::Get() ),
1505 mDamageObserver( damageObserver ),
1506 mRotationObserver( NULL ),
1507 mDragAndDropDetector( dndDetector ),
1508 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1509 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1510 mClipboard( Clipboard::Get() ),
1514 Ecore_Wl_Window* window = 0;
1516 // this code only works with the Ecore RenderSurface so need to downcast
1517 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1520 window = ecoreSurface->GetWlWindow();
1523 mImpl = new Impl(this, window);
1526 EventHandler::~EventHandler()
1533 mGestureManager.Stop();
1536 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1540 timeStamp = GetCurrentMilliSeconds();
1543 mImpl->ConvertTouchPosition( point );
1545 Integration::TouchEvent touchEvent;
1546 Integration::HoverEvent hoverEvent;
1547 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1548 if(type != Integration::TouchEventCombiner::DispatchNone )
1550 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);
1552 // First the touch and/or hover event & related gesture events are queued
1553 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1555 mCoreEventInterface.QueueCoreEvent( touchEvent );
1556 mGestureManager.SendEvent(touchEvent);
1559 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1561 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1564 // Next the events are processed with a single call into Core
1565 mCoreEventInterface.ProcessCoreEvents();
1569 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1571 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1572 if ( physicalKeyboard )
1574 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1576 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1580 // Create send KeyEvent to Core.
1581 mCoreEventInterface.QueueCoreEvent( keyEvent );
1582 mCoreEventInterface.ProcessCoreEvents();
1585 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1587 // Create WheelEvent and send to Core.
1588 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1589 mCoreEventInterface.QueueCoreEvent( event );
1590 mCoreEventInterface.ProcessCoreEvents();
1593 void EventHandler::SendEvent( StyleChange::Type styleChange )
1595 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1596 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1599 void EventHandler::SendEvent( const DamageArea& area )
1601 mDamageObserver.OnDamaged( area );
1604 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1606 if( mRotationObserver != NULL )
1608 mImpl->mRotationAngle = event.angle;
1609 mImpl->mWindowWidth = event.width;
1610 mImpl->mWindowHeight = event.height;
1612 mRotationObserver->OnRotationPrepare( event );
1613 mRotationObserver->OnRotationRequest();
1617 void EventHandler::SendRotationRequestEvent( )
1619 // No need to separate event into prepare and request in wayland
1622 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1624 Integration::Point convertedPoint( point );
1625 SendEvent(convertedPoint, timeStamp);
1628 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1630 SendWheelEvent( wheelEvent );
1633 void EventHandler::FeedKeyEvent( KeyEvent& event )
1635 Integration::KeyEvent convertedEvent( event );
1636 SendEvent( convertedEvent );
1639 void EventHandler::FeedEvent( Integration::Event& event )
1641 mCoreEventInterface.QueueCoreEvent( event );
1642 mCoreEventInterface.ProcessCoreEvents();
1645 void EventHandler::Reset()
1649 // Any touch listeners should be told of the interruption.
1650 Integration::TouchEvent event;
1651 Integration::Point point;
1652 point.SetState( PointState::INTERRUPTED );
1653 event.AddPoint( point );
1655 // First the touch event & related gesture events are queued
1656 mCoreEventInterface.QueueCoreEvent( event );
1657 mGestureManager.SendEvent( event );
1659 // Next the events are processed with a single call into Core
1660 mCoreEventInterface.ProcessCoreEvents();
1663 void EventHandler::Pause()
1669 void EventHandler::Resume()
1675 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1677 mDragAndDropDetector = detector;
1680 void EventHandler::SetRotationObserver( RotationObserver* observer )
1682 mRotationObserver = observer;
1685 } // namespace Adaptor
1687 } // namespace Internal
1691 #pragma GCC diagnostic pop