2 * Copyright (c) 2015 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>
23 #include <Ecore_Input.h>
27 #include <X11/extensions/XInput2.h>
28 #include <X11/extensions/XI2.h>
34 #ifndef DALI_PROFILE_UBUNTU
36 #include <vconf-keys.h>
37 #endif // DALI_PROFILE_UBUNTU
39 #ifdef DALI_ELDBUS_AVAILABLE
41 #endif // DALI_ELDBUS_AVAILABLE
43 #include <dali/public-api/common/vector-wrapper.h>
44 #include <dali/public-api/events/touch-point.h>
45 #include <dali/public-api/events/key-event.h>
46 #include <dali/public-api/events/wheel-event.h>
47 #include <dali/integration-api/debug.h>
48 #include <dali/integration-api/events/key-event-integ.h>
49 #include <dali/integration-api/events/touch-event-integ.h>
50 #include <dali/integration-api/events/hover-event-integ.h>
51 #include <dali/integration-api/events/wheel-event-integ.h>
52 #include <dali/devel-api/events/key-event-devel.h>
55 #include <events/gesture-manager.h>
56 #include <window-render-surface.h>
57 #include <clipboard-impl.h>
59 #include <physical-keyboard-impl.h>
60 #include <style-monitor-impl.h>
61 #include <base/core-event-interface.h>
72 #if defined(DEBUG_ENABLED)
75 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
76 Integration::Log::Filter* gClientMessageLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_CLIENT_MESSAGE");
77 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
78 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
79 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
80 } // unnamed namespace
87 const char * DETENT_DEVICE_NAME = "tizen_detent";
88 const std::string DEFAULT_DEVICE_NAME = "";
89 const DevelKeyEvent::DeviceClass::Type DEFAULT_DEVICE_CLASS = DevelKeyEvent::DeviceClass::NONE;
92 #define A11Y_BUS "org.a11y.Bus"
93 #define A11Y_INTERFACE "org.a11y.Bus"
94 #define A11Y_PATH "/org/a11y/bus"
95 #define A11Y_GET_ADDRESS "GetAddress"
96 #define BUS "com.samsung.EModule"
97 #define INTERFACE "com.samsung.GestureNavigation"
98 #define PATH "/com/samsung/GestureNavigation"
99 #define SIGNAL "GestureDetected"
101 #ifndef DALI_PROFILE_UBUNTU
102 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
103 #endif // DALI_PROFILE_UBUNTU
105 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
107 #ifndef DALI_PROFILE_UBUNTU
108 const char * CLIPBOARD_ATOM = "CBHM_MSG";
109 const char * CLIPBOARD_SET_OWNER_MESSAGE = "SET_OWNER";
110 #endif // DALI_PROFILE_UBUNTU
112 /// The atoms required by Ecore for Drag & Drop behaviour.
113 Ecore_X_Atom DRAG_AND_DROP_ATOMS[] =
115 ECORE_X_ATOM_XDND_ACTION_COPY,
118 /// The types that we support.
119 const char * DRAG_AND_DROP_TYPES[] =
121 ECORE_X_SELECTION_TARGET_UTF8_STRING,
124 const unsigned int DRAG_AND_DROP_ATOMS_NUMBER = sizeof( DRAG_AND_DROP_ATOMS ) / sizeof( Ecore_X_Atom );
125 const unsigned int DRAG_AND_DROP_TYPES_NUMBER = sizeof( DRAG_AND_DROP_TYPES ) / sizeof( const char * );
127 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
129 #ifdef DALI_ELDBUS_AVAILABLE
130 // DBus gesture string matching lists.
131 // TODO: This needs moving to its own module.
132 const char * ElDBusAccessibilityFingerCountStrings[] =
138 const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
143 GESTURE_TYPE_SINGLE_TAP,
144 GESTURE_TYPE_DOUBLE_TAP,
145 GESTURE_TYPE_TRIPLE_TAP
147 struct GestureTypeTable
150 const GestureType type;
152 GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
154 { "Hover", GESTURE_TYPE_HOVER },
155 { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
156 { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
157 { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
159 const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
162 SUB_GESTURE_TYPE_NONE,
163 SUB_GESTURE_TYPE_FLICK
165 struct SubGestureTypeTable
168 const SubGestureType type;
170 SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
172 { "Flick", SUB_GESTURE_TYPE_FLICK }
174 const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
175 enum GestureDirection
177 GESTURE_DIRECTION_NONE,
178 GESTURE_DIRECTION_UP,
179 GESTURE_DIRECTION_DOWN,
180 GESTURE_DIRECTION_LEFT,
181 GESTURE_DIRECTION_RIGHT,
182 GESTURE_DIRECTION_UP_RETURN,
183 GESTURE_DIRECTION_DOWN_RETURN,
184 GESTURE_DIRECTION_LEFT_RETURN,
185 GESTURE_DIRECTION_RIGHT_RETURN
187 struct GestureDirectionTable
190 const GestureDirection direction;
192 GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
194 { "Up", GESTURE_DIRECTION_UP },
195 { "Down", GESTURE_DIRECTION_DOWN },
196 { "Left", GESTURE_DIRECTION_LEFT },
197 { "Right", GESTURE_DIRECTION_RIGHT },
198 { "UpReturn", GESTURE_DIRECTION_UP_RETURN },
199 { "DownReturn", GESTURE_DIRECTION_DOWN_RETURN },
200 { "LeftReturn", GESTURE_DIRECTION_LEFT_RETURN },
201 { "RightReturn", GESTURE_DIRECTION_RIGHT_RETURN }
203 const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
204 #endif // DALI_ELDBUS_AVAILABLE
207 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
208 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
209 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
210 * @return the Ecore_IMF_Keyboard_Modifiers output.
212 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
214 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
217 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
219 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
222 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
224 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
227 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
229 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
232 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
234 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
237 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
239 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
242 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
246 // Copied from x server
247 static unsigned int GetCurrentMilliSeconds(void)
252 static clockid_t clockid;
256 #ifdef CLOCK_MONOTONIC_COARSE
257 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
258 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
260 clockid = CLOCK_MONOTONIC_COARSE;
264 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
266 clockid = CLOCK_MONOTONIC;
273 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
275 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
278 gettimeofday(&tv, NULL);
279 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
282 } // unnamed namespace
284 // Impl to hide EFL implementation.
285 struct EventHandler::Impl
287 // Construction & Destruction
292 Impl( EventHandler* handler, Ecore_X_Window window )
293 : mHandler( handler ),
294 mEcoreEventHandler(),
297 #ifdef DALI_ELDBUS_AVAILABLE
298 , mSessionConnection( NULL ),
299 mA11yConnection( NULL )
302 // Only register for touch and key events if we have a window
305 // Register Touch events
306 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
307 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
308 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
309 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
311 // Register Mouse wheel events
312 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
314 // Register Key events
315 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
316 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
318 // Register Focus events
319 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
320 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
322 // Register Window damage events
323 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_DAMAGE, EcoreEventWindowDamaged, handler ) );
325 // Enable Drag & Drop and register DnD events
326 ecore_x_dnd_aware_set( window, EINA_TRUE );
327 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_ENTER, EcoreEventDndEnter, handler) );
328 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_POSITION, EcoreEventDndPosition, handler) );
329 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_LEAVE, EcoreEventDndLeave, handler) );
330 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_DROP, EcoreEventDndDrop, handler) );
331 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_FINISHED, EcoreEventDndFinished, handler) );
332 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_STATUS, EcoreEventDndStatus, handler) );
334 // Register Client message events - accessibility etc.
335 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_CLIENT_MESSAGE, EcoreEventClientMessage, handler ) );
337 // Register Selection event - clipboard selection, Drag & Drop selection etc.
338 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_CLEAR, EcoreEventSelectionClear, handler ) );
339 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_NOTIFY, EcoreEventSelectionNotify, handler ) );
341 // Initialize Xi2 system
342 Display* display = static_cast< Display* >(ecore_x_display_get());
343 Ecore_X_Window rootWindow = ecore_x_window_root_first_get();
344 int opcode = 0, event = 0, error = 0;
345 int major = XI_2_Major;
346 int minor = XI_2_Minor;
348 XIEventMask xiEventMask;
350 // Check if X input extension available
351 if( XQueryExtension( display, "XInputExtension", &opcode, &event, &error ) )
353 // We support version 2.0
354 if( XIQueryVersion( display, &major, &minor ) != BadRequest )
356 xiEventMask.deviceid = XIAllDevices;
360 XIDeviceInfo* deviceInfo = NULL;
361 deviceInfo = XIQueryDevice( display, XIAllDevices, &deviceCount );
363 for( int i = 0; i < deviceCount; i++ )
365 if( !strncmp( deviceInfo[i].name, DETENT_DEVICE_NAME, strlen( DETENT_DEVICE_NAME ) ) )
367 xiEventMask.deviceid = deviceInfo[i].deviceid;
375 mXiDeviceId = xiEventMask.deviceid;
378 Dali::Vector< unsigned char > mask;
379 std::size_t xiMaskLen = XIMaskLen( XI_LASTEVENT );
380 mask.Reserve( xiMaskLen );
381 xiEventMask.mask = mask.Begin();
383 XISetMask( xiEventMask.mask, XI_RawMotion );
385 xiEventMask.mask_len = xiMaskLen * sizeof( unsigned char );
387 int ret = XISelectEvents( display, rootWindow, &xiEventMask, 1 );
390 // Register custom wheel events
391 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_GENERIC, EcoreEventCustomWheel, handler ) );
395 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to Select Events\n" );
399 if( deviceInfo != NULL )
401 XIFreeDeviceInfo( deviceInfo );
406 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XI Version\n" );
411 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XInputExtension\n" );
414 #ifndef DALI_PROFILE_UBUNTU
415 // Register Vconf notify - font name, font size and style
416 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, handler );
417 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
418 #endif // DALI_PROFILE_UBUNTU
420 #ifdef DALI_ELDBUS_AVAILABLE
422 // Initialize ElDBus.
423 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
426 mSessionConnection = eldbus_connection_get( ELDBUS_CONNECTION_TYPE_SESSION );
428 Eldbus_Object *a11yObject = eldbus_object_get( mSessionConnection, A11Y_BUS, A11Y_PATH );
429 Eldbus_Proxy *elDBusManager = eldbus_proxy_get( a11yObject, A11Y_INTERFACE );
431 // Pass in handler in the cb_data field so we can access the accessibility adaptor within the callback.
432 eldbus_proxy_call( elDBusManager, A11Y_GET_ADDRESS, EcoreElDBusInitialisation, handler, -1, "" );
434 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
436 #endif // DALI_ELDBUS_AVAILABLE
445 #ifndef DALI_PROFILE_UBUNTU
446 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
447 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged );
448 #endif // DALI_PROFILE_UBUNTU
450 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
452 ecore_event_handler_del( *iter );
455 #ifdef DALI_ELDBUS_AVAILABLE
457 if( mA11yConnection )
459 eldbus_connection_unref( mA11yConnection );
462 if( mSessionConnection )
464 eldbus_connection_unref( mSessionConnection );
468 #endif // DALI_ELDBUS_AVAILABLE
473 /////////////////////////////////////////////////////////////////////////////////////////////////
475 /////////////////////////////////////////////////////////////////////////////////////////////////
478 * Called when a touch down is received.
480 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
482 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
483 EventHandler* handler( (EventHandler*)data );
485 if ( touchEvent->window == handler->mImpl->mWindow )
487 PointState::Type state ( PointState::DOWN );
489 // Check if the buttons field is set and ensure it's the primary touch button.
490 // If this event was triggered by buttons other than the primary button (used for touch), then
491 // just send an interrupted event to Core.
492 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
494 state = PointState::INTERRUPTED;
497 Integration::Point point;
498 point.SetDeviceId( touchEvent->multi.device );
499 point.SetState( state );
500 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
501 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
502 point.SetPressure( touchEvent->multi.pressure );
503 point.SetAngle( Degree( touchEvent->multi.angle ) );
504 handler->SendEvent( point, touchEvent->timestamp );
507 return ECORE_CALLBACK_PASS_ON;
511 * Called when a touch up is received.
513 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
515 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
516 EventHandler* handler( (EventHandler*)data );
518 if ( touchEvent->window == handler->mImpl->mWindow )
520 Integration::Point point;
521 point.SetDeviceId( touchEvent->multi.device );
522 point.SetState( PointState::UP );
523 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
524 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
525 point.SetPressure( touchEvent->multi.pressure );
526 point.SetAngle( Degree( touchEvent->multi.angle ) );
527 handler->SendEvent( point, touchEvent->timestamp );
530 return ECORE_CALLBACK_PASS_ON;
534 * Called when a touch motion is received.
536 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
538 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
539 EventHandler* handler( (EventHandler*)data );
541 if ( touchEvent->window == handler->mImpl->mWindow )
543 Integration::Point point;
544 point.SetDeviceId( touchEvent->multi.device );
545 point.SetState( PointState::MOTION );
546 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
547 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
548 point.SetPressure( touchEvent->multi.pressure );
549 point.SetAngle( Degree( touchEvent->multi.angle ) );
550 handler->SendEvent( point, touchEvent->timestamp );
553 return ECORE_CALLBACK_PASS_ON;
556 /////////////////////////////////////////////////////////////////////////////////////////////////
558 /////////////////////////////////////////////////////////////////////////////////////////////////
561 * Called when a mouse wheel is received.
563 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
565 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
567 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 );
569 EventHandler* handler( (EventHandler*)data );
570 if ( mouseWheelEvent->window == handler->mImpl->mWindow )
572 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
573 handler->SendWheelEvent( wheelEvent );
575 return ECORE_CALLBACK_PASS_ON;
579 * Called when a custom wheel is received.
581 static Eina_Bool EcoreEventCustomWheel( void* data, int type, void* event )
583 Ecore_X_Event_Generic *genericEvent( (Ecore_X_Event_Generic*)event );
584 EventHandler* handler( (EventHandler*)data );
586 switch( genericEvent->evtype )
590 XIRawEvent* xiRawEvent = static_cast< XIRawEvent* >( genericEvent->data );
591 unsigned int timeStamp = 0;
593 if( xiRawEvent->deviceid != handler->mImpl->mXiDeviceId )
595 return ECORE_CALLBACK_PASS_ON;
598 // X(0): rotate: NOT USED
602 double* value = xiRawEvent->raw_values;
604 if( XIMaskIsSet( xiRawEvent->valuators.mask, 1) )
606 timeStamp = static_cast< unsigned int >( *(value + 1) );
609 if( XIMaskIsSet( xiRawEvent->valuators.mask, 2) )
611 // if z == 1, clockwise
612 // otherwise counter-clockwise
613 int z = static_cast< int >( *(value + 2) );
615 // In DALi, positive value means clockwise, and negative value means counter-clockwise
621 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventCustomWheel: z: %d\n", z );
623 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), z, timeStamp );
624 handler->SendWheelEvent( wheelEvent );
634 return ECORE_CALLBACK_PASS_ON;
637 /////////////////////////////////////////////////////////////////////////////////////////////////
639 /////////////////////////////////////////////////////////////////////////////////////////////////
642 * Called when a key down is received.
644 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
646 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
648 EventHandler* handler( (EventHandler*)data );
649 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
650 bool eventHandled( false );
652 // If a device key then skip ecore_imf_context_filter_event.
653 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
655 Ecore_IMF_Context* imfContext = NULL;
656 Dali::ImfManager imfManager( ImfManager::Get() );
659 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
664 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
665 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
666 ecoreKeyDownEvent.keyname = keyEvent->keyname;
667 ecoreKeyDownEvent.key = keyEvent->key;
668 ecoreKeyDownEvent.string = keyEvent->string;
669 ecoreKeyDownEvent.compose = keyEvent->compose;
670 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
671 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
672 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
673 #ifdef ECORE_IMF_1_13
674 ecoreKeyDownEvent.dev_name = "";
675 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
676 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
677 #endif // ECORE_IMF_1_13
679 eventHandled = ecore_imf_context_filter_event( imfContext,
680 ECORE_IMF_EVENT_KEY_DOWN,
681 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
683 // If the event has not been handled by IMF then check if we should reset our IMF context
686 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
687 !strcmp( keyEvent->keyname, "Return" ) ||
688 !strcmp( keyEvent->keyname, "KP_Enter" ) )
690 ecore_imf_context_reset( imfContext );
696 // If the event wasn't handled then we should send a key event.
699 if ( keyEvent->window == handler->mImpl->mWindow )
701 std::string keyName( keyEvent->keyname );
702 std::string keyString( "" );
703 int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
704 int modifier( keyEvent->modifiers );
705 unsigned long time = keyEvent->timestamp;
707 // Ensure key event string is not NULL as keys like SHIFT have a null string.
708 if ( keyEvent->string )
710 keyString = keyEvent->string;
713 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_CLASS );
714 handler->SendEvent( keyEvent );
718 return ECORE_CALLBACK_PASS_ON;
722 * Called when a key up is received.
724 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
726 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp \n" );
728 EventHandler* handler( (EventHandler*)data );
729 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
730 bool eventHandled( false );
732 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
733 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
735 Ecore_IMF_Context* imfContext = NULL;
736 Dali::ImfManager imfManager( ImfManager::Get() );
739 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
744 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
745 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
746 ecoreKeyUpEvent.keyname = keyEvent->keyname;
747 ecoreKeyUpEvent.key = keyEvent->key;
748 ecoreKeyUpEvent.string = keyEvent->string;
749 ecoreKeyUpEvent.compose = keyEvent->compose;
750 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
751 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
752 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
753 #ifdef ECORE_IMF_1_13
754 ecoreKeyUpEvent.dev_name = "";
755 #endif // ECORE_IMF_1_13
757 eventHandled = ecore_imf_context_filter_event( imfContext,
758 ECORE_IMF_EVENT_KEY_UP,
759 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
763 // If the event wasn't handled then we should send a key event.
766 if ( keyEvent->window == handler->mImpl->mWindow )
768 std::string keyName( keyEvent->keyname );
769 std::string keyString( "" );
770 int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
771 int modifier( keyEvent->modifiers );
772 unsigned long time( keyEvent->timestamp );
774 // Ensure key event string is not NULL as keys like SHIFT have a null string.
775 if ( keyEvent->string )
777 keyString = keyEvent->string;
780 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_CLASS );
782 handler->SendEvent( keyEvent );
786 return ECORE_CALLBACK_PASS_ON;
789 /////////////////////////////////////////////////////////////////////////////////////////////////
791 /////////////////////////////////////////////////////////////////////////////////////////////////
794 * Called when the window gains focus.
796 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
798 Ecore_X_Event_Window_Focus_In* focusInEvent( (Ecore_X_Event_Window_Focus_In*)event );
799 EventHandler* handler( (EventHandler*)data );
801 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
803 // If the window gains focus and we hid the keyboard then show it again.
804 if ( focusInEvent->win == handler->mImpl->mWindow )
806 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
808 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
810 Dali::ImfManager imfManager( ImfManager::Get() );
813 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
814 if( imfManagerImpl.RestoreAfterFocusLost() )
816 imfManagerImpl.Activate();
820 // No need to connect callbacks as KeyboardStatusChanged will be called.
823 return ECORE_CALLBACK_PASS_ON;
827 * Called when the window loses focus.
829 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
831 Ecore_X_Event_Window_Focus_Out* focusOutEvent( (Ecore_X_Event_Window_Focus_Out*)event );
832 EventHandler* handler( (EventHandler*)data );
834 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
836 // If the window loses focus then hide the keyboard.
837 if ( focusOutEvent->win == handler->mImpl->mWindow )
839 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
841 Dali::ImfManager imfManager( ImfManager::Get() );
844 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
845 if( imfManagerImpl.RestoreAfterFocusLost() )
847 imfManagerImpl.Deactivate();
852 // Clipboard don't support that whether clipboard is shown or not. Hide clipboard.
853 Dali::Clipboard clipboard = Clipboard::Get();
854 clipboard.HideClipboard();
857 return ECORE_CALLBACK_PASS_ON;
861 * Called when the window is damaged.
863 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
865 Ecore_X_Event_Window_Damage* windowDamagedEvent( (Ecore_X_Event_Window_Damage*)event );
866 EventHandler* handler( (EventHandler*)data );
868 if( windowDamagedEvent->win == handler->mImpl->mWindow )
871 area.x = windowDamagedEvent->x;
872 area.y = windowDamagedEvent->y;
873 area.width = windowDamagedEvent->w;
874 area.height = windowDamagedEvent->h;
876 handler->SendEvent( area );
879 return ECORE_CALLBACK_PASS_ON;
883 * Called when the window properties are changed.
884 * We are only interested in the font change.
888 /////////////////////////////////////////////////////////////////////////////////////////////////
889 // Drag & Drop Callbacks
890 /////////////////////////////////////////////////////////////////////////////////////////////////
893 * Called when a dragged item enters our window's bounds.
894 * This is when items are dragged INTO our window.
896 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
898 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
900 Ecore_X_Event_Xdnd_Enter* enterEvent( (Ecore_X_Event_Xdnd_Enter*) event );
901 EventHandler* handler( (EventHandler*)data );
902 Ecore_X_Window window ( handler->mImpl->mWindow );
904 if ( enterEvent->win == window )
906 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
908 // Check whether the Drag & Drop detector has Drag & Drop behaviour enabled before we accept.
909 if ( dndDetector && dndDetector->IsEnabled() )
911 // Tell Ecore that we want to enable drop in the entire window.
912 Ecore_X_Rectangle rect;
914 ecore_x_window_geometry_get( window, NULL, NULL, (int*)&rect.width, (int*)&rect.height );
916 // Tell Ecore that we are able to process a drop.
917 ecore_x_dnd_send_status( EINA_TRUE, EINA_FALSE, rect, ECORE_X_ATOM_XDND_DROP );
919 // Register the required atoms and types.
920 ecore_x_dnd_actions_set( window, DRAG_AND_DROP_ATOMS, DRAG_AND_DROP_ATOMS_NUMBER );
921 ecore_x_dnd_types_set( window, DRAG_AND_DROP_TYPES, DRAG_AND_DROP_TYPES_NUMBER );
923 // Request to get the content from Ecore.
924 ecore_x_selection_xdnd_request( window, ECORE_X_SELECTION_TARGET_UTF8_STRING );
926 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndEnter: Requesting Drag & Drop\n" );
928 // Clear the previous content
929 dndDetector->ClearContent();
931 // Emit the entered signal
932 dndDetector->EmitEnteredSignal();
936 return ECORE_CALLBACK_PASS_ON;
940 * Called when a dragged item is moved within our window.
941 * This is when items are dragged INTO our window.
943 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
945 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
947 Ecore_X_Event_Xdnd_Position* positionEvent( (Ecore_X_Event_Xdnd_Position*) event );
948 EventHandler* handler( (EventHandler*)data );
950 if ( positionEvent->win == handler->mImpl->mWindow )
952 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
954 // If we have a detector then update its latest position.
957 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndPosition: position ( %d x %d )\n", positionEvent->position.x, positionEvent->position.y );
958 dndDetector->SetPosition( Vector2( positionEvent->position.x, positionEvent->position.y ));
959 dndDetector->EmitMovedSignal();
963 return ECORE_CALLBACK_PASS_ON;
967 * Called when a dragged item leaves our window's bounds.
968 * This is when items are dragged INTO our window.
970 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
972 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
974 Ecore_X_Event_Xdnd_Leave* leaveEvent( (Ecore_X_Event_Xdnd_Leave*) event );
975 EventHandler* handler( (EventHandler*)data );
977 if ( leaveEvent->win == handler->mImpl->mWindow )
979 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
981 // If we have a detector then clear its content and emit the exited-signal. Also tell Ecore that we have finished.
984 dndDetector->ClearContent();
985 dndDetector->EmitExitedSignal();
987 ecore_x_dnd_send_finished();
989 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndLeave: Finished\n" );
993 return ECORE_CALLBACK_PASS_ON;
997 * Called when the dragged item is dropped within our window's bounds.
998 * This is when items are dragged INTO our window.
1000 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
1002 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
1004 Ecore_X_Event_Xdnd_Drop* dropEvent ( (Ecore_X_Event_Xdnd_Drop*) event);
1005 EventHandler* handler( (EventHandler*)data );
1007 if ( dropEvent->win == handler->mImpl->mWindow )
1009 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
1011 // Something has been dropped, inform the detector (if we have one) and tell Ecore that we have finished.
1014 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: position ( %d x %d )\n", dropEvent->position.x, dropEvent->position.y );
1016 dndDetector->SetPosition( Vector2( dropEvent->position.x, dropEvent->position.y ) );
1017 dndDetector->EmitDroppedSignal();
1018 ecore_x_dnd_send_finished();
1020 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: Finished\n" );
1024 return ECORE_CALLBACK_PASS_ON;
1028 * Called when a dragged item is moved from our window and the target window has done processing it.
1029 * This is when items are dragged FROM our window.
1031 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
1033 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
1034 return ECORE_CALLBACK_PASS_ON;
1038 * Called when a dragged item is moved from our window and the target window has sent us a status.
1039 * This is when items are dragged FROM our window.
1041 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
1043 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
1044 return ECORE_CALLBACK_PASS_ON;
1048 * Called when the client messages (i.e. the accessibility events) are received.
1050 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
1052 #ifndef DALI_PROFILE_UBUNTU
1053 Ecore_X_Event_Client_Message* clientMessageEvent( (Ecore_X_Event_Client_Message*)event );
1054 EventHandler* handler( (EventHandler*)data );
1056 if (clientMessageEvent->message_type == ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL)
1058 if ( ( (unsigned int)clientMessageEvent->data.l[0] == handler->mImpl->mWindow ) && handler->mAccessibilityAdaptor )
1060 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1062 if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_SCROLL)
1064 // 2 finger touch & move, 2 finger flick
1066 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1069 TouchPoint::State state(TouchPoint::Down);
1071 if ((unsigned int)clientMessageEvent->data.l[2] == 0)
1073 state = TouchPoint::Down; // mouse down
1075 else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
1077 state = TouchPoint::Motion; // mouse move
1079 else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
1081 state = TouchPoint::Up; // mouse up
1085 state = TouchPoint::Interrupted; // error
1088 DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1089 "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1090 (unsigned int)clientMessageEvent->data.l[2],
1091 (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1093 // Send touch event to accessibility adaptor.
1094 TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1096 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1097 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1099 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_MOUSE)
1101 // 1 finger double tap and hold
1103 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1106 TouchPoint::State state(TouchPoint::Down);
1108 if ((unsigned int)clientMessageEvent->data.l[2] == 0)
1110 state = TouchPoint::Down; // mouse down
1112 else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
1114 state = TouchPoint::Motion; // mouse move
1116 else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
1118 state = TouchPoint::Up; // mouse up
1122 state = TouchPoint::Interrupted; // error
1125 DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1126 "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1127 (unsigned int)clientMessageEvent->data.l[2],
1128 (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1130 // Send touch event to accessibility adaptor.
1131 TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1133 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1134 accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1136 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_BACK)
1138 // 2 finger circle draw, do back
1139 accessibilityAdaptor->HandleActionBackEvent();
1141 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_NEXT)
1143 // one finger flick down
1144 // focus next object
1145 if(accessibilityAdaptor)
1147 accessibilityAdaptor->HandleActionNextEvent();
1150 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_PREV)
1152 // one finger flick up
1153 // focus previous object
1154 if(accessibilityAdaptor)
1156 accessibilityAdaptor->HandleActionPreviousEvent();
1159 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE)
1161 // one finger double tap
1162 // same as one finger tap in normal mode (i.e. execute focused actor)
1163 if(accessibilityAdaptor)
1165 accessibilityAdaptor->HandleActionActivateEvent();
1168 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ)
1171 // focus & read an actor at ( e->data.l[2], e->data.l[3] ) position according to finger
1172 if(accessibilityAdaptor)
1174 accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[2], (unsigned int)clientMessageEvent->data.l[3], true /* allow read again*/);
1177 #if defined(DALI_PROFILE_MOBILE)
1178 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_OVER)
1180 // one finger tap & move
1181 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1184 // focus & read an actor at (x, y) position according to finger
1185 if(accessibilityAdaptor && (unsigned int)clientMessageEvent->data.l[2] == 1 /*only work for move event*/)
1187 accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4], false /* not allow read again*/);
1191 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_NEXT)
1193 // one finger flick right
1194 // focus next object
1195 if(accessibilityAdaptor)
1197 accessibilityAdaptor->HandleActionReadNextEvent();
1200 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_PREV)
1202 // one finger flick left
1203 // focus previous object
1204 if(accessibilityAdaptor)
1206 accessibilityAdaptor->HandleActionReadPreviousEvent();
1209 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_UP)
1211 // double down and move (right, up)
1212 // change slider value
1213 if(accessibilityAdaptor)
1215 accessibilityAdaptor->HandleActionUpEvent();
1218 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DOWN)
1220 // double down and move (left, down)
1221 // change slider value
1222 if(accessibilityAdaptor)
1224 accessibilityAdaptor->HandleActionDownEvent();
1227 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ENABLE)
1229 if(accessibilityAdaptor)
1231 accessibilityAdaptor->HandleActionEnableEvent();
1234 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DISABLE)
1236 if(accessibilityAdaptor)
1238 accessibilityAdaptor->HandleActionDisableEvent();
1241 // TODO: some more actions could be added later
1244 else if(clientMessageEvent->message_type == ecore_x_atom_get(CLIPBOARD_ATOM))
1246 std::string message(clientMessageEvent->data.b);
1247 if( message == CLIPBOARD_SET_OWNER_MESSAGE)
1249 // Claim the ownership of the SECONDARY selection.
1250 ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1252 // Show the clipboard window
1253 Dali::Clipboard clipboard = Dali::Clipboard::Get();
1254 clipboard.ShowClipboard();
1257 else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_PREPARE )
1259 RotationEvent rotationEvent;
1260 rotationEvent.angle = static_cast<int>(clientMessageEvent->data.l[1]);
1261 rotationEvent.winResize = static_cast<int>(clientMessageEvent->data.l[2]);
1262 rotationEvent.width = static_cast<int>(clientMessageEvent->data.l[3]);
1263 rotationEvent.height = static_cast<int>(clientMessageEvent->data.l[4]);
1264 handler->SendRotationPrepareEvent( rotationEvent );
1266 else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_REQUEST )
1268 handler->SendRotationRequestEvent();
1271 #endif // DALI_PROFILE_UBUNTU
1272 return ECORE_CALLBACK_PASS_ON;
1276 /////////////////////////////////////////////////////////////////////////////////////////////////
1277 // ElDBus Accessibility Callbacks
1278 /////////////////////////////////////////////////////////////////////////////////////////////////
1280 #ifdef DALI_ELDBUS_AVAILABLE
1281 // Callback for Ecore ElDBus accessibility events.
1282 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
1284 EventHandler* handler = static_cast< EventHandler* >( context );
1285 // Ignore any accessibility events when paused.
1286 if( handler->mPaused )
1291 if ( !handler->mAccessibilityAdaptor )
1293 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
1297 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1298 if ( !accessibilityAdaptor )
1300 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
1304 const char *gestureName;
1308 // The string defines the arg-list's respective types.
1309 if( !eldbus_message_arguments_get( message, "siiiiu", &gestureName, &xS, &yS, &xE, &yE, &state ) )
1311 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1314 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %s Args: %d,%d,%d,%d State: %d\n", gestureName, xS, yS, xE, yE );
1316 unsigned int fingers = 0;
1317 char* stringPosition = ( char* )gestureName;
1319 // Check how many fingers the gesture uses.
1320 for( unsigned int i = 0; i < FingerCountStringsTotal; ++i )
1322 unsigned int matchLength = strlen( ElDBusAccessibilityFingerCountStrings[ i ] );
1323 if( strncmp( gestureName, ElDBusAccessibilityFingerCountStrings[ i ], matchLength ) == 0 )
1326 stringPosition += matchLength;
1333 // Error: invalid gesture.
1337 GestureType gestureType = GESTURE_TYPE_NONE;
1338 SubGestureType subGestureType = SUB_GESTURE_TYPE_NONE;
1339 GestureDirection direction = GESTURE_DIRECTION_NONE;
1341 // Check for full gesture type names first.
1342 for( unsigned int i = 0; i < FullEventTypeStringsTotal; ++i )
1344 unsigned int matchLength = strlen( ElDBusAccessibilityFullEventTypeStrings[ i ].name );
1345 if( strncmp( stringPosition, ElDBusAccessibilityFullEventTypeStrings[ i ].name, matchLength ) == 0 )
1347 gestureType = ElDBusAccessibilityFullEventTypeStrings[ i ].type;
1352 // If we didn't find a full gesture, check for sub gesture type names.
1353 if( gestureType == GESTURE_TYPE_NONE )
1355 // No full gesture name found, look for partial types.
1356 for( unsigned int i = 0; i < DirectionalEventTypeStringsTotal; ++i )
1358 unsigned int matchLength = strlen( ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name );
1359 if( strncmp( stringPosition, ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name, matchLength ) == 0 )
1361 subGestureType = ElDBusAccessibilityDirectionalEventTypeStrings[ i ].type;
1362 stringPosition += matchLength;
1367 if( subGestureType == SUB_GESTURE_TYPE_NONE )
1369 // ERROR: Gesture not recognised.
1373 // If the gesture was a sub type, get it's respective direction.
1374 for( unsigned int i = 0; i < DirectionStringsTotal; ++i )
1376 unsigned int matchLength = strlen( ElDBusAccessibilityDirectionStrings[ i ].name );
1377 if( strncmp( stringPosition, ElDBusAccessibilityDirectionStrings[ i ].name, matchLength ) == 0 )
1379 direction = ElDBusAccessibilityDirectionStrings[ i ].direction;
1380 stringPosition += matchLength;
1385 if( direction == GESTURE_DIRECTION_NONE )
1387 // ERROR: Gesture not recognised.
1392 // Action the detected gesture here.
1393 if( gestureType != GESTURE_TYPE_NONE )
1395 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d Gesture type: %d\n", fingers, gestureType );
1399 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d Gesture sub type: %d Gesture direction: %d\n",
1400 fingers, subGestureType, direction );
1403 // Create a touch point object.
1404 TouchPoint::State touchPointState( TouchPoint::Down );
1407 touchPointState = TouchPoint::Down; // Mouse down.
1409 else if ( state == 1 )
1411 touchPointState = TouchPoint::Motion; // Mouse move.
1413 else if ( state == 2 )
1415 touchPointState = TouchPoint::Up; // Mouse up.
1419 touchPointState = TouchPoint::Interrupted; // Error.
1422 // Send touch event to accessibility adaptor.
1423 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1425 // Perform actions based on received gestures.
1426 // Note: This is seperated from the reading so we can (in future)
1427 // have other input readers without changing the below code.
1432 if( gestureType == GESTURE_TYPE_SINGLE_TAP || ( gestureType == GESTURE_TYPE_HOVER && touchPointState == TouchPoint::Motion ) )
1435 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1437 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1439 if( false ) // TODO: how to detect double tap + hold?
1441 // Move or drag icon / view more options for selected items.
1442 // accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1446 // Activate selected item / active edit mode.
1447 accessibilityAdaptor->HandleActionActivateEvent();
1450 else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1453 accessibilityAdaptor->HandleActionZoomEvent();
1455 else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1457 if( direction == GESTURE_DIRECTION_LEFT )
1459 // Move to previous item.
1460 accessibilityAdaptor->HandleActionReadPreviousEvent();
1462 else if( direction == GESTURE_DIRECTION_RIGHT )
1464 // Move to next item.
1465 accessibilityAdaptor->HandleActionReadNextEvent();
1467 else if( direction == GESTURE_DIRECTION_UP )
1469 // Move to next item.
1470 accessibilityAdaptor->HandleActionPreviousEvent();
1472 else if( direction == GESTURE_DIRECTION_DOWN )
1474 // Move to next item.
1475 accessibilityAdaptor->HandleActionNextEvent();
1477 else if( direction == GESTURE_DIRECTION_LEFT_RETURN )
1479 // Scroll up to the previous page
1480 accessibilityAdaptor->HandleActionPageUpEvent();
1482 else if( direction == GESTURE_DIRECTION_RIGHT_RETURN )
1484 // Scroll down to the next page
1485 accessibilityAdaptor->HandleActionPageDownEvent();
1487 else if( direction == GESTURE_DIRECTION_UP_RETURN )
1489 // Move to the first item on screen
1490 accessibilityAdaptor->HandleActionMoveToFirstEvent();
1492 else if( direction == GESTURE_DIRECTION_DOWN_RETURN )
1494 // Move to the last item on screen
1495 accessibilityAdaptor->HandleActionMoveToLastEvent();
1503 if( gestureType == GESTURE_TYPE_HOVER )
1505 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1506 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1508 else if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1510 // Pause/Resume current speech
1511 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1513 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1515 // Start/Stop current action
1516 accessibilityAdaptor->HandleActionStartStopEvent();
1518 else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1520 // Read information from indicator
1521 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1523 else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1525 if( direction == GESTURE_DIRECTION_LEFT )
1527 // Scroll left to the previous page
1528 accessibilityAdaptor->HandleActionPageLeftEvent();
1530 else if( direction == GESTURE_DIRECTION_RIGHT )
1532 // Scroll right to the next page
1533 accessibilityAdaptor->HandleActionPageRightEvent();
1535 else if( direction == GESTURE_DIRECTION_UP )
1537 // Scroll up the list.
1538 accessibilityAdaptor->HandleActionScrollUpEvent();
1540 else if( direction == GESTURE_DIRECTION_DOWN )
1542 // Scroll down the list.
1543 accessibilityAdaptor->HandleActionScrollDownEvent();
1551 if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1553 // Read from top item on screen continuously.
1554 accessibilityAdaptor->HandleActionReadFromTopEvent();
1556 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1558 // Read from next item continuously.
1559 accessibilityAdaptor->HandleActionReadFromNextEvent();
1566 // Callback for to set up Ecore ElDBus for accessibility callbacks.
1567 static void EcoreElDBusInitialisation( void *handle, const Eldbus_Message *message, Eldbus_Pending *pending EINA_UNUSED )
1569 Eldbus_Object *object;
1570 Eldbus_Proxy *manager;
1571 const char *a11yBusAddress = NULL;
1572 EventHandler* handler = static_cast< EventHandler* >( handle );
1574 // The string defines the arg-list's respective types.
1575 if( !eldbus_message_arguments_get( message, "s", &a11yBusAddress ) )
1577 DALI_LOG_ERROR( "EcoreElDBusInitialisation: Error getting arguments\n" );
1580 DALI_LOG_INFO( gImfLogging, Debug::General, "Ecore ElDBus Accessibility address: %s\n", a11yBusAddress );
1582 handler->mImpl->mA11yConnection = eldbus_address_connection_get( a11yBusAddress );
1584 object = eldbus_object_get( handler->mImpl->mA11yConnection, BUS, PATH );
1585 manager = eldbus_proxy_get( object, INTERFACE );
1587 // Pass the callback data through to the signal handler.
1588 eldbus_proxy_signal_handler_add( manager, SIGNAL, OnEcoreElDBusAccessibilityNotification, handle );
1590 #endif // DALI_ELDBUS_AVAILABLE
1593 * Called when the source window notifies us the content in clipboard is selected.
1595 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1597 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1598 Ecore_X_Event_Selection_Clear* selectionClearEvent( (Ecore_X_Event_Selection_Clear*) event );
1599 EventHandler* handler( (EventHandler*)data );
1601 if ( selectionClearEvent->win == handler->mImpl->mWindow )
1603 if ( selectionClearEvent->selection == ECORE_X_SELECTION_SECONDARY )
1605 // Request to get the content from Ecore.
1606 ecore_x_selection_secondary_request(selectionClearEvent->win, ECORE_X_SELECTION_TARGET_TEXT);
1609 return ECORE_CALLBACK_PASS_ON;
1613 * Called when the source window sends us about the selected content.
1614 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1616 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1618 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1620 Ecore_X_Event_Selection_Notify* selectionNotifyEvent( (Ecore_X_Event_Selection_Notify*) event );
1621 EventHandler* handler( (EventHandler*)data );
1623 if ( selectionNotifyEvent->win == handler->mImpl->mWindow )
1625 Ecore_X_Selection_Data* selectionData( (Ecore_X_Selection_Data*) selectionNotifyEvent->data );
1626 if ( selectionData->data )
1628 if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_XDND )
1630 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
1632 // We have got the content that is to be dropped, inform the DndListener (if we have one).
1635 std::string content( (char*) selectionData->data, selectionData->length );
1636 dndDetector->SetContent( content );
1638 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1639 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1640 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1641 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1644 else if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_SECONDARY )
1646 // We have got the selected content, inform the clipboard event listener (if we have one).
1647 if ( handler->mClipboardEventNotifier )
1649 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1650 std::string content( (char*) selectionData->data, selectionData->length );
1651 clipboardEventNotifier.SetContent( content );
1652 clipboardEventNotifier.EmitContentSelectedSignal();
1655 // Claim the ownership of the SECONDARY selection.
1656 ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1658 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1659 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1660 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1661 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1665 return ECORE_CALLBACK_PASS_ON;
1669 #ifndef DALI_PROFILE_UBUNTU
1670 /////////////////////////////////////////////////////////////////////////////////////////////////
1672 /////////////////////////////////////////////////////////////////////////////////////////////////
1674 * Called when a font name is changed.
1676 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1678 EventHandler* handler = static_cast<EventHandler*>( data );
1679 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1683 * Called when a font size is changed.
1685 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1687 DALI_LOG_INFO(gTouchEventLogFilter, Debug::Verbose, "VconfNotifyFontSizeChanged\n" );
1688 EventHandler* handler = static_cast<EventHandler*>( data );
1689 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1691 #endif // DALI_PROFILE_UBUNTU
1694 EventHandler* mHandler;
1695 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1696 Ecore_X_Window mWindow;
1699 #ifdef DALI_ELDBUS_AVAILABLE
1700 Eldbus_Connection* mSessionConnection;
1701 Eldbus_Connection* mA11yConnection;
1705 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1706 : mCoreEventInterface( coreEventInterface ),
1707 mGestureManager( gestureManager ),
1708 mStyleMonitor( StyleMonitor::Get() ),
1709 mDamageObserver( damageObserver ),
1710 mRotationObserver( NULL ),
1711 mDragAndDropDetector( dndDetector ),
1712 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1713 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1714 mClipboard( Clipboard::Get() ),
1718 Ecore_X_Window window = 0;
1720 // this code only works with the EcoreX11 RenderSurface so need to downcast
1721 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1724 // enable multi touch
1725 window = ecoreSurface->GetXWindow();
1728 mImpl = new Impl(this, window);
1731 EventHandler::~EventHandler()
1735 mGestureManager.Stop();
1738 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1742 timeStamp = GetCurrentMilliSeconds();
1745 Integration::TouchEvent touchEvent;
1746 Integration::HoverEvent hoverEvent;
1747 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1748 if(type != Integration::TouchEventCombiner::DispatchNone )
1750 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);
1752 // First the touch and/or hover event & related gesture events are queued
1753 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1755 mCoreEventInterface.QueueCoreEvent( touchEvent );
1756 mGestureManager.SendEvent(touchEvent);
1759 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1761 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1764 // Next the events are processed with a single call into Core
1765 mCoreEventInterface.ProcessCoreEvents();
1769 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1771 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1772 if ( physicalKeyboard )
1774 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1776 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1780 // Send to KeyEvent Core.
1781 mCoreEventInterface.QueueCoreEvent( keyEvent );
1782 mCoreEventInterface.ProcessCoreEvents();
1785 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1787 // Create WheelEvent and send to Core.
1788 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1789 mCoreEventInterface.QueueCoreEvent( event );
1790 mCoreEventInterface.ProcessCoreEvents();
1793 void EventHandler::SendEvent( StyleChange::Type styleChange )
1795 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1796 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1799 void EventHandler::SendEvent( const DamageArea& area )
1801 mDamageObserver.OnDamaged( area );
1804 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1806 if( mRotationObserver != NULL )
1808 mRotationObserver->OnRotationPrepare( event );
1812 void EventHandler::SendRotationRequestEvent( )
1814 if( mRotationObserver != NULL )
1816 mRotationObserver->OnRotationRequest( );
1820 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1822 Integration::Point convertedPoint( point );
1824 SendEvent(convertedPoint, timeStamp);
1827 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1829 SendWheelEvent( wheelEvent );
1832 void EventHandler::FeedKeyEvent( KeyEvent& event )
1834 Integration::KeyEvent convertedEvent( event );
1835 SendEvent( convertedEvent );
1838 void EventHandler::FeedEvent( Integration::Event& event )
1840 mCoreEventInterface.QueueCoreEvent( event );
1841 mCoreEventInterface.ProcessCoreEvents();
1844 void EventHandler::Reset()
1848 // Any touch listeners should be told of the interruption.
1849 Integration::TouchEvent event;
1850 Integration::Point point;
1851 point.SetState( PointState::INTERRUPTED );
1852 event.AddPoint( point );
1854 // First the touch event & related gesture events are queued
1855 mCoreEventInterface.QueueCoreEvent( event );
1856 mGestureManager.SendEvent( event );
1858 // Next the events are processed with a single call into Core
1859 mCoreEventInterface.ProcessCoreEvents();
1862 void EventHandler::Pause()
1868 void EventHandler::Resume()
1874 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1876 mDragAndDropDetector = detector;
1879 void EventHandler::SetRotationObserver( RotationObserver* observer )
1881 mRotationObserver = observer;
1884 } // namespace Adaptor
1886 } // namespace Internal