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>
30 #include <X11/extensions/XInput2.h>
31 #include <X11/extensions/XI2.h>
37 #ifndef DALI_PROFILE_UBUNTU
39 #include <vconf-keys.h>
40 #endif // DALI_PROFILE_UBUNTU
42 #ifdef DALI_ELDBUS_AVAILABLE
44 #endif // DALI_ELDBUS_AVAILABLE
46 #include <dali/public-api/common/vector-wrapper.h>
47 #include <dali/public-api/events/touch-point.h>
48 #include <dali/public-api/events/key-event.h>
49 #include <dali/public-api/events/wheel-event.h>
50 #include <dali/integration-api/debug.h>
51 #include <dali/integration-api/events/key-event-integ.h>
52 #include <dali/integration-api/events/touch-event-integ.h>
53 #include <dali/integration-api/events/hover-event-integ.h>
54 #include <dali/integration-api/events/wheel-event-integ.h>
57 #include <dali/internal/input/common/gesture-manager.h>
58 #include <dali/internal/window-system/ubuntu-x11/window-render-surface-ecore-x.h>
59 #include <dali/internal/clipboard/common/clipboard-impl.h>
60 #include <dali/internal/input/common/key-impl.h>
61 #include <dali/internal/input/common/physical-keyboard-impl.h>
62 #include <dali/internal/styling/common/style-monitor-impl.h>
63 #include <dali/internal/system/common/core-event-interface.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* gClientMessageLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_CLIENT_MESSAGE");
79 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
80 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
81 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
82 } // unnamed namespace
89 const char * DETENT_DEVICE_NAME = "tizen_detent";
90 const std::string DEFAULT_DEVICE_NAME = "";
91 const Device::Class::Type DEFAULT_DEVICE_CLASS = Device::Class::NONE;
92 const Device::Subclass::Type DEFAULT_DEVICE_SUBCLASS = Device::Subclass::NONE;
95 #define A11Y_BUS "org.a11y.Bus"
96 #define A11Y_INTERFACE "org.a11y.Bus"
97 #define A11Y_PATH "/org/a11y/bus"
98 #define A11Y_GET_ADDRESS "GetAddress"
99 #define BUS "com.samsung.EModule"
100 #define INTERFACE "com.samsung.GestureNavigation"
101 #define PATH "/com/samsung/GestureNavigation"
102 #define SIGNAL "GestureDetected"
104 #ifndef DALI_PROFILE_UBUNTU
105 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
106 #endif // DALI_PROFILE_UBUNTU
108 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
110 #ifndef DALI_PROFILE_UBUNTU
111 const char * CLIPBOARD_ATOM = "CBHM_MSG";
112 const char * CLIPBOARD_SET_OWNER_MESSAGE = "SET_OWNER";
113 #endif // DALI_PROFILE_UBUNTU
115 /// The atoms required by Ecore for Drag & Drop behaviour.
116 Ecore_X_Atom DRAG_AND_DROP_ATOMS[] =
118 ECORE_X_ATOM_XDND_ACTION_COPY,
121 /// The types that we support.
122 const char * DRAG_AND_DROP_TYPES[] =
124 ECORE_X_SELECTION_TARGET_UTF8_STRING,
127 const unsigned int DRAG_AND_DROP_ATOMS_NUMBER = sizeof( DRAG_AND_DROP_ATOMS ) / sizeof( Ecore_X_Atom );
128 const unsigned int DRAG_AND_DROP_TYPES_NUMBER = sizeof( DRAG_AND_DROP_TYPES ) / sizeof( const char * );
130 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
132 #ifdef DALI_ELDBUS_AVAILABLE
133 // DBus gesture string matching lists.
134 // TODO: This needs moving to its own module.
135 const char * ElDBusAccessibilityFingerCountStrings[] =
141 const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
146 GESTURE_TYPE_SINGLE_TAP,
147 GESTURE_TYPE_DOUBLE_TAP,
148 GESTURE_TYPE_TRIPLE_TAP
150 struct GestureTypeTable
153 const GestureType type;
155 GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
157 { "Hover", GESTURE_TYPE_HOVER },
158 { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
159 { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
160 { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
162 const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
165 SUB_GESTURE_TYPE_NONE,
166 SUB_GESTURE_TYPE_FLICK
168 struct SubGestureTypeTable
171 const SubGestureType type;
173 SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
175 { "Flick", SUB_GESTURE_TYPE_FLICK }
177 const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
178 enum GestureDirection
180 GESTURE_DIRECTION_NONE,
181 GESTURE_DIRECTION_UP,
182 GESTURE_DIRECTION_DOWN,
183 GESTURE_DIRECTION_LEFT,
184 GESTURE_DIRECTION_RIGHT,
185 GESTURE_DIRECTION_UP_RETURN,
186 GESTURE_DIRECTION_DOWN_RETURN,
187 GESTURE_DIRECTION_LEFT_RETURN,
188 GESTURE_DIRECTION_RIGHT_RETURN
190 struct GestureDirectionTable
193 const GestureDirection direction;
195 GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
197 { "Up", GESTURE_DIRECTION_UP },
198 { "Down", GESTURE_DIRECTION_DOWN },
199 { "Left", GESTURE_DIRECTION_LEFT },
200 { "Right", GESTURE_DIRECTION_RIGHT },
201 { "UpReturn", GESTURE_DIRECTION_UP_RETURN },
202 { "DownReturn", GESTURE_DIRECTION_DOWN_RETURN },
203 { "LeftReturn", GESTURE_DIRECTION_LEFT_RETURN },
204 { "RightReturn", GESTURE_DIRECTION_RIGHT_RETURN }
206 const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
207 #endif // DALI_ELDBUS_AVAILABLE
209 // Copied from x server
210 static unsigned int GetCurrentMilliSeconds(void)
215 static clockid_t clockid;
219 #ifdef CLOCK_MONOTONIC_COARSE
220 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
221 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
223 clockid = CLOCK_MONOTONIC_COARSE;
227 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
229 clockid = CLOCK_MONOTONIC;
236 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
238 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
241 gettimeofday(&tv, NULL);
242 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
245 } // unnamed namespace
247 // Impl to hide EFL implementation.
248 struct EventHandler::Impl
250 // Construction & Destruction
255 Impl( EventHandler* handler, Ecore_X_Window window )
256 : mHandler( handler ),
257 mEcoreEventHandler(),
260 #ifdef DALI_ELDBUS_AVAILABLE
261 , mSessionConnection( NULL ),
262 mA11yConnection( NULL )
265 // Only register for touch and key events if we have a window
268 // Register Touch events
269 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
270 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
271 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
272 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
274 // Register Mouse wheel events
275 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
277 // Register Key events
278 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
279 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
281 // Register Focus events
282 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
283 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
285 // Register Window damage events
286 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_DAMAGE, EcoreEventWindowDamaged, handler ) );
288 // Enable Drag & Drop and register DnD events
289 ecore_x_dnd_aware_set( window, EINA_TRUE );
290 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_ENTER, EcoreEventDndEnter, handler) );
291 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_POSITION, EcoreEventDndPosition, handler) );
292 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_LEAVE, EcoreEventDndLeave, handler) );
293 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_DROP, EcoreEventDndDrop, handler) );
294 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_FINISHED, EcoreEventDndFinished, handler) );
295 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_STATUS, EcoreEventDndStatus, handler) );
297 // Register Client message events - accessibility etc.
298 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_CLIENT_MESSAGE, EcoreEventClientMessage, handler ) );
300 // Register Selection event - clipboard selection, Drag & Drop selection etc.
301 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_CLEAR, EcoreEventSelectionClear, handler ) );
302 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_NOTIFY, EcoreEventSelectionNotify, handler ) );
304 // Initialize Xi2 system
305 Display* display = static_cast< Display* >(ecore_x_display_get());
306 Ecore_X_Window rootWindow = ecore_x_window_root_first_get();
307 int opcode = 0, event = 0, error = 0;
308 int major = XI_2_Major;
309 int minor = XI_2_Minor;
311 XIEventMask xiEventMask;
313 // Check if X input extension available
314 if( XQueryExtension( display, "XInputExtension", &opcode, &event, &error ) )
316 // We support version 2.0
317 if( XIQueryVersion( display, &major, &minor ) != BadRequest )
319 xiEventMask.deviceid = XIAllDevices;
323 XIDeviceInfo* deviceInfo = NULL;
324 deviceInfo = XIQueryDevice( display, XIAllDevices, &deviceCount );
326 for( int i = 0; i < deviceCount; i++ )
328 if( !strncmp( deviceInfo[i].name, DETENT_DEVICE_NAME, strlen( DETENT_DEVICE_NAME ) ) )
330 xiEventMask.deviceid = deviceInfo[i].deviceid;
338 mXiDeviceId = xiEventMask.deviceid;
341 Dali::Vector< unsigned char > mask;
342 std::size_t xiMaskLen = XIMaskLen( XI_LASTEVENT );
343 mask.Reserve( xiMaskLen );
344 xiEventMask.mask = mask.Begin();
346 XISetMask( xiEventMask.mask, XI_RawMotion );
348 xiEventMask.mask_len = xiMaskLen * sizeof( unsigned char );
350 int ret = XISelectEvents( display, rootWindow, &xiEventMask, 1 );
353 // Register custom wheel events
354 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_GENERIC, EcoreEventCustomWheel, handler ) );
358 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to Select Events\n" );
362 if( deviceInfo != NULL )
364 XIFreeDeviceInfo( deviceInfo );
369 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XI Version\n" );
374 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XInputExtension\n" );
377 #ifndef DALI_PROFILE_UBUNTU
378 // Register Vconf notify - font name, font size and style
379 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, handler );
380 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
381 #endif // DALI_PROFILE_UBUNTU
383 #ifdef DALI_ELDBUS_AVAILABLE
385 // Initialize ElDBus.
386 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
389 mSessionConnection = eldbus_connection_get( ELDBUS_CONNECTION_TYPE_SESSION );
391 Eldbus_Object *a11yObject = eldbus_object_get( mSessionConnection, A11Y_BUS, A11Y_PATH );
392 Eldbus_Proxy *elDBusManager = eldbus_proxy_get( a11yObject, A11Y_INTERFACE );
394 // Pass in handler in the cb_data field so we can access the accessibility adaptor within the callback.
395 eldbus_proxy_call( elDBusManager, A11Y_GET_ADDRESS, EcoreElDBusInitialisation, handler, -1, "" );
397 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
399 #endif // DALI_ELDBUS_AVAILABLE
408 #ifndef DALI_PROFILE_UBUNTU
409 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
410 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged );
411 #endif // DALI_PROFILE_UBUNTU
413 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
415 ecore_event_handler_del( *iter );
418 #ifdef DALI_ELDBUS_AVAILABLE
420 if( mA11yConnection )
422 eldbus_connection_unref( mA11yConnection );
425 if( mSessionConnection )
427 eldbus_connection_unref( mSessionConnection );
431 #endif // DALI_ELDBUS_AVAILABLE
436 /////////////////////////////////////////////////////////////////////////////////////////////////
438 /////////////////////////////////////////////////////////////////////////////////////////////////
441 * Called when a touch down is received.
443 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
445 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
446 EventHandler* handler( (EventHandler*)data );
448 if ( touchEvent->window == handler->mImpl->mWindow )
450 PointState::Type state ( PointState::DOWN );
452 // Check if the buttons field is set and ensure it's the primary touch button.
453 // If this event was triggered by buttons other than the primary button (used for touch), then
454 // just send an interrupted event to Core.
455 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
457 state = PointState::INTERRUPTED;
460 Integration::Point point;
461 point.SetDeviceId( touchEvent->multi.device );
462 point.SetState( state );
463 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
464 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
465 point.SetPressure( touchEvent->multi.pressure );
466 point.SetAngle( Degree( touchEvent->multi.angle ) );
467 handler->SendEvent( point, touchEvent->timestamp );
470 return ECORE_CALLBACK_PASS_ON;
474 * Called when a touch up is received.
476 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
478 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
479 EventHandler* handler( (EventHandler*)data );
481 if ( touchEvent->window == handler->mImpl->mWindow )
483 Integration::Point point;
484 point.SetDeviceId( touchEvent->multi.device );
485 point.SetState( PointState::UP );
486 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
487 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
488 point.SetPressure( touchEvent->multi.pressure );
489 point.SetAngle( Degree( touchEvent->multi.angle ) );
490 handler->SendEvent( point, touchEvent->timestamp );
493 return ECORE_CALLBACK_PASS_ON;
497 * Called when a touch motion is received.
499 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
501 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
502 EventHandler* handler( (EventHandler*)data );
504 if ( touchEvent->window == handler->mImpl->mWindow )
506 Integration::Point point;
507 point.SetDeviceId( touchEvent->multi.device );
508 point.SetState( PointState::MOTION );
509 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
510 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
511 point.SetPressure( touchEvent->multi.pressure );
512 point.SetAngle( Degree( touchEvent->multi.angle ) );
513 handler->SendEvent( point, touchEvent->timestamp );
516 return ECORE_CALLBACK_PASS_ON;
519 /////////////////////////////////////////////////////////////////////////////////////////////////
521 /////////////////////////////////////////////////////////////////////////////////////////////////
524 * Called when a mouse wheel is received.
526 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
528 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
530 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 );
532 EventHandler* handler( (EventHandler*)data );
533 if ( mouseWheelEvent->window == handler->mImpl->mWindow )
535 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
536 handler->SendWheelEvent( wheelEvent );
538 return ECORE_CALLBACK_PASS_ON;
542 * Called when a custom wheel is received.
544 static Eina_Bool EcoreEventCustomWheel( void* data, int type, void* event )
546 Ecore_X_Event_Generic *genericEvent( (Ecore_X_Event_Generic*)event );
547 EventHandler* handler( (EventHandler*)data );
549 switch( genericEvent->evtype )
553 XIRawEvent* xiRawEvent = static_cast< XIRawEvent* >( genericEvent->data );
554 unsigned int timeStamp = 0;
556 if( xiRawEvent->deviceid != handler->mImpl->mXiDeviceId )
558 return ECORE_CALLBACK_PASS_ON;
561 // X(0): rotate: NOT USED
565 double* value = xiRawEvent->raw_values;
567 if( XIMaskIsSet( xiRawEvent->valuators.mask, 1) )
569 timeStamp = static_cast< unsigned int >( *(value + 1) );
572 if( XIMaskIsSet( xiRawEvent->valuators.mask, 2) )
574 // if z == 1, clockwise
575 // otherwise counter-clockwise
576 int z = static_cast< int >( *(value + 2) );
578 // In DALi, positive value means clockwise, and negative value means counter-clockwise
584 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventCustomWheel: z: %d\n", z );
586 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), z, timeStamp );
587 handler->SendWheelEvent( wheelEvent );
597 return ECORE_CALLBACK_PASS_ON;
600 /////////////////////////////////////////////////////////////////////////////////////////////////
602 /////////////////////////////////////////////////////////////////////////////////////////////////
605 * Called when a key down is received.
607 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
609 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
611 EventHandler* handler( (EventHandler*)data );
612 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
613 bool eventHandled( false );
615 // If the event wasn't handled then we should send a key event.
618 if ( keyEvent->window == handler->mImpl->mWindow )
620 std::string keyName( keyEvent->keyname );
621 std::string keyString( "" );
622 std::string compose ( "" );
624 // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
625 if ( keyEvent->compose )
627 compose = keyEvent->compose;
629 int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
630 int modifier( keyEvent->modifiers );
631 unsigned long time = keyEvent->timestamp;
633 // Ensure key event string is not NULL as keys like SHIFT have a null string.
634 if ( keyEvent->string )
636 keyString = keyEvent->string;
639 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, compose, DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS );
640 handler->SendEvent( keyEvent );
644 return ECORE_CALLBACK_PASS_ON;
648 * Called when a key up is received.
650 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
652 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp \n" );
654 EventHandler* handler( (EventHandler*)data );
655 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
656 bool eventHandled( false );
658 // If the event wasn't handled then we should send a key event.
661 if ( keyEvent->window == handler->mImpl->mWindow )
663 std::string keyName( keyEvent->keyname );
664 std::string keyString( "" );
665 std::string compose( "" );
667 // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
668 if ( keyEvent->compose )
670 compose = keyEvent->compose;
672 int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
673 int modifier( keyEvent->modifiers );
674 unsigned long time( keyEvent->timestamp );
676 // Ensure key event string is not NULL as keys like SHIFT have a null string.
677 if ( keyEvent->string )
679 keyString = keyEvent->string;
682 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, compose, DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_CLASS, DEFAULT_DEVICE_SUBCLASS );
684 handler->SendEvent( keyEvent );
688 return ECORE_CALLBACK_PASS_ON;
691 /////////////////////////////////////////////////////////////////////////////////////////////////
693 /////////////////////////////////////////////////////////////////////////////////////////////////
696 * Called when the window gains focus.
698 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
700 Ecore_X_Event_Window_Focus_In* focusInEvent( (Ecore_X_Event_Window_Focus_In*)event );
701 EventHandler* handler( (EventHandler*)data );
703 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
705 // If the window gains focus and we hid the keyboard then show it again.
706 if ( focusInEvent->win == handler->mImpl->mWindow )
708 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
711 return ECORE_CALLBACK_PASS_ON;
715 * Called when the window loses focus.
717 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
719 Ecore_X_Event_Window_Focus_Out* focusOutEvent( (Ecore_X_Event_Window_Focus_Out*)event );
720 EventHandler* handler( (EventHandler*)data );
722 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
724 // If the window loses focus then hide the keyboard.
725 if ( focusOutEvent->win == handler->mImpl->mWindow )
727 // Clipboard don't support that whether clipboard is shown or not. Hide clipboard.
728 Dali::Clipboard clipboard = Clipboard::Get();
729 clipboard.HideClipboard();
732 return ECORE_CALLBACK_PASS_ON;
736 * Called when the window is damaged.
738 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
740 Ecore_X_Event_Window_Damage* windowDamagedEvent( (Ecore_X_Event_Window_Damage*)event );
741 EventHandler* handler( (EventHandler*)data );
743 if( windowDamagedEvent->win == handler->mImpl->mWindow )
746 area.x = windowDamagedEvent->x;
747 area.y = windowDamagedEvent->y;
748 area.width = windowDamagedEvent->w;
749 area.height = windowDamagedEvent->h;
751 handler->SendEvent( area );
754 return ECORE_CALLBACK_PASS_ON;
758 * Called when the window properties are changed.
759 * We are only interested in the font change.
763 /////////////////////////////////////////////////////////////////////////////////////////////////
764 // Drag & Drop Callbacks
765 /////////////////////////////////////////////////////////////////////////////////////////////////
768 * Called when a dragged item enters our window's bounds.
769 * This is when items are dragged INTO our window.
771 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
773 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
775 Ecore_X_Event_Xdnd_Enter* enterEvent( (Ecore_X_Event_Xdnd_Enter*) event );
776 EventHandler* handler( (EventHandler*)data );
777 Ecore_X_Window window ( handler->mImpl->mWindow );
779 if ( enterEvent->win == window )
781 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
783 // Check whether the Drag & Drop detector has Drag & Drop behaviour enabled before we accept.
784 if ( dndDetector && dndDetector->IsEnabled() )
786 // Tell Ecore that we want to enable drop in the entire window.
787 Ecore_X_Rectangle rect;
789 ecore_x_window_geometry_get( window, NULL, NULL, (int*)&rect.width, (int*)&rect.height );
791 // Tell Ecore that we are able to process a drop.
792 ecore_x_dnd_send_status( EINA_TRUE, EINA_FALSE, rect, ECORE_X_ATOM_XDND_DROP );
794 // Register the required atoms and types.
795 ecore_x_dnd_actions_set( window, DRAG_AND_DROP_ATOMS, DRAG_AND_DROP_ATOMS_NUMBER );
796 ecore_x_dnd_types_set( window, DRAG_AND_DROP_TYPES, DRAG_AND_DROP_TYPES_NUMBER );
798 // Request to get the content from Ecore.
799 ecore_x_selection_xdnd_request( window, ECORE_X_SELECTION_TARGET_UTF8_STRING );
801 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndEnter: Requesting Drag & Drop\n" );
803 // Clear the previous content
804 dndDetector->ClearContent();
806 // Emit the entered signal
807 dndDetector->EmitEnteredSignal();
811 return ECORE_CALLBACK_PASS_ON;
815 * Called when a dragged item is moved within our window.
816 * This is when items are dragged INTO our window.
818 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
820 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
822 Ecore_X_Event_Xdnd_Position* positionEvent( (Ecore_X_Event_Xdnd_Position*) event );
823 EventHandler* handler( (EventHandler*)data );
825 if ( positionEvent->win == handler->mImpl->mWindow )
827 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
829 // If we have a detector then update its latest position.
832 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndPosition: position ( %d x %d )\n", positionEvent->position.x, positionEvent->position.y );
833 dndDetector->SetPosition( Vector2( positionEvent->position.x, positionEvent->position.y ));
834 dndDetector->EmitMovedSignal();
838 return ECORE_CALLBACK_PASS_ON;
842 * Called when a dragged item leaves our window's bounds.
843 * This is when items are dragged INTO our window.
845 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
847 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
849 Ecore_X_Event_Xdnd_Leave* leaveEvent( (Ecore_X_Event_Xdnd_Leave*) event );
850 EventHandler* handler( (EventHandler*)data );
852 if ( leaveEvent->win == handler->mImpl->mWindow )
854 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
856 // If we have a detector then clear its content and emit the exited-signal. Also tell Ecore that we have finished.
859 dndDetector->ClearContent();
860 dndDetector->EmitExitedSignal();
862 ecore_x_dnd_send_finished();
864 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndLeave: Finished\n" );
868 return ECORE_CALLBACK_PASS_ON;
872 * Called when the dragged item is dropped within our window's bounds.
873 * This is when items are dragged INTO our window.
875 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
877 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
879 Ecore_X_Event_Xdnd_Drop* dropEvent ( (Ecore_X_Event_Xdnd_Drop*) event);
880 EventHandler* handler( (EventHandler*)data );
882 if ( dropEvent->win == handler->mImpl->mWindow )
884 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
886 // Something has been dropped, inform the detector (if we have one) and tell Ecore that we have finished.
889 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: position ( %d x %d )\n", dropEvent->position.x, dropEvent->position.y );
891 dndDetector->SetPosition( Vector2( dropEvent->position.x, dropEvent->position.y ) );
892 dndDetector->EmitDroppedSignal();
893 ecore_x_dnd_send_finished();
895 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: Finished\n" );
899 return ECORE_CALLBACK_PASS_ON;
903 * Called when a dragged item is moved from our window and the target window has done processing it.
904 * This is when items are dragged FROM our window.
906 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
908 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
909 return ECORE_CALLBACK_PASS_ON;
913 * Called when a dragged item is moved from our window and the target window has sent us a status.
914 * This is when items are dragged FROM our window.
916 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
918 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
919 return ECORE_CALLBACK_PASS_ON;
923 * Called when the client messages (i.e. the accessibility events) are received.
925 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
927 #ifndef DALI_PROFILE_UBUNTU
928 Ecore_X_Event_Client_Message* clientMessageEvent( (Ecore_X_Event_Client_Message*)event );
929 EventHandler* handler( (EventHandler*)data );
931 if (clientMessageEvent->message_type == ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL)
933 if ( ( (unsigned int)clientMessageEvent->data.l[0] == handler->mImpl->mWindow ) && handler->mAccessibilityAdaptor )
935 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
937 if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_SCROLL)
939 // 2 finger touch & move, 2 finger flick
941 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
944 TouchPoint::State state(TouchPoint::Down);
946 if ((unsigned int)clientMessageEvent->data.l[2] == 0)
948 state = TouchPoint::Down; // mouse down
950 else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
952 state = TouchPoint::Motion; // mouse move
954 else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
956 state = TouchPoint::Up; // mouse up
960 state = TouchPoint::Interrupted; // error
963 DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
964 "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
965 (unsigned int)clientMessageEvent->data.l[2],
966 (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
968 // Send touch event to accessibility adaptor.
969 TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
971 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
972 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
974 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_MOUSE)
976 // 1 finger double tap and hold
978 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
981 TouchPoint::State state(TouchPoint::Down);
983 if ((unsigned int)clientMessageEvent->data.l[2] == 0)
985 state = TouchPoint::Down; // mouse down
987 else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
989 state = TouchPoint::Motion; // mouse move
991 else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
993 state = TouchPoint::Up; // mouse up
997 state = TouchPoint::Interrupted; // error
1000 DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1001 "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1002 (unsigned int)clientMessageEvent->data.l[2],
1003 (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1005 // Send touch event to accessibility adaptor.
1006 TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1008 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1009 accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1011 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_BACK)
1013 // 2 finger circle draw, do back
1014 accessibilityAdaptor->HandleActionBackEvent();
1016 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_NEXT)
1018 // one finger flick down
1019 // focus next object
1020 if(accessibilityAdaptor)
1022 accessibilityAdaptor->HandleActionNextEvent();
1025 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_PREV)
1027 // one finger flick up
1028 // focus previous object
1029 if(accessibilityAdaptor)
1031 accessibilityAdaptor->HandleActionPreviousEvent();
1034 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE)
1036 // one finger double tap
1037 // same as one finger tap in normal mode (i.e. execute focused actor)
1038 if(accessibilityAdaptor)
1040 accessibilityAdaptor->HandleActionActivateEvent();
1043 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ)
1046 // focus & read an actor at ( e->data.l[2], e->data.l[3] ) position according to finger
1047 if(accessibilityAdaptor)
1049 accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[2], (unsigned int)clientMessageEvent->data.l[3], true /* allow read again*/);
1052 #if defined(DALI_PROFILE_MOBILE)
1053 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_OVER)
1055 // one finger tap & move
1056 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1059 // focus & read an actor at (x, y) position according to finger
1060 if(accessibilityAdaptor && (unsigned int)clientMessageEvent->data.l[2] == 1 /*only work for move event*/)
1062 accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4], false /* not allow read again*/);
1066 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_NEXT)
1068 // one finger flick right
1069 // focus next object
1070 if(accessibilityAdaptor)
1072 accessibilityAdaptor->HandleActionReadNextEvent();
1075 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_PREV)
1077 // one finger flick left
1078 // focus previous object
1079 if(accessibilityAdaptor)
1081 accessibilityAdaptor->HandleActionReadPreviousEvent();
1084 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_UP)
1086 // double down and move (right, up)
1087 // change slider value
1088 if(accessibilityAdaptor)
1090 accessibilityAdaptor->HandleActionUpEvent();
1093 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DOWN)
1095 // double down and move (left, down)
1096 // change slider value
1097 if(accessibilityAdaptor)
1099 accessibilityAdaptor->HandleActionDownEvent();
1102 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ENABLE)
1104 if(accessibilityAdaptor)
1106 accessibilityAdaptor->HandleActionEnableEvent();
1109 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DISABLE)
1111 if(accessibilityAdaptor)
1113 accessibilityAdaptor->HandleActionDisableEvent();
1116 // TODO: some more actions could be added later
1119 else if(clientMessageEvent->message_type == ecore_x_atom_get(CLIPBOARD_ATOM))
1121 std::string message(clientMessageEvent->data.b);
1122 if( message == CLIPBOARD_SET_OWNER_MESSAGE)
1124 // Claim the ownership of the SECONDARY selection.
1125 ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1127 // Show the clipboard window
1128 Dali::Clipboard clipboard = Dali::Clipboard::Get();
1129 clipboard.ShowClipboard();
1132 else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_PREPARE )
1134 RotationEvent rotationEvent;
1135 rotationEvent.angle = static_cast<int>(clientMessageEvent->data.l[1]);
1136 rotationEvent.winResize = static_cast<int>(clientMessageEvent->data.l[2]);
1137 rotationEvent.width = static_cast<int>(clientMessageEvent->data.l[3]);
1138 rotationEvent.height = static_cast<int>(clientMessageEvent->data.l[4]);
1139 handler->SendRotationPrepareEvent( rotationEvent );
1141 else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_REQUEST )
1143 handler->SendRotationRequestEvent();
1146 #endif // DALI_PROFILE_UBUNTU
1147 return ECORE_CALLBACK_PASS_ON;
1151 /////////////////////////////////////////////////////////////////////////////////////////////////
1152 // ElDBus Accessibility Callbacks
1153 /////////////////////////////////////////////////////////////////////////////////////////////////
1155 #ifdef DALI_ELDBUS_AVAILABLE
1156 // Callback for Ecore ElDBus accessibility events.
1157 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
1159 EventHandler* handler = static_cast< EventHandler* >( context );
1160 // Ignore any accessibility events when paused.
1161 if( handler->mPaused )
1166 if ( !handler->mAccessibilityAdaptor )
1168 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
1172 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1173 if ( !accessibilityAdaptor )
1175 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
1179 const char *gestureName;
1183 // The string defines the arg-list's respective types.
1184 if( !eldbus_message_arguments_get( message, "siiiiu", &gestureName, &xS, &yS, &xE, &yE, &state ) )
1186 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1189 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %s Args: %d,%d,%d,%d State: %d\n", gestureName, xS, yS, xE, yE );
1191 unsigned int fingers = 0;
1192 char* stringPosition = ( char* )gestureName;
1194 // Check how many fingers the gesture uses.
1195 for( unsigned int i = 0; i < FingerCountStringsTotal; ++i )
1197 unsigned int matchLength = strlen( ElDBusAccessibilityFingerCountStrings[ i ] );
1198 if( strncmp( gestureName, ElDBusAccessibilityFingerCountStrings[ i ], matchLength ) == 0 )
1201 stringPosition += matchLength;
1208 // Error: invalid gesture.
1212 GestureType gestureType = GESTURE_TYPE_NONE;
1213 SubGestureType subGestureType = SUB_GESTURE_TYPE_NONE;
1214 GestureDirection direction = GESTURE_DIRECTION_NONE;
1216 // Check for full gesture type names first.
1217 for( unsigned int i = 0; i < FullEventTypeStringsTotal; ++i )
1219 unsigned int matchLength = strlen( ElDBusAccessibilityFullEventTypeStrings[ i ].name );
1220 if( strncmp( stringPosition, ElDBusAccessibilityFullEventTypeStrings[ i ].name, matchLength ) == 0 )
1222 gestureType = ElDBusAccessibilityFullEventTypeStrings[ i ].type;
1227 // If we didn't find a full gesture, check for sub gesture type names.
1228 if( gestureType == GESTURE_TYPE_NONE )
1230 // No full gesture name found, look for partial types.
1231 for( unsigned int i = 0; i < DirectionalEventTypeStringsTotal; ++i )
1233 unsigned int matchLength = strlen( ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name );
1234 if( strncmp( stringPosition, ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name, matchLength ) == 0 )
1236 subGestureType = ElDBusAccessibilityDirectionalEventTypeStrings[ i ].type;
1237 stringPosition += matchLength;
1242 if( subGestureType == SUB_GESTURE_TYPE_NONE )
1244 // ERROR: Gesture not recognised.
1248 // If the gesture was a sub type, get it's respective direction.
1249 for( unsigned int i = 0; i < DirectionStringsTotal; ++i )
1251 unsigned int matchLength = strlen( ElDBusAccessibilityDirectionStrings[ i ].name );
1252 if( strncmp( stringPosition, ElDBusAccessibilityDirectionStrings[ i ].name, matchLength ) == 0 )
1254 direction = ElDBusAccessibilityDirectionStrings[ i ].direction;
1255 stringPosition += matchLength;
1260 if( direction == GESTURE_DIRECTION_NONE )
1262 // ERROR: Gesture not recognised.
1267 // Action the detected gesture here.
1268 if( gestureType != GESTURE_TYPE_NONE )
1270 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d Gesture type: %d\n", fingers, gestureType );
1274 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d Gesture sub type: %d Gesture direction: %d\n",
1275 fingers, subGestureType, direction );
1278 // Create a touch point object.
1279 TouchPoint::State touchPointState( TouchPoint::Down );
1282 touchPointState = TouchPoint::Down; // Mouse down.
1284 else if ( state == 1 )
1286 touchPointState = TouchPoint::Motion; // Mouse move.
1288 else if ( state == 2 )
1290 touchPointState = TouchPoint::Up; // Mouse up.
1294 touchPointState = TouchPoint::Interrupted; // Error.
1297 // Send touch event to accessibility adaptor.
1298 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1300 // Perform actions based on received gestures.
1301 // Note: This is seperated from the reading so we can (in future)
1302 // have other input readers without changing the below code.
1307 if( gestureType == GESTURE_TYPE_SINGLE_TAP || ( gestureType == GESTURE_TYPE_HOVER && touchPointState == TouchPoint::Motion ) )
1310 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1312 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1314 if( false ) // TODO: how to detect double tap + hold?
1316 // Move or drag icon / view more options for selected items.
1317 // accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1321 // Activate selected item / active edit mode.
1322 accessibilityAdaptor->HandleActionActivateEvent();
1325 else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1328 accessibilityAdaptor->HandleActionZoomEvent();
1330 else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1332 if( direction == GESTURE_DIRECTION_LEFT )
1334 // Move to previous item.
1335 accessibilityAdaptor->HandleActionReadPreviousEvent();
1337 else if( direction == GESTURE_DIRECTION_RIGHT )
1339 // Move to next item.
1340 accessibilityAdaptor->HandleActionReadNextEvent();
1342 else if( direction == GESTURE_DIRECTION_UP )
1344 // Move to next item.
1345 accessibilityAdaptor->HandleActionPreviousEvent();
1347 else if( direction == GESTURE_DIRECTION_DOWN )
1349 // Move to next item.
1350 accessibilityAdaptor->HandleActionNextEvent();
1352 else if( direction == GESTURE_DIRECTION_LEFT_RETURN )
1354 // Scroll up to the previous page
1355 accessibilityAdaptor->HandleActionPageUpEvent();
1357 else if( direction == GESTURE_DIRECTION_RIGHT_RETURN )
1359 // Scroll down to the next page
1360 accessibilityAdaptor->HandleActionPageDownEvent();
1362 else if( direction == GESTURE_DIRECTION_UP_RETURN )
1364 // Move to the first item on screen
1365 accessibilityAdaptor->HandleActionMoveToFirstEvent();
1367 else if( direction == GESTURE_DIRECTION_DOWN_RETURN )
1369 // Move to the last item on screen
1370 accessibilityAdaptor->HandleActionMoveToLastEvent();
1378 if( gestureType == GESTURE_TYPE_HOVER )
1380 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1381 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1383 else if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1385 // Pause/Resume current speech
1386 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1388 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1390 // Start/Stop current action
1391 accessibilityAdaptor->HandleActionStartStopEvent();
1393 else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1395 // Read information from indicator
1396 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1398 else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1400 if( direction == GESTURE_DIRECTION_LEFT )
1402 // Scroll left to the previous page
1403 accessibilityAdaptor->HandleActionPageLeftEvent();
1405 else if( direction == GESTURE_DIRECTION_RIGHT )
1407 // Scroll right to the next page
1408 accessibilityAdaptor->HandleActionPageRightEvent();
1410 else if( direction == GESTURE_DIRECTION_UP )
1412 // Scroll up the list.
1413 accessibilityAdaptor->HandleActionScrollUpEvent();
1415 else if( direction == GESTURE_DIRECTION_DOWN )
1417 // Scroll down the list.
1418 accessibilityAdaptor->HandleActionScrollDownEvent();
1426 if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1428 // Read from top item on screen continuously.
1429 accessibilityAdaptor->HandleActionReadFromTopEvent();
1431 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1433 // Read from next item continuously.
1434 accessibilityAdaptor->HandleActionReadFromNextEvent();
1441 // Callback for to set up Ecore ElDBus for accessibility callbacks.
1442 static void EcoreElDBusInitialisation( void *handle, const Eldbus_Message *message, Eldbus_Pending *pending EINA_UNUSED )
1444 Eldbus_Object *object;
1445 Eldbus_Proxy *manager;
1446 const char *a11yBusAddress = NULL;
1447 EventHandler* handler = static_cast< EventHandler* >( handle );
1449 // The string defines the arg-list's respective types.
1450 if( !eldbus_message_arguments_get( message, "s", &a11yBusAddress ) )
1452 DALI_LOG_ERROR( "EcoreElDBusInitialisation: Error getting arguments\n" );
1455 DALI_LOG_INFO( gImfLogging, Debug::General, "Ecore ElDBus Accessibility address: %s\n", a11yBusAddress );
1457 handler->mImpl->mA11yConnection = eldbus_address_connection_get( a11yBusAddress );
1459 object = eldbus_object_get( handler->mImpl->mA11yConnection, BUS, PATH );
1460 manager = eldbus_proxy_get( object, INTERFACE );
1462 // Pass the callback data through to the signal handler.
1463 eldbus_proxy_signal_handler_add( manager, SIGNAL, OnEcoreElDBusAccessibilityNotification, handle );
1465 #endif // DALI_ELDBUS_AVAILABLE
1468 * Called when the source window notifies us the content in clipboard is selected.
1470 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1472 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1473 Ecore_X_Event_Selection_Clear* selectionClearEvent( (Ecore_X_Event_Selection_Clear*) event );
1474 EventHandler* handler( (EventHandler*)data );
1476 if ( selectionClearEvent->win == handler->mImpl->mWindow )
1478 if ( selectionClearEvent->selection == ECORE_X_SELECTION_SECONDARY )
1480 // Request to get the content from Ecore.
1481 ecore_x_selection_secondary_request(selectionClearEvent->win, ECORE_X_SELECTION_TARGET_TEXT);
1484 return ECORE_CALLBACK_PASS_ON;
1488 * Called when the source window sends us about the selected content.
1489 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1491 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1493 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1495 Ecore_X_Event_Selection_Notify* selectionNotifyEvent( (Ecore_X_Event_Selection_Notify*) event );
1496 EventHandler* handler( (EventHandler*)data );
1498 if ( selectionNotifyEvent->win == handler->mImpl->mWindow )
1500 Ecore_X_Selection_Data* selectionData( (Ecore_X_Selection_Data*) selectionNotifyEvent->data );
1501 if ( selectionData->data )
1503 if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_XDND )
1505 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
1507 // We have got the content that is to be dropped, inform the DndListener (if we have one).
1510 std::string content( (char*) selectionData->data, selectionData->length );
1511 dndDetector->SetContent( content );
1513 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1514 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1515 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1516 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1519 else if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_SECONDARY )
1521 // We have got the selected content, inform the clipboard event listener (if we have one).
1522 if ( handler->mClipboardEventNotifier )
1524 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1525 std::string content( (char*) selectionData->data, selectionData->length );
1526 clipboardEventNotifier.SetContent( content );
1527 clipboardEventNotifier.EmitContentSelectedSignal();
1530 // Claim the ownership of the SECONDARY selection.
1531 ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1533 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1534 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1535 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1536 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1540 return ECORE_CALLBACK_PASS_ON;
1544 #ifndef DALI_PROFILE_UBUNTU
1545 /////////////////////////////////////////////////////////////////////////////////////////////////
1547 /////////////////////////////////////////////////////////////////////////////////////////////////
1549 * Called when a font name is changed.
1551 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1553 EventHandler* handler = static_cast<EventHandler*>( data );
1554 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1558 * Called when a font size is changed.
1560 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1562 DALI_LOG_INFO(gTouchEventLogFilter, Debug::Verbose, "VconfNotifyFontSizeChanged\n" );
1563 EventHandler* handler = static_cast<EventHandler*>( data );
1564 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1566 #endif // DALI_PROFILE_UBUNTU
1569 EventHandler* mHandler;
1570 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1571 Ecore_X_Window mWindow;
1574 #ifdef DALI_ELDBUS_AVAILABLE
1575 Eldbus_Connection* mSessionConnection;
1576 Eldbus_Connection* mA11yConnection;
1580 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1581 : mCoreEventInterface( coreEventInterface ),
1582 mGestureManager( gestureManager ),
1583 mStyleMonitor( StyleMonitor::Get() ),
1584 mDamageObserver( damageObserver ),
1585 mRotationObserver( NULL ),
1586 mDragAndDropDetector( dndDetector ),
1587 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1588 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1589 mClipboard( Clipboard::Get() ),
1593 Ecore_X_Window window = 0;
1595 // this code only works with the WindowRenderSurface so need to downcast
1596 WindowRenderSurfaceEcoreX* ecoreSurface = static_cast< WindowRenderSurfaceEcoreX* >( surface );
1599 // enable multi touch
1600 window = ecoreSurface->GetXWindow();
1603 mImpl = new Impl(this, window);
1606 EventHandler::~EventHandler()
1610 mGestureManager.Stop();
1613 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1617 timeStamp = GetCurrentMilliSeconds();
1620 Integration::TouchEvent touchEvent;
1621 Integration::HoverEvent hoverEvent;
1622 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1623 if(type != Integration::TouchEventCombiner::DispatchNone )
1625 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);
1627 // First the touch and/or hover event & related gesture events are queued
1628 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1630 mCoreEventInterface.QueueCoreEvent( touchEvent );
1631 mGestureManager.SendEvent(touchEvent);
1634 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1636 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1639 // Next the events are processed with a single call into Core
1640 mCoreEventInterface.ProcessCoreEvents();
1644 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1646 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1647 if ( physicalKeyboard )
1649 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1651 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1655 // Send to KeyEvent Core.
1656 mCoreEventInterface.QueueCoreEvent( keyEvent );
1657 mCoreEventInterface.ProcessCoreEvents();
1660 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1662 // Create WheelEvent and send to Core.
1663 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1664 mCoreEventInterface.QueueCoreEvent( event );
1665 mCoreEventInterface.ProcessCoreEvents();
1668 void EventHandler::SendEvent( StyleChange::Type styleChange )
1670 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1671 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1674 void EventHandler::SendEvent( const DamageArea& area )
1676 mDamageObserver.OnDamaged( area );
1679 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1681 if( mRotationObserver != NULL )
1683 mRotationObserver->OnRotationPrepare( event );
1687 void EventHandler::SendRotationRequestEvent( )
1689 if( mRotationObserver != NULL )
1691 mRotationObserver->OnRotationRequest( );
1695 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1697 Integration::Point convertedPoint( point );
1699 SendEvent(convertedPoint, timeStamp);
1702 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1704 SendWheelEvent( wheelEvent );
1707 void EventHandler::FeedKeyEvent( KeyEvent& event )
1709 Integration::KeyEvent convertedEvent( event );
1710 SendEvent( convertedEvent );
1713 void EventHandler::FeedEvent( Integration::Event& event )
1715 mCoreEventInterface.QueueCoreEvent( event );
1716 mCoreEventInterface.ProcessCoreEvents();
1719 void EventHandler::Reset()
1723 // Any touch listeners should be told of the interruption.
1724 Integration::TouchEvent event;
1725 Integration::Point point;
1726 point.SetState( PointState::INTERRUPTED );
1727 event.AddPoint( point );
1729 // First the touch event & related gesture events are queued
1730 mCoreEventInterface.QueueCoreEvent( event );
1731 mGestureManager.SendEvent( event );
1733 // Next the events are processed with a single call into Core
1734 mCoreEventInterface.ProcessCoreEvents();
1737 void EventHandler::Pause()
1743 void EventHandler::Resume()
1749 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1751 mDragAndDropDetector = detector;
1754 void EventHandler::SetRotationObserver( RotationObserver* observer )
1756 mRotationObserver = observer;
1759 } // namespace Adaptor
1761 } // namespace Internal
1765 #pragma GCC diagnostic pop