2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/window-system/common/event-handler.h>
22 // Ecore is littered with C style cast
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wold-style-cast"
26 #include <Ecore_Input.h>
27 #include <Ecore_IMF.h>
32 #ifndef DALI_PROFILE_UBUNTU
34 #include <vconf-keys.h>
35 #endif // DALI_PROFILE_UBUNTU
37 #ifdef DALI_ELDBUS_AVAILABLE
39 #endif // DALI_ELDBUS_AVAILABLE
41 #include <dali/public-api/common/vector-wrapper.h>
42 #include <dali/public-api/events/device.h>
43 #include <dali/public-api/events/touch-point.h>
44 #include <dali/public-api/events/key-event.h>
45 #include <dali/public-api/events/wheel-event.h>
46 #include <dali/integration-api/debug.h>
47 #include <dali/integration-api/events/key-event-integ.h>
48 #include <dali/integration-api/events/touch-event-integ.h>
49 #include <dali/integration-api/events/hover-event-integ.h>
50 #include <dali/integration-api/events/wheel-event-integ.h>
53 #include <dali/internal/input/common/gesture-manager.h>
54 #include <dali/internal/window-system/tizen-wayland/ecore-wl2/window-render-surface-ecore-wl2.h>
55 #include <dali/internal/clipboard/common/clipboard-impl.h>
56 #include <dali/internal/input/common/key-impl.h>
57 #include <dali/internal/input/common/physical-keyboard-impl.h>
58 #include <dali/internal/styling/common/style-monitor-impl.h>
59 #include <dali/internal/system/common/core-event-interface.h>
60 #include <dali/devel-api/adaptor-framework/virtual-keyboard.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* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
76 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
77 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
78 } // unnamed namespace
86 const char* BUS = "org.enlightenment.wm-screen-reader";
87 const char* INTERFACE = "org.tizen.GestureNavigation";
88 const char* PATH = "/org/tizen/GestureNavigation";
90 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
92 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
94 // Copied from x server
95 static unsigned int GetCurrentMilliSeconds(void)
100 static clockid_t clockid;
104 #ifdef CLOCK_MONOTONIC_COARSE
105 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
106 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
108 clockid = CLOCK_MONOTONIC_COARSE;
112 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
114 clockid = CLOCK_MONOTONIC;
121 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
123 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
126 gettimeofday(&tv, NULL);
127 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
130 #ifndef DALI_PROFILE_UBUNTU
131 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
132 #endif // DALI_PROFILE_UBUNTU
135 * Get the device name from the provided ecore key event
137 void GetDeviceName( Ecore_Event_Key* keyEvent, std::string& result )
139 const char* ecoreDeviceName = ecore_device_name_get( keyEvent->dev );
141 if ( ecoreDeviceName )
143 result = ecoreDeviceName;
148 * Get the device class from the provided ecore event
150 void GetDeviceClass( Ecore_Device_Class ecoreDeviceClass, Device::Class::Type& deviceClass )
152 switch( ecoreDeviceClass )
154 case ECORE_DEVICE_CLASS_SEAT:
156 deviceClass = Device::Class::USER;
159 case ECORE_DEVICE_CLASS_KEYBOARD:
161 deviceClass = Device::Class::KEYBOARD;
164 case ECORE_DEVICE_CLASS_MOUSE:
166 deviceClass = Device::Class::MOUSE;
169 case ECORE_DEVICE_CLASS_TOUCH:
171 deviceClass = Device::Class::TOUCH;
174 case ECORE_DEVICE_CLASS_PEN:
176 deviceClass = Device::Class::PEN;
179 case ECORE_DEVICE_CLASS_POINTER:
181 deviceClass = Device::Class::POINTER;
184 case ECORE_DEVICE_CLASS_GAMEPAD:
186 deviceClass = Device::Class::GAMEPAD;
191 deviceClass = Device::Class::NONE;
197 void GetDeviceSubclass( Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subclass::Type& deviceSubclass )
199 switch( ecoreDeviceSubclass )
201 case ECORE_DEVICE_SUBCLASS_FINGER:
203 deviceSubclass = Device::Subclass::FINGER;
206 case ECORE_DEVICE_SUBCLASS_FINGERNAIL:
208 deviceSubclass = Device::Subclass::FINGERNAIL;
211 case ECORE_DEVICE_SUBCLASS_KNUCKLE:
213 deviceSubclass = Device::Subclass::KNUCKLE;
216 case ECORE_DEVICE_SUBCLASS_PALM:
218 deviceSubclass = Device::Subclass::PALM;
221 case ECORE_DEVICE_SUBCLASS_HAND_SIZE:
223 deviceSubclass = Device::Subclass::HAND_SIDE;
226 case ECORE_DEVICE_SUBCLASS_HAND_FLAT:
228 deviceSubclass = Device::Subclass::HAND_FLAT;
231 case ECORE_DEVICE_SUBCLASS_PEN_TIP:
233 deviceSubclass = Device::Subclass::PEN_TIP;
236 case ECORE_DEVICE_SUBCLASS_TRACKPAD:
238 deviceSubclass = Device::Subclass::TRACKPAD;
241 case ECORE_DEVICE_SUBCLASS_TRACKPOINT:
243 deviceSubclass = Device::Subclass::TRACKPOINT;
246 case ECORE_DEVICE_SUBCLASS_TRACKBALL:
248 deviceSubclass = Device::Subclass::TRACKBALL;
251 #ifdef OVER_TIZEN_VERSION_4
252 case ECORE_DEVICE_SUBCLASS_REMOCON:
254 deviceSubclass = Device::Subclass::REMOCON;
257 case ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD:
259 deviceSubclass = Device::Subclass::VIRTUAL_KEYBOARD;
265 deviceSubclass = Device::Subclass::NONE;
271 } // unnamed namespace
273 // Impl to hide EFL implementation.
274 struct EventHandler::Impl
276 // Construction & Destruction
281 Impl( EventHandler* handler, Ecore_Wl2_Window* window )
282 : mHandler( handler ),
283 mEcoreEventHandler(),
288 #ifdef DALI_ELDBUS_AVAILABLE
289 , mSystemConnection( NULL )
290 #endif // DALI_ELDBUS_AVAILABLE
292 // Only register for touch and key events if we have a window
295 // Register Touch events
296 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
297 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
298 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
299 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, handler ) );
301 // Register Mouse wheel events
302 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
304 // Register Focus events
305 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL2_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
306 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL2_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
308 // Register Key events
309 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
310 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
312 // Register Selection event - clipboard selection
313 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL2_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
314 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL2_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
316 // Register Rotate event
317 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL2_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
319 // Register Detent event
320 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
322 #ifndef DALI_PROFILE_UBUNTU
323 // Register Vconf notify - font name and size
324 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
325 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
326 #endif // DALI_PROFILE_UBUNTU
328 #ifdef DALI_ELDBUS_AVAILABLE
329 // Initialize ElDBus.
330 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
333 EcoreElDBusInitialisation( handler );
335 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
336 #endif // DALI_ELDBUS_AVAILABLE
345 #ifndef DALI_PROFILE_UBUNTU
346 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
347 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
348 #endif // DALI_PROFILE_UBUNTU
350 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
352 ecore_event_handler_del( *iter );
355 #ifdef DALI_ELDBUS_AVAILABLE
356 // Close down ElDBus connections.
357 if( mSystemConnection )
359 eldbus_connection_unref( mSystemConnection );
361 #endif // DALI_ELDBUS_AVAILABLE
366 /////////////////////////////////////////////////////////////////////////////////////////////////
368 /////////////////////////////////////////////////////////////////////////////////////////////////
371 * Called when a touch down is received.
373 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
375 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
376 EventHandler* handler( (EventHandler*)data );
378 if ( touchEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
380 PointState::Type state ( PointState::DOWN );
382 // Check if the buttons field is set and ensure it's the primary touch button.
383 // If this event was triggered by buttons other than the primary button (used for touch), then
384 // just send an interrupted event to Core.
385 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
387 state = PointState::INTERRUPTED;
390 Device::Class::Type deviceClass;
391 Device::Subclass::Type deviceSubclass;
393 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
394 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
396 Integration::Point point;
397 point.SetDeviceId( touchEvent->multi.device );
398 point.SetState( state );
399 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
400 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
401 point.SetPressure( touchEvent->multi.pressure );
402 point.SetAngle( Degree( touchEvent->multi.angle ) );
403 point.SetDeviceClass( deviceClass );
404 point.SetDeviceSubclass( deviceSubclass );
406 handler->SendEvent( point, touchEvent->timestamp );
409 return ECORE_CALLBACK_PASS_ON;
413 * Called when a touch up is received.
415 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
417 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
418 EventHandler* handler( (EventHandler*)data );
420 if ( touchEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
422 Device::Class::Type deviceClass;
423 Device::Subclass::Type deviceSubclass;
425 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
426 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
428 Integration::Point point;
429 point.SetDeviceId( touchEvent->multi.device );
430 point.SetState( PointState::UP );
431 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
432 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
433 point.SetPressure( touchEvent->multi.pressure );
434 point.SetAngle( Degree( touchEvent->multi.angle ) );
435 point.SetDeviceClass( deviceClass );
436 point.SetDeviceSubclass( deviceSubclass );
438 handler->SendEvent( point, touchEvent->timestamp );
441 return ECORE_CALLBACK_PASS_ON;
445 * Called when a touch motion is received.
447 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
449 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
450 EventHandler* handler( (EventHandler*)data );
452 if ( touchEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
454 Device::Class::Type deviceClass;
455 Device::Subclass::Type deviceSubclass;
457 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
458 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
460 Integration::Point point;
461 point.SetDeviceId( touchEvent->multi.device );
462 point.SetState( PointState::MOTION );
463 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
464 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
465 point.SetPressure( touchEvent->multi.pressure );
466 point.SetAngle( Degree( touchEvent->multi.angle ) );
467 point.SetDeviceClass( deviceClass );
468 point.SetDeviceSubclass( deviceSubclass );
470 handler->SendEvent( point, touchEvent->timestamp );
473 return ECORE_CALLBACK_PASS_ON;
477 * Called when a touch is canceled.
479 static Eina_Bool EcoreEventMouseButtonCancel( void* data, int type, void* event )
481 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
482 EventHandler* handler( (EventHandler*)data );
484 if( touchEvent->window == (unsigned int)ecore_wl2_window_id_get( handler->mImpl->mWindow ) )
486 Integration::Point point;
487 point.SetDeviceId( touchEvent->multi.device );
488 point.SetState( PointState::INTERRUPTED );
489 point.SetScreenPosition( Vector2( 0.0f, 0.0f ) );
490 handler->SendEvent( point, touchEvent->timestamp );
492 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventMouseButtonCancel\n" );
495 return ECORE_CALLBACK_PASS_ON;
499 * Called when a mouse wheel is received.
501 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
503 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
505 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);
507 EventHandler* handler( (EventHandler*)data );
508 if ( mouseWheelEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
510 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
511 handler->SendWheelEvent( wheelEvent );
513 return ECORE_CALLBACK_PASS_ON;
516 /////////////////////////////////////////////////////////////////////////////////////////////////
518 /////////////////////////////////////////////////////////////////////////////////////////////////
521 * Called when a key down is received.
523 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
525 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
527 EventHandler* handler( (EventHandler*)data );
528 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
529 bool eventHandled( false );
531 // If the event wasn't handled then we should send a key event.
534 if ( keyEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
536 std::string keyName( keyEvent->keyname );
537 std::string keyString( "" );
538 std::string compose( "" );
540 // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
541 if ( keyEvent->compose )
543 compose = keyEvent->compose;
546 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
547 keyCode = (keyCode == -1) ? 0 : keyCode;
548 int modifier( keyEvent->modifiers );
549 unsigned long time = keyEvent->timestamp;
550 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
551 keyCode = atoi(keyEvent->keyname + 8);
553 // Ensure key event string is not NULL as keys like SHIFT have a null string.
554 if ( keyEvent->string )
556 keyString = keyEvent->string;
559 std::string deviceName;
560 Device::Class::Type deviceClass;
561 Device::Subclass::Type deviceSubclass;
563 GetDeviceName( keyEvent, deviceName );
564 GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
565 GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
567 DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s) deviceClass(%d)\n", deviceName.c_str(), deviceClass );
569 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, compose, deviceName, deviceClass, deviceSubclass );
570 handler->SendEvent( keyEvent );
574 return ECORE_CALLBACK_PASS_ON;
578 * Called when a key up is received.
580 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
582 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
584 EventHandler* handler( (EventHandler*)data );
585 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
586 bool eventHandled( false );
588 // If the event wasn't handled then we should send a key event.
591 if ( keyEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
593 std::string keyName( keyEvent->keyname );
594 std::string keyString( "" );
595 std::string compose( "" );
597 // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
598 if ( keyEvent->compose )
600 compose = keyEvent->compose;
603 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
604 keyCode = (keyCode == -1) ? 0 : keyCode;
605 int modifier( keyEvent->modifiers );
606 unsigned long time = keyEvent->timestamp;
607 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
608 keyCode = atoi(keyEvent->keyname + 8);
610 // Ensure key event string is not NULL as keys like SHIFT have a null string.
611 if ( keyEvent->string )
613 keyString = keyEvent->string;
616 std::string deviceName;
617 Device::Class::Type deviceClass;
618 Device::Subclass::Type deviceSubclass;
620 GetDeviceName( keyEvent, deviceName );
621 GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
622 GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
624 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, compose, deviceName, deviceClass, deviceSubclass );
625 handler->SendEvent( keyEvent );
629 return ECORE_CALLBACK_PASS_ON;
632 /////////////////////////////////////////////////////////////////////////////////////////////////
634 /////////////////////////////////////////////////////////////////////////////////////////////////
637 * Called when the window gains focus.
639 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
641 Ecore_Wl2_Event_Focus_In* focusInEvent( (Ecore_Wl2_Event_Focus_In*)event );
642 EventHandler* handler( (EventHandler*)data );
644 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
646 // If the window gains focus and we hid the keyboard then show it again.
647 if ( focusInEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
649 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
651 Dali::Clipboard clipboard = Clipboard::Get();
652 clipboard.HideClipboard();
655 return ECORE_CALLBACK_PASS_ON;
659 * Called when the window loses focus.
661 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
663 Ecore_Wl2_Event_Focus_Out* focusOutEvent( (Ecore_Wl2_Event_Focus_Out*)event );
664 EventHandler* handler( (EventHandler*)data );
666 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
668 // If the window loses focus then hide the keyboard.
669 if ( focusOutEvent->window == (unsigned int)ecore_wl2_window_id_get(handler->mImpl->mWindow) )
671 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
672 Dali::Clipboard clipboard = Clipboard::Get();
675 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
676 clipBoardImpl.HideClipboard(true);
680 return ECORE_CALLBACK_PASS_ON;
684 * Called when the window is damaged.
686 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
688 return ECORE_CALLBACK_PASS_ON;
692 * Called when the window properties are changed.
693 * We are only interested in the font change.
697 /////////////////////////////////////////////////////////////////////////////////////////////////
698 // Drag & Drop Callbacks
699 /////////////////////////////////////////////////////////////////////////////////////////////////
702 * Called when a dragged item enters our window's bounds.
703 * This is when items are dragged INTO our window.
705 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
707 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
709 return ECORE_CALLBACK_PASS_ON;
713 * Called when a dragged item is moved within our window.
714 * This is when items are dragged INTO our window.
716 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
718 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
720 return ECORE_CALLBACK_PASS_ON;
724 * Called when a dragged item leaves our window's bounds.
725 * This is when items are dragged INTO our window.
727 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
729 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
731 return ECORE_CALLBACK_PASS_ON;
735 * Called when the dragged item is dropped within our window's bounds.
736 * This is when items are dragged INTO our window.
738 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
740 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
742 return ECORE_CALLBACK_PASS_ON;
746 * Called when a dragged item is moved from our window and the target window has done processing it.
747 * This is when items are dragged FROM our window.
749 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
751 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
752 return ECORE_CALLBACK_PASS_ON;
756 * Called when a dragged item is moved from our window and the target window has sent us a status.
757 * This is when items are dragged FROM our window.
759 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
761 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
762 return ECORE_CALLBACK_PASS_ON;
766 * Called when the client messages (i.e. the accessibility events) are received.
768 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
770 return ECORE_CALLBACK_PASS_ON;
774 /////////////////////////////////////////////////////////////////////////////////////////////////
775 // ElDBus Accessibility Callbacks
776 /////////////////////////////////////////////////////////////////////////////////////////////////
778 #ifdef DALI_ELDBUS_AVAILABLE
779 // Callback for Ecore ElDBus accessibility events.
780 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
782 EventHandler* handler = static_cast< EventHandler* >( context );
783 // Ignore any accessibility events when paused.
784 if( handler->mPaused )
789 if( !handler->mAccessibilityAdaptor )
791 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
795 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
796 if( !accessibilityAdaptor )
798 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
804 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
807 // The string defines the arg-list's respective types.
808 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
810 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
813 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
815 // Create a touch point object.
816 TouchPoint::State touchPointState( TouchPoint::Down );
819 touchPointState = TouchPoint::Down; // Mouse down.
821 else if( state == 1 )
823 touchPointState = TouchPoint::Motion; // Mouse move.
825 else if( state == 2 )
827 touchPointState = TouchPoint::Up; // Mouse up.
831 touchPointState = TouchPoint::Interrupted; // Error.
834 // Send touch event to accessibility adaptor.
835 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
837 // Perform actions based on received gestures.
838 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
839 switch( gestureValue )
841 case 0: // OneFingerHover
844 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
847 case 1: // TwoFingersHover
849 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
850 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
853 case 2: // ThreeFingersHover
855 // Read from top item on screen continuously.
856 accessibilityAdaptor->HandleActionReadFromTopEvent();
859 case 3: // OneFingerFlickLeft
861 // Move to previous item.
862 accessibilityAdaptor->HandleActionReadPreviousEvent();
865 case 4: // OneFingerFlickRight
867 // Move to next item.
868 accessibilityAdaptor->HandleActionReadNextEvent();
871 case 5: // OneFingerFlickUp
873 // Move to previous item.
874 accessibilityAdaptor->HandleActionPreviousEvent();
877 case 6: // OneFingerFlickDown
879 // Move to next item.
880 accessibilityAdaptor->HandleActionNextEvent();
883 case 7: // TwoFingersFlickUp
885 // Scroll up the list.
886 accessibilityAdaptor->HandleActionScrollUpEvent();
889 case 8: // TwoFingersFlickDown
891 // Scroll down the list.
892 accessibilityAdaptor->HandleActionScrollDownEvent();
895 case 9: // TwoFingersFlickLeft
897 // Scroll left to the previous page
898 accessibilityAdaptor->HandleActionPageLeftEvent();
901 case 10: // TwoFingersFlickRight
903 // Scroll right to the next page
904 accessibilityAdaptor->HandleActionPageRightEvent();
907 case 11: // ThreeFingersFlickLeft
912 case 12: // ThreeFingersFlickRight
917 case 13: // ThreeFingersFlickUp
922 case 14: // ThreeFingersFlickDown
927 case 15: // OneFingerSingleTap
930 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
933 case 16: // OneFingerDoubleTap
935 // Activate selected item / active edit mode.
936 accessibilityAdaptor->HandleActionActivateEvent();
939 case 17: // OneFingerTripleTap
942 accessibilityAdaptor->HandleActionZoomEvent();
945 case 18: // TwoFingersSingleTap
947 // Pause/Resume current speech
948 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
951 case 19: // TwoFingersDoubleTap
953 // Start/Stop current action
954 accessibilityAdaptor->HandleActionStartStopEvent();
957 case 20: // TwoFingersTripleTap
959 // Read information from indicator
960 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
963 case 21: // ThreeFingersSingleTap
965 // Read from top item on screen continuously.
966 accessibilityAdaptor->HandleActionReadFromTopEvent();
969 case 22: // ThreeFingersDoubleTap
971 // Read from next item continuously.
972 accessibilityAdaptor->HandleActionReadFromNextEvent();
975 case 23: // ThreeFingersTripleTap
980 case 24: // OneFingerFlickLeftReturn
982 // Scroll up to the previous page
983 accessibilityAdaptor->HandleActionPageUpEvent();
986 case 25: // OneFingerFlickRightReturn
988 // Scroll down to the next page
989 accessibilityAdaptor->HandleActionPageDownEvent();
992 case 26: // OneFingerFlickUpReturn
994 // Move to the first item on screen
995 accessibilityAdaptor->HandleActionMoveToFirstEvent();
998 case 27: // OneFingerFlickDownReturn
1000 // Move to the last item on screen
1001 accessibilityAdaptor->HandleActionMoveToLastEvent();
1004 case 28: // TwoFingersFlickLeftReturn
1009 case 29: // TwoFingersFlickRightReturn
1014 case 30: // TwoFingersFlickUpReturn
1019 case 31: // TwoFingersFlickDownReturn
1024 case 32: // ThreeFingersFlickLeftReturn
1029 case 33: // ThreeFingersFlickRightReturn
1034 case 34: // ThreeFingersFlickUpReturn
1039 case 35: // ThreeFingersFlickDownReturn
1047 void EcoreElDBusInitialisation( void *handle )
1049 Eldbus_Object *object;
1050 Eldbus_Proxy *manager;
1052 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1054 DALI_LOG_ERROR( "Unable to get system bus\n" );
1057 object = eldbus_object_get( mSystemConnection, BUS, PATH );
1060 DALI_LOG_ERROR( "Getting object failed\n" );
1064 manager = eldbus_proxy_get( object, INTERFACE );
1067 DALI_LOG_ERROR( "Getting proxy failed\n" );
1071 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1073 DALI_LOG_ERROR( "No signal handler returned\n" );
1076 #endif // DALI_ELDBUS_AVAILABLE
1079 * Called when the source window notifies us the content in clipboard is selected.
1081 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1083 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1084 return ECORE_CALLBACK_PASS_ON;
1088 * Called when the source window sends us about the selected content.
1089 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1091 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1093 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1094 return ECORE_CALLBACK_PASS_ON;
1098 * Called when the source window notifies us the content in clipboard is selected.
1100 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1102 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1104 Dali::Clipboard clipboard = Clipboard::Get();
1107 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1108 clipBoardImpl.ExcuteBuffered( true, event );
1110 return ECORE_CALLBACK_PASS_ON;
1114 * Called when the source window sends us about the selected content.
1115 * For example, when item is selected in the clipboard.
1117 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1119 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1121 EventHandler* handler( (EventHandler*)data );
1122 Dali::Clipboard clipboard = Clipboard::Get();
1123 char *selectionData = NULL;
1126 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1127 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1129 if ( selectionData && handler->mClipboardEventNotifier )
1131 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1132 std::string content( selectionData, strlen(selectionData) );
1134 clipboardEventNotifier.SetContent( content );
1135 clipboardEventNotifier.EmitContentSelectedSignal();
1137 return ECORE_CALLBACK_PASS_ON;
1141 * Called when rotate event is recevied
1143 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1145 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1147 EventHandler* handler( (EventHandler*)data );
1148 Ecore_Wl2_Event_Window_Rotation* ev( (Ecore_Wl2_Event_Window_Rotation*)event );
1150 if( ev->win != (unsigned int)ecore_wl2_window_id_get( handler->mImpl->mWindow ) )
1152 return ECORE_CALLBACK_PASS_ON;
1155 RotationEvent rotationEvent;
1156 rotationEvent.angle = ev->angle;
1157 rotationEvent.winResize = 0;
1159 if( ev->angle == 0 || ev->angle == 180 )
1161 rotationEvent.width = ev->w;
1162 rotationEvent.height = ev->h;
1166 rotationEvent.width = ev->h;
1167 rotationEvent.height = ev->w;
1170 handler->SendRotationPrepareEvent( rotationEvent );
1172 return ECORE_CALLBACK_PASS_ON;
1176 * Called when detent event is recevied
1178 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1180 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1181 EventHandler* handler( (EventHandler*)data );
1182 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1183 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1184 int timeStamp = e->timestamp;
1186 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1187 handler->SendWheelEvent( wheelEvent );
1188 return ECORE_CALLBACK_PASS_ON;
1191 /////////////////////////////////////////////////////////////////////////////////////////////////
1193 /////////////////////////////////////////////////////////////////////////////////////////////////
1195 * Called when a font name is changed.
1197 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1199 EventHandler* handler = static_cast<EventHandler*>( data );
1200 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1204 * Called when a font size is changed.
1206 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1208 EventHandler* handler = static_cast<EventHandler*>( data );
1209 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1212 void ConvertTouchPosition( Integration::Point& point )
1214 Vector2 position = point.GetScreenPosition();
1215 Vector2 convertedPosition;
1217 switch( mRotationAngle )
1221 convertedPosition.x = mWindowWidth - position.y;
1222 convertedPosition.y = position.x;
1227 convertedPosition.x = mWindowWidth - position.x;
1228 convertedPosition.y = mWindowHeight - position.y;
1233 convertedPosition.x = position.y;
1234 convertedPosition.y = mWindowHeight - position.x;
1239 convertedPosition = position;
1244 point.SetScreenPosition( convertedPosition );
1248 EventHandler* mHandler;
1249 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1250 Ecore_Wl2_Window* mWindow;
1254 #ifdef DALI_ELDBUS_AVAILABLE
1255 Eldbus_Connection* mSystemConnection;
1256 #endif // DALI_ELDBUS_AVAILABLE
1259 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1260 : mCoreEventInterface( coreEventInterface ),
1261 mGestureManager( gestureManager ),
1262 mStyleMonitor( StyleMonitor::Get() ),
1263 mDamageObserver( damageObserver ),
1264 mRotationObserver( NULL ),
1265 mDragAndDropDetector( dndDetector ),
1266 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1267 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1268 mClipboard( Clipboard::Get() ),
1272 Ecore_Wl2_Window* window = 0;
1274 // this code only works with the WindowRenderSurface so need to downcast
1275 WindowRenderSurfaceEcoreWl2* ecoreSurface = static_cast< WindowRenderSurfaceEcoreWl2* >( surface );
1278 window = ecoreSurface->GetWlWindow();
1281 mImpl = new Impl(this, window);
1284 EventHandler::~EventHandler()
1291 mGestureManager.Stop();
1294 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1298 timeStamp = GetCurrentMilliSeconds();
1301 mImpl->ConvertTouchPosition( point );
1303 Integration::TouchEvent touchEvent;
1304 Integration::HoverEvent hoverEvent;
1305 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1306 if(type != Integration::TouchEventCombiner::DispatchNone )
1308 DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.GetDeviceId(), point.GetState(), point.GetScreenPosition().x, point.GetScreenPosition().y);
1310 // First the touch and/or hover event & related gesture events are queued
1311 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1313 mCoreEventInterface.QueueCoreEvent( touchEvent );
1314 mGestureManager.SendEvent(touchEvent);
1317 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1319 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1322 // Next the events are processed with a single call into Core
1323 mCoreEventInterface.ProcessCoreEvents();
1327 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1329 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1330 if ( physicalKeyboard )
1332 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1334 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1338 // Create send KeyEvent to Core.
1339 mCoreEventInterface.QueueCoreEvent( keyEvent );
1340 mCoreEventInterface.ProcessCoreEvents();
1343 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1345 // Create WheelEvent and send to Core.
1346 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1347 mCoreEventInterface.QueueCoreEvent( event );
1348 mCoreEventInterface.ProcessCoreEvents();
1351 void EventHandler::SendEvent( StyleChange::Type styleChange )
1353 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1354 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1357 void EventHandler::SendEvent( const DamageArea& area )
1359 mDamageObserver.OnDamaged( area );
1362 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1364 if( mRotationObserver != NULL )
1366 mImpl->mRotationAngle = event.angle;
1367 mImpl->mWindowWidth = event.width;
1368 mImpl->mWindowHeight = event.height;
1370 mRotationObserver->OnRotationPrepare( event );
1371 mRotationObserver->OnRotationRequest();
1375 void EventHandler::SendRotationRequestEvent( )
1377 // No need to separate event into prepare and request in wayland
1380 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1382 Integration::Point convertedPoint( point );
1383 SendEvent(convertedPoint, timeStamp);
1386 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1388 SendWheelEvent( wheelEvent );
1391 void EventHandler::FeedKeyEvent( KeyEvent& event )
1393 Integration::KeyEvent convertedEvent( event );
1394 SendEvent( convertedEvent );
1397 void EventHandler::FeedEvent( Integration::Event& event )
1399 mCoreEventInterface.QueueCoreEvent( event );
1400 mCoreEventInterface.ProcessCoreEvents();
1403 void EventHandler::Reset()
1407 // Any touch listeners should be told of the interruption.
1408 Integration::TouchEvent event;
1409 Integration::Point point;
1410 point.SetState( PointState::INTERRUPTED );
1411 event.AddPoint( point );
1413 // First the touch event & related gesture events are queued
1414 mCoreEventInterface.QueueCoreEvent( event );
1415 mGestureManager.SendEvent( event );
1417 // Next the events are processed with a single call into Core
1418 mCoreEventInterface.ProcessCoreEvents();
1421 void EventHandler::Pause()
1427 void EventHandler::Resume()
1433 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1435 mDragAndDropDetector = detector;
1438 void EventHandler::SetRotationObserver( RotationObserver* observer )
1440 mRotationObserver = observer;
1443 } // namespace Adaptor
1445 } // namespace Internal
1449 #pragma GCC diagnostic pop