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>
28 #include <dali/integration-api/wayland/ecore-wl-render-surface.h>
29 //#include <dali/window-system/tizen-wayland/window-render-surface-ecore-wl.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/device.h>
45 #include <dali/public-api/events/touch-point.h>
46 #include <dali/public-api/events/key-event.h>
47 #include <dali/public-api/events/wheel-event.h>
48 #include <dali/integration-api/debug.h>
49 #include <dali/integration-api/events/key-event-integ.h>
50 #include <dali/integration-api/events/touch-event-integ.h>
51 #include <dali/integration-api/events/hover-event-integ.h>
52 #include <dali/integration-api/events/wheel-event-integ.h>
55 #include <dali/internal/input/common/gesture-manager.h>
56 #include <dali/internal/window-system/tizen-wayland/window-render-surface-ecore-wl.h>
57 #include <dali/internal/clipboard/common/clipboard-impl.h>
58 #include <dali/internal/input/common/key-impl.h>
59 #include <dali/internal/input/common/physical-keyboard-impl.h>
60 #include <dali/internal/styling/common/style-monitor-impl.h>
61 #include <dali/internal/system/common/core-event-interface.h>
62 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
73 #if defined(DEBUG_ENABLED)
76 Integration::Log::Filter* gTouchEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
77 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
78 Integration::Log::Filter* gImfLogging = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
79 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
80 } // unnamed namespace
88 const char* BUS = "org.enlightenment.wm-screen-reader";
89 const char* INTERFACE = "org.tizen.GestureNavigation";
90 const char* PATH = "/org/tizen/GestureNavigation";
92 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
94 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
96 // Copied from x server
97 static unsigned int GetCurrentMilliSeconds(void)
102 static clockid_t clockid;
106 #ifdef CLOCK_MONOTONIC_COARSE
107 if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
108 (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
110 clockid = CLOCK_MONOTONIC_COARSE;
114 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
116 clockid = CLOCK_MONOTONIC;
123 if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
125 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
128 gettimeofday(&tv, NULL);
129 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
132 #ifndef DALI_PROFILE_UBUNTU
133 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
134 #endif // DALI_PROFILE_UBUNTU
137 * Get the device name from the provided ecore key event
139 void GetDeviceName( Ecore_Event_Key* keyEvent, std::string& result )
141 const char* ecoreDeviceName = ecore_device_name_get( keyEvent->dev );
143 if ( ecoreDeviceName )
145 result = ecoreDeviceName;
150 * Get the device class from the provided ecore event
152 void GetDeviceClass( Ecore_Device_Class ecoreDeviceClass, Device::Class::Type& deviceClass )
154 switch( ecoreDeviceClass )
156 case ECORE_DEVICE_CLASS_SEAT:
158 deviceClass = Device::Class::USER;
161 case ECORE_DEVICE_CLASS_KEYBOARD:
163 deviceClass = Device::Class::KEYBOARD;
166 case ECORE_DEVICE_CLASS_MOUSE:
168 deviceClass = Device::Class::MOUSE;
171 case ECORE_DEVICE_CLASS_TOUCH:
173 deviceClass = Device::Class::TOUCH;
176 case ECORE_DEVICE_CLASS_PEN:
178 deviceClass = Device::Class::PEN;
181 case ECORE_DEVICE_CLASS_POINTER:
183 deviceClass = Device::Class::POINTER;
186 case ECORE_DEVICE_CLASS_GAMEPAD:
188 deviceClass = Device::Class::GAMEPAD;
193 deviceClass = Device::Class::NONE;
199 void GetDeviceSubclass( Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subclass::Type& deviceSubclass )
201 switch( ecoreDeviceSubclass )
203 case ECORE_DEVICE_SUBCLASS_FINGER:
205 deviceSubclass = Device::Subclass::FINGER;
208 case ECORE_DEVICE_SUBCLASS_FINGERNAIL:
210 deviceSubclass = Device::Subclass::FINGERNAIL;
213 case ECORE_DEVICE_SUBCLASS_KNUCKLE:
215 deviceSubclass = Device::Subclass::KNUCKLE;
218 case ECORE_DEVICE_SUBCLASS_PALM:
220 deviceSubclass = Device::Subclass::PALM;
223 case ECORE_DEVICE_SUBCLASS_HAND_SIZE:
225 deviceSubclass = Device::Subclass::HAND_SIDE;
228 case ECORE_DEVICE_SUBCLASS_HAND_FLAT:
230 deviceSubclass = Device::Subclass::HAND_FLAT;
233 case ECORE_DEVICE_SUBCLASS_PEN_TIP:
235 deviceSubclass = Device::Subclass::PEN_TIP;
238 case ECORE_DEVICE_SUBCLASS_TRACKPAD:
240 deviceSubclass = Device::Subclass::TRACKPAD;
243 case ECORE_DEVICE_SUBCLASS_TRACKPOINT:
245 deviceSubclass = Device::Subclass::TRACKPOINT;
248 case ECORE_DEVICE_SUBCLASS_TRACKBALL:
250 deviceSubclass = Device::Subclass::TRACKBALL;
253 #ifdef OVER_TIZEN_VERSION_4
254 case ECORE_DEVICE_SUBCLASS_REMOCON:
256 deviceSubclass = Device::Subclass::REMOCON;
259 case ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD:
261 deviceSubclass = Device::Subclass::VIRTUAL_KEYBOARD;
267 deviceSubclass = Device::Subclass::NONE;
273 } // unnamed namespace
275 // Impl to hide EFL implementation.
276 struct EventHandler::Impl
278 // Construction & Destruction
283 Impl( EventHandler* handler, Ecore_Wl_Window* window )
284 : mHandler( handler ),
285 mEcoreEventHandler(),
290 #ifdef DALI_ELDBUS_AVAILABLE
291 , mSystemConnection( NULL )
292 #endif // DALI_ELDBUS_AVAILABLE
294 // Only register for touch and key events if we have a window
297 // Register Touch events
298 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, handler ) );
299 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, handler ) );
300 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, handler ) );
301 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, handler ) );
303 // Register Mouse wheel events
304 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, handler ) );
306 // Register Focus events
307 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, handler ) );
308 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, handler ) );
310 // Register Key events
311 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, handler ) );
312 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP, EcoreEventKeyUp, handler ) );
314 // Register Selection event - clipboard selection
315 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
316 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
318 // Register Rotate event
319 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
321 // Register Detent event
322 mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
324 #ifndef DALI_PROFILE_UBUNTU
325 // Register Vconf notify - font name and size
326 vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
327 vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
328 #endif // DALI_PROFILE_UBUNTU
330 #ifdef DALI_ELDBUS_AVAILABLE
331 // Initialize ElDBus.
332 DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
335 EcoreElDBusInitialisation( handler );
337 DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
338 #endif // DALI_ELDBUS_AVAILABLE
347 #ifndef DALI_PROFILE_UBUNTU
348 vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
349 vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
350 #endif // DALI_PROFILE_UBUNTU
352 for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
354 ecore_event_handler_del( *iter );
357 #ifdef DALI_ELDBUS_AVAILABLE
358 // Close down ElDBus connections.
359 if( mSystemConnection )
361 eldbus_connection_unref( mSystemConnection );
363 #endif // DALI_ELDBUS_AVAILABLE
368 /////////////////////////////////////////////////////////////////////////////////////////////////
370 /////////////////////////////////////////////////////////////////////////////////////////////////
373 * Called when a touch down is received.
375 static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
377 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
378 EventHandler* handler( (EventHandler*)data );
380 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
382 PointState::Type state ( PointState::DOWN );
384 // Check if the buttons field is set and ensure it's the primary touch button.
385 // If this event was triggered by buttons other than the primary button (used for touch), then
386 // just send an interrupted event to Core.
387 if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
389 state = PointState::INTERRUPTED;
392 Device::Class::Type deviceClass;
393 Device::Subclass::Type deviceSubclass;
395 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
396 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
398 Integration::Point point;
399 point.SetDeviceId( touchEvent->multi.device );
400 point.SetState( state );
401 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
402 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
403 point.SetPressure( touchEvent->multi.pressure );
404 point.SetAngle( Degree( touchEvent->multi.angle ) );
405 point.SetDeviceClass( deviceClass );
406 point.SetDeviceSubclass( deviceSubclass );
408 handler->SendEvent( point, touchEvent->timestamp );
411 return ECORE_CALLBACK_PASS_ON;
415 * Called when a touch up is received.
417 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
419 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
420 EventHandler* handler( (EventHandler*)data );
422 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
424 Device::Class::Type deviceClass;
425 Device::Subclass::Type deviceSubclass;
427 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
428 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
430 Integration::Point point;
431 point.SetDeviceId( touchEvent->multi.device );
432 point.SetState( PointState::UP );
433 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
434 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
435 point.SetPressure( touchEvent->multi.pressure );
436 point.SetAngle( Degree( touchEvent->multi.angle ) );
437 point.SetDeviceClass( deviceClass );
438 point.SetDeviceSubclass( deviceSubclass );
440 handler->SendEvent( point, touchEvent->timestamp );
443 return ECORE_CALLBACK_PASS_ON;
447 * Called when a touch motion is received.
449 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
451 Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
452 EventHandler* handler( (EventHandler*)data );
454 if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
456 Device::Class::Type deviceClass;
457 Device::Subclass::Type deviceSubclass;
459 GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
460 GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
462 Integration::Point point;
463 point.SetDeviceId( touchEvent->multi.device );
464 point.SetState( PointState::MOTION );
465 point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
466 point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
467 point.SetPressure( touchEvent->multi.pressure );
468 point.SetAngle( Degree( touchEvent->multi.angle ) );
469 point.SetDeviceClass( deviceClass );
470 point.SetDeviceSubclass( deviceSubclass );
472 handler->SendEvent( point, touchEvent->timestamp );
475 return ECORE_CALLBACK_PASS_ON;
479 * Called when a touch is canceled.
481 static Eina_Bool EcoreEventMouseButtonCancel( void* data, int type, void* event )
483 Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
484 EventHandler* handler( (EventHandler*)data );
486 if( touchEvent->window == (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
488 Integration::Point point;
489 point.SetDeviceId( touchEvent->multi.device );
490 point.SetState( PointState::INTERRUPTED );
491 point.SetScreenPosition( Vector2( 0.0f, 0.0f ) );
492 handler->SendEvent( point, touchEvent->timestamp );
494 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventMouseButtonCancel\n" );
497 return ECORE_CALLBACK_PASS_ON;
501 * Called when a mouse wheel is received.
503 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
505 Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
507 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);
509 EventHandler* handler( (EventHandler*)data );
510 if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
512 WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
513 handler->SendWheelEvent( wheelEvent );
515 return ECORE_CALLBACK_PASS_ON;
518 /////////////////////////////////////////////////////////////////////////////////////////////////
520 /////////////////////////////////////////////////////////////////////////////////////////////////
523 * Called when a key down is received.
525 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
527 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
529 EventHandler* handler( (EventHandler*)data );
530 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
531 bool eventHandled( false );
533 // If the event wasn't handled then we should send a key event.
536 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
538 std::string keyName( keyEvent->keyname );
539 std::string keyString( "" );
540 std::string compose( "" );
542 // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
543 if ( keyEvent->compose )
545 compose = keyEvent->compose;
548 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
549 keyCode = (keyCode == -1) ? 0 : keyCode;
550 int modifier( keyEvent->modifiers );
551 unsigned long time = keyEvent->timestamp;
552 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
553 keyCode = atoi(keyEvent->keyname + 8);
555 // Ensure key event string is not NULL as keys like SHIFT have a null string.
556 if ( keyEvent->string )
558 keyString = keyEvent->string;
561 std::string deviceName;
562 Device::Class::Type deviceClass;
563 Device::Subclass::Type deviceSubclass;
565 GetDeviceName( keyEvent, deviceName );
566 GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
567 GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
569 DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s) deviceClass(%d)\n", deviceName.c_str(), deviceClass );
571 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, compose, deviceName, deviceClass, deviceSubclass );
572 handler->SendEvent( keyEvent );
576 return ECORE_CALLBACK_PASS_ON;
580 * Called when a key up is received.
582 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
584 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
586 EventHandler* handler( (EventHandler*)data );
587 Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
588 bool eventHandled( false );
590 // If the event wasn't handled then we should send a key event.
593 if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
595 std::string keyName( keyEvent->keyname );
596 std::string keyString( "" );
597 std::string compose( "" );
599 // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
600 if ( keyEvent->compose )
602 compose = keyEvent->compose;
605 int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
606 keyCode = (keyCode == -1) ? 0 : keyCode;
607 int modifier( keyEvent->modifiers );
608 unsigned long time = keyEvent->timestamp;
609 if (!strncmp(keyEvent->keyname, "Keycode-", 8))
610 keyCode = atoi(keyEvent->keyname + 8);
612 // Ensure key event string is not NULL as keys like SHIFT have a null string.
613 if ( keyEvent->string )
615 keyString = keyEvent->string;
618 std::string deviceName;
619 Device::Class::Type deviceClass;
620 Device::Subclass::Type deviceSubclass;
622 GetDeviceName( keyEvent, deviceName );
623 GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
624 GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
626 Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, compose, deviceName, deviceClass, deviceSubclass );
627 handler->SendEvent( keyEvent );
631 return ECORE_CALLBACK_PASS_ON;
634 /////////////////////////////////////////////////////////////////////////////////////////////////
636 /////////////////////////////////////////////////////////////////////////////////////////////////
639 * Called when the window gains focus.
641 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
643 Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
644 EventHandler* handler( (EventHandler*)data );
646 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
648 // If the window gains focus and we hid the keyboard then show it again.
649 if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
651 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
653 Dali::Clipboard clipboard = Clipboard::Get();
654 clipboard.HideClipboard();
657 return ECORE_CALLBACK_PASS_ON;
661 * Called when the window loses focus.
663 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
665 Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
666 EventHandler* handler( (EventHandler*)data );
668 DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
670 // If the window loses focus then hide the keyboard.
671 if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
673 // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
674 Dali::Clipboard clipboard = Clipboard::Get();
677 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
678 clipBoardImpl.HideClipboard(true);
682 return ECORE_CALLBACK_PASS_ON;
686 * Called when the window is damaged.
688 static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
690 return ECORE_CALLBACK_PASS_ON;
694 * Called when the window properties are changed.
695 * We are only interested in the font change.
699 /////////////////////////////////////////////////////////////////////////////////////////////////
700 // Drag & Drop Callbacks
701 /////////////////////////////////////////////////////////////////////////////////////////////////
704 * Called when a dragged item enters our window's bounds.
705 * This is when items are dragged INTO our window.
707 static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
709 DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
711 return ECORE_CALLBACK_PASS_ON;
715 * Called when a dragged item is moved within our window.
716 * This is when items are dragged INTO our window.
718 static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
720 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
722 return ECORE_CALLBACK_PASS_ON;
726 * Called when a dragged item leaves our window's bounds.
727 * This is when items are dragged INTO our window.
729 static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
731 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
733 return ECORE_CALLBACK_PASS_ON;
737 * Called when the dragged item is dropped within our window's bounds.
738 * This is when items are dragged INTO our window.
740 static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
742 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
744 return ECORE_CALLBACK_PASS_ON;
748 * Called when a dragged item is moved from our window and the target window has done processing it.
749 * This is when items are dragged FROM our window.
751 static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
753 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
754 return ECORE_CALLBACK_PASS_ON;
758 * Called when a dragged item is moved from our window and the target window has sent us a status.
759 * This is when items are dragged FROM our window.
761 static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
763 DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
764 return ECORE_CALLBACK_PASS_ON;
768 * Called when the client messages (i.e. the accessibility events) are received.
770 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
772 return ECORE_CALLBACK_PASS_ON;
776 /////////////////////////////////////////////////////////////////////////////////////////////////
777 // ElDBus Accessibility Callbacks
778 /////////////////////////////////////////////////////////////////////////////////////////////////
780 #ifdef DALI_ELDBUS_AVAILABLE
781 // Callback for Ecore ElDBus accessibility events.
782 static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
784 EventHandler* handler = static_cast< EventHandler* >( context );
785 // Ignore any accessibility events when paused.
786 if( handler->mPaused )
791 if( !handler->mAccessibilityAdaptor )
793 DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
797 AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
798 if( !accessibilityAdaptor )
800 DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
806 int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
809 // The string defines the arg-list's respective types.
810 if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
812 DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
815 DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d Args: %d,%d,%d,%d State: %d\n", gestureValue, xS, yS, xE, yE );
817 // Create a touch point object.
818 TouchPoint::State touchPointState( TouchPoint::Down );
821 touchPointState = TouchPoint::Down; // Mouse down.
823 else if( state == 1 )
825 touchPointState = TouchPoint::Motion; // Mouse move.
827 else if( state == 2 )
829 touchPointState = TouchPoint::Up; // Mouse up.
833 touchPointState = TouchPoint::Interrupted; // Error.
836 // Send touch event to accessibility adaptor.
837 TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
839 // Perform actions based on received gestures.
840 // Note: This is seperated from the reading so we can have other input readers without changing the below code.
841 switch( gestureValue )
843 case 0: // OneFingerHover
846 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
849 case 1: // TwoFingersHover
851 // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
852 accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
855 case 2: // ThreeFingersHover
857 // Read from top item on screen continuously.
858 accessibilityAdaptor->HandleActionReadFromTopEvent();
861 case 3: // OneFingerFlickLeft
863 // Move to previous item.
864 accessibilityAdaptor->HandleActionReadPreviousEvent();
867 case 4: // OneFingerFlickRight
869 // Move to next item.
870 accessibilityAdaptor->HandleActionReadNextEvent();
873 case 5: // OneFingerFlickUp
875 // Move to previous item.
876 accessibilityAdaptor->HandleActionPreviousEvent();
879 case 6: // OneFingerFlickDown
881 // Move to next item.
882 accessibilityAdaptor->HandleActionNextEvent();
885 case 7: // TwoFingersFlickUp
887 // Scroll up the list.
888 accessibilityAdaptor->HandleActionScrollUpEvent();
891 case 8: // TwoFingersFlickDown
893 // Scroll down the list.
894 accessibilityAdaptor->HandleActionScrollDownEvent();
897 case 9: // TwoFingersFlickLeft
899 // Scroll left to the previous page
900 accessibilityAdaptor->HandleActionPageLeftEvent();
903 case 10: // TwoFingersFlickRight
905 // Scroll right to the next page
906 accessibilityAdaptor->HandleActionPageRightEvent();
909 case 11: // ThreeFingersFlickLeft
914 case 12: // ThreeFingersFlickRight
919 case 13: // ThreeFingersFlickUp
924 case 14: // ThreeFingersFlickDown
929 case 15: // OneFingerSingleTap
932 accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
935 case 16: // OneFingerDoubleTap
937 // Activate selected item / active edit mode.
938 accessibilityAdaptor->HandleActionActivateEvent();
941 case 17: // OneFingerTripleTap
944 accessibilityAdaptor->HandleActionZoomEvent();
947 case 18: // TwoFingersSingleTap
949 // Pause/Resume current speech
950 accessibilityAdaptor->HandleActionReadPauseResumeEvent();
953 case 19: // TwoFingersDoubleTap
955 // Start/Stop current action
956 accessibilityAdaptor->HandleActionStartStopEvent();
959 case 20: // TwoFingersTripleTap
961 // Read information from indicator
962 accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
965 case 21: // ThreeFingersSingleTap
967 // Read from top item on screen continuously.
968 accessibilityAdaptor->HandleActionReadFromTopEvent();
971 case 22: // ThreeFingersDoubleTap
973 // Read from next item continuously.
974 accessibilityAdaptor->HandleActionReadFromNextEvent();
977 case 23: // ThreeFingersTripleTap
982 case 24: // OneFingerFlickLeftReturn
984 // Scroll up to the previous page
985 accessibilityAdaptor->HandleActionPageUpEvent();
988 case 25: // OneFingerFlickRightReturn
990 // Scroll down to the next page
991 accessibilityAdaptor->HandleActionPageDownEvent();
994 case 26: // OneFingerFlickUpReturn
996 // Move to the first item on screen
997 accessibilityAdaptor->HandleActionMoveToFirstEvent();
1000 case 27: // OneFingerFlickDownReturn
1002 // Move to the last item on screen
1003 accessibilityAdaptor->HandleActionMoveToLastEvent();
1006 case 28: // TwoFingersFlickLeftReturn
1011 case 29: // TwoFingersFlickRightReturn
1016 case 30: // TwoFingersFlickUpReturn
1021 case 31: // TwoFingersFlickDownReturn
1026 case 32: // ThreeFingersFlickLeftReturn
1031 case 33: // ThreeFingersFlickRightReturn
1036 case 34: // ThreeFingersFlickUpReturn
1041 case 35: // ThreeFingersFlickDownReturn
1049 void EcoreElDBusInitialisation( void *handle )
1051 Eldbus_Object *object;
1052 Eldbus_Proxy *manager;
1054 if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1056 DALI_LOG_ERROR( "Unable to get system bus\n" );
1059 object = eldbus_object_get( mSystemConnection, BUS, PATH );
1062 DALI_LOG_ERROR( "Getting object failed\n" );
1066 manager = eldbus_proxy_get( object, INTERFACE );
1069 DALI_LOG_ERROR( "Getting proxy failed\n" );
1073 if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1075 DALI_LOG_ERROR( "No signal handler returned\n" );
1078 #endif // DALI_ELDBUS_AVAILABLE
1081 * Called when the source window notifies us the content in clipboard is selected.
1083 static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1085 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1086 return ECORE_CALLBACK_PASS_ON;
1090 * Called when the source window sends us about the selected content.
1091 * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1093 static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1095 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1096 return ECORE_CALLBACK_PASS_ON;
1100 * Called when the source window notifies us the content in clipboard is selected.
1102 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1104 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1106 Dali::Clipboard clipboard = Clipboard::Get();
1109 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1110 clipBoardImpl.ExcuteBuffered( true, event );
1112 return ECORE_CALLBACK_PASS_ON;
1116 * Called when the source window sends us about the selected content.
1117 * For example, when item is selected in the clipboard.
1119 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1121 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1123 EventHandler* handler( (EventHandler*)data );
1124 Dali::Clipboard clipboard = Clipboard::Get();
1125 char *selectionData = NULL;
1128 Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1129 selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1131 if ( selectionData && handler->mClipboardEventNotifier )
1133 ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1134 std::string content( selectionData, strlen(selectionData) );
1136 clipboardEventNotifier.SetContent( content );
1137 clipboardEventNotifier.EmitContentSelectedSignal();
1139 return ECORE_CALLBACK_PASS_ON;
1143 * Called when rotate event is recevied
1145 static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1147 DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1149 EventHandler* handler( (EventHandler*)data );
1150 Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1152 if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1154 return ECORE_CALLBACK_PASS_ON;
1157 RotationEvent rotationEvent;
1158 rotationEvent.angle = ev->angle;
1159 rotationEvent.winResize = 0;
1161 if( ev->angle == 0 || ev->angle == 180 )
1163 rotationEvent.width = ev->w;
1164 rotationEvent.height = ev->h;
1168 rotationEvent.width = ev->h;
1169 rotationEvent.height = ev->w;
1172 handler->SendRotationPrepareEvent( rotationEvent );
1174 return ECORE_CALLBACK_PASS_ON;
1178 * Called when detent event is recevied
1180 static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1182 DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1183 EventHandler* handler( (EventHandler*)data );
1184 Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1185 int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1186 int timeStamp = e->timestamp;
1188 WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1189 handler->SendWheelEvent( wheelEvent );
1190 return ECORE_CALLBACK_PASS_ON;
1193 /////////////////////////////////////////////////////////////////////////////////////////////////
1195 /////////////////////////////////////////////////////////////////////////////////////////////////
1197 * Called when a font name is changed.
1199 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1201 EventHandler* handler = static_cast<EventHandler*>( data );
1202 handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1206 * Called when a font size is changed.
1208 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1210 EventHandler* handler = static_cast<EventHandler*>( data );
1211 handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1214 void ConvertTouchPosition( Integration::Point& point )
1216 Vector2 position = point.GetScreenPosition();
1217 Vector2 convertedPosition;
1219 switch( mRotationAngle )
1223 convertedPosition.x = mWindowWidth - position.y;
1224 convertedPosition.y = position.x;
1229 convertedPosition.x = mWindowWidth - position.x;
1230 convertedPosition.y = mWindowHeight - position.y;
1235 convertedPosition.x = position.y;
1236 convertedPosition.y = mWindowHeight - position.x;
1241 convertedPosition = position;
1246 point.SetScreenPosition( convertedPosition );
1250 EventHandler* mHandler;
1251 std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1252 Ecore_Wl_Window* mWindow;
1256 #ifdef DALI_ELDBUS_AVAILABLE
1257 Eldbus_Connection* mSystemConnection;
1258 #endif // DALI_ELDBUS_AVAILABLE
1261 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1262 : mCoreEventInterface( coreEventInterface ),
1263 mGestureManager( gestureManager ),
1264 mStyleMonitor( StyleMonitor::Get() ),
1265 mDamageObserver( damageObserver ),
1266 mRotationObserver( NULL ),
1267 mDragAndDropDetector( dndDetector ),
1268 mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1269 mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1270 mClipboard( Clipboard::Get() ),
1274 Ecore_Wl_Window* window = 0;
1276 // this code only works with the Ecore RenderSurface so need to downcast
1277 ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1280 window = ecoreSurface->GetWlWindow();
1283 mImpl = new Impl(this, window);
1286 EventHandler::~EventHandler()
1293 mGestureManager.Stop();
1296 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1300 timeStamp = GetCurrentMilliSeconds();
1303 mImpl->ConvertTouchPosition( point );
1305 Integration::TouchEvent touchEvent;
1306 Integration::HoverEvent hoverEvent;
1307 Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1308 if(type != Integration::TouchEventCombiner::DispatchNone )
1310 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);
1312 // First the touch and/or hover event & related gesture events are queued
1313 if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1315 mCoreEventInterface.QueueCoreEvent( touchEvent );
1316 mGestureManager.SendEvent(touchEvent);
1319 if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1321 mCoreEventInterface.QueueCoreEvent( hoverEvent );
1324 // Next the events are processed with a single call into Core
1325 mCoreEventInterface.ProcessCoreEvents();
1329 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1331 Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1332 if ( physicalKeyboard )
1334 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1336 GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1340 // Create send KeyEvent to Core.
1341 mCoreEventInterface.QueueCoreEvent( keyEvent );
1342 mCoreEventInterface.ProcessCoreEvents();
1345 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1347 // Create WheelEvent and send to Core.
1348 Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1349 mCoreEventInterface.QueueCoreEvent( event );
1350 mCoreEventInterface.ProcessCoreEvents();
1353 void EventHandler::SendEvent( StyleChange::Type styleChange )
1355 DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1356 GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1359 void EventHandler::SendEvent( const DamageArea& area )
1361 mDamageObserver.OnDamaged( area );
1364 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1366 if( mRotationObserver != NULL )
1368 mImpl->mRotationAngle = event.angle;
1369 mImpl->mWindowWidth = event.width;
1370 mImpl->mWindowHeight = event.height;
1372 mRotationObserver->OnRotationPrepare( event );
1373 mRotationObserver->OnRotationRequest();
1377 void EventHandler::SendRotationRequestEvent( )
1379 // No need to separate event into prepare and request in wayland
1382 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1384 Integration::Point convertedPoint( point );
1385 SendEvent(convertedPoint, timeStamp);
1388 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1390 SendWheelEvent( wheelEvent );
1393 void EventHandler::FeedKeyEvent( KeyEvent& event )
1395 Integration::KeyEvent convertedEvent( event );
1396 SendEvent( convertedEvent );
1399 void EventHandler::FeedEvent( Integration::Event& event )
1401 mCoreEventInterface.QueueCoreEvent( event );
1402 mCoreEventInterface.ProcessCoreEvents();
1405 void EventHandler::Reset()
1409 // Any touch listeners should be told of the interruption.
1410 Integration::TouchEvent event;
1411 Integration::Point point;
1412 point.SetState( PointState::INTERRUPTED );
1413 event.AddPoint( point );
1415 // First the touch event & related gesture events are queued
1416 mCoreEventInterface.QueueCoreEvent( event );
1417 mGestureManager.SendEvent( event );
1419 // Next the events are processed with a single call into Core
1420 mCoreEventInterface.ProcessCoreEvents();
1423 void EventHandler::Pause()
1429 void EventHandler::Resume()
1435 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1437 mDragAndDropDetector = detector;
1440 void EventHandler::SetRotationObserver( RotationObserver* observer )
1442 mRotationObserver = observer;
1445 } // namespace Adaptor
1447 } // namespace Internal
1451 #pragma GCC diagnostic pop