2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <events/event-handler.h>
22 // Ecore is littered with C style cast
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wold-style-cast"
26 #include <Ecore_Input.h>
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>
55 #include <dali/devel-api/events/key-event-devel.h>
58 #include <events/gesture-manager.h>
59 #include <window-render-surface.h>
60 #include <clipboard-impl.h>
62 #include <physical-keyboard-impl.h>
63 #include <style-monitor-impl.h>
64 #include <base/core-event-interface.h>
75 #if defined(DEBUG_ENABLED)
78 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
79 Integration::Log::Filter* gClientMessageLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_CLIENT_MESSAGE");
80 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
81 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
82 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
83 } // unnamed namespace
90 const char * DETENT_DEVICE_NAME = "tizen_detent";
91 const std::string DEFAULT_DEVICE_NAME = "";
92 const DevelKeyEvent::DeviceClass::Type DEFAULT_DEVICE_CLASS = DevelKeyEvent::DeviceClass::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
210 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
211 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
212 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
213 * @return the Ecore_IMF_Keyboard_Modifiers output.
215 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
217 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
220 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
222 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
225 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
227 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
230 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
232 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
235 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
237 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
240 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
242 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
245 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
249 // Copied from x server
250 static unsigned int GetCurrentMilliSeconds(void)
255 static clockid_t clockid;
259 #ifdef CLOCK_MONOTONIC_COARSE
260 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
261 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
263 clockid = CLOCK_MONOTONIC_COARSE;
267 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
269 clockid = CLOCK_MONOTONIC;
276 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
278 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
281 gettimeofday(&tv, NULL);
282 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
285 } // unnamed namespace
287 // Impl to hide EFL implementation.
288 struct EventHandler::Impl
290 // Construction & Destruction
295 Impl( EventHandler* handler, Ecore_X_Window window )
296 : mHandler( handler ),
297 mEcoreEventHandler(),
300 #ifdef DALI_ELDBUS_AVAILABLE
301 , mSessionConnection( NULL ),
302 mA11yConnection( NULL )
305 // Only register for touch and key events if we have a window
308 // Register Touch events
309 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
310 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
311 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
312 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
314 // Register Mouse wheel events
315 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
317 // Register Key events
318 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
319 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
321 // Register Focus events
322 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
323 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
325 // Register Window damage events
326 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_DAMAGE, EcoreEventWindowDamaged, handler ) );
328 // Enable Drag & Drop and register DnD events
329 ecore_x_dnd_aware_set( window, EINA_TRUE );
330 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_ENTER, EcoreEventDndEnter, handler) );
331 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_POSITION, EcoreEventDndPosition, handler) );
332 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_LEAVE, EcoreEventDndLeave, handler) );
333 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_DROP, EcoreEventDndDrop, handler) );
334 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_FINISHED, EcoreEventDndFinished, handler) );
335 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_STATUS, EcoreEventDndStatus, handler) );
337 // Register Client message events - accessibility etc.
338 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_CLIENT_MESSAGE, EcoreEventClientMessage, handler ) );
340 // Register Selection event - clipboard selection, Drag & Drop selection etc.
341 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_CLEAR, EcoreEventSelectionClear, handler ) );
342 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_NOTIFY, EcoreEventSelectionNotify, handler ) );
344 // Initialize Xi2 system
345 Display* display = static_cast< Display* >(ecore_x_display_get());
346 Ecore_X_Window rootWindow = ecore_x_window_root_first_get();
347 int opcode = 0, event = 0, error = 0;
348 int major = XI_2_Major;
349 int minor = XI_2_Minor;
351 XIEventMask xiEventMask;
353 // Check if X input extension available
354 if( XQueryExtension( display, "XInputExtension", &opcode, &event, &error ) )
356 // We support version 2.0
357 if( XIQueryVersion( display, &major, &minor ) != BadRequest )
359 xiEventMask.deviceid = XIAllDevices;
363 XIDeviceInfo* deviceInfo = NULL;
364 deviceInfo = XIQueryDevice( display, XIAllDevices, &deviceCount );
366 for( int i = 0; i < deviceCount; i++ )
368 if( !strncmp( deviceInfo[i].name, DETENT_DEVICE_NAME, strlen( DETENT_DEVICE_NAME ) ) )
370 xiEventMask.deviceid = deviceInfo[i].deviceid;
378 mXiDeviceId = xiEventMask.deviceid;
381 Dali::Vector< unsigned char > mask;
382 std::size_t xiMaskLen = XIMaskLen( XI_LASTEVENT );
383 mask.Reserve( xiMaskLen );
384 xiEventMask.mask = mask.Begin();
386 XISetMask( xiEventMask.mask, XI_RawMotion );
388 xiEventMask.mask_len = xiMaskLen * sizeof( unsigned char );
390 int ret = XISelectEvents( display, rootWindow, &xiEventMask, 1 );
393 // Register custom wheel events
394 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_GENERIC, EcoreEventCustomWheel, handler ) );
398 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to Select Events\n" );
402 if( deviceInfo != NULL )
404 XIFreeDeviceInfo( deviceInfo );
409 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XI Version\n" );
414 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XInputExtension\n" );
417 #ifndef DALI_PROFILE_UBUNTU
418 // Register Vconf notify - font name, font size and style
419 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, handler );
420 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
421 #endif // DALI_PROFILE_UBUNTU
423 #ifdef DALI_ELDBUS_AVAILABLE
425 // Initialize ElDBus.
426 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
429 mSessionConnection = eldbus_connection_get( ELDBUS_CONNECTION_TYPE_SESSION );
431 Eldbus_Object *a11yObject = eldbus_object_get( mSessionConnection, A11Y_BUS, A11Y_PATH );
432 Eldbus_Proxy *elDBusManager = eldbus_proxy_get( a11yObject, A11Y_INTERFACE );
434 // Pass in handler in the cb_data field so we can access the accessibility adaptor within the callback.
435 eldbus_proxy_call( elDBusManager, A11Y_GET_ADDRESS, EcoreElDBusInitialisation, handler, -1, "" );
437 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
439 #endif // DALI_ELDBUS_AVAILABLE
448 #ifndef DALI_PROFILE_UBUNTU
449 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
450 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged );
451 #endif // DALI_PROFILE_UBUNTU
453 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
455 ecore_event_handler_del( *iter );
458 #ifdef DALI_ELDBUS_AVAILABLE
460 if( mA11yConnection )
462 eldbus_connection_unref( mA11yConnection );
465 if( mSessionConnection )
467 eldbus_connection_unref( mSessionConnection );
471 #endif // DALI_ELDBUS_AVAILABLE
476 /////////////////////////////////////////////////////////////////////////////////////////////////
478 /////////////////////////////////////////////////////////////////////////////////////////////////
481 * Called when a touch down is received.
483 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
485 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
486 EventHandler* handler( (EventHandler*)data );
488 if ( touchEvent->window == handler->mImpl->mWindow )
490 PointState::Type state ( PointState::DOWN );
492 // Check if the buttons field is set and ensure it's the primary touch button.
493 // If this event was triggered by buttons other than the primary button (used for touch), then
494 // just send an interrupted event to Core.
495 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
497 state = PointState::INTERRUPTED;
500 Integration::Point point;
501 point.SetDeviceId( touchEvent->multi.device );
502 point.SetState( state );
503 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
504 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
505 point.SetPressure( touchEvent->multi.pressure );
506 point.SetAngle( Degree( touchEvent->multi.angle ) );
507 handler->SendEvent( point, touchEvent->timestamp );
510 return ECORE_CALLBACK_PASS_ON;
514 * Called when a touch up is received.
516 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
518 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
519 EventHandler* handler( (EventHandler*)data );
521 if ( touchEvent->window == handler->mImpl->mWindow )
523 Integration::Point point;
524 point.SetDeviceId( touchEvent->multi.device );
525 point.SetState( PointState::UP );
526 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
527 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
528 point.SetPressure( touchEvent->multi.pressure );
529 point.SetAngle( Degree( touchEvent->multi.angle ) );
530 handler->SendEvent( point, touchEvent->timestamp );
533 return ECORE_CALLBACK_PASS_ON;
537 * Called when a touch motion is received.
539 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
541 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
542 EventHandler* handler( (EventHandler*)data );
544 if ( touchEvent->window == handler->mImpl->mWindow )
546 Integration::Point point;
547 point.SetDeviceId( touchEvent->multi.device );
548 point.SetState( PointState::MOTION );
549 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
550 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
551 point.SetPressure( touchEvent->multi.pressure );
552 point.SetAngle( Degree( touchEvent->multi.angle ) );
553 handler->SendEvent( point, touchEvent->timestamp );
556 return ECORE_CALLBACK_PASS_ON;
559 /////////////////////////////////////////////////////////////////////////////////////////////////
561 /////////////////////////////////////////////////////////////////////////////////////////////////
564 * Called when a mouse wheel is received.
566 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
568 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
570 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 );
572 EventHandler* handler( (EventHandler*)data );
573 if ( mouseWheelEvent->window == handler->mImpl->mWindow )
575 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
576 handler->SendWheelEvent( wheelEvent );
578 return ECORE_CALLBACK_PASS_ON;
582 * Called when a custom wheel is received.
584 static Eina_Bool EcoreEventCustomWheel( void* data, int type, void* event )
586 Ecore_X_Event_Generic *genericEvent( (Ecore_X_Event_Generic*)event );
587 EventHandler* handler( (EventHandler*)data );
589 switch( genericEvent->evtype )
593 XIRawEvent* xiRawEvent = static_cast< XIRawEvent* >( genericEvent->data );
594 unsigned int timeStamp = 0;
596 if( xiRawEvent->deviceid != handler->mImpl->mXiDeviceId )
598 return ECORE_CALLBACK_PASS_ON;
601 // X(0): rotate: NOT USED
605 double* value = xiRawEvent->raw_values;
607 if( XIMaskIsSet( xiRawEvent->valuators.mask, 1) )
609 timeStamp = static_cast< unsigned int >( *(value + 1) );
612 if( XIMaskIsSet( xiRawEvent->valuators.mask, 2) )
614 // if z == 1, clockwise
615 // otherwise counter-clockwise
616 int z = static_cast< int >( *(value + 2) );
618 // In DALi, positive value means clockwise, and negative value means counter-clockwise
624 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventCustomWheel: z: %d\n", z );
626 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), z, timeStamp );
627 handler->SendWheelEvent( wheelEvent );
637 return ECORE_CALLBACK_PASS_ON;
640 /////////////////////////////////////////////////////////////////////////////////////////////////
642 /////////////////////////////////////////////////////////////////////////////////////////////////
645 * Called when a key down is received.
647 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
649 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
651 EventHandler* handler( (EventHandler*)data );
652 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
653 bool eventHandled( false );
655 // If a device key then skip ecore_imf_context_filter_event.
656 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
658 Ecore_IMF_Context* imfContext = NULL;
659 Dali::ImfManager imfManager( ImfManager::Get() );
662 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
667 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
668 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
669 ecoreKeyDownEvent.keyname = keyEvent->keyname;
670 ecoreKeyDownEvent.key = keyEvent->key;
671 ecoreKeyDownEvent.string = keyEvent->string;
672 ecoreKeyDownEvent.compose = keyEvent->compose;
673 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
674 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
675 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
676 #ifdef ECORE_IMF_1_13
677 ecoreKeyDownEvent.dev_name = "";
678 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
679 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
680 #endif // ECORE_IMF_1_13
682 eventHandled = ecore_imf_context_filter_event( imfContext,
683 ECORE_IMF_EVENT_KEY_DOWN,
684 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
686 // If the event has not been handled by IMF then check if we should reset our IMF context
689 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
690 !strcmp( keyEvent->keyname, "Return" ) ||
691 !strcmp( keyEvent->keyname, "KP_Enter" ) )
693 ecore_imf_context_reset( imfContext );
699 // If the event wasn't handled then we should send a key event.
702 if ( keyEvent->window == handler->mImpl->mWindow )
704 std::string keyName( keyEvent->keyname );
705 std::string keyString( "" );
706 int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
707 int modifier( keyEvent->modifiers );
708 unsigned long time = keyEvent->timestamp;
710 // Ensure key event string is not NULL as keys like SHIFT have a null string.
711 if ( keyEvent->string )
713 keyString = keyEvent->string;
716 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_CLASS );
717 handler->SendEvent( keyEvent );
721 return ECORE_CALLBACK_PASS_ON;
725 * Called when a key up is received.
727 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
729 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp \n" );
731 EventHandler* handler( (EventHandler*)data );
732 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
733 bool eventHandled( false );
735 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
736 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
738 Ecore_IMF_Context* imfContext = NULL;
739 Dali::ImfManager imfManager( ImfManager::Get() );
742 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
747 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
748 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
749 ecoreKeyUpEvent.keyname = keyEvent->keyname;
750 ecoreKeyUpEvent.key = keyEvent->key;
751 ecoreKeyUpEvent.string = keyEvent->string;
752 ecoreKeyUpEvent.compose = keyEvent->compose;
753 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
754 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
755 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
756 #ifdef ECORE_IMF_1_13
757 ecoreKeyUpEvent.dev_name = "";
758 #endif // ECORE_IMF_1_13
760 eventHandled = ecore_imf_context_filter_event( imfContext,
761 ECORE_IMF_EVENT_KEY_UP,
762 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
766 // If the event wasn't handled then we should send a key event.
769 if ( keyEvent->window == handler->mImpl->mWindow )
771 std::string keyName( keyEvent->keyname );
772 std::string keyString( "" );
773 int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
774 int modifier( keyEvent->modifiers );
775 unsigned long time( keyEvent->timestamp );
777 // Ensure key event string is not NULL as keys like SHIFT have a null string.
778 if ( keyEvent->string )
780 keyString = keyEvent->string;
783 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_CLASS );
785 handler->SendEvent( keyEvent );
789 return ECORE_CALLBACK_PASS_ON;
792 /////////////////////////////////////////////////////////////////////////////////////////////////
794 /////////////////////////////////////////////////////////////////////////////////////////////////
797 * Called when the window gains focus.
799 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
801 Ecore_X_Event_Window_Focus_In* focusInEvent( (Ecore_X_Event_Window_Focus_In*)event );
802 EventHandler* handler( (EventHandler*)data );
804 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
806 // If the window gains focus and we hid the keyboard then show it again.
807 if ( focusInEvent->win == handler->mImpl->mWindow )
809 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
811 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
813 Dali::ImfManager imfManager( ImfManager::Get() );
816 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
817 if( imfManagerImpl.RestoreAfterFocusLost() )
819 imfManagerImpl.Activate();
823 // No need to connect callbacks as KeyboardStatusChanged will be called.
826 return ECORE_CALLBACK_PASS_ON;
830 * Called when the window loses focus.
832 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
834 Ecore_X_Event_Window_Focus_Out* focusOutEvent( (Ecore_X_Event_Window_Focus_Out*)event );
835 EventHandler* handler( (EventHandler*)data );
837 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
839 // If the window loses focus then hide the keyboard.
840 if ( focusOutEvent->win == handler->mImpl->mWindow )
842 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
844 Dali::ImfManager imfManager( ImfManager::Get() );
847 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
848 if( imfManagerImpl.RestoreAfterFocusLost() )
850 imfManagerImpl.Deactivate();
855 // Clipboard don't support that whether clipboard is shown or not. Hide clipboard.
856 Dali::Clipboard clipboard = Clipboard::Get();
857 clipboard.HideClipboard();
860 return ECORE_CALLBACK_PASS_ON;
864 * Called when the window is damaged.
866 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
868 Ecore_X_Event_Window_Damage* windowDamagedEvent( (Ecore_X_Event_Window_Damage*)event );
869 EventHandler* handler( (EventHandler*)data );
871 if( windowDamagedEvent->win == handler->mImpl->mWindow )
874 area.x = windowDamagedEvent->x;
875 area.y = windowDamagedEvent->y;
876 area.width = windowDamagedEvent->w;
877 area.height = windowDamagedEvent->h;
879 handler->SendEvent( area );
882 return ECORE_CALLBACK_PASS_ON;
886 * Called when the window properties are changed.
887 * We are only interested in the font change.
891 /////////////////////////////////////////////////////////////////////////////////////////////////
892 // Drag & Drop Callbacks
893 /////////////////////////////////////////////////////////////////////////////////////////////////
896 * Called when a dragged item enters our window's bounds.
897 * This is when items are dragged INTO our window.
899 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
901 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
903 Ecore_X_Event_Xdnd_Enter* enterEvent( (Ecore_X_Event_Xdnd_Enter*) event );
904 EventHandler* handler( (EventHandler*)data );
905 Ecore_X_Window window ( handler->mImpl->mWindow );
907 if ( enterEvent->win == window )
909 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
911 // Check whether the Drag & Drop detector has Drag & Drop behaviour enabled before we accept.
912 if ( dndDetector && dndDetector->IsEnabled() )
914 // Tell Ecore that we want to enable drop in the entire window.
915 Ecore_X_Rectangle rect;
917 ecore_x_window_geometry_get( window, NULL, NULL, (int*)&rect.width, (int*)&rect.height );
919 // Tell Ecore that we are able to process a drop.
920 ecore_x_dnd_send_status( EINA_TRUE, EINA_FALSE, rect, ECORE_X_ATOM_XDND_DROP );
922 // Register the required atoms and types.
923 ecore_x_dnd_actions_set( window, DRAG_AND_DROP_ATOMS, DRAG_AND_DROP_ATOMS_NUMBER );
924 ecore_x_dnd_types_set( window, DRAG_AND_DROP_TYPES, DRAG_AND_DROP_TYPES_NUMBER );
926 // Request to get the content from Ecore.
927 ecore_x_selection_xdnd_request( window, ECORE_X_SELECTION_TARGET_UTF8_STRING );
929 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndEnter: Requesting Drag & Drop\n" );
931 // Clear the previous content
932 dndDetector->ClearContent();
934 // Emit the entered signal
935 dndDetector->EmitEnteredSignal();
939 return ECORE_CALLBACK_PASS_ON;
943 * Called when a dragged item is moved within our window.
944 * This is when items are dragged INTO our window.
946 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
948 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
950 Ecore_X_Event_Xdnd_Position* positionEvent( (Ecore_X_Event_Xdnd_Position*) event );
951 EventHandler* handler( (EventHandler*)data );
953 if ( positionEvent->win == handler->mImpl->mWindow )
955 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
957 // If we have a detector then update its latest position.
960 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndPosition: position ( %d x %d )\n", positionEvent->position.x, positionEvent->position.y );
961 dndDetector->SetPosition( Vector2( positionEvent->position.x, positionEvent->position.y ));
962 dndDetector->EmitMovedSignal();
966 return ECORE_CALLBACK_PASS_ON;
970 * Called when a dragged item leaves our window's bounds.
971 * This is when items are dragged INTO our window.
973 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
975 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
977 Ecore_X_Event_Xdnd_Leave* leaveEvent( (Ecore_X_Event_Xdnd_Leave*) event );
978 EventHandler* handler( (EventHandler*)data );
980 if ( leaveEvent->win == handler->mImpl->mWindow )
982 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
984 // If we have a detector then clear its content and emit the exited-signal. Also tell Ecore that we have finished.
987 dndDetector->ClearContent();
988 dndDetector->EmitExitedSignal();
990 ecore_x_dnd_send_finished();
992 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndLeave: Finished\n" );
996 return ECORE_CALLBACK_PASS_ON;
1000 * Called when the dragged item is dropped within our window's bounds.
1001 * This is when items are dragged INTO our window.
1003 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
1005 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
1007 Ecore_X_Event_Xdnd_Drop* dropEvent ( (Ecore_X_Event_Xdnd_Drop*) event);
1008 EventHandler* handler( (EventHandler*)data );
1010 if ( dropEvent->win == handler->mImpl->mWindow )
1012 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
1014 // Something has been dropped, inform the detector (if we have one) and tell Ecore that we have finished.
1017 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: position ( %d x %d )\n", dropEvent->position.x, dropEvent->position.y );
1019 dndDetector->SetPosition( Vector2( dropEvent->position.x, dropEvent->position.y ) );
1020 dndDetector->EmitDroppedSignal();
1021 ecore_x_dnd_send_finished();
1023 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: Finished\n" );
1027 return ECORE_CALLBACK_PASS_ON;
1031 * Called when a dragged item is moved from our window and the target window has done processing it.
1032 * This is when items are dragged FROM our window.
1034 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
1036 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
1037 return ECORE_CALLBACK_PASS_ON;
1041 * Called when a dragged item is moved from our window and the target window has sent us a status.
1042 * This is when items are dragged FROM our window.
1044 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
1046 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
1047 return ECORE_CALLBACK_PASS_ON;
1051 * Called when the client messages (i.e. the accessibility events) are received.
1053 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
1055 #ifndef DALI_PROFILE_UBUNTU
1056 Ecore_X_Event_Client_Message* clientMessageEvent( (Ecore_X_Event_Client_Message*)event );
1057 EventHandler* handler( (EventHandler*)data );
1059 if (clientMessageEvent->message_type == ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL)
1061 if ( ( (unsigned int)clientMessageEvent->data.l[0] == handler->mImpl->mWindow ) && handler->mAccessibilityAdaptor )
1063 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1065 if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_SCROLL)
1067 // 2 finger touch & move, 2 finger flick
1069 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1072 TouchPoint::State state(TouchPoint::Down);
1074 if ((unsigned int)clientMessageEvent->data.l[2] == 0)
1076 state = TouchPoint::Down; // mouse down
1078 else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
1080 state = TouchPoint::Motion; // mouse move
1082 else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
1084 state = TouchPoint::Up; // mouse up
1088 state = TouchPoint::Interrupted; // error
1091 DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1092 "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1093 (unsigned int)clientMessageEvent->data.l[2],
1094 (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1096 // Send touch event to accessibility adaptor.
1097 TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1099 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1100 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1102 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_MOUSE)
1104 // 1 finger double tap and hold
1106 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1109 TouchPoint::State state(TouchPoint::Down);
1111 if ((unsigned int)clientMessageEvent->data.l[2] == 0)
1113 state = TouchPoint::Down; // mouse down
1115 else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
1117 state = TouchPoint::Motion; // mouse move
1119 else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
1121 state = TouchPoint::Up; // mouse up
1125 state = TouchPoint::Interrupted; // error
1128 DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1129 "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1130 (unsigned int)clientMessageEvent->data.l[2],
1131 (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1133 // Send touch event to accessibility adaptor.
1134 TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1136 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1137 accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1139 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_BACK)
1141 // 2 finger circle draw, do back
1142 accessibilityAdaptor->HandleActionBackEvent();
1144 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_NEXT)
1146 // one finger flick down
1147 // focus next object
1148 if(accessibilityAdaptor)
1150 accessibilityAdaptor->HandleActionNextEvent();
1153 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_PREV)
1155 // one finger flick up
1156 // focus previous object
1157 if(accessibilityAdaptor)
1159 accessibilityAdaptor->HandleActionPreviousEvent();
1162 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE)
1164 // one finger double tap
1165 // same as one finger tap in normal mode (i.e. execute focused actor)
1166 if(accessibilityAdaptor)
1168 accessibilityAdaptor->HandleActionActivateEvent();
1171 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ)
1174 // focus & read an actor at ( e->data.l[2], e->data.l[3] ) position according to finger
1175 if(accessibilityAdaptor)
1177 accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[2], (unsigned int)clientMessageEvent->data.l[3], true /* allow read again*/);
1180 #if defined(DALI_PROFILE_MOBILE)
1181 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_OVER)
1183 // one finger tap & move
1184 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1187 // focus & read an actor at (x, y) position according to finger
1188 if(accessibilityAdaptor && (unsigned int)clientMessageEvent->data.l[2] == 1 /*only work for move event*/)
1190 accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4], false /* not allow read again*/);
1194 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_NEXT)
1196 // one finger flick right
1197 // focus next object
1198 if(accessibilityAdaptor)
1200 accessibilityAdaptor->HandleActionReadNextEvent();
1203 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_PREV)
1205 // one finger flick left
1206 // focus previous object
1207 if(accessibilityAdaptor)
1209 accessibilityAdaptor->HandleActionReadPreviousEvent();
1212 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_UP)
1214 // double down and move (right, up)
1215 // change slider value
1216 if(accessibilityAdaptor)
1218 accessibilityAdaptor->HandleActionUpEvent();
1221 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DOWN)
1223 // double down and move (left, down)
1224 // change slider value
1225 if(accessibilityAdaptor)
1227 accessibilityAdaptor->HandleActionDownEvent();
1230 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ENABLE)
1232 if(accessibilityAdaptor)
1234 accessibilityAdaptor->HandleActionEnableEvent();
1237 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DISABLE)
1239 if(accessibilityAdaptor)
1241 accessibilityAdaptor->HandleActionDisableEvent();
1244 // TODO: some more actions could be added later
1247 else if(clientMessageEvent->message_type == ecore_x_atom_get(CLIPBOARD_ATOM))
1249 std::string message(clientMessageEvent->data.b);
1250 if( message == CLIPBOARD_SET_OWNER_MESSAGE)
1252 // Claim the ownership of the SECONDARY selection.
1253 ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1255 // Show the clipboard window
1256 Dali::Clipboard clipboard = Dali::Clipboard::Get();
1257 clipboard.ShowClipboard();
1260 else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_PREPARE )
1262 RotationEvent rotationEvent;
1263 rotationEvent.angle = static_cast<int>(clientMessageEvent->data.l[1]);
1264 rotationEvent.winResize = static_cast<int>(clientMessageEvent->data.l[2]);
1265 rotationEvent.width = static_cast<int>(clientMessageEvent->data.l[3]);
1266 rotationEvent.height = static_cast<int>(clientMessageEvent->data.l[4]);
1267 handler->SendRotationPrepareEvent( rotationEvent );
1269 else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_REQUEST )
1271 handler->SendRotationRequestEvent();
1274 #endif // DALI_PROFILE_UBUNTU
1275 return ECORE_CALLBACK_PASS_ON;
1279 /////////////////////////////////////////////////////////////////////////////////////////////////
1280 // ElDBus Accessibility Callbacks
1281 /////////////////////////////////////////////////////////////////////////////////////////////////
1283 #ifdef DALI_ELDBUS_AVAILABLE
1284 // Callback for Ecore ElDBus accessibility events.
1285 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
1287 EventHandler* handler = static_cast< EventHandler* >( context );
1288 // Ignore any accessibility events when paused.
1289 if( handler->mPaused )
1294 if ( !handler->mAccessibilityAdaptor )
1296 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
1300 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1301 if ( !accessibilityAdaptor )
1303 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
1307 const char *gestureName;
1311 // The string defines the arg-list's respective types.
1312 if( !eldbus_message_arguments_get( message, "siiiiu", &gestureName, &xS, &yS, &xE, &yE, &state ) )
1314 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1317 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %s Args: %d,%d,%d,%d State: %d\n", gestureName, xS, yS, xE, yE );
1319 unsigned int fingers = 0;
1320 char* stringPosition = ( char* )gestureName;
1322 // Check how many fingers the gesture uses.
1323 for( unsigned int i = 0; i < FingerCountStringsTotal; ++i )
1325 unsigned int matchLength = strlen( ElDBusAccessibilityFingerCountStrings[ i ] );
1326 if( strncmp( gestureName, ElDBusAccessibilityFingerCountStrings[ i ], matchLength ) == 0 )
1329 stringPosition += matchLength;
1336 // Error: invalid gesture.
1340 GestureType gestureType = GESTURE_TYPE_NONE;
1341 SubGestureType subGestureType = SUB_GESTURE_TYPE_NONE;
1342 GestureDirection direction = GESTURE_DIRECTION_NONE;
1344 // Check for full gesture type names first.
1345 for( unsigned int i = 0; i < FullEventTypeStringsTotal; ++i )
1347 unsigned int matchLength = strlen( ElDBusAccessibilityFullEventTypeStrings[ i ].name );
1348 if( strncmp( stringPosition, ElDBusAccessibilityFullEventTypeStrings[ i ].name, matchLength ) == 0 )
1350 gestureType = ElDBusAccessibilityFullEventTypeStrings[ i ].type;
1355 // If we didn't find a full gesture, check for sub gesture type names.
1356 if( gestureType == GESTURE_TYPE_NONE )
1358 // No full gesture name found, look for partial types.
1359 for( unsigned int i = 0; i < DirectionalEventTypeStringsTotal; ++i )
1361 unsigned int matchLength = strlen( ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name );
1362 if( strncmp( stringPosition, ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name, matchLength ) == 0 )
1364 subGestureType = ElDBusAccessibilityDirectionalEventTypeStrings[ i ].type;
1365 stringPosition += matchLength;
1370 if( subGestureType == SUB_GESTURE_TYPE_NONE )
1372 // ERROR: Gesture not recognised.
1376 // If the gesture was a sub type, get it's respective direction.
1377 for( unsigned int i = 0; i < DirectionStringsTotal; ++i )
1379 unsigned int matchLength = strlen( ElDBusAccessibilityDirectionStrings[ i ].name );
1380 if( strncmp( stringPosition, ElDBusAccessibilityDirectionStrings[ i ].name, matchLength ) == 0 )
1382 direction = ElDBusAccessibilityDirectionStrings[ i ].direction;
1383 stringPosition += matchLength;
1388 if( direction == GESTURE_DIRECTION_NONE )
1390 // ERROR: Gesture not recognised.
1395 // Action the detected gesture here.
1396 if( gestureType != GESTURE_TYPE_NONE )
1398 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d Gesture type: %d\n", fingers, gestureType );
1402 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d Gesture sub type: %d Gesture direction: %d\n",
1403 fingers, subGestureType, direction );
1406 // Create a touch point object.
1407 TouchPoint::State touchPointState( TouchPoint::Down );
1410 touchPointState = TouchPoint::Down; // Mouse down.
1412 else if ( state == 1 )
1414 touchPointState = TouchPoint::Motion; // Mouse move.
1416 else if ( state == 2 )
1418 touchPointState = TouchPoint::Up; // Mouse up.
1422 touchPointState = TouchPoint::Interrupted; // Error.
1425 // Send touch event to accessibility adaptor.
1426 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1428 // Perform actions based on received gestures.
1429 // Note: This is seperated from the reading so we can (in future)
1430 // have other input readers without changing the below code.
1435 if( gestureType == GESTURE_TYPE_SINGLE_TAP || ( gestureType == GESTURE_TYPE_HOVER && touchPointState == TouchPoint::Motion ) )
1438 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1440 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1442 if( false ) // TODO: how to detect double tap + hold?
1444 // Move or drag icon / view more options for selected items.
1445 // accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1449 // Activate selected item / active edit mode.
1450 accessibilityAdaptor->HandleActionActivateEvent();
1453 else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1456 accessibilityAdaptor->HandleActionZoomEvent();
1458 else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1460 if( direction == GESTURE_DIRECTION_LEFT )
1462 // Move to previous item.
1463 accessibilityAdaptor->HandleActionReadPreviousEvent();
1465 else if( direction == GESTURE_DIRECTION_RIGHT )
1467 // Move to next item.
1468 accessibilityAdaptor->HandleActionReadNextEvent();
1470 else if( direction == GESTURE_DIRECTION_UP )
1472 // Move to next item.
1473 accessibilityAdaptor->HandleActionPreviousEvent();
1475 else if( direction == GESTURE_DIRECTION_DOWN )
1477 // Move to next item.
1478 accessibilityAdaptor->HandleActionNextEvent();
1480 else if( direction == GESTURE_DIRECTION_LEFT_RETURN )
1482 // Scroll up to the previous page
1483 accessibilityAdaptor->HandleActionPageUpEvent();
1485 else if( direction == GESTURE_DIRECTION_RIGHT_RETURN )
1487 // Scroll down to the next page
1488 accessibilityAdaptor->HandleActionPageDownEvent();
1490 else if( direction == GESTURE_DIRECTION_UP_RETURN )
1492 // Move to the first item on screen
1493 accessibilityAdaptor->HandleActionMoveToFirstEvent();
1495 else if( direction == GESTURE_DIRECTION_DOWN_RETURN )
1497 // Move to the last item on screen
1498 accessibilityAdaptor->HandleActionMoveToLastEvent();
1506 if( gestureType == GESTURE_TYPE_HOVER )
1508 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1509 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1511 else if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1513 // Pause/Resume current speech
1514 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1516 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1518 // Start/Stop current action
1519 accessibilityAdaptor->HandleActionStartStopEvent();
1521 else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1523 // Read information from indicator
1524 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1526 else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1528 if( direction == GESTURE_DIRECTION_LEFT )
1530 // Scroll left to the previous page
1531 accessibilityAdaptor->HandleActionPageLeftEvent();
1533 else if( direction == GESTURE_DIRECTION_RIGHT )
1535 // Scroll right to the next page
1536 accessibilityAdaptor->HandleActionPageRightEvent();
1538 else if( direction == GESTURE_DIRECTION_UP )
1540 // Scroll up the list.
1541 accessibilityAdaptor->HandleActionScrollUpEvent();
1543 else if( direction == GESTURE_DIRECTION_DOWN )
1545 // Scroll down the list.
1546 accessibilityAdaptor->HandleActionScrollDownEvent();
1554 if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1556 // Read from top item on screen continuously.
1557 accessibilityAdaptor->HandleActionReadFromTopEvent();
1559 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1561 // Read from next item continuously.
1562 accessibilityAdaptor->HandleActionReadFromNextEvent();
1569 // Callback for to set up Ecore ElDBus for accessibility callbacks.
1570 static void EcoreElDBusInitialisation( void *handle, const Eldbus_Message *message, Eldbus_Pending *pending EINA_UNUSED )
1572 Eldbus_Object *object;
1573 Eldbus_Proxy *manager;
1574 const char *a11yBusAddress = NULL;
1575 EventHandler* handler = static_cast< EventHandler* >( handle );
1577 // The string defines the arg-list's respective types.
1578 if( !eldbus_message_arguments_get( message, "s", &a11yBusAddress ) )
1580 DALI_LOG_ERROR( "EcoreElDBusInitialisation: Error getting arguments\n" );
1583 DALI_LOG_INFO( gImfLogging, Debug::General, "Ecore ElDBus Accessibility address: %s\n", a11yBusAddress );
1585 handler->mImpl->mA11yConnection = eldbus_address_connection_get( a11yBusAddress );
1587 object = eldbus_object_get( handler->mImpl->mA11yConnection, BUS, PATH );
1588 manager = eldbus_proxy_get( object, INTERFACE );
1590 // Pass the callback data through to the signal handler.
1591 eldbus_proxy_signal_handler_add( manager, SIGNAL, OnEcoreElDBusAccessibilityNotification, handle );
1593 #endif // DALI_ELDBUS_AVAILABLE
1596 * Called when the source window notifies us the content in clipboard is selected.
1598 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1600 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1601 Ecore_X_Event_Selection_Clear* selectionClearEvent( (Ecore_X_Event_Selection_Clear*) event );
1602 EventHandler* handler( (EventHandler*)data );
1604 if ( selectionClearEvent->win == handler->mImpl->mWindow )
1606 if ( selectionClearEvent->selection == ECORE_X_SELECTION_SECONDARY )
1608 // Request to get the content from Ecore.
1609 ecore_x_selection_secondary_request(selectionClearEvent->win, ECORE_X_SELECTION_TARGET_TEXT);
1612 return ECORE_CALLBACK_PASS_ON;
1616 * Called when the source window sends us about the selected content.
1617 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1619 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1621 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1623 Ecore_X_Event_Selection_Notify* selectionNotifyEvent( (Ecore_X_Event_Selection_Notify*) event );
1624 EventHandler* handler( (EventHandler*)data );
1626 if ( selectionNotifyEvent->win == handler->mImpl->mWindow )
1628 Ecore_X_Selection_Data* selectionData( (Ecore_X_Selection_Data*) selectionNotifyEvent->data );
1629 if ( selectionData->data )
1631 if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_XDND )
1633 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
1635 // We have got the content that is to be dropped, inform the DndListener (if we have one).
1638 std::string content( (char*) selectionData->data, selectionData->length );
1639 dndDetector->SetContent( content );
1641 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1642 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1643 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1644 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1647 else if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_SECONDARY )
1649 // We have got the selected content, inform the clipboard event listener (if we have one).
1650 if ( handler->mClipboardEventNotifier )
1652 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1653 std::string content( (char*) selectionData->data, selectionData->length );
1654 clipboardEventNotifier.SetContent( content );
1655 clipboardEventNotifier.EmitContentSelectedSignal();
1658 // Claim the ownership of the SECONDARY selection.
1659 ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1661 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1662 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1663 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1664 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1668 return ECORE_CALLBACK_PASS_ON;
1672 #ifndef DALI_PROFILE_UBUNTU
1673 /////////////////////////////////////////////////////////////////////////////////////////////////
1675 /////////////////////////////////////////////////////////////////////////////////////////////////
1677 * Called when a font name is changed.
1679 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1681 EventHandler* handler = static_cast<EventHandler*>( data );
1682 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1686 * Called when a font size is changed.
1688 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1690 DALI_LOG_INFO(gTouchEventLogFilter, Debug::Verbose, "VconfNotifyFontSizeChanged\n" );
1691 EventHandler* handler = static_cast<EventHandler*>( data );
1692 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1694 #endif // DALI_PROFILE_UBUNTU
1697 EventHandler* mHandler;
1698 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1699 Ecore_X_Window mWindow;
1702 #ifdef DALI_ELDBUS_AVAILABLE
1703 Eldbus_Connection* mSessionConnection;
1704 Eldbus_Connection* mA11yConnection;
1708 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1709 : mCoreEventInterface( coreEventInterface ),
1710 mGestureManager( gestureManager ),
1711 mStyleMonitor( StyleMonitor::Get() ),
1712 mDamageObserver( damageObserver ),
1713 mRotationObserver( NULL ),
1714 mDragAndDropDetector( dndDetector ),
1715 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1716 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1717 mClipboard( Clipboard::Get() ),
1721 Ecore_X_Window window = 0;
1723 // this code only works with the EcoreX11 RenderSurface so need to downcast
1724 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1727 // enable multi touch
1728 window = ecoreSurface->GetXWindow();
1731 mImpl = new Impl(this, window);
1734 EventHandler::~EventHandler()
1738 mGestureManager.Stop();
1741 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1745 timeStamp = GetCurrentMilliSeconds();
1748 Integration::TouchEvent touchEvent;
1749 Integration::HoverEvent hoverEvent;
1750 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1751 if(type != Integration::TouchEventCombiner::DispatchNone )
1753 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);
1755 // First the touch and/or hover event & related gesture events are queued
1756 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1758 mCoreEventInterface.QueueCoreEvent( touchEvent );
1759 mGestureManager.SendEvent(touchEvent);
1762 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1764 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1767 // Next the events are processed with a single call into Core
1768 mCoreEventInterface.ProcessCoreEvents();
1772 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1774 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1775 if ( physicalKeyboard )
1777 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1779 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1783 // Send to KeyEvent Core.
1784 mCoreEventInterface.QueueCoreEvent( keyEvent );
1785 mCoreEventInterface.ProcessCoreEvents();
1788 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1790 // Create WheelEvent and send to Core.
1791 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1792 mCoreEventInterface.QueueCoreEvent( event );
1793 mCoreEventInterface.ProcessCoreEvents();
1796 void EventHandler::SendEvent( StyleChange::Type styleChange )
1798 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1799 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1802 void EventHandler::SendEvent( const DamageArea& area )
1804 mDamageObserver.OnDamaged( area );
1807 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1809 if( mRotationObserver != NULL )
1811 mRotationObserver->OnRotationPrepare( event );
1815 void EventHandler::SendRotationRequestEvent( )
1817 if( mRotationObserver != NULL )
1819 mRotationObserver->OnRotationRequest( );
1823 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1825 Integration::Point convertedPoint( point );
1827 SendEvent(convertedPoint, timeStamp);
1830 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1832 SendWheelEvent( wheelEvent );
1835 void EventHandler::FeedKeyEvent( KeyEvent& event )
1837 Integration::KeyEvent convertedEvent( event );
1838 SendEvent( convertedEvent );
1841 void EventHandler::FeedEvent( Integration::Event& event )
1843 mCoreEventInterface.QueueCoreEvent( event );
1844 mCoreEventInterface.ProcessCoreEvents();
1847 void EventHandler::Reset()
1851 // Any touch listeners should be told of the interruption.
1852 Integration::TouchEvent event;
1853 Integration::Point point;
1854 point.SetState( PointState::INTERRUPTED );
1855 event.AddPoint( point );
1857 // First the touch event & related gesture events are queued
1858 mCoreEventInterface.QueueCoreEvent( event );
1859 mGestureManager.SendEvent( event );
1861 // Next the events are processed with a single call into Core
1862 mCoreEventInterface.ProcessCoreEvents();
1865 void EventHandler::Pause()
1871 void EventHandler::Resume()
1877 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1879 mDragAndDropDetector = detector;
1882 void EventHandler::SetRotationObserver( RotationObserver* observer )
1884 mRotationObserver = observer;
1887 } // namespace Adaptor
1889 } // namespace Internal
1893 #pragma GCC diagnostic pop