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 Dali::Vector< unsigned char > mask;
376 std::size_t xiMaskLen = XIMaskLen( XI_LASTEVENT );
377 mask.Reserve( xiMaskLen );
378 xiEventMask.mask = mask.Begin();
380 XISetMask( xiEventMask.mask, XI_RawMotion );
382 xiEventMask.mask_len = xiMaskLen * sizeof( unsigned char );
384 int ret = XISelectEvents( display, rootWindow, &xiEventMask, 1 );
387 // Register custom wheel events
388 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_GENERIC, EcoreEventCustomWheel, handler ) );
392 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to Select Events\n" );
396 if( deviceInfo != NULL )
398 XIFreeDeviceInfo( deviceInfo );
403 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XI Version\n" );
408 DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XInputExtension\n" );
411 #ifndef DALI_PROFILE_UBUNTU
412 // Register Vconf notify - font name, font size and style
413 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, handler );
414 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
415 #endif // DALI_PROFILE_UBUNTU
417 #ifdef DALI_ELDBUS_AVAILABLE
419 // Initialize ElDBus.
420 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization" );
423 mSessionConnection = eldbus_connection_get( ELDBUS_CONNECTION_TYPE_SESSION );
425 Eldbus_Object *a11yObject = eldbus_object_get( mSessionConnection, A11Y_BUS, A11Y_PATH );
426 Eldbus_Proxy *elDBusManager = eldbus_proxy_get( a11yObject, A11Y_INTERFACE );
428 // Pass in handler in the cb_data field so we can access the accessibility adaptor within the callback.
429 eldbus_proxy_call( elDBusManager, A11Y_GET_ADDRESS, EcoreElDBusInitialisation, handler, -1, "" );
431 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization" );
433 #endif // DALI_ELDBUS_AVAILABLE
442 #ifndef DALI_PROFILE_UBUNTU
443 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
444 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged );
445 #endif // DALI_PROFILE_UBUNTU
447 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
449 ecore_event_handler_del( *iter );
452 #ifdef DALI_ELDBUS_AVAILABLE
454 if( mA11yConnection )
456 eldbus_connection_unref( mA11yConnection );
459 if( mSessionConnection )
461 eldbus_connection_unref( mSessionConnection );
465 #endif // DALI_ELDBUS_AVAILABLE
470 /////////////////////////////////////////////////////////////////////////////////////////////////
472 /////////////////////////////////////////////////////////////////////////////////////////////////
475 * Called when a touch down is received.
477 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
479 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
480 EventHandler* handler( (EventHandler*)data );
482 if ( touchEvent->window == handler->mImpl->mWindow )
484 TouchPoint::State state ( TouchPoint::Down );
486 // Check if the buttons field is set and ensure it's the primary touch button.
487 // If this event was triggered by buttons other than the primary button (used for touch), then
488 // just send an interrupted event to Core.
489 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
491 state = TouchPoint::Interrupted;
494 TouchPoint point( touchEvent->multi.device, state, touchEvent->x, touchEvent->y );
495 handler->SendEvent( point, touchEvent->timestamp );
498 return ECORE_CALLBACK_PASS_ON;
502 * Called when a touch up is received.
504 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
506 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
507 EventHandler* handler( (EventHandler*)data );
509 if ( touchEvent->window == handler->mImpl->mWindow )
511 TouchPoint point( touchEvent->multi.device, TouchPoint::Up, touchEvent->x, touchEvent->y );
512 handler->SendEvent( point, touchEvent->timestamp );
515 return ECORE_CALLBACK_PASS_ON;
519 * Called when a touch motion is received.
521 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
523 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
524 EventHandler* handler( (EventHandler*)data );
526 if ( touchEvent->window == handler->mImpl->mWindow )
528 TouchPoint point( touchEvent->multi.device, TouchPoint::Motion, touchEvent->x, touchEvent->y );
529 handler->SendEvent( point, touchEvent->timestamp );
532 return ECORE_CALLBACK_PASS_ON;
535 /////////////////////////////////////////////////////////////////////////////////////////////////
537 /////////////////////////////////////////////////////////////////////////////////////////////////
540 * Called when a mouse wheel is received.
542 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
544 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
546 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 );
548 EventHandler* handler( (EventHandler*)data );
549 if ( mouseWheelEvent->window == handler->mImpl->mWindow )
551 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
552 handler->SendWheelEvent( wheelEvent );
554 return ECORE_CALLBACK_PASS_ON;
558 * Called when a custom wheel is received.
560 static Eina_Bool EcoreEventCustomWheel( void* data, int type, void* event )
562 Ecore_X_Event_Generic *genericEvent( (Ecore_X_Event_Generic*)event );
563 EventHandler* handler( (EventHandler*)data );
565 switch( genericEvent->evtype )
569 XIRawEvent* xiRawEvent = static_cast< XIRawEvent* >( genericEvent->data );
570 unsigned int timeStamp = 0;
572 if( xiRawEvent->deviceid != handler->mImpl->mXiDeviceId )
574 return ECORE_CALLBACK_PASS_ON;
577 // X(0): rotate: NOT USED
581 double* value = xiRawEvent->raw_values;
583 if( XIMaskIsSet( xiRawEvent->valuators.mask, 1) )
585 timeStamp = static_cast< unsigned int >( *(value + 1) );
588 if( XIMaskIsSet( xiRawEvent->valuators.mask, 2) )
590 // if z == 1, clockwise
591 // otherwise counter-clockwise
592 int z = static_cast< int >( *(value + 2) );
594 // In DALi, positive value means clockwise, and negative value means counter-clockwise
600 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventCustomWheel: z: %d\n", z );
602 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), z, timeStamp );
603 handler->SendWheelEvent( wheelEvent );
613 return ECORE_CALLBACK_PASS_ON;
616 /////////////////////////////////////////////////////////////////////////////////////////////////
618 /////////////////////////////////////////////////////////////////////////////////////////////////
621 * Called when a key down is received.
623 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
625 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
627 EventHandler* handler( (EventHandler*)data );
628 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
629 bool eventHandled( false );
631 // If a device key then skip ecore_imf_context_filter_event.
632 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
634 Ecore_IMF_Context* imfContext = NULL;
635 Dali::ImfManager imfManager( ImfManager::Get() );
638 imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
643 // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
644 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
645 ecoreKeyDownEvent.keyname = keyEvent->keyname;
646 ecoreKeyDownEvent.key = keyEvent->key;
647 ecoreKeyDownEvent.string = keyEvent->string;
648 ecoreKeyDownEvent.compose = keyEvent->compose;
649 ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
650 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
651 ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
652 #ifdef ECORE_IMF_1_13
653 ecoreKeyDownEvent.dev_name = "";
654 #endif // ECORE_IMF_1_13
656 eventHandled = ecore_imf_context_filter_event( imfContext,
657 ECORE_IMF_EVENT_KEY_DOWN,
658 (Ecore_IMF_Event *) &ecoreKeyDownEvent );
660 // If the event has not been handled by IMF then check if we should reset our IMF context
663 if ( !strcmp( keyEvent->keyname, "Escape" ) ||
664 !strcmp( keyEvent->keyname, "Return" ) ||
665 !strcmp( keyEvent->keyname, "KP_Enter" ) )
667 ecore_imf_context_reset( imfContext );
673 // If the event wasn't handled then we should send a key event.
676 if ( keyEvent->window == handler->mImpl->mWindow )
678 std::string keyName( keyEvent->keyname );
679 std::string keyString( "" );
680 int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
681 int modifier( keyEvent->modifiers );
682 unsigned long time = keyEvent->timestamp;
684 // Ensure key event string is not NULL as keys like SHIFT have a null string.
685 if ( keyEvent->string )
687 keyString = keyEvent->string;
690 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Down);
691 handler->SendEvent( keyEvent );
695 return ECORE_CALLBACK_PASS_ON;
699 * Called when a key up is received.
701 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
703 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp \n" );
705 EventHandler* handler( (EventHandler*)data );
706 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
707 bool eventHandled( false );
709 // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
710 if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
712 Ecore_IMF_Context* imfContext = NULL;
713 Dali::ImfManager imfManager( ImfManager::Get() );
716 imfContext = ImfManager::GetImplementation( 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;
730 #ifdef ECORE_IMF_1_13
731 ecoreKeyUpEvent.dev_name = "";
732 #endif // ECORE_IMF_1_13
734 eventHandled = ecore_imf_context_filter_event( imfContext,
735 ECORE_IMF_EVENT_KEY_UP,
736 (Ecore_IMF_Event *) &ecoreKeyUpEvent );
740 // If the event wasn't handled then we should send a key event.
743 if ( keyEvent->window == handler->mImpl->mWindow )
745 std::string keyName( keyEvent->keyname );
746 std::string keyString( "" );
747 int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
748 int modifier( keyEvent->modifiers );
749 unsigned long time( keyEvent->timestamp );
751 // Ensure key event string is not NULL as keys like SHIFT have a null string.
752 if ( keyEvent->string )
754 keyString = keyEvent->string;
757 KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
758 handler->SendEvent( keyEvent );
763 return ECORE_CALLBACK_PASS_ON;
766 /////////////////////////////////////////////////////////////////////////////////////////////////
768 /////////////////////////////////////////////////////////////////////////////////////////////////
771 * Called when the window gains focus.
773 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
775 Ecore_X_Event_Window_Focus_In* focusInEvent( (Ecore_X_Event_Window_Focus_In*)event );
776 EventHandler* handler( (EventHandler*)data );
778 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
780 // If the window gains focus and we hid the keyboard then show it again.
781 if ( focusInEvent->win == handler->mImpl->mWindow )
783 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
785 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
787 Dali::ImfManager imfManager( ImfManager::Get() );
790 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
791 if( imfManagerImpl.RestoreAfterFocusLost() )
793 imfManagerImpl.Activate();
797 // No need to connect callbacks as KeyboardStatusChanged will be called.
800 return ECORE_CALLBACK_PASS_ON;
804 * Called when the window loses focus.
806 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
808 Ecore_X_Event_Window_Focus_Out* focusOutEvent( (Ecore_X_Event_Window_Focus_Out*)event );
809 EventHandler* handler( (EventHandler*)data );
811 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
813 // If the window loses focus then hide the keyboard.
814 if ( focusOutEvent->win == handler->mImpl->mWindow )
816 if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
818 Dali::ImfManager imfManager( ImfManager::Get() );
821 ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
822 if( imfManagerImpl.RestoreAfterFocusLost() )
824 imfManagerImpl.Deactivate();
829 // Clipboard don't support that whether clipboard is shown or not. Hide clipboard.
830 Dali::Clipboard clipboard = Clipboard::Get();
831 clipboard.HideClipboard();
834 return ECORE_CALLBACK_PASS_ON;
838 * Called when the window is damaged.
840 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
842 Ecore_X_Event_Window_Damage* windowDamagedEvent( (Ecore_X_Event_Window_Damage*)event );
843 EventHandler* handler( (EventHandler*)data );
845 if( windowDamagedEvent->win == handler->mImpl->mWindow )
848 area.x = windowDamagedEvent->x;
849 area.y = windowDamagedEvent->y;
850 area.width = windowDamagedEvent->w;
851 area.height = windowDamagedEvent->h;
853 handler->SendEvent( area );
856 return ECORE_CALLBACK_PASS_ON;
860 * Called when the window properties are changed.
861 * We are only interested in the font change.
865 /////////////////////////////////////////////////////////////////////////////////////////////////
866 // Drag & Drop Callbacks
867 /////////////////////////////////////////////////////////////////////////////////////////////////
870 * Called when a dragged item enters our window's bounds.
871 * This is when items are dragged INTO our window.
873 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
875 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
877 Ecore_X_Event_Xdnd_Enter* enterEvent( (Ecore_X_Event_Xdnd_Enter*) event );
878 EventHandler* handler( (EventHandler*)data );
879 Ecore_X_Window window ( handler->mImpl->mWindow );
881 if ( enterEvent->win == window )
883 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
885 // Check whether the Drag & Drop detector has Drag & Drop behaviour enabled before we accept.
886 if ( dndDetector && dndDetector->IsEnabled() )
888 // Tell Ecore that we want to enable drop in the entire window.
889 Ecore_X_Rectangle rect;
891 ecore_x_window_geometry_get( window, NULL, NULL, (int*)&rect.width, (int*)&rect.height );
893 // Tell Ecore that we are able to process a drop.
894 ecore_x_dnd_send_status( EINA_TRUE, EINA_FALSE, rect, ECORE_X_ATOM_XDND_DROP );
896 // Register the required atoms and types.
897 ecore_x_dnd_actions_set( window, DRAG_AND_DROP_ATOMS, DRAG_AND_DROP_ATOMS_NUMBER );
898 ecore_x_dnd_types_set( window, DRAG_AND_DROP_TYPES, DRAG_AND_DROP_TYPES_NUMBER );
900 // Request to get the content from Ecore.
901 ecore_x_selection_xdnd_request( window, ECORE_X_SELECTION_TARGET_UTF8_STRING );
903 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndEnter: Requesting Drag & Drop\n" );
905 // Clear the previous content
906 dndDetector->ClearContent();
908 // Emit the entered signal
909 dndDetector->EmitEnteredSignal();
913 return ECORE_CALLBACK_PASS_ON;
917 * Called when a dragged item is moved within our window.
918 * This is when items are dragged INTO our window.
920 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
922 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
924 Ecore_X_Event_Xdnd_Position* positionEvent( (Ecore_X_Event_Xdnd_Position*) event );
925 EventHandler* handler( (EventHandler*)data );
927 if ( positionEvent->win == handler->mImpl->mWindow )
929 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
931 // If we have a detector then update its latest position.
934 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndPosition: position ( %d x %d )\n", positionEvent->position.x, positionEvent->position.y );
935 dndDetector->SetPosition( Vector2( positionEvent->position.x, positionEvent->position.y ));
936 dndDetector->EmitMovedSignal();
940 return ECORE_CALLBACK_PASS_ON;
944 * Called when a dragged item leaves our window's bounds.
945 * This is when items are dragged INTO our window.
947 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
949 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
951 Ecore_X_Event_Xdnd_Leave* leaveEvent( (Ecore_X_Event_Xdnd_Leave*) event );
952 EventHandler* handler( (EventHandler*)data );
954 if ( leaveEvent->win == handler->mImpl->mWindow )
956 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
958 // If we have a detector then clear its content and emit the exited-signal. Also tell Ecore that we have finished.
961 dndDetector->ClearContent();
962 dndDetector->EmitExitedSignal();
964 ecore_x_dnd_send_finished();
966 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndLeave: Finished\n" );
970 return ECORE_CALLBACK_PASS_ON;
974 * Called when the dragged item is dropped within our window's bounds.
975 * This is when items are dragged INTO our window.
977 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
979 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
981 Ecore_X_Event_Xdnd_Drop* dropEvent ( (Ecore_X_Event_Xdnd_Drop*) event);
982 EventHandler* handler( (EventHandler*)data );
984 if ( dropEvent->win == handler->mImpl->mWindow )
986 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
988 // Something has been dropped, inform the detector (if we have one) and tell Ecore that we have finished.
991 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: position ( %d x %d )\n", dropEvent->position.x, dropEvent->position.y );
993 dndDetector->SetPosition( Vector2( dropEvent->position.x, dropEvent->position.y ) );
994 dndDetector->EmitDroppedSignal();
995 ecore_x_dnd_send_finished();
997 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: Finished\n" );
1001 return ECORE_CALLBACK_PASS_ON;
1005 * Called when a dragged item is moved from our window and the target window has done processing it.
1006 * This is when items are dragged FROM our window.
1008 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
1010 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
1011 return ECORE_CALLBACK_PASS_ON;
1015 * Called when a dragged item is moved from our window and the target window has sent us a status.
1016 * This is when items are dragged FROM our window.
1018 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
1020 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
1021 return ECORE_CALLBACK_PASS_ON;
1025 * Called when the client messages (i.e. the accessibility events) are received.
1027 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
1029 #ifndef DALI_PROFILE_UBUNTU
1030 Ecore_X_Event_Client_Message* clientMessageEvent( (Ecore_X_Event_Client_Message*)event );
1031 EventHandler* handler( (EventHandler*)data );
1033 if (clientMessageEvent->message_type == ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL)
1035 if ( ( (unsigned int)clientMessageEvent->data.l[0] == handler->mImpl->mWindow ) && handler->mAccessibilityAdaptor )
1037 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1039 if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_SCROLL)
1041 // 2 finger touch & move, 2 finger flick
1043 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1046 TouchPoint::State state(TouchPoint::Down);
1048 if ((unsigned int)clientMessageEvent->data.l[2] == 0)
1050 state = TouchPoint::Down; // mouse down
1052 else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
1054 state = TouchPoint::Motion; // mouse move
1056 else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
1058 state = TouchPoint::Up; // mouse up
1062 state = TouchPoint::Interrupted; // error
1065 DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1066 "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1067 (unsigned int)clientMessageEvent->data.l[2],
1068 (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1070 // Send touch event to accessibility adaptor.
1071 TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1073 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1074 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1076 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_MOUSE)
1078 // 1 finger double tap and hold
1080 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1083 TouchPoint::State state(TouchPoint::Down);
1085 if ((unsigned int)clientMessageEvent->data.l[2] == 0)
1087 state = TouchPoint::Down; // mouse down
1089 else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
1091 state = TouchPoint::Motion; // mouse move
1093 else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
1095 state = TouchPoint::Up; // mouse up
1099 state = TouchPoint::Interrupted; // error
1102 DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1103 "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1104 (unsigned int)clientMessageEvent->data.l[2],
1105 (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1107 // Send touch event to accessibility adaptor.
1108 TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1110 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1111 accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1113 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_BACK)
1115 // 2 finger circle draw, do back
1116 accessibilityAdaptor->HandleActionBackEvent();
1118 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_NEXT)
1120 // one finger flick down
1121 // focus next object
1122 if(accessibilityAdaptor)
1124 accessibilityAdaptor->HandleActionNextEvent();
1127 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_PREV)
1129 // one finger flick up
1130 // focus previous object
1131 if(accessibilityAdaptor)
1133 accessibilityAdaptor->HandleActionPreviousEvent();
1136 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE)
1138 // one finger double tap
1139 // same as one finger tap in normal mode (i.e. execute focused actor)
1140 if(accessibilityAdaptor)
1142 accessibilityAdaptor->HandleActionActivateEvent();
1145 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ)
1148 // focus & read an actor at ( e->data.l[2], e->data.l[3] ) position according to finger
1149 if(accessibilityAdaptor)
1151 accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[2], (unsigned int)clientMessageEvent->data.l[3], true /* allow read again*/);
1154 #if defined(DALI_PROFILE_MOBILE)
1155 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_OVER)
1157 // one finger tap & move
1158 // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1161 // focus & read an actor at (x, y) position according to finger
1162 if(accessibilityAdaptor && (unsigned int)clientMessageEvent->data.l[2] == 1 /*only work for move event*/)
1164 accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4], false /* not allow read again*/);
1168 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_NEXT)
1170 // one finger flick right
1171 // focus next object
1172 if(accessibilityAdaptor)
1174 accessibilityAdaptor->HandleActionReadNextEvent();
1177 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_PREV)
1179 // one finger flick left
1180 // focus previous object
1181 if(accessibilityAdaptor)
1183 accessibilityAdaptor->HandleActionReadPreviousEvent();
1186 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_UP)
1188 // double down and move (right, up)
1189 // change slider value
1190 if(accessibilityAdaptor)
1192 accessibilityAdaptor->HandleActionUpEvent();
1195 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DOWN)
1197 // double down and move (left, down)
1198 // change slider value
1199 if(accessibilityAdaptor)
1201 accessibilityAdaptor->HandleActionDownEvent();
1204 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ENABLE)
1206 if(accessibilityAdaptor)
1208 accessibilityAdaptor->HandleActionEnableEvent();
1211 else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DISABLE)
1213 if(accessibilityAdaptor)
1215 accessibilityAdaptor->HandleActionDisableEvent();
1218 // TODO: some more actions could be added later
1221 else if(clientMessageEvent->message_type == ecore_x_atom_get(CLIPBOARD_ATOM))
1223 std::string message(clientMessageEvent->data.b);
1224 if( message == CLIPBOARD_SET_OWNER_MESSAGE)
1226 // Claim the ownership of the SECONDARY selection.
1227 ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1229 // Show the clipboard window
1230 Dali::Clipboard clipboard = Dali::Clipboard::Get();
1231 clipboard.ShowClipboard();
1234 else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_PREPARE )
1236 RotationEvent rotationEvent;
1237 rotationEvent.angle = static_cast<int>(clientMessageEvent->data.l[1]);
1238 rotationEvent.winResize = static_cast<int>(clientMessageEvent->data.l[2]);
1239 rotationEvent.width = static_cast<int>(clientMessageEvent->data.l[3]);
1240 rotationEvent.height = static_cast<int>(clientMessageEvent->data.l[4]);
1241 handler->SendRotationPrepareEvent( rotationEvent );
1243 else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_REQUEST )
1245 handler->SendRotationRequestEvent();
1248 #endif // DALI_PROFILE_UBUNTU
1249 return ECORE_CALLBACK_PASS_ON;
1253 /////////////////////////////////////////////////////////////////////////////////////////////////
1254 // ElDBus Accessibility Callbacks
1255 /////////////////////////////////////////////////////////////////////////////////////////////////
1257 #ifdef DALI_ELDBUS_AVAILABLE
1258 // Callback for Ecore ElDBus accessibility events.
1259 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
1261 EventHandler* handler = static_cast< EventHandler* >( context );
1262 // Ignore any accessibility events when paused.
1263 if( handler->mPaused )
1268 if ( !handler->mAccessibilityAdaptor )
1270 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
1274 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1275 if ( !accessibilityAdaptor )
1277 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
1281 const char *gestureName;
1285 // The string defines the arg-list's respective types.
1286 if( !eldbus_message_arguments_get( message, "siiiiu", &gestureName, &xS, &yS, &xE, &yE, &state ) )
1288 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1291 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %s Args: %d,%d,%d,%d State: %d\n", gestureName, xS, yS, xE, yE );
1293 unsigned int fingers = 0;
1294 char* stringPosition = ( char* )gestureName;
1296 // Check how many fingers the gesture uses.
1297 for( unsigned int i = 0; i < FingerCountStringsTotal; ++i )
1299 unsigned int matchLength = strlen( ElDBusAccessibilityFingerCountStrings[ i ] );
1300 if( strncmp( gestureName, ElDBusAccessibilityFingerCountStrings[ i ], matchLength ) == 0 )
1303 stringPosition += matchLength;
1310 // Error: invalid gesture.
1314 GestureType gestureType = GESTURE_TYPE_NONE;
1315 SubGestureType subGestureType = SUB_GESTURE_TYPE_NONE;
1316 GestureDirection direction = GESTURE_DIRECTION_NONE;
1318 // Check for full gesture type names first.
1319 for( unsigned int i = 0; i < FullEventTypeStringsTotal; ++i )
1321 unsigned int matchLength = strlen( ElDBusAccessibilityFullEventTypeStrings[ i ].name );
1322 if( strncmp( stringPosition, ElDBusAccessibilityFullEventTypeStrings[ i ].name, matchLength ) == 0 )
1324 gestureType = ElDBusAccessibilityFullEventTypeStrings[ i ].type;
1329 // If we didn't find a full gesture, check for sub gesture type names.
1330 if( gestureType == GESTURE_TYPE_NONE )
1332 // No full gesture name found, look for partial types.
1333 for( unsigned int i = 0; i < DirectionalEventTypeStringsTotal; ++i )
1335 unsigned int matchLength = strlen( ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name );
1336 if( strncmp( stringPosition, ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name, matchLength ) == 0 )
1338 subGestureType = ElDBusAccessibilityDirectionalEventTypeStrings[ i ].type;
1339 stringPosition += matchLength;
1344 if( subGestureType == SUB_GESTURE_TYPE_NONE )
1346 // ERROR: Gesture not recognised.
1350 // If the gesture was a sub type, get it's respective direction.
1351 for( unsigned int i = 0; i < DirectionStringsTotal; ++i )
1353 unsigned int matchLength = strlen( ElDBusAccessibilityDirectionStrings[ i ].name );
1354 if( strncmp( stringPosition, ElDBusAccessibilityDirectionStrings[ i ].name, matchLength ) == 0 )
1356 direction = ElDBusAccessibilityDirectionStrings[ i ].direction;
1357 stringPosition += matchLength;
1362 if( direction == GESTURE_DIRECTION_NONE )
1364 // ERROR: Gesture not recognised.
1369 // Action the detected gesture here.
1370 if( gestureType != GESTURE_TYPE_NONE )
1372 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d Gesture type: %d\n", fingers, gestureType );
1376 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d Gesture sub type: %d Gesture direction: %d\n",
1377 fingers, subGestureType, direction );
1380 // Create a touch point object.
1381 TouchPoint::State touchPointState( TouchPoint::Down );
1384 touchPointState = TouchPoint::Down; // Mouse down.
1386 else if ( state == 1 )
1388 touchPointState = TouchPoint::Motion; // Mouse move.
1390 else if ( state == 2 )
1392 touchPointState = TouchPoint::Up; // Mouse up.
1396 touchPointState = TouchPoint::Interrupted; // Error.
1399 // Send touch event to accessibility adaptor.
1400 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1402 // Perform actions based on received gestures.
1403 // Note: This is seperated from the reading so we can (in future)
1404 // have other input readers without changing the below code.
1409 if( gestureType == GESTURE_TYPE_SINGLE_TAP || ( gestureType == GESTURE_TYPE_HOVER && touchPointState == TouchPoint::Motion ) )
1412 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1414 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1416 if( false ) // TODO: how to detect double tap + hold?
1418 // Move or drag icon / view more options for selected items.
1419 // accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1423 // Activate selected item / active edit mode.
1424 accessibilityAdaptor->HandleActionActivateEvent();
1427 else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1430 accessibilityAdaptor->HandleActionZoomEvent();
1432 else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1434 if( direction == GESTURE_DIRECTION_LEFT )
1436 // Move to previous item.
1437 accessibilityAdaptor->HandleActionReadPreviousEvent();
1439 else if( direction == GESTURE_DIRECTION_RIGHT )
1441 // Move to next item.
1442 accessibilityAdaptor->HandleActionReadNextEvent();
1444 else if( direction == GESTURE_DIRECTION_UP )
1446 // Move to next item.
1447 accessibilityAdaptor->HandleActionPreviousEvent();
1449 else if( direction == GESTURE_DIRECTION_DOWN )
1451 // Move to next item.
1452 accessibilityAdaptor->HandleActionNextEvent();
1454 else if( direction == GESTURE_DIRECTION_LEFT_RETURN )
1456 // Scroll up to the previous page
1457 accessibilityAdaptor->HandleActionPageUpEvent();
1459 else if( direction == GESTURE_DIRECTION_RIGHT_RETURN )
1461 // Scroll down to the next page
1462 accessibilityAdaptor->HandleActionPageDownEvent();
1464 else if( direction == GESTURE_DIRECTION_UP_RETURN )
1466 // Move to the first item on screen
1467 accessibilityAdaptor->HandleActionMoveToFirstEvent();
1469 else if( direction == GESTURE_DIRECTION_DOWN_RETURN )
1471 // Move to the last item on screen
1472 accessibilityAdaptor->HandleActionMoveToLastEvent();
1480 if( gestureType == GESTURE_TYPE_HOVER )
1482 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1483 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1485 else if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1487 // Pause/Resume current speech
1488 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1490 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1492 // Start/Stop current action
1493 accessibilityAdaptor->HandleActionStartStopEvent();
1495 else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1497 // Read information from indicator
1498 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1500 else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1502 if( direction == GESTURE_DIRECTION_LEFT )
1504 // Scroll left to the previous page
1505 accessibilityAdaptor->HandleActionPageLeftEvent();
1507 else if( direction == GESTURE_DIRECTION_RIGHT )
1509 // Scroll right to the next page
1510 accessibilityAdaptor->HandleActionPageRightEvent();
1512 else if( direction == GESTURE_DIRECTION_UP )
1514 // Scroll up the list.
1515 accessibilityAdaptor->HandleActionScrollUpEvent();
1517 else if( direction == GESTURE_DIRECTION_DOWN )
1519 // Scroll down the list.
1520 accessibilityAdaptor->HandleActionScrollDownEvent();
1528 if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1530 // Read from top item on screen continuously.
1531 accessibilityAdaptor->HandleActionReadFromTopEvent();
1533 else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1535 // Read from next item continuously.
1536 accessibilityAdaptor->HandleActionReadFromNextEvent();
1543 // Callback for to set up Ecore ElDBus for accessibility callbacks.
1544 static void EcoreElDBusInitialisation( void *handle, const Eldbus_Message *message, Eldbus_Pending *pending EINA_UNUSED )
1546 Eldbus_Object *object;
1547 Eldbus_Proxy *manager;
1548 const char *a11yBusAddress = NULL;
1549 EventHandler* handler = static_cast< EventHandler* >( handle );
1551 // The string defines the arg-list's respective types.
1552 if( !eldbus_message_arguments_get( message, "s", &a11yBusAddress ) )
1554 DALI_LOG_ERROR( "EcoreElDBusInitialisation: Error getting arguments\n" );
1557 DALI_LOG_INFO( gImfLogging, Debug::General, "Ecore ElDBus Accessibility address: %s\n", a11yBusAddress );
1559 handler->mImpl->mA11yConnection = eldbus_address_connection_get( a11yBusAddress );
1561 object = eldbus_object_get( handler->mImpl->mA11yConnection, BUS, PATH );
1562 manager = eldbus_proxy_get( object, INTERFACE );
1564 // Pass the callback data through to the signal handler.
1565 eldbus_proxy_signal_handler_add( manager, SIGNAL, OnEcoreElDBusAccessibilityNotification, handle );
1567 #endif // DALI_ELDBUS_AVAILABLE
1570 * Called when the source window notifies us the content in clipboard is selected.
1572 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1574 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1575 Ecore_X_Event_Selection_Clear* selectionClearEvent( (Ecore_X_Event_Selection_Clear*) event );
1576 EventHandler* handler( (EventHandler*)data );
1578 if ( selectionClearEvent->win == handler->mImpl->mWindow )
1580 if ( selectionClearEvent->selection == ECORE_X_SELECTION_SECONDARY )
1582 // Request to get the content from Ecore.
1583 ecore_x_selection_secondary_request(selectionClearEvent->win, ECORE_X_SELECTION_TARGET_TEXT);
1586 return ECORE_CALLBACK_PASS_ON;
1590 * Called when the source window sends us about the selected content.
1591 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1593 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1595 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1597 Ecore_X_Event_Selection_Notify* selectionNotifyEvent( (Ecore_X_Event_Selection_Notify*) event );
1598 EventHandler* handler( (EventHandler*)data );
1600 if ( selectionNotifyEvent->win == handler->mImpl->mWindow )
1602 Ecore_X_Selection_Data* selectionData( (Ecore_X_Selection_Data*) selectionNotifyEvent->data );
1603 if ( selectionData->data )
1605 if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_XDND )
1607 DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
1609 // We have got the content that is to be dropped, inform the DndListener (if we have one).
1612 std::string content( (char*) selectionData->data, selectionData->length );
1613 dndDetector->SetContent( content );
1615 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1616 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1617 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1618 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1621 else if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_SECONDARY )
1623 // We have got the selected content, inform the clipboard event listener (if we have one).
1624 if ( handler->mClipboardEventNotifier )
1626 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1627 std::string content( (char*) selectionData->data, selectionData->length );
1628 clipboardEventNotifier.SetContent( content );
1629 clipboardEventNotifier.EmitContentSelectedSignal();
1632 // Claim the ownership of the SECONDARY selection.
1633 ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1635 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1636 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1637 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1638 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1642 return ECORE_CALLBACK_PASS_ON;
1646 #ifndef DALI_PROFILE_UBUNTU
1647 /////////////////////////////////////////////////////////////////////////////////////////////////
1649 /////////////////////////////////////////////////////////////////////////////////////////////////
1651 * Called when a font name is changed.
1653 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1655 EventHandler* handler = static_cast<EventHandler*>( data );
1656 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1660 * Called when a font size is changed.
1662 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1664 DALI_LOG_INFO(gTouchEventLogFilter, Debug::Verbose, "VconfNotifyFontSizeChanged\n" );
1665 EventHandler* handler = static_cast<EventHandler*>( data );
1666 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1668 #endif // DALI_PROFILE_UBUNTU
1671 EventHandler* mHandler;
1672 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1673 Ecore_X_Window mWindow;
1676 #ifdef DALI_ELDBUS_AVAILABLE
1677 Eldbus_Connection* mSessionConnection;
1678 Eldbus_Connection* mA11yConnection;
1682 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1683 : mCoreEventInterface( coreEventInterface ),
1684 mGestureManager( gestureManager ),
1685 mStyleMonitor( StyleMonitor::Get() ),
1686 mDamageObserver( damageObserver ),
1687 mRotationObserver( NULL ),
1688 mDragAndDropDetector( dndDetector ),
1689 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1690 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1691 mClipboard( Clipboard::Get() ),
1695 Ecore_X_Window window = 0;
1697 // this code only works with the EcoreX11 RenderSurface so need to downcast
1698 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1701 // enable multi touch
1702 window = ecoreSurface->GetXWindow();
1705 mImpl = new Impl(this, window);
1708 EventHandler::~EventHandler()
1712 mGestureManager.Stop();
1715 void EventHandler::SendEvent(TouchPoint& point, unsigned long timeStamp)
1719 timeStamp = GetCurrentMilliSeconds();
1722 Integration::TouchEvent touchEvent;
1723 Integration::HoverEvent hoverEvent;
1724 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1725 if(type != Integration::TouchEventCombiner::DispatchNone )
1727 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);
1729 // First the touch and/or hover event & related gesture events are queued
1730 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1732 mCoreEventInterface.QueueCoreEvent( touchEvent );
1733 mGestureManager.SendEvent(touchEvent);
1736 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1738 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1741 // Next the events are processed with a single call into Core
1742 mCoreEventInterface.ProcessCoreEvents();
1746 void EventHandler::SendEvent(KeyEvent& keyEvent)
1748 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1749 if ( physicalKeyboard )
1751 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
1753 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1757 // Create KeyEvent and send to Core.
1758 Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
1759 keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
1760 mCoreEventInterface.QueueCoreEvent( event );
1761 mCoreEventInterface.ProcessCoreEvents();
1764 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1766 // Create WheelEvent and send to Core.
1767 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1768 mCoreEventInterface.QueueCoreEvent( event );
1769 mCoreEventInterface.ProcessCoreEvents();
1772 void EventHandler::SendEvent( StyleChange::Type styleChange )
1774 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1775 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1778 void EventHandler::SendEvent( const DamageArea& area )
1780 mDamageObserver.OnDamaged( area );
1783 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1785 if( mRotationObserver != NULL )
1787 mRotationObserver->OnRotationPrepare( event );
1791 void EventHandler::SendRotationRequestEvent( )
1793 if( mRotationObserver != NULL )
1795 mRotationObserver->OnRotationRequest( );
1799 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1801 SendEvent(point, timeStamp);
1804 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1806 SendWheelEvent( wheelEvent );
1809 void EventHandler::FeedKeyEvent( KeyEvent& event )
1814 void EventHandler::FeedEvent( Integration::Event& event )
1816 mCoreEventInterface.QueueCoreEvent( event );
1817 mCoreEventInterface.ProcessCoreEvents();
1820 void EventHandler::Reset()
1824 // Any touch listeners should be told of the interruption.
1825 Integration::TouchEvent event;
1826 TouchPoint point(0, TouchPoint::Interrupted, 0, 0);
1827 event.AddPoint( point );
1829 // First the touch event & related gesture events are queued
1830 mCoreEventInterface.QueueCoreEvent( event );
1831 mGestureManager.SendEvent( event );
1833 // Next the events are processed with a single call into Core
1834 mCoreEventInterface.ProcessCoreEvents();
1837 void EventHandler::Pause()
1843 void EventHandler::Resume()
1849 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1851 mDragAndDropDetector = detector;
1854 void EventHandler::SetRotationObserver( RotationObserver* observer )
1856 mRotationObserver = observer;
1859 } // namespace Adaptor
1861 } // namespace Internal