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>
54 #include <events/gesture-manager.h>
55 #include <window-render-surface.h>
56 #include <clipboard-impl.h>
58 #include <physical-keyboard-impl.h>
59 #include <style-monitor-impl.h>
60 #include <base/core-event-interface.h>
71 #if defined(DEBUG_ENABLED)
74 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
75 Integration::Log::Filter* gClientMessageLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_CLIENT_MESSAGE");
76 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
77 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
78 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
79 } // unnamed namespace
86 const char * DETENT_DEVICE_NAME = "tizen_detent";
89 #define A11Y_BUS "org.a11y.Bus"
90 #define A11Y_INTERFACE "org.a11y.Bus"
91 #define A11Y_PATH "/org/a11y/bus"
92 #define A11Y_GET_ADDRESS "GetAddress"
93 #define BUS "com.samsung.EModule"
94 #define INTERFACE "com.samsung.GestureNavigation"
95 #define PATH "/com/samsung/GestureNavigation"
96 #define SIGNAL "GestureDetected"
98 #ifndef DALI_PROFILE_UBUNTU
99 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
100 #endif // DALI_PROFILE_UBUNTU
102 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
104 #ifndef DALI_PROFILE_UBUNTU
105 const char * CLIPBOARD_ATOM = "CBHM_MSG";
106 const char * CLIPBOARD_SET_OWNER_MESSAGE = "SET_OWNER";
107 #endif // DALI_PROFILE_UBUNTU
109 /// The atoms required by Ecore for Drag & Drop behaviour.
110 Ecore_X_Atom DRAG_AND_DROP_ATOMS[] =
112 ECORE_X_ATOM_XDND_ACTION_COPY,
115 /// The types that we support.
116 const char * DRAG_AND_DROP_TYPES[] =
118 ECORE_X_SELECTION_TARGET_UTF8_STRING,
121 const unsigned int DRAG_AND_DROP_ATOMS_NUMBER = sizeof( DRAG_AND_DROP_ATOMS ) / sizeof( Ecore_X_Atom );
122 const unsigned int DRAG_AND_DROP_TYPES_NUMBER = sizeof( DRAG_AND_DROP_TYPES ) / sizeof( const char * );
124 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
126 #ifdef DALI_ELDBUS_AVAILABLE
127 // DBus gesture string matching lists.
128 // TODO: This needs moving to its own module.
129 const char * ElDBusAccessibilityFingerCountStrings[] =
135 const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
140 GESTURE_TYPE_SINGLE_TAP,
141 GESTURE_TYPE_DOUBLE_TAP,
142 GESTURE_TYPE_TRIPLE_TAP
144 struct GestureTypeTable
147 const GestureType type;
149 GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
151 { "Hover", GESTURE_TYPE_HOVER },
152 { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
153 { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
154 { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
156 const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
159 SUB_GESTURE_TYPE_NONE,
160 SUB_GESTURE_TYPE_FLICK
162 struct SubGestureTypeTable
165 const SubGestureType type;
167 SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
169 { "Flick", SUB_GESTURE_TYPE_FLICK }
171 const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
172 enum GestureDirection
174 GESTURE_DIRECTION_NONE,
175 GESTURE_DIRECTION_UP,
176 GESTURE_DIRECTION_DOWN,
177 GESTURE_DIRECTION_LEFT,
178 GESTURE_DIRECTION_RIGHT,
179 GESTURE_DIRECTION_UP_RETURN,
180 GESTURE_DIRECTION_DOWN_RETURN,
181 GESTURE_DIRECTION_LEFT_RETURN,
182 GESTURE_DIRECTION_RIGHT_RETURN
184 struct GestureDirectionTable
187 const GestureDirection direction;
189 GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
191 { "Up", GESTURE_DIRECTION_UP },
192 { "Down", GESTURE_DIRECTION_DOWN },
193 { "Left", GESTURE_DIRECTION_LEFT },
194 { "Right", GESTURE_DIRECTION_RIGHT },
195 { "UpReturn", GESTURE_DIRECTION_UP_RETURN },
196 { "DownReturn", GESTURE_DIRECTION_DOWN_RETURN },
197 { "LeftReturn", GESTURE_DIRECTION_LEFT_RETURN },
198 { "RightReturn", GESTURE_DIRECTION_RIGHT_RETURN }
200 const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
201 #endif // DALI_ELDBUS_AVAILABLE
204 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
205 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
206 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
207 * @return the Ecore_IMF_Keyboard_Modifiers output.
209 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
211 int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
214 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
216 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
219 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
221 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
224 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
226 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
229 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
231 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
234 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
236 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
239 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
243 // Copied from x server
244 static unsigned int GetCurrentMilliSeconds(void)
249 static clockid_t clockid;
253 #ifdef CLOCK_MONOTONIC_COARSE
254 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
255 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
257 clockid = CLOCK_MONOTONIC_COARSE;
261 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
263 clockid = CLOCK_MONOTONIC;
270 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
272 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
275 gettimeofday(&tv, NULL);
276 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
279 } // unnamed namespace
281 // Impl to hide EFL implementation.
282 struct EventHandler::Impl
284 // Construction & Destruction
289 Impl( EventHandler* handler, Ecore_X_Window window )
290 : mHandler( handler ),
291 mEcoreEventHandler(),
294 #ifdef DALI_ELDBUS_AVAILABLE
295 , mSessionConnection( NULL ),
296 mA11yConnection( NULL )
299 // Only register for touch and key events if we have a window
302 // Register Touch events
303 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
304 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
305 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
306 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT, EcoreEventMouseButtonUp, handler ) ); // process mouse out event like up event
308 // Register Mouse wheel events
309 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
311 // Register Key events
312 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
313 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
315 // Register Focus events
316 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
317 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
319 // Register Window damage events
320 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_DAMAGE, EcoreEventWindowDamaged, handler ) );
322 // Enable Drag & Drop and register DnD events
323 ecore_x_dnd_aware_set( window, EINA_TRUE );
324 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_ENTER, EcoreEventDndEnter, handler) );
325 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_POSITION, EcoreEventDndPosition, handler) );
326 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_LEAVE, EcoreEventDndLeave, handler) );
327 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_DROP, EcoreEventDndDrop, handler) );
328 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_FINISHED, EcoreEventDndFinished, handler) );
329 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_STATUS, EcoreEventDndStatus, handler) );
331 // Register Client message events - accessibility etc.
332 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_CLIENT_MESSAGE, EcoreEventClientMessage, handler ) );
334 // Register Selection event - clipboard selection, Drag & Drop selection etc.
335 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_CLEAR, EcoreEventSelectionClear, handler ) );
336 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_NOTIFY, EcoreEventSelectionNotify, handler ) );
338 // Initialize Xi2 system
339 Display* display = static_cast< Display* >(ecore_x_display_get());
340 Ecore_X_Window rootWindow = ecore_x_window_root_first_get();
341 int opcode = 0, event = 0, error = 0;
342 int major = XI_2_Major;
343 int minor = XI_2_Minor;
345 XIEventMask xiEventMask;
347 // Check if X input extension available
348 if( XQueryExtension( display, "XInputExtension", &opcode, &event, &error ) )
350 // We support version 2.0
351 if( XIQueryVersion( display, &major, &minor ) != BadRequest )
353 xiEventMask.deviceid = XIAllDevices;
357 XIDeviceInfo* deviceInfo = NULL;
358 deviceInfo = XIQueryDevice( display, XIAllDevices, &deviceCount );
360 for( int i = 0; i < deviceCount; i++ )
362 if( !strncmp( deviceInfo[i].name, DETENT_DEVICE_NAME, strlen( DETENT_DEVICE_NAME ) ) )
364 xiEventMask.deviceid = deviceInfo[i].deviceid;
372 mXiDeviceId = xiEventMask.deviceid;
375 xiEventMask.mask = (unsigned char*)(calloc( 1, XIMaskLen( XI_LASTEVENT ) ) );
376 XISetMask( xiEventMask.mask, XI_RawMotion );
378 xiEventMask.mask_len = sizeof( xiEventMask.mask );
380 int ret = XISelectEvents( display, rootWindow, &xiEventMask, 1 );
383 // Register custom wheel events
384 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_GENERIC, EcoreEventCustomWheel, handler ) );
388 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to Select Events\n" );
391 free( xiEventMask.mask );
393 if( deviceInfo != NULL )
395 XIFreeDeviceInfo( deviceInfo );
401 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XI Version\n" );
406 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XInputExtension\n" );
409 #ifndef DALI_PROFILE_UBUNTU
410 // Register Vconf notify - font name, font size and style
411 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, handler );
412 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
413 #endif // DALI_PROFILE_UBUNTU
415 #ifdef DALI_ELDBUS_AVAILABLE
417 // Initialize ElDBus.
418 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization" );
421 mSessionConnection = eldbus_connection_get( ELDBUS_CONNECTION_TYPE_SESSION );
423 Eldbus_Object *a11yObject = eldbus_object_get( mSessionConnection, A11Y_BUS, A11Y_PATH );
424 Eldbus_Proxy *elDBusManager = eldbus_proxy_get( a11yObject, A11Y_INTERFACE );
426 // Pass in handler in the cb_data field so we can access the accessibility adaptor within the callback.
427 eldbus_proxy_call( elDBusManager, A11Y_GET_ADDRESS, EcoreElDBusInitialisation, handler, -1, "" );
429 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization" );
431 #endif // DALI_ELDBUS_AVAILABLE
440 #ifndef DALI_PROFILE_UBUNTU
441 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
442 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged );
443 #endif // DALI_PROFILE_UBUNTU
445 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
447 ecore_event_handler_del( *iter );
450 #ifdef DALI_ELDBUS_AVAILABLE
452 if( mA11yConnection )
454 eldbus_connection_unref( mA11yConnection );
457 if( mSessionConnection )
459 eldbus_connection_unref( mSessionConnection );
463 #endif // DALI_ELDBUS_AVAILABLE
468 /////////////////////////////////////////////////////////////////////////////////////////////////
470 /////////////////////////////////////////////////////////////////////////////////////////////////
473 * Called when a touch down is received.
475 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
477 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
478 EventHandler* handler( (EventHandler*)data );
480 if ( touchEvent->window == handler->mImpl->mWindow )
482 TouchPoint::State state ( TouchPoint::Down );
484 // Check if the buttons field is set and ensure it's the primary touch button.
485 // If this event was triggered by buttons other than the primary button (used for touch), then
486 // just send an interrupted event to Core.
487 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
489 state = TouchPoint::Interrupted;
492 TouchPoint point( touchEvent->multi.device, state, touchEvent->x, touchEvent->y );
493 handler->SendEvent( point, touchEvent->timestamp );
496 return ECORE_CALLBACK_PASS_ON;
500 * Called when a touch up is received.
502 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
504 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
505 EventHandler* handler( (EventHandler*)data );
507 if ( touchEvent->window == handler->mImpl->mWindow )
509 TouchPoint point( touchEvent->multi.device, TouchPoint::Up, touchEvent->x, touchEvent->y );
510 handler->SendEvent( point, touchEvent->timestamp );
513 return ECORE_CALLBACK_PASS_ON;
517 * Called when a touch motion is received.
519 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
521 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
522 EventHandler* handler( (EventHandler*)data );
524 if ( touchEvent->window == handler->mImpl->mWindow )
526 TouchPoint point( touchEvent->multi.device, TouchPoint::Motion, touchEvent->x, touchEvent->y );
527 handler->SendEvent( point, touchEvent->timestamp );
530 return ECORE_CALLBACK_PASS_ON;
533 /////////////////////////////////////////////////////////////////////////////////////////////////
535 /////////////////////////////////////////////////////////////////////////////////////////////////
538 * Called when a mouse wheel is received.
540 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
542 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
544 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 );
546 EventHandler* handler( (EventHandler*)data );
547 if ( mouseWheelEvent->window == handler->mImpl->mWindow )
549 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
550 handler->SendWheelEvent( wheelEvent );
552 return ECORE_CALLBACK_PASS_ON;
556 * Called when a custom wheel is received.
558 static Eina_Bool EcoreEventCustomWheel( void* data, int type, void* event )
560 Ecore_X_Event_Generic *genericEvent( (Ecore_X_Event_Generic*)event );
561 EventHandler* handler( (EventHandler*)data );
563 switch( genericEvent->evtype )
567 XIRawEvent* xiRawEvent = static_cast< XIRawEvent* >( genericEvent->data );
568 unsigned int timeStamp = 0;
570 if( xiRawEvent->deviceid != handler->mImpl->mXiDeviceId )
572 return ECORE_CALLBACK_PASS_ON;
575 // X(0): rotate: NOT USED
579 double* value = xiRawEvent->raw_values;
581 if( XIMaskIsSet( xiRawEvent->valuators.mask, 1) )
583 timeStamp = static_cast< unsigned int >( *(value + 1) );
586 if( XIMaskIsSet( xiRawEvent->valuators.mask, 2) )
588 // if z == 1, clockwise
589 // otherwise counter-clockwise
590 int z = static_cast< int >( *(value + 2) );
592 // In DALi, positive value means clockwise, and negative value means counter-clockwise
598 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventCustomWheel: z: %d\n", z );
600 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), z, timeStamp );
601 handler->SendWheelEvent( wheelEvent );
611 return ECORE_CALLBACK_PASS_ON;
614 /////////////////////////////////////////////////////////////////////////////////////////////////
616 /////////////////////////////////////////////////////////////////////////////////////////////////
619 * Called when a key down is received.
621 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
623 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
625 EventHandler* handler( (EventHandler*)data );
626 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
627 bool eventHandled( false );
629 // If a device key then skip ecore_imf_context_filter_event.
630 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
632 Ecore_IMF_Context* imfContext = NULL;
633 Dali::ImfManager imfManager( ImfManager::Get() );
636 imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
641 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
642 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
643 ecoreKeyDownEvent.keyname = keyEvent->keyname;
644 ecoreKeyDownEvent.key = keyEvent->key;
645 ecoreKeyDownEvent.string = keyEvent->string;
646 ecoreKeyDownEvent.compose = keyEvent->compose;
647 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
648 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
649 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
651 eventHandled = ecore_imf_context_filter_event( imfContext,
652 ECORE_IMF_EVENT_KEY_DOWN,
653 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
655 // If the event has not been handled by IMF then check if we should reset our IMF context
658 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
659 !strcmp( keyEvent->keyname, "Return" ) ||
660 !strcmp( keyEvent->keyname, "KP_Enter" ) )
662 ecore_imf_context_reset( imfContext );
668 // If the event wasn't handled then we should send a key event.
671 if ( keyEvent->window == handler->mImpl->mWindow )
673 std::string keyName( keyEvent->keyname );
674 std::string keyString( "" );
675 int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
676 int modifier( keyEvent->modifiers );
677 unsigned long time = keyEvent->timestamp;
679 // Ensure key event string is not NULL as keys like SHIFT have a null string.
680 if ( keyEvent->string )
682 keyString = keyEvent->string;
685 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Down);
686 handler->SendEvent( keyEvent );
690 return ECORE_CALLBACK_PASS_ON;
694 * Called when a key up is received.
696 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
698 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp \n" );
700 EventHandler* handler( (EventHandler*)data );
701 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
702 bool eventHandled( false );
704 // Menu, home, back button must skip ecore_imf_context_filter_event.
705 static const char* menuKeyName = KeyLookup::GetKeyName( DALI_KEY_MENU );
706 static const char* homeKeyName = KeyLookup::GetKeyName( DALI_KEY_HOME );
707 static const char* backKeyName = KeyLookup::GetKeyName( DALI_KEY_BACK );
708 if ( ( menuKeyName && strcmp( keyEvent->keyname, menuKeyName ) != 0 ) &&
709 ( homeKeyName && strcmp( keyEvent->keyname, homeKeyName ) != 0 ) &&
710 ( backKeyName && strcmp( keyEvent->keyname, backKeyName ) != 0 ) )
712 Ecore_IMF_Context* imfContext = NULL;
713 Dali::ImfManager imfManager( ImfManager::Get() );
716 imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
721 // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
722 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
723 ecoreKeyUpEvent.keyname = keyEvent->keyname;
724 ecoreKeyUpEvent.key = keyEvent->key;
725 ecoreKeyUpEvent.string = keyEvent->string;
726 ecoreKeyUpEvent.compose = keyEvent->compose;
727 ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
728 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
729 ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
731 eventHandled = ecore_imf_context_filter_event( imfContext,
732 ECORE_IMF_EVENT_KEY_UP,
733 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
737 // If the event wasn't handled then we should send a key event.
740 if ( keyEvent->window == handler->mImpl->mWindow )
742 std::string keyName( keyEvent->keyname );
743 std::string keyString( "" );
744 int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
745 int modifier( keyEvent->modifiers );
746 unsigned long time( keyEvent->timestamp );
748 // Ensure key event string is not NULL as keys like SHIFT have a null string.
749 if ( keyEvent->string )
751 keyString = keyEvent->string;
754 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
755 handler->SendEvent( keyEvent );
760 return ECORE_CALLBACK_PASS_ON;
763 /////////////////////////////////////////////////////////////////////////////////////////////////
765 /////////////////////////////////////////////////////////////////////////////////////////////////
768 * Called when the window gains focus.
770 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
772 Ecore_X_Event_Window_Focus_In* focusInEvent( (Ecore_X_Event_Window_Focus_In*)event );
773 EventHandler* handler( (EventHandler*)data );
775 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
777 // If the window gains focus and we hid the keyboard then show it again.
778 if ( focusInEvent->win == handler->mImpl->mWindow )
780 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
782 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
784 Dali::ImfManager imfManager( ImfManager::Get() );
787 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
788 if( imfManagerImpl.RestoreAfterFocusLost() )
790 imfManagerImpl.Activate();
794 // No need to connect callbacks as KeyboardStatusChanged will be called.
797 return ECORE_CALLBACK_PASS_ON;
801 * Called when the window loses focus.
803 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
805 Ecore_X_Event_Window_Focus_Out* focusOutEvent( (Ecore_X_Event_Window_Focus_Out*)event );
806 EventHandler* handler( (EventHandler*)data );
808 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
810 // If the window loses focus then hide the keyboard.
811 if ( focusOutEvent->win == handler->mImpl->mWindow )
813 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
815 Dali::ImfManager imfManager( ImfManager::Get() );
818 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
819 if( imfManagerImpl.RestoreAfterFocusLost() )
821 imfManagerImpl.Deactivate();
826 // Clipboard don't support that whether clipboard is shown or not. Hide clipboard.
827 Dali::Clipboard clipboard = Clipboard::Get();
828 clipboard.HideClipboard();
831 return ECORE_CALLBACK_PASS_ON;
835 * Called when the window is damaged.
837 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
839 Ecore_X_Event_Window_Damage* windowDamagedEvent( (Ecore_X_Event_Window_Damage*)event );
840 EventHandler* handler( (EventHandler*)data );
842 if( windowDamagedEvent->win == handler->mImpl->mWindow )
845 area.x = windowDamagedEvent->x;
846 area.y = windowDamagedEvent->y;
847 area.width = windowDamagedEvent->w;
848 area.height = windowDamagedEvent->h;
850 handler->SendEvent( area );
853 return ECORE_CALLBACK_PASS_ON;
857 * Called when the window properties are changed.
858 * We are only interested in the font change.
862 /////////////////////////////////////////////////////////////////////////////////////////////////
863 // Drag & Drop Callbacks
864 /////////////////////////////////////////////////////////////////////////////////////////////////
867 * Called when a dragged item enters our window's bounds.
868 * This is when items are dragged INTO our window.
870 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
872 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
874 Ecore_X_Event_Xdnd_Enter* enterEvent( (Ecore_X_Event_Xdnd_Enter*) event );
875 EventHandler* handler( (EventHandler*)data );
876 Ecore_X_Window window ( handler->mImpl->mWindow );
878 if ( enterEvent->win == window )
880 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
882 // Check whether the Drag & Drop detector has Drag & Drop behaviour enabled before we accept.
883 if ( dndDetector && dndDetector->IsEnabled() )
885 // Tell Ecore that we want to enable drop in the entire window.
886 Ecore_X_Rectangle rect;
888 ecore_x_window_geometry_get( window, NULL, NULL, (int*)&rect.width, (int*)&rect.height );
890 // Tell Ecore that we are able to process a drop.
891 ecore_x_dnd_send_status( EINA_TRUE, EINA_FALSE, rect, ECORE_X_ATOM_XDND_DROP );
893 // Register the required atoms and types.
894 ecore_x_dnd_actions_set( window, DRAG_AND_DROP_ATOMS, DRAG_AND_DROP_ATOMS_NUMBER );
895 ecore_x_dnd_types_set( window, DRAG_AND_DROP_TYPES, DRAG_AND_DROP_TYPES_NUMBER );
897 // Request to get the content from Ecore.
898 ecore_x_selection_xdnd_request( window, ECORE_X_SELECTION_TARGET_UTF8_STRING );
900 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndEnter: Requesting Drag & Drop\n" );
902 // Clear the previous content
903 dndDetector->ClearContent();
905 // Emit the entered signal
906 dndDetector->EmitEnteredSignal();
910 return ECORE_CALLBACK_PASS_ON;
914 * Called when a dragged item is moved within our window.
915 * This is when items are dragged INTO our window.
917 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
919 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
921 Ecore_X_Event_Xdnd_Position* positionEvent( (Ecore_X_Event_Xdnd_Position*) event );
922 EventHandler* handler( (EventHandler*)data );
924 if ( positionEvent->win == handler->mImpl->mWindow )
926 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
928 // If we have a detector then update its latest position.
931 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndPosition: position ( %d x %d )\n", positionEvent->position.x, positionEvent->position.y );
932 dndDetector->SetPosition( Vector2( positionEvent->position.x, positionEvent->position.y ));
933 dndDetector->EmitMovedSignal();
937 return ECORE_CALLBACK_PASS_ON;
941 * Called when a dragged item leaves our window's bounds.
942 * This is when items are dragged INTO our window.
944 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
946 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
948 Ecore_X_Event_Xdnd_Leave* leaveEvent( (Ecore_X_Event_Xdnd_Leave*) event );
949 EventHandler* handler( (EventHandler*)data );
951 if ( leaveEvent->win == handler->mImpl->mWindow )
953 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
955 // If we have a detector then clear its content and emit the exited-signal. Also tell Ecore that we have finished.
958 dndDetector->ClearContent();
959 dndDetector->EmitExitedSignal();
961 ecore_x_dnd_send_finished();
963 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndLeave: Finished\n" );
967 return ECORE_CALLBACK_PASS_ON;
971 * Called when the dragged item is dropped within our window's bounds.
972 * This is when items are dragged INTO our window.
974 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
976 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
978 Ecore_X_Event_Xdnd_Drop* dropEvent ( (Ecore_X_Event_Xdnd_Drop*) event);
979 EventHandler* handler( (EventHandler*)data );
981 if ( dropEvent->win == handler->mImpl->mWindow )
983 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
985 // Something has been dropped, inform the detector (if we have one) and tell Ecore that we have finished.
988 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: position ( %d x %d )\n", dropEvent->position.x, dropEvent->position.y );
990 dndDetector->SetPosition( Vector2( dropEvent->position.x, dropEvent->position.y ) );
991 dndDetector->EmitDroppedSignal();
992 ecore_x_dnd_send_finished();
994 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: Finished\n" );
998 return ECORE_CALLBACK_PASS_ON;
1002 * Called when a dragged item is moved from our window and the target window has done processing it.
1003 * This is when items are dragged FROM our window.
1005 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
1007 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
1008 return ECORE_CALLBACK_PASS_ON;
1012 * Called when a dragged item is moved from our window and the target window has sent us a status.
1013 * This is when items are dragged FROM our window.
1015 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
1017 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
1018 return ECORE_CALLBACK_PASS_ON;
1022 * Called when the client messages (i.e. the accessibility events) are received.
1024 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
1026 #ifndef DALI_PROFILE_UBUNTU
1027 Ecore_X_Event_Client_Message* clientMessageEvent( (Ecore_X_Event_Client_Message*)event );
1028 EventHandler* handler( (EventHandler*)data );
1030 if (clientMessageEvent->message_type == ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL)
1032 if ( ( (unsigned int)clientMessageEvent->data.l[0] == handler->mImpl->mWindow ) && handler->mAccessibilityAdaptor )
1034 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1036 if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_SCROLL)
1038 // 2 finger touch & move, 2 finger flick
1040 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1043 TouchPoint::State state(TouchPoint::Down);
1045 if ((unsigned int)clientMessageEvent->data.l[2] == 0)
1047 state = TouchPoint::Down; // mouse down
1049 else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
1051 state = TouchPoint::Motion; // mouse move
1053 else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
1055 state = TouchPoint::Up; // mouse up
1059 state = TouchPoint::Interrupted; // error
1062 DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1063 "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1064 (unsigned int)clientMessageEvent->data.l[2],
1065 (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1067 // Send touch event to accessibility adaptor.
1068 TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1070 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1071 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1073 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_MOUSE)
1075 // 1 finger double tap and hold
1077 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1080 TouchPoint::State state(TouchPoint::Down);
1082 if ((unsigned int)clientMessageEvent->data.l[2] == 0)
1084 state = TouchPoint::Down; // mouse down
1086 else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
1088 state = TouchPoint::Motion; // mouse move
1090 else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
1092 state = TouchPoint::Up; // mouse up
1096 state = TouchPoint::Interrupted; // error
1099 DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1100 "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1101 (unsigned int)clientMessageEvent->data.l[2],
1102 (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1104 // Send touch event to accessibility adaptor.
1105 TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1107 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1108 accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1110 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_BACK)
1112 // 2 finger circle draw, do back
1113 accessibilityAdaptor->HandleActionBackEvent();
1115 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_NEXT)
1117 // one finger flick down
1118 // focus next object
1119 if(accessibilityAdaptor)
1121 accessibilityAdaptor->HandleActionNextEvent();
1124 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_PREV)
1126 // one finger flick up
1127 // focus previous object
1128 if(accessibilityAdaptor)
1130 accessibilityAdaptor->HandleActionPreviousEvent();
1133 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE)
1135 // one finger double tap
1136 // same as one finger tap in normal mode (i.e. execute focused actor)
1137 if(accessibilityAdaptor)
1139 accessibilityAdaptor->HandleActionActivateEvent();
1142 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ)
1145 // focus & read an actor at ( e->data.l[2], e->data.l[3] ) position according to finger
1146 if(accessibilityAdaptor)
1148 accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[2], (unsigned int)clientMessageEvent->data.l[3], true /* allow read again*/);
1151 #if defined(DALI_PROFILE_MOBILE)
1152 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_OVER)
1154 // one finger tap & move
1155 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1158 // focus & read an actor at (x, y) position according to finger
1159 if(accessibilityAdaptor && (unsigned int)clientMessageEvent->data.l[2] == 1 /*only work for move event*/)
1161 accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4], false /* not allow read again*/);
1165 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_NEXT)
1167 // one finger flick right
1168 // focus next object
1169 if(accessibilityAdaptor)
1171 accessibilityAdaptor->HandleActionReadNextEvent();
1174 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_PREV)
1176 // one finger flick left
1177 // focus previous object
1178 if(accessibilityAdaptor)
1180 accessibilityAdaptor->HandleActionReadPreviousEvent();
1183 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_UP)
1185 // double down and move (right, up)
1186 // change slider value
1187 if(accessibilityAdaptor)
1189 accessibilityAdaptor->HandleActionUpEvent();
1192 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DOWN)
1194 // double down and move (left, down)
1195 // change slider value
1196 if(accessibilityAdaptor)
1198 accessibilityAdaptor->HandleActionDownEvent();
1201 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ENABLE)
1203 if(accessibilityAdaptor)
1205 accessibilityAdaptor->HandleActionEnableEvent();
1208 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DISABLE)
1210 if(accessibilityAdaptor)
1212 accessibilityAdaptor->HandleActionDisableEvent();
1215 // TODO: some more actions could be added later
1218 else if(clientMessageEvent->message_type == ecore_x_atom_get(CLIPBOARD_ATOM))
1220 std::string message(clientMessageEvent->data.b);
1221 if( message == CLIPBOARD_SET_OWNER_MESSAGE)
1223 // Claim the ownership of the SECONDARY selection.
1224 ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1226 // Show the clipboard window
1227 Dali::Clipboard clipboard = Dali::Clipboard::Get();
1228 clipboard.ShowClipboard();
1231 else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_PREPARE )
1233 RotationEvent rotationEvent;
1234 rotationEvent.angle = static_cast<int>(clientMessageEvent->data.l[1]);
1235 rotationEvent.winResize = static_cast<int>(clientMessageEvent->data.l[2]);
1236 rotationEvent.width = static_cast<int>(clientMessageEvent->data.l[3]);
1237 rotationEvent.height = static_cast<int>(clientMessageEvent->data.l[4]);
1238 handler->SendRotationPrepareEvent( rotationEvent );
1240 else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_REQUEST )
1242 handler->SendRotationRequestEvent();
1245 #endif // DALI_PROFILE_UBUNTU
1246 return ECORE_CALLBACK_PASS_ON;
1250 /////////////////////////////////////////////////////////////////////////////////////////////////
1251 // ElDBus Accessibility Callbacks
1252 /////////////////////////////////////////////////////////////////////////////////////////////////
1254 #ifdef DALI_ELDBUS_AVAILABLE
1255 // Callback for Ecore ElDBus accessibility events.
1256 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
1258 EventHandler* handler( (EventHandler*)context );
1260 if ( !handler->mAccessibilityAdaptor )
1262 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
1266 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1267 if ( !accessibilityAdaptor )
1269 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
1273 const char *gestureName;
1277 // The string defines the arg-list's respective types.
1278 if( !eldbus_message_arguments_get( message, "siiiiu", &gestureName, &xS, &yS, &xE, &yE, &state ) )
1280 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1283 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %s Args: %d,%d,%d,%d State: %d\n", gestureName, xS, yS, xE, yE );
1285 unsigned int fingers = 0;
1286 char* stringPosition = ( char* )gestureName;
1288 // Check how many fingers the gesture uses.
1289 for( unsigned int i = 0; i < FingerCountStringsTotal; ++i )
1291 unsigned int matchLength = strlen( ElDBusAccessibilityFingerCountStrings[ i ] );
1292 if( strncmp( gestureName, ElDBusAccessibilityFingerCountStrings[ i ], matchLength ) == 0 )
1295 stringPosition += matchLength;
1302 // Error: invalid gesture.
1306 GestureType gestureType = GESTURE_TYPE_NONE;
1307 SubGestureType subGestureType = SUB_GESTURE_TYPE_NONE;
1308 GestureDirection direction = GESTURE_DIRECTION_NONE;
1310 // Check for full gesture type names first.
1311 for( unsigned int i = 0; i < FullEventTypeStringsTotal; ++i )
1313 unsigned int matchLength = strlen( ElDBusAccessibilityFullEventTypeStrings[ i ].name );
1314 if( strncmp( stringPosition, ElDBusAccessibilityFullEventTypeStrings[ i ].name, matchLength ) == 0 )
1316 gestureType = ElDBusAccessibilityFullEventTypeStrings[ i ].type;
1321 // If we didn't find a full gesture, check for sub gesture type names.
1322 if( gestureType == GESTURE_TYPE_NONE )
1324 // No full gesture name found, look for partial types.
1325 for( unsigned int i = 0; i < DirectionalEventTypeStringsTotal; ++i )
1327 unsigned int matchLength = strlen( ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name );
1328 if( strncmp( stringPosition, ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name, matchLength ) == 0 )
1330 subGestureType = ElDBusAccessibilityDirectionalEventTypeStrings[ i ].type;
1331 stringPosition += matchLength;
1336 if( subGestureType == SUB_GESTURE_TYPE_NONE )
1338 // ERROR: Gesture not recognised.
1342 // If the gesture was a sub type, get it's respective direction.
1343 for( unsigned int i = 0; i < DirectionStringsTotal; ++i )
1345 unsigned int matchLength = strlen( ElDBusAccessibilityDirectionStrings[ i ].name );
1346 if( strncmp( stringPosition, ElDBusAccessibilityDirectionStrings[ i ].name, matchLength ) == 0 )
1348 direction = ElDBusAccessibilityDirectionStrings[ i ].direction;
1349 stringPosition += matchLength;
1354 if( direction == GESTURE_DIRECTION_NONE )
1356 // ERROR: Gesture not recognised.
1361 // Action the detected gesture here.
1362 if( gestureType != GESTURE_TYPE_NONE )
1364 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d Gesture type: %d\n", fingers, gestureType );
1368 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d Gesture sub type: %d Gesture direction: %d\n",
1369 fingers, subGestureType, direction );
1372 // Create a touch point object.
1373 TouchPoint::State touchPointState( TouchPoint::Down );
1376 touchPointState = TouchPoint::Down; // Mouse down.
1378 else if ( state == 1 )
1380 touchPointState = TouchPoint::Motion; // Mouse move.
1382 else if ( state == 2 )
1384 touchPointState = TouchPoint::Up; // Mouse up.
1388 touchPointState = TouchPoint::Interrupted; // Error.
1391 // Send touch event to accessibility adaptor.
1392 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1394 // Perform actions based on received gestures.
1395 // Note: This is seperated from the reading so we can (in future)
1396 // have other input readers without changing the below code.
1401 if( gestureType == GESTURE_TYPE_SINGLE_TAP || ( gestureType == GESTURE_TYPE_HOVER && touchPointState == TouchPoint::Motion ) )
1404 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1406 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1408 if( false ) // TODO: how to detect double tap + hold?
1410 // Move or drag icon / view more options for selected items.
1411 // accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1415 // Activate selected item / active edit mode.
1416 accessibilityAdaptor->HandleActionActivateEvent();
1419 else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1422 accessibilityAdaptor->HandleActionZoomEvent();
1424 else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1426 if( direction == GESTURE_DIRECTION_LEFT )
1428 // Move to previous item.
1429 accessibilityAdaptor->HandleActionReadPreviousEvent();
1431 else if( direction == GESTURE_DIRECTION_RIGHT )
1433 // Move to next item.
1434 accessibilityAdaptor->HandleActionReadNextEvent();
1436 else if( direction == GESTURE_DIRECTION_UP )
1438 // Move to next item.
1439 accessibilityAdaptor->HandleActionPreviousEvent();
1441 else if( direction == GESTURE_DIRECTION_DOWN )
1443 // Move to next item.
1444 accessibilityAdaptor->HandleActionNextEvent();
1446 else if( direction == GESTURE_DIRECTION_LEFT_RETURN )
1448 // Scroll up to the previous page
1449 accessibilityAdaptor->HandleActionPageUpEvent();
1451 else if( direction == GESTURE_DIRECTION_RIGHT_RETURN )
1453 // Scroll down to the next page
1454 accessibilityAdaptor->HandleActionPageDownEvent();
1456 else if( direction == GESTURE_DIRECTION_UP_RETURN )
1458 // Move to the first item on screen
1459 accessibilityAdaptor->HandleActionMoveToFirstEvent();
1461 else if( direction == GESTURE_DIRECTION_DOWN_RETURN )
1463 // Move to the last item on screen
1464 accessibilityAdaptor->HandleActionMoveToLastEvent();
1472 if( gestureType == GESTURE_TYPE_HOVER )
1474 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1475 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1477 else if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1479 // Pause/Resume current speech
1480 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1482 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1484 // Start/Stop current action
1485 accessibilityAdaptor->HandleActionStartStopEvent();
1487 else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1489 // Read information from indicator
1490 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1492 else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1494 if( direction == GESTURE_DIRECTION_LEFT )
1496 // Scroll left to the previous page
1497 accessibilityAdaptor->HandleActionPageLeftEvent();
1499 else if( direction == GESTURE_DIRECTION_RIGHT )
1501 // Scroll right to the next page
1502 accessibilityAdaptor->HandleActionPageRightEvent();
1504 else if( direction == GESTURE_DIRECTION_UP )
1506 // Scroll up the list.
1507 accessibilityAdaptor->HandleActionScrollUpEvent();
1509 else if( direction == GESTURE_DIRECTION_DOWN )
1511 // Scroll down the list.
1512 accessibilityAdaptor->HandleActionScrollDownEvent();
1520 if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1522 // Read from top item on screen continuously.
1523 accessibilityAdaptor->HandleActionReadFromTopEvent();
1525 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1527 // Read from next item continuously.
1528 accessibilityAdaptor->HandleActionReadFromNextEvent();
1535 // Callback for to set up Ecore ElDBus for accessibility callbacks.
1536 static void EcoreElDBusInitialisation( void *handle, const Eldbus_Message *message, Eldbus_Pending *pending EINA_UNUSED )
1538 Eldbus_Object *object;
1539 Eldbus_Proxy *manager;
1540 const char *a11yBusAddress = NULL;
1541 EventHandler* handler = static_cast< EventHandler* >( handle );
1543 // The string defines the arg-list's respective types.
1544 if( !eldbus_message_arguments_get( message, "s", &a11yBusAddress ) )
1546 DALI_LOG_ERROR( "EcoreElDBusInitialisation: Error getting arguments\n" );
1549 DALI_LOG_INFO( gImfLogging, Debug::General, "Ecore ElDBus Accessibility address: %s\n", a11yBusAddress );
1551 handler->mImpl->mA11yConnection = eldbus_address_connection_get( a11yBusAddress );
1553 object = eldbus_object_get( handler->mImpl->mA11yConnection, BUS, PATH );
1554 manager = eldbus_proxy_get( object, INTERFACE );
1556 // Pass the callback data through to the signal handler.
1557 eldbus_proxy_signal_handler_add( manager, SIGNAL, OnEcoreElDBusAccessibilityNotification, handle );
1559 #endif // DALI_ELDBUS_AVAILABLE
1562 * Called when the source window notifies us the content in clipboard is selected.
1564 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1566 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1567 Ecore_X_Event_Selection_Clear* selectionClearEvent( (Ecore_X_Event_Selection_Clear*) event );
1568 EventHandler* handler( (EventHandler*)data );
1570 if ( selectionClearEvent->win == handler->mImpl->mWindow )
1572 if ( selectionClearEvent->selection == ECORE_X_SELECTION_SECONDARY )
1574 // Request to get the content from Ecore.
1575 ecore_x_selection_secondary_request(selectionClearEvent->win, ECORE_X_SELECTION_TARGET_TEXT);
1578 return ECORE_CALLBACK_PASS_ON;
1582 * Called when the source window sends us about the selected content.
1583 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1585 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1587 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1589 Ecore_X_Event_Selection_Notify* selectionNotifyEvent( (Ecore_X_Event_Selection_Notify*) event );
1590 EventHandler* handler( (EventHandler*)data );
1592 if ( selectionNotifyEvent->win == handler->mImpl->mWindow )
1594 Ecore_X_Selection_Data* selectionData( (Ecore_X_Selection_Data*) selectionNotifyEvent->data );
1595 if ( selectionData->data )
1597 if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_XDND )
1599 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
1601 // We have got the content that is to be dropped, inform the DndListener (if we have one).
1604 std::string content( (char*) selectionData->data, selectionData->length );
1605 dndDetector->SetContent( content );
1607 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1608 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1609 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1610 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1613 else if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_SECONDARY )
1615 // We have got the selected content, inform the clipboard event listener (if we have one).
1616 if ( handler->mClipboardEventNotifier )
1618 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1619 std::string content( (char*) selectionData->data, selectionData->length );
1620 clipboardEventNotifier.SetContent( content );
1621 clipboardEventNotifier.EmitContentSelectedSignal();
1624 // Claim the ownership of the SECONDARY selection.
1625 ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1627 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1628 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1629 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1630 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1634 return ECORE_CALLBACK_PASS_ON;
1638 #ifndef DALI_PROFILE_UBUNTU
1639 /////////////////////////////////////////////////////////////////////////////////////////////////
1641 /////////////////////////////////////////////////////////////////////////////////////////////////
1643 * Called when a font name is changed.
1645 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1647 EventHandler* handler = static_cast<EventHandler*>( data );
1648 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1652 * Called when a font size is changed.
1654 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1656 EventHandler* handler = static_cast<EventHandler*>( data );
1657 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1659 #endif // DALI_PROFILE_UBUNTU
1662 EventHandler* mHandler;
1663 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1664 Ecore_X_Window mWindow;
1667 #ifdef DALI_ELDBUS_AVAILABLE
1668 Eldbus_Connection* mSessionConnection;
1669 Eldbus_Connection* mA11yConnection;
1673 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1674 : mCoreEventInterface(coreEventInterface),
1675 mGestureManager( gestureManager ),
1676 mStyleMonitor( StyleMonitor::Get() ),
1677 mDamageObserver( damageObserver ),
1678 mRotationObserver( NULL ),
1679 mDragAndDropDetector( dndDetector ),
1680 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1681 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1682 mClipboard(Clipboard::Get()),
1685 Ecore_X_Window window = 0;
1687 // this code only works with the EcoreX11 RenderSurface so need to downcast
1688 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1691 // enable multi touch
1692 window = ecoreSurface->GetXWindow();
1695 mImpl = new Impl(this, window);
1698 EventHandler::~EventHandler()
1705 mGestureManager.Stop();
1708 void EventHandler::SendEvent(TouchPoint& point, unsigned long timeStamp)
1712 timeStamp = GetCurrentMilliSeconds();
1715 Integration::TouchEvent touchEvent;
1716 Integration::HoverEvent hoverEvent;
1717 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1718 if(type != Integration::TouchEventCombiner::DispatchNone )
1720 DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.deviceId, point.state, point.local.x, point.local.y);
1722 // First the touch and/or hover event & related gesture events are queued
1723 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1725 mCoreEventInterface.QueueCoreEvent( touchEvent );
1726 mGestureManager.SendEvent(touchEvent);
1729 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1731 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1734 // Next the events are processed with a single call into Core
1735 mCoreEventInterface.ProcessCoreEvents();
1739 void EventHandler::SendEvent(KeyEvent& keyEvent)
1741 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1742 if ( physicalKeyboard )
1744 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
1746 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1750 // Create KeyEvent and send to Core.
1751 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
1752 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
1753 mCoreEventInterface.QueueCoreEvent( event );
1754 mCoreEventInterface.ProcessCoreEvents();
1757 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1759 // Create WheelEvent and send to Core.
1760 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1761 mCoreEventInterface.QueueCoreEvent( event );
1762 mCoreEventInterface.ProcessCoreEvents();
1765 void EventHandler::SendEvent( StyleChange::Type styleChange )
1767 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1768 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1771 void EventHandler::SendEvent( const DamageArea& area )
1773 mDamageObserver.OnDamaged( area );
1776 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1778 if( mRotationObserver != NULL )
1780 mRotationObserver->OnRotationPrepare( event );
1784 void EventHandler::SendRotationRequestEvent( )
1786 if( mRotationObserver != NULL )
1788 mRotationObserver->OnRotationRequest( );
1792 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1794 SendEvent(point, timeStamp);
1797 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1799 SendWheelEvent( wheelEvent );
1802 void EventHandler::FeedKeyEvent( KeyEvent& event )
1807 void EventHandler::FeedEvent( Integration::Event& event )
1809 mCoreEventInterface.QueueCoreEvent( event );
1810 mCoreEventInterface.ProcessCoreEvents();
1813 void EventHandler::Reset()
1817 // Any touch listeners should be told of the interruption.
1818 Integration::TouchEvent event;
1819 TouchPoint point(0, TouchPoint::Interrupted, 0, 0);
1820 event.AddPoint( point );
1822 // First the touch event & related gesture events are queued
1823 mCoreEventInterface.QueueCoreEvent( event );
1824 mGestureManager.SendEvent( event );
1826 // Next the events are processed with a single call into Core
1827 mCoreEventInterface.ProcessCoreEvents();
1830 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1832 mDragAndDropDetector = detector;
1835 void EventHandler::SetRotationObserver( RotationObserver* observer )
1837 mRotationObserver = observer;
1840 } // namespace Adaptor
1842 } // namespace Internal