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>
28 #ifdef DALI_ELDBUS_AVAILABLE
30 #endif // DALI_ELDBUS_AVAILABLE
32 #include <Ecore_IMF.h>
33 #include <dali/integration-api/wayland/ecore-wl2/ecore-wl2-render-surface.h>
34 //#include <dali/window-system/tizen-wayland/ecore-wl2/window-render-surface-ecore-wl2.h>
39 #ifndef DALI_PROFILE_UBUNTU
41 #include <vconf-keys.h>
42 #endif // DALI_PROFILE_UBUNTU
44 #include <dali/public-api/common/vector-wrapper.h>
45 #include <dali/public-api/events/device.h>
46 #include <dali/public-api/events/touch-point.h>
47 #include <dali/public-api/events/key-event.h>
48 #include <dali/public-api/events/wheel-event.h>
49 #include <dali/integration-api/debug.h>
50 #include <dali/integration-api/events/key-event-integ.h>
51 #include <dali/integration-api/events/touch-event-integ.h>
52 #include <dali/integration-api/events/hover-event-integ.h>
53 #include <dali/integration-api/events/wheel-event-integ.h>
56 #include <dali/internal/input/common/gesture-manager.h>
57 #include <dali/internal/window-system/tizen-wayland/ecore-wl2/window-render-surface-ecore-wl2.h>
58 #include <dali/internal/clipboard/common/clipboard-impl.h>
59 #include <dali/internal/input/common/key-impl.h>
60 #include <dali/internal/input/common/physical-keyboard-impl.h>
61 #include <dali/internal/styling/common/style-monitor-impl.h>
62 #include <dali/internal/system/common/core-event-interface.h>
63 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
74 #if defined(DEBUG_ENABLED)
77 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
78 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
79 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
80 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
81 } // unnamed namespace
89 const char* BUS = "org.enlightenment.wm-screen-reader";
90 const char* INTERFACE = "org.tizen.GestureNavigation";
91 const char* PATH = "/org/tizen/GestureNavigation";
93 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
95 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
97 #ifdef DALI_ELDBUS_AVAILABLE
98 // DBus gesture string matching lists.
99 // TODO: This needs moving to its own module.
100 const char * ElDBusAccessibilityFingerCountStrings[] =
106 const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
111 GESTURE_TYPE_SINGLE_TAP,
112 GESTURE_TYPE_DOUBLE_TAP,
113 GESTURE_TYPE_TRIPLE_TAP
115 struct GestureTypeTable
118 const GestureType type;
120 GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
122 { "Hover", GESTURE_TYPE_HOVER },
123 { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
124 { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
125 { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
127 const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
130 SUB_GESTURE_TYPE_NONE,
131 SUB_GESTURE_TYPE_FLICK
133 struct SubGestureTypeTable
136 const SubGestureType type;
138 SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
140 { "Flick", SUB_GESTURE_TYPE_FLICK }
142 const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
143 enum GestureDirection
145 GESTURE_DIRECTION_NONE,
146 GESTURE_DIRECTION_UP,
147 GESTURE_DIRECTION_DOWN,
148 GESTURE_DIRECTION_LEFT,
149 GESTURE_DIRECTION_RIGHT,
150 GESTURE_DIRECTION_UP_RETURN,
151 GESTURE_DIRECTION_DOWN_RETURN,
152 GESTURE_DIRECTION_LEFT_RETURN,
153 GESTURE_DIRECTION_RIGHT_RETURN
155 struct GestureDirectionTable
158 const GestureDirection direction;
160 GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
162 { "Up", GESTURE_DIRECTION_UP },
163 { "Down", GESTURE_DIRECTION_DOWN },
164 { "Left", GESTURE_DIRECTION_LEFT },
165 { "Right", GESTURE_DIRECTION_RIGHT },
166 { "UpReturn", GESTURE_DIRECTION_UP_RETURN },
167 { "DownReturn", GESTURE_DIRECTION_DOWN_RETURN },
168 { "LeftReturn", GESTURE_DIRECTION_LEFT_RETURN },
169 { "RightReturn", GESTURE_DIRECTION_RIGHT_RETURN }
171 const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
172 #endif // DALI_ELDBUS_AVAILABLE
175 * EcoreInputModifierToEcoreIMFLock function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Locks enums.
176 * @param[in] modifier the Ecore_Event_Modifier input.
177 * @return the Ecore_IMF_Keyboard_Locks output.
179 Ecore_IMF_Keyboard_Locks EcoreInputModifierToEcoreIMFLock( unsigned int modifier )
181 unsigned int lock( ECORE_IMF_KEYBOARD_LOCK_NONE ); // If no other matches, returns NONE.
183 if( modifier & ECORE_EVENT_LOCK_NUM )
185 lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.
188 if( modifier & ECORE_EVENT_LOCK_CAPS )
190 lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.
193 if( modifier & ECORE_EVENT_LOCK_SCROLL )
195 lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.
198 return static_cast<Ecore_IMF_Keyboard_Locks>( lock );
202 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
203 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
204 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
205 * @return the Ecore_IMF_Keyboard_Modifiers output.
207 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
209 unsigned int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
212 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
214 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
217 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
219 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
222 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
224 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
227 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
229 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
232 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
234 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
237 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
241 // Copied from x server
242 static unsigned int GetCurrentMilliSeconds(void)
247 static clockid_t clockid;
251 #ifdef CLOCK_MONOTONIC_COARSE
252 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
253 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
255 clockid = CLOCK_MONOTONIC_COARSE;
259 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
261 clockid = CLOCK_MONOTONIC;
268 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
270 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
273 gettimeofday(&tv, NULL);
274 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
277 #ifndef DALI_PROFILE_UBUNTU
278 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
279 #endif // DALI_PROFILE_UBUNTU
282 * Get the device name from the provided ecore key event
284 void GetDeviceName( Ecore_Event_Key* keyEvent, std::string& result )
286 const char* ecoreDeviceName = ecore_device_name_get( keyEvent->dev );
288 if ( ecoreDeviceName )
290 result = ecoreDeviceName;
295 * Get the device class from the provided ecore event
297 void GetDeviceClass( Ecore_Device_Class ecoreDeviceClass, Device::Class::Type& deviceClass )
299 switch( ecoreDeviceClass )
301 case ECORE_DEVICE_CLASS_SEAT:
303 deviceClass = Device::Class::USER;
306 case ECORE_DEVICE_CLASS_KEYBOARD:
308 deviceClass = Device::Class::KEYBOARD;
311 case ECORE_DEVICE_CLASS_MOUSE:
313 deviceClass = Device::Class::MOUSE;
316 case ECORE_DEVICE_CLASS_TOUCH:
318 deviceClass = Device::Class::TOUCH;
321 case ECORE_DEVICE_CLASS_PEN:
323 deviceClass = Device::Class::PEN;
326 case ECORE_DEVICE_CLASS_POINTER:
328 deviceClass = Device::Class::POINTER;
331 case ECORE_DEVICE_CLASS_GAMEPAD:
333 deviceClass = Device::Class::GAMEPAD;
338 deviceClass = Device::Class::NONE;
344 void GetDeviceSubclass( Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subclass::Type& deviceSubclass )
346 switch( ecoreDeviceSubclass )
348 case ECORE_DEVICE_SUBCLASS_FINGER:
350 deviceSubclass = Device::Subclass::FINGER;
353 case ECORE_DEVICE_SUBCLASS_FINGERNAIL:
355 deviceSubclass = Device::Subclass::FINGERNAIL;
358 case ECORE_DEVICE_SUBCLASS_KNUCKLE:
360 deviceSubclass = Device::Subclass::KNUCKLE;
363 case ECORE_DEVICE_SUBCLASS_PALM:
365 deviceSubclass = Device::Subclass::PALM;
368 case ECORE_DEVICE_SUBCLASS_HAND_SIZE:
370 deviceSubclass = Device::Subclass::HAND_SIDE;
373 case ECORE_DEVICE_SUBCLASS_HAND_FLAT:
375 deviceSubclass = Device::Subclass::HAND_FLAT;
378 case ECORE_DEVICE_SUBCLASS_PEN_TIP:
380 deviceSubclass = Device::Subclass::PEN_TIP;
383 case ECORE_DEVICE_SUBCLASS_TRACKPAD:
385 deviceSubclass = Device::Subclass::TRACKPAD;
388 case ECORE_DEVICE_SUBCLASS_TRACKPOINT:
390 deviceSubclass = Device::Subclass::TRACKPOINT;
393 case ECORE_DEVICE_SUBCLASS_TRACKBALL:
395 deviceSubclass = Device::Subclass::TRACKBALL;
398 #ifdef OVER_TIZEN_VERSION_4
399 case ECORE_DEVICE_SUBCLASS_REMOCON:
401 deviceSubclass = Device::Subclass::REMOCON;
404 case ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD:
406 deviceSubclass = Device::Subclass::VIRTUAL_KEYBOARD;
412 deviceSubclass = Device::Subclass::NONE;
418 } // unnamed namespace
420 // Impl to hide EFL implementation.
421 struct EventHandler::Impl
423 // Construction & Destruction
428 Impl( EventHandler* handler, Ecore_Wl2_Window* window )
429 : mHandler( handler ),
430 mEcoreEventHandler(),
435 #ifdef DALI_ELDBUS_AVAILABLE
436 , mSystemConnection( NULL )
437 #endif // DALI_ELDBUS_AVAILABLE
439 // Only register for touch and key events if we have a window
442 // Register Touch events
443 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
444 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
445 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
446 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, handler ) );
448 // Register Mouse wheel events
449 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
451 // Register Focus events
452 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL2_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
453 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL2_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
455 // Register Key events
456 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
457 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
459 // Register Selection event - clipboard selection
460 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL2_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
461 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL2_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
463 // Register Rotate event
464 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL2_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
466 // Register Detent event
467 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
469 #ifndef DALI_PROFILE_UBUNTU
470 // Register Vconf notify - font name and size
471 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
472 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
473 #endif // DALI_PROFILE_UBUNTU
475 #ifdef DALI_ELDBUS_AVAILABLE
476 // Initialize ElDBus.
477 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
480 EcoreElDBusInitialisation( handler );
482 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
483 #endif // DALI_ELDBUS_AVAILABLE
492 #ifndef DALI_PROFILE_UBUNTU
493 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
494 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
495 #endif // DALI_PROFILE_UBUNTU
497 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
499 ecore_event_handler_del( *iter );
502 #ifdef DALI_ELDBUS_AVAILABLE
503 // Close down ElDBus connections.
504 if( mSystemConnection )
506 eldbus_connection_unref( mSystemConnection );
508 #endif // DALI_ELDBUS_AVAILABLE
513 /////////////////////////////////////////////////////////////////////////////////////////////////
515 /////////////////////////////////////////////////////////////////////////////////////////////////
518 * Called when a touch down is received.
520 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
522 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
523 EventHandler* handler( (EventHandler*)data );
525 if ( touchEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
527 PointState::Type state ( PointState::DOWN );
529 // Check if the buttons field is set and ensure it's the primary touch button.
530 // If this event was triggered by buttons other than the primary button (used for touch), then
531 // just send an interrupted event to Core.
532 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
534 state = PointState::INTERRUPTED;
537 Device::Class::Type deviceClass;
538 Device::Subclass::Type deviceSubclass;
540 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
541 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
543 Integration::Point point;
544 point.SetDeviceId( touchEvent->multi.device );
545 point.SetState( state );
546 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
547 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
548 point.SetPressure( touchEvent->multi.pressure );
549 point.SetAngle( Degree( touchEvent->multi.angle ) );
550 point.SetDeviceClass( deviceClass );
551 point.SetDeviceSubclass( deviceSubclass );
553 handler->SendEvent( point, touchEvent->timestamp );
556 return ECORE_CALLBACK_PASS_ON;
560 * Called when a touch up is received.
562 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
564 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
565 EventHandler* handler( (EventHandler*)data );
567 if ( touchEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
569 Device::Class::Type deviceClass;
570 Device::Subclass::Type deviceSubclass;
572 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
573 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
575 Integration::Point point;
576 point.SetDeviceId( touchEvent->multi.device );
577 point.SetState( PointState::UP );
578 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
579 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
580 point.SetPressure( touchEvent->multi.pressure );
581 point.SetAngle( Degree( touchEvent->multi.angle ) );
582 point.SetDeviceClass( deviceClass );
583 point.SetDeviceSubclass( deviceSubclass );
585 handler->SendEvent( point, touchEvent->timestamp );
588 return ECORE_CALLBACK_PASS_ON;
592 * Called when a touch motion is received.
594 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
596 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
597 EventHandler* handler( (EventHandler*)data );
599 if ( touchEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
601 Device::Class::Type deviceClass;
602 Device::Subclass::Type deviceSubclass;
604 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
605 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
607 Integration::Point point;
608 point.SetDeviceId( touchEvent->multi.device );
609 point.SetState( PointState::MOTION );
610 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
611 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
612 point.SetPressure( touchEvent->multi.pressure );
613 point.SetAngle( Degree( touchEvent->multi.angle ) );
614 point.SetDeviceClass( deviceClass );
615 point.SetDeviceSubclass( deviceSubclass );
617 handler->SendEvent( point, touchEvent->timestamp );
620 return ECORE_CALLBACK_PASS_ON;
624 * Called when a touch is canceled.
626 static Eina_Bool EcoreEventMouseButtonCancel( void* data, int type, void* event )
628 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
629 EventHandler* handler( (EventHandler*)data );
631 if( touchEvent->window == (unsigned int)ecore_wl2_window_id_get( handler->mImpl->mWindow ) )
633 Integration::Point point;
634 point.SetDeviceId( touchEvent->multi.device );
635 point.SetState( PointState::INTERRUPTED );
636 point.SetScreenPosition( Vector2( 0.0f, 0.0f ) );
637 handler->SendEvent( point, touchEvent->timestamp );
639 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventMouseButtonCancel\n" );
642 return ECORE_CALLBACK_PASS_ON;
646 * Called when a mouse wheel is received.
648 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
650 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
652 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);
654 EventHandler* handler( (EventHandler*)data );
655 if ( mouseWheelEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
657 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
658 handler->SendWheelEvent( wheelEvent );
660 return ECORE_CALLBACK_PASS_ON;
663 /////////////////////////////////////////////////////////////////////////////////////////////////
665 /////////////////////////////////////////////////////////////////////////////////////////////////
668 * Called when a key down is received.
670 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
672 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
674 EventHandler* handler( (EventHandler*)data );
675 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
676 bool eventHandled( false );
678 // If a device key then skip ecore_imf_context_filter_event.
679 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
681 Ecore_IMF_Context* imfContext = NULL;
682 Dali::ImfManager imfManager( ImfManager::Get() );
685 imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
690 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
691 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
692 ecoreKeyDownEvent.keyname = keyEvent->keyname;
693 ecoreKeyDownEvent.key = keyEvent->key;
694 ecoreKeyDownEvent.string = keyEvent->string;
695 ecoreKeyDownEvent.compose = keyEvent->compose;
696 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
697 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
698 ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent->modifiers );
699 ecoreKeyDownEvent.dev_name = ecore_device_name_get( keyEvent->dev );
700 ecoreKeyDownEvent.dev_class = static_cast<Ecore_IMF_Device_Class>( ecore_device_class_get( keyEvent->dev ) );
701 ecoreKeyDownEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass>( ecore_device_subclass_get( keyEvent->dev ) );
703 std::string checkDevice;
704 GetDeviceName( keyEvent, checkDevice );
706 // 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.
707 if( ( checkDevice == "ime" ) && ( ( !strncmp( keyEvent->keyname, "Left", 4 ) ) ||
708 ( !strncmp( keyEvent->keyname, "Right", 5 ) ) ||
709 ( !strncmp( keyEvent->keyname, "Up", 2 ) ) ||
710 ( !strncmp( keyEvent->keyname, "Down", 4 ) ) ) )
716 eventHandled = ecore_imf_context_filter_event( imfContext,
717 ECORE_IMF_EVENT_KEY_DOWN,
718 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
721 // If the event has not been handled by IMF then check if we should reset our IMF context
724 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
725 !strcmp( keyEvent->keyname, "Return" ) ||
726 !strcmp( keyEvent->keyname, "KP_Enter" ) )
728 ecore_imf_context_reset( imfContext );
734 // If the event wasn't handled then we should send a key event.
737 if ( keyEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
739 std::string keyName( keyEvent->keyname );
740 std::string keyString( "" );
741 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
742 keyCode = (keyCode == -1) ? 0 : keyCode;
743 int modifier( keyEvent->modifiers );
744 unsigned long time = keyEvent->timestamp;
745 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
746 keyCode = atoi(keyEvent->keyname + 8);
748 // Ensure key event string is not NULL as keys like SHIFT have a null string.
749 if ( keyEvent->string )
751 keyString = keyEvent->string;
754 std::string deviceName;
755 Device::Class::Type deviceClass;
756 Device::Subclass::Type deviceSubclass;
758 GetDeviceName( keyEvent, deviceName );
759 GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
760 GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
762 DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s) deviceClass(%d)\n", deviceName.c_str(), deviceClass );
764 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, deviceName, deviceClass, deviceSubclass );
765 handler->SendEvent( keyEvent );
769 return ECORE_CALLBACK_PASS_ON;
773 * Called when a key up is received.
775 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
777 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
779 EventHandler* handler( (EventHandler*)data );
780 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
781 bool eventHandled( false );
783 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
784 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
786 Ecore_IMF_Context* imfContext = NULL;
787 Dali::ImfManager imfManager( ImfManager::Get() );
790 imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
795 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
796 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
797 ecoreKeyUpEvent.keyname = keyEvent->keyname;
798 ecoreKeyUpEvent.key = keyEvent->key;
799 ecoreKeyUpEvent.string = keyEvent->string;
800 ecoreKeyUpEvent.compose = keyEvent->compose;
801 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
802 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
803 ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent->modifiers );
804 ecoreKeyUpEvent.dev_name = ecore_device_name_get( keyEvent->dev );
805 ecoreKeyUpEvent.dev_class = static_cast<Ecore_IMF_Device_Class>( ecore_device_class_get( keyEvent->dev ) );
806 ecoreKeyUpEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass>( ecore_device_subclass_get( keyEvent->dev ) );
808 eventHandled = ecore_imf_context_filter_event( imfContext,
809 ECORE_IMF_EVENT_KEY_UP,
810 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
814 // If the event wasn't handled then we should send a key event.
817 if ( keyEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
819 std::string keyName( keyEvent->keyname );
820 std::string keyString( "" );
821 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
822 keyCode = (keyCode == -1) ? 0 : keyCode;
823 int modifier( keyEvent->modifiers );
824 unsigned long time = keyEvent->timestamp;
825 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
826 keyCode = atoi(keyEvent->keyname + 8);
828 // Ensure key event string is not NULL as keys like SHIFT have a null string.
829 if ( keyEvent->string )
831 keyString = keyEvent->string;
834 std::string deviceName;
835 Device::Class::Type deviceClass;
836 Device::Subclass::Type deviceSubclass;
838 GetDeviceName( keyEvent, deviceName );
839 GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
840 GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
842 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, deviceName, deviceClass, deviceSubclass );
843 handler->SendEvent( keyEvent );
847 return ECORE_CALLBACK_PASS_ON;
850 /////////////////////////////////////////////////////////////////////////////////////////////////
852 /////////////////////////////////////////////////////////////////////////////////////////////////
855 * Called when the window gains focus.
857 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
859 Ecore_Wl2_Event_Focus_In* focusInEvent( (Ecore_Wl2_Event_Focus_In*)event );
860 EventHandler* handler( (EventHandler*)data );
862 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
864 // If the window gains focus and we hid the keyboard then show it again.
865 if ( focusInEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
867 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
869 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
871 Dali::ImfManager imfManager( ImfManager::Get() );
874 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
875 if( imfManagerImpl.RestoreAfterFocusLost() )
877 imfManagerImpl.Activate();
881 Dali::Clipboard clipboard = Clipboard::Get();
882 clipboard.HideClipboard();
885 return ECORE_CALLBACK_PASS_ON;
889 * Called when the window loses focus.
891 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
893 Ecore_Wl2_Event_Focus_Out* focusOutEvent( (Ecore_Wl2_Event_Focus_Out*)event );
894 EventHandler* handler( (EventHandler*)data );
896 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
898 // If the window loses focus then hide the keyboard.
899 if ( focusOutEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
901 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
903 Dali::ImfManager imfManager( ImfManager::Get() );
906 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
907 if( imfManagerImpl.RestoreAfterFocusLost() )
909 imfManagerImpl.Deactivate();
914 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
915 Dali::Clipboard clipboard = Clipboard::Get();
918 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
919 clipBoardImpl.HideClipboard(true);
923 return ECORE_CALLBACK_PASS_ON;
927 * Called when the window is damaged.
929 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
931 return ECORE_CALLBACK_PASS_ON;
935 * Called when the window properties are changed.
936 * We are only interested in the font change.
940 /////////////////////////////////////////////////////////////////////////////////////////////////
941 // Drag & Drop Callbacks
942 /////////////////////////////////////////////////////////////////////////////////////////////////
945 * Called when a dragged item enters our window's bounds.
946 * This is when items are dragged INTO our window.
948 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
950 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
952 return ECORE_CALLBACK_PASS_ON;
956 * Called when a dragged item is moved within our window.
957 * This is when items are dragged INTO our window.
959 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
961 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
963 return ECORE_CALLBACK_PASS_ON;
967 * Called when a dragged item leaves our window's bounds.
968 * This is when items are dragged INTO our window.
970 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
972 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
974 return ECORE_CALLBACK_PASS_ON;
978 * Called when the dragged item is dropped within our window's bounds.
979 * This is when items are dragged INTO our window.
981 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
983 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
985 return ECORE_CALLBACK_PASS_ON;
989 * Called when a dragged item is moved from our window and the target window has done processing it.
990 * This is when items are dragged FROM our window.
992 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
994 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
995 return ECORE_CALLBACK_PASS_ON;
999 * Called when a dragged item is moved from our window and the target window has sent us a status.
1000 * This is when items are dragged FROM our window.
1002 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
1004 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
1005 return ECORE_CALLBACK_PASS_ON;
1009 * Called when the client messages (i.e. the accessibility events) are received.
1011 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
1013 return ECORE_CALLBACK_PASS_ON;
1017 /////////////////////////////////////////////////////////////////////////////////////////////////
1018 // ElDBus Accessibility Callbacks
1019 /////////////////////////////////////////////////////////////////////////////////////////////////
1021 #ifdef DALI_ELDBUS_AVAILABLE
1022 // Callback for Ecore ElDBus accessibility events.
1023 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
1025 EventHandler* handler = static_cast< EventHandler* >( context );
1026 // Ignore any accessibility events when paused.
1027 if( handler->mPaused )
1032 if( !handler->mAccessibilityAdaptor )
1034 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
1038 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1039 if( !accessibilityAdaptor )
1041 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
1047 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
1050 // The string defines the arg-list's respective types.
1051 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
1053 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1056 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
1058 // Create a touch point object.
1059 TouchPoint::State touchPointState( TouchPoint::Down );
1062 touchPointState = TouchPoint::Down; // Mouse down.
1064 else if( state == 1 )
1066 touchPointState = TouchPoint::Motion; // Mouse move.
1068 else if( state == 2 )
1070 touchPointState = TouchPoint::Up; // Mouse up.
1074 touchPointState = TouchPoint::Interrupted; // Error.
1077 // Send touch event to accessibility adaptor.
1078 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1080 // Perform actions based on received gestures.
1081 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
1082 switch( gestureValue )
1084 case 0: // OneFingerHover
1087 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1090 case 1: // TwoFingersHover
1092 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1093 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1096 case 2: // ThreeFingersHover
1098 // Read from top item on screen continuously.
1099 accessibilityAdaptor->HandleActionReadFromTopEvent();
1102 case 3: // OneFingerFlickLeft
1104 // Move to previous item.
1105 accessibilityAdaptor->HandleActionReadPreviousEvent();
1108 case 4: // OneFingerFlickRight
1110 // Move to next item.
1111 accessibilityAdaptor->HandleActionReadNextEvent();
1114 case 5: // OneFingerFlickUp
1116 // Move to previous item.
1117 accessibilityAdaptor->HandleActionPreviousEvent();
1120 case 6: // OneFingerFlickDown
1122 // Move to next item.
1123 accessibilityAdaptor->HandleActionNextEvent();
1126 case 7: // TwoFingersFlickUp
1128 // Scroll up the list.
1129 accessibilityAdaptor->HandleActionScrollUpEvent();
1132 case 8: // TwoFingersFlickDown
1134 // Scroll down the list.
1135 accessibilityAdaptor->HandleActionScrollDownEvent();
1138 case 9: // TwoFingersFlickLeft
1140 // Scroll left to the previous page
1141 accessibilityAdaptor->HandleActionPageLeftEvent();
1144 case 10: // TwoFingersFlickRight
1146 // Scroll right to the next page
1147 accessibilityAdaptor->HandleActionPageRightEvent();
1150 case 11: // ThreeFingersFlickLeft
1155 case 12: // ThreeFingersFlickRight
1160 case 13: // ThreeFingersFlickUp
1165 case 14: // ThreeFingersFlickDown
1170 case 15: // OneFingerSingleTap
1173 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1176 case 16: // OneFingerDoubleTap
1178 // Activate selected item / active edit mode.
1179 accessibilityAdaptor->HandleActionActivateEvent();
1182 case 17: // OneFingerTripleTap
1185 accessibilityAdaptor->HandleActionZoomEvent();
1188 case 18: // TwoFingersSingleTap
1190 // Pause/Resume current speech
1191 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1194 case 19: // TwoFingersDoubleTap
1196 // Start/Stop current action
1197 accessibilityAdaptor->HandleActionStartStopEvent();
1200 case 20: // TwoFingersTripleTap
1202 // Read information from indicator
1203 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1206 case 21: // ThreeFingersSingleTap
1208 // Read from top item on screen continuously.
1209 accessibilityAdaptor->HandleActionReadFromTopEvent();
1212 case 22: // ThreeFingersDoubleTap
1214 // Read from next item continuously.
1215 accessibilityAdaptor->HandleActionReadFromNextEvent();
1218 case 23: // ThreeFingersTripleTap
1223 case 24: // OneFingerFlickLeftReturn
1225 // Scroll up to the previous page
1226 accessibilityAdaptor->HandleActionPageUpEvent();
1229 case 25: // OneFingerFlickRightReturn
1231 // Scroll down to the next page
1232 accessibilityAdaptor->HandleActionPageDownEvent();
1235 case 26: // OneFingerFlickUpReturn
1237 // Move to the first item on screen
1238 accessibilityAdaptor->HandleActionMoveToFirstEvent();
1241 case 27: // OneFingerFlickDownReturn
1243 // Move to the last item on screen
1244 accessibilityAdaptor->HandleActionMoveToLastEvent();
1247 case 28: // TwoFingersFlickLeftReturn
1252 case 29: // TwoFingersFlickRightReturn
1257 case 30: // TwoFingersFlickUpReturn
1262 case 31: // TwoFingersFlickDownReturn
1267 case 32: // ThreeFingersFlickLeftReturn
1272 case 33: // ThreeFingersFlickRightReturn
1277 case 34: // ThreeFingersFlickUpReturn
1282 case 35: // ThreeFingersFlickDownReturn
1290 void EcoreElDBusInitialisation( void *handle )
1292 Eldbus_Object *object;
1293 Eldbus_Proxy *manager;
1295 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1297 DALI_LOG_ERROR( "Unable to get system bus\n" );
1300 object = eldbus_object_get( mSystemConnection, BUS, PATH );
1303 DALI_LOG_ERROR( "Getting object failed\n" );
1307 manager = eldbus_proxy_get( object, INTERFACE );
1310 DALI_LOG_ERROR( "Getting proxy failed\n" );
1314 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1316 DALI_LOG_ERROR( "No signal handler returned\n" );
1319 #endif // DALI_ELDBUS_AVAILABLE
1322 * Called when the source window notifies us the content in clipboard is selected.
1324 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1326 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1327 return ECORE_CALLBACK_PASS_ON;
1331 * Called when the source window sends us about the selected content.
1332 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1334 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1336 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1337 return ECORE_CALLBACK_PASS_ON;
1341 * Called when the source window notifies us the content in clipboard is selected.
1343 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1345 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1347 Dali::Clipboard clipboard = Clipboard::Get();
1350 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1351 clipBoardImpl.ExcuteBuffered( true, event );
1353 return ECORE_CALLBACK_PASS_ON;
1357 * Called when the source window sends us about the selected content.
1358 * For example, when item is selected in the clipboard.
1360 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1362 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1364 EventHandler* handler( (EventHandler*)data );
1365 Dali::Clipboard clipboard = Clipboard::Get();
1366 char *selectionData = NULL;
1369 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1370 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1372 if ( selectionData && handler->mClipboardEventNotifier )
1374 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1375 std::string content( selectionData, strlen(selectionData) );
1377 clipboardEventNotifier.SetContent( content );
1378 clipboardEventNotifier.EmitContentSelectedSignal();
1380 return ECORE_CALLBACK_PASS_ON;
1384 * Called when rotate event is recevied
1386 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1388 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1390 EventHandler* handler( (EventHandler*)data );
1391 Ecore_Wl2_Event_Window_Rotation* ev( (Ecore_Wl2_Event_Window_Rotation*)event );
1393 if( ev->win != (unsigned int)ecore_wl2_window_id_get( handler->mImpl->mWindow ) )
1395 return ECORE_CALLBACK_PASS_ON;
1398 RotationEvent rotationEvent;
1399 rotationEvent.angle = ev->angle;
1400 rotationEvent.winResize = 0;
1402 if( ev->angle == 0 || ev->angle == 180 )
1404 rotationEvent.width = ev->w;
1405 rotationEvent.height = ev->h;
1409 rotationEvent.width = ev->h;
1410 rotationEvent.height = ev->w;
1413 handler->SendRotationPrepareEvent( rotationEvent );
1415 return ECORE_CALLBACK_PASS_ON;
1419 * Called when detent event is recevied
1421 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1423 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1424 EventHandler* handler( (EventHandler*)data );
1425 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1426 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1427 int timeStamp = e->timestamp;
1429 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1430 handler->SendWheelEvent( wheelEvent );
1431 return ECORE_CALLBACK_PASS_ON;
1434 /////////////////////////////////////////////////////////////////////////////////////////////////
1436 /////////////////////////////////////////////////////////////////////////////////////////////////
1438 * Called when a font name is changed.
1440 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1442 EventHandler* handler = static_cast<EventHandler*>( data );
1443 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1447 * Called when a font size is changed.
1449 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1451 EventHandler* handler = static_cast<EventHandler*>( data );
1452 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1455 void ConvertTouchPosition( Integration::Point& point )
1457 Vector2 position = point.GetScreenPosition();
1458 Vector2 convertedPosition;
1460 switch( mRotationAngle )
1464 convertedPosition.x = mWindowWidth - position.y;
1465 convertedPosition.y = position.x;
1470 convertedPosition.x = mWindowWidth - position.x;
1471 convertedPosition.y = mWindowHeight - position.y;
1476 convertedPosition.x = position.y;
1477 convertedPosition.y = mWindowHeight - position.x;
1482 convertedPosition = position;
1487 point.SetScreenPosition( convertedPosition );
1491 EventHandler* mHandler;
1492 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1493 Ecore_Wl2_Window* mWindow;
1497 #ifdef DALI_ELDBUS_AVAILABLE
1498 Eldbus_Connection* mSystemConnection;
1499 #endif // DALI_ELDBUS_AVAILABLE
1502 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1503 : mCoreEventInterface( coreEventInterface ),
1504 mGestureManager( gestureManager ),
1505 mStyleMonitor( StyleMonitor::Get() ),
1506 mDamageObserver( damageObserver ),
1507 mRotationObserver( NULL ),
1508 mDragAndDropDetector( dndDetector ),
1509 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1510 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1511 mClipboard( Clipboard::Get() ),
1515 Ecore_Wl2_Window* window = 0;
1517 // this code only works with the Ecore RenderSurface so need to downcast
1518 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1521 window = ecoreSurface->GetWlWindow();
1524 mImpl = new Impl(this, window);
1527 EventHandler::~EventHandler()
1534 mGestureManager.Stop();
1537 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1541 timeStamp = GetCurrentMilliSeconds();
1544 mImpl->ConvertTouchPosition( point );
1546 Integration::TouchEvent touchEvent;
1547 Integration::HoverEvent hoverEvent;
1548 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1549 if(type != Integration::TouchEventCombiner::DispatchNone )
1551 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);
1553 // First the touch and/or hover event & related gesture events are queued
1554 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1556 mCoreEventInterface.QueueCoreEvent( touchEvent );
1557 mGestureManager.SendEvent(touchEvent);
1560 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1562 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1565 // Next the events are processed with a single call into Core
1566 mCoreEventInterface.ProcessCoreEvents();
1570 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1572 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1573 if ( physicalKeyboard )
1575 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1577 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1581 // Create send KeyEvent to Core.
1582 mCoreEventInterface.QueueCoreEvent( keyEvent );
1583 mCoreEventInterface.ProcessCoreEvents();
1586 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1588 // Create WheelEvent and send to Core.
1589 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1590 mCoreEventInterface.QueueCoreEvent( event );
1591 mCoreEventInterface.ProcessCoreEvents();
1594 void EventHandler::SendEvent( StyleChange::Type styleChange )
1596 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1597 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1600 void EventHandler::SendEvent( const DamageArea& area )
1602 mDamageObserver.OnDamaged( area );
1605 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1607 if( mRotationObserver != NULL )
1609 mImpl->mRotationAngle = event.angle;
1610 mImpl->mWindowWidth = event.width;
1611 mImpl->mWindowHeight = event.height;
1613 mRotationObserver->OnRotationPrepare( event );
1614 mRotationObserver->OnRotationRequest();
1618 void EventHandler::SendRotationRequestEvent( )
1620 // No need to separate event into prepare and request in wayland
1623 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1625 Integration::Point convertedPoint( point );
1626 SendEvent(convertedPoint, timeStamp);
1629 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1631 SendWheelEvent( wheelEvent );
1634 void EventHandler::FeedKeyEvent( KeyEvent& event )
1636 Integration::KeyEvent convertedEvent( event );
1637 SendEvent( convertedEvent );
1640 void EventHandler::FeedEvent( Integration::Event& event )
1642 mCoreEventInterface.QueueCoreEvent( event );
1643 mCoreEventInterface.ProcessCoreEvents();
1646 void EventHandler::Reset()
1650 // Any touch listeners should be told of the interruption.
1651 Integration::TouchEvent event;
1652 Integration::Point point;
1653 point.SetState( PointState::INTERRUPTED );
1654 event.AddPoint( point );
1656 // First the touch event & related gesture events are queued
1657 mCoreEventInterface.QueueCoreEvent( event );
1658 mGestureManager.SendEvent( event );
1660 // Next the events are processed with a single call into Core
1661 mCoreEventInterface.ProcessCoreEvents();
1664 void EventHandler::Pause()
1670 void EventHandler::Resume()
1676 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1678 mDragAndDropDetector = detector;
1681 void EventHandler::SetRotationObserver( RotationObserver* observer )
1683 mRotationObserver = observer;
1686 } // namespace Adaptor
1688 } // namespace Internal
1692 #pragma GCC diagnostic pop