Change WheelEvent 59/39759/4
authorHeeyong Song <heeyong.song@samsung.com>
Fri, 22 May 2015 04:37:08 +0000 (13:37 +0900)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 29 May 2015 14:32:49 +0000 (07:32 -0700)
  - Replace MouseWheelEvent with WheelEvent
  - Add custom wheel event type

Change-Id: Ie56513a13b2b6d512e151223d1c47623b4b055b8

adaptors/common/adaptor-impl.cpp
adaptors/common/adaptor-impl.h
adaptors/common/adaptor.cpp
adaptors/common/events/event-handler.h
adaptors/devel-api/adaptor-framework/event-feeder.cpp
adaptors/devel-api/adaptor-framework/event-feeder.h
adaptors/integration-api/adaptor.h
adaptors/wayland/event-handler-wl.cpp
adaptors/x11/event-handler-x.cpp
packaging/dali-adaptor.spec

index c3dede8..1038e11 100644 (file)
@@ -368,7 +368,7 @@ void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
   mEventHandler->FeedTouchPoint( point, timeStamp );
 }
 
-void Adaptor::FeedWheelEvent( MouseWheelEvent& wheelEvent )
+void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
 {
   mEventHandler->FeedWheelEvent( wheelEvent );
 }
index 620ecdf..5e4e25e 100644 (file)
@@ -150,7 +150,7 @@ public: // AdaptorInternalServices implementation
   /**
    * @copydoc Dali::EventFeeder::FeedWheelEvent()
    */
-  virtual void FeedWheelEvent( MouseWheelEvent& wheelEvent );
+  virtual void FeedWheelEvent( WheelEvent& wheelEvent );
 
   /**
    * @copydoc Dali::EventFeeder::FeedKeyEvent()
index 42d969c..944650c 100644 (file)
@@ -150,7 +150,7 @@ void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
   mImpl->FeedTouchPoint(point, timeStamp);
 }
 
-void Adaptor::FeedWheelEvent( MouseWheelEvent& wheelEvent )
+void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
 {
   mImpl->FeedWheelEvent(wheelEvent);
 }
index 4997700..f431d18 100644 (file)
@@ -77,10 +77,10 @@ public:
   void FeedTouchPoint( TouchPoint& point, int timeStamp );
 
   /**
-   * Feed (Send) mouse wheel event to core and gesture manager
-   * @param[in]  wheelEvent The mouse wheel event
+   * Feed (Send) wheel event to core and gesture manager
+   * @param[in]  wheelEvent The wheel event
    */
-  void FeedWheelEvent( MouseWheelEvent& wheelEvent );
+  void FeedWheelEvent( WheelEvent& wheelEvent );
 
   /**
    * Feed (Send) key event to core
@@ -127,10 +127,10 @@ private:
   void SendEvent(KeyEvent& keyEvent);
 
   /**
-   * Send mouse wheel event to core.
-   * @param[in]  wheelEvent The mouse wheel event
+   * Send wheel event to core.
+   * @param[in]  wheelEvent The wheel event
    */
-  void SendMouseWheelEvent( MouseWheelEvent& wheelEvent );
+  void SendWheelEvent( WheelEvent& wheelEvent );
 
   /**
    * Send a style change event to the style monitor.
index 56299d0..7ddf711 100644 (file)
@@ -35,7 +35,7 @@ void FeedTouchPoint( TouchPoint& point, int timeStamp )
   }
 }
 
-void FeedWheelEvent( MouseWheelEvent& wheelEvent )
+void FeedWheelEvent( WheelEvent& wheelEvent )
 {
   if ( Adaptor::IsAvailable() )
   {
index dec490a..2a10220 100644 (file)
@@ -25,7 +25,7 @@ namespace Dali
 {
 
 struct KeyEvent;
-struct MouseWheelEvent;
+struct WheelEvent;
 struct TouchPoint;
 
 namespace EventFeeder
@@ -42,13 +42,13 @@ namespace EventFeeder
 DALI_IMPORT_API void FeedTouchPoint( TouchPoint& point, int timeStamp );
 
 /**
- * Feed a mouse wheel event to the adaptor.
+ * Feed a wheel event to the adaptor.
  *
- * @param[in]  wheelEvent mouse wheel event
+ * @param[in]  wheelEvent wheel event
  *
  * @note For testing/automation purposes only.
  */
-DALI_IMPORT_API void FeedWheelEvent( MouseWheelEvent& wheelEvent );
+DALI_IMPORT_API void FeedWheelEvent( WheelEvent& wheelEvent );
 
 /**
  * Feed a key event to the adaptor.
index 025f1e8..6ac79ea 100644 (file)
@@ -274,11 +274,11 @@ public:
   void FeedTouchPoint( TouchPoint& point, int timeStamp );
 
   /**
-   * @brief Feed a mouse wheel event to the adaptor.
+   * @brief Feed a wheel event to the adaptor.
    *
-   * @param[in]  wheelEvent mouse wheel event
+   * @param[in]  wheelEvent wheel event
    */
-  void FeedWheelEvent( MouseWheelEvent& wheelEvent );
+  void FeedWheelEvent( WheelEvent& wheelEvent );
 
   /**
    * @brief Feed a key event to the adaptor.
index 52c2369..177cadc 100644 (file)
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/events/touch-point.h>
 #include <dali/public-api/events/key-event.h>
-#include <dali/public-api/events/mouse-wheel-event.h>
+#include <dali/public-api/events/wheel-event.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/events/key-event-integ.h>
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali/integration-api/events/hover-event-integ.h>
-#include <dali/integration-api/events/mouse-wheel-event-integ.h>
+#include <dali/integration-api/events/wheel-event-integ.h>
 
 // INTERNAL INCLUDES
 #include <events/gesture-manager.h>
@@ -274,8 +274,8 @@ struct EventHandler::Impl
     EventHandler* handler( (EventHandler*)data );
     if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
     {
-      MouseWheelEvent wheelEvent(mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp);
-      handler->SendMouseWheelEvent( wheelEvent );
+      WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
+      handler->SendWheelEvent( wheelEvent );
     }
     return ECORE_CALLBACK_PASS_ON;
   }
@@ -738,10 +738,10 @@ void EventHandler::SendEvent(KeyEvent& keyEvent)
   mCoreEventInterface.ProcessCoreEvents();
 }
 
-void EventHandler::SendMouseWheelEvent( MouseWheelEvent& wheelEvent )
+void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
 {
-  // Create MouseWheelEvent and send to Core.
-  Integration::MouseWheelEvent event(wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp);
+  // Create WheelEvent and send to Core.
+  Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
   mCoreEventInterface.QueueCoreEvent( event );
   mCoreEventInterface.ProcessCoreEvents();
 }
@@ -778,9 +778,9 @@ void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
   SendEvent(point, timeStamp);
 }
 
-void EventHandler::FeedWheelEvent( MouseWheelEvent& wheelEvent )
+void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
 {
-  SendMouseWheelEvent( wheelEvent );
+  SendWheelEvent( wheelEvent );
 }
 
 void EventHandler::FeedKeyEvent( KeyEvent& event )
index a63f950..090cd0f 100644 (file)
 #include <Ecore_Input.h>
 #include <Ecore_X.h>
 
+#include <X11/Xlib.h>
+#include <X11/extensions/XInput2.h>
+#include <X11/extensions/XI2.h>
+
 #include <cstring>
 
 #include <sys/time.h>
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/events/touch-point.h>
 #include <dali/public-api/events/key-event.h>
-#include <dali/public-api/events/mouse-wheel-event.h>
+#include <dali/public-api/events/wheel-event.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/events/key-event-integ.h>
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali/integration-api/events/hover-event-integ.h>
-#include <dali/integration-api/events/mouse-wheel-event-integ.h>
+#include <dali/integration-api/events/wheel-event-integ.h>
 
 // INTERNAL INCLUDES
 #include <events/gesture-manager.h>
@@ -74,6 +78,9 @@ Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::N
 
 namespace
 {
+
+const char * DETENT_DEVICE_NAME = "tizen_detent";
+
 #ifndef DALI_PROFILE_UBUNTU
 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
 #endif // DALI_PROFILE_UBUNTU
@@ -191,7 +198,8 @@ struct EventHandler::Impl
   Impl( EventHandler* handler, Ecore_X_Window window )
   : mHandler( handler ),
     mEcoreEventHandler(),
-    mWindow( window )
+    mWindow( window ),
+    mXiDeviceId( 0 )
   {
     // Only register for touch and key events if we have a window
     if ( window != 0 )
@@ -232,6 +240,70 @@ struct EventHandler::Impl
       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_CLEAR, EcoreEventSelectionClear, handler ) );
       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_NOTIFY, EcoreEventSelectionNotify, handler ) );
 
+      // Initialize Xi2 system
+      Display* display = static_cast< Display* >(ecore_x_display_get());
+      Ecore_X_Window rootWindow = ecore_x_window_root_first_get();
+      int opcode = 0, event = 0, error = 0;
+      int major = XI_2_Major;
+      int minor = XI_2_Minor;
+      int deviceCount = 0;
+      XIEventMask xiEventMask;
+
+      // Check if X input extension available
+      if( XQueryExtension( display, "XInputExtension", &opcode, &event, &error ) )
+      {
+        // We support version 2.0
+        if( XIQueryVersion( display, &major, &minor ) != BadRequest )
+        {
+          xiEventMask.deviceid = XIAllDevices;
+
+          // Check device id
+          bool match = false;
+          XIDeviceInfo* deviceInfo = NULL;
+          deviceInfo = XIQueryDevice( display, XIAllDevices, &deviceCount );
+
+          for( int i = 0; i < deviceCount; i++ )
+          {
+            if( !strncmp( deviceInfo[i].name, DETENT_DEVICE_NAME, strlen( DETENT_DEVICE_NAME ) ) )
+            {
+              xiEventMask.deviceid = deviceInfo[i].deviceid;
+              match = true;
+              break;
+            }
+          }
+
+          if( match )
+          {
+            mXiDeviceId = xiEventMask.deviceid;
+
+            // SelectXi2Event
+            xiEventMask.mask = (unsigned char*)(calloc( 1, XIMaskLen( XI_LASTEVENT ) ) );
+            XISetMask( xiEventMask.mask, XI_RawMotion );
+
+            xiEventMask.mask_len = sizeof( xiEventMask.mask );
+
+            int ret = XISelectEvents( display, rootWindow, &xiEventMask, 1 );
+            if( ret == 0 )
+            {
+              // Register custom wheel events
+              mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_GENERIC, EcoreEventCustomWheel, handler ) );
+            }
+            else
+            {
+              DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to Select Events\n" );
+            }
+          }
+        }
+        else
+        {
+          DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XI Version\n" );
+        }
+      }
+      else
+      {
+        DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XInputExtension\n" );
+      }
+
 #ifndef DALI_PROFILE_UBUNTU
       // Register Vconf notify - font name, font size and style
       vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, handler );
@@ -307,35 +379,98 @@ struct EventHandler::Impl
   }
 
   /**
-   * Called when a touch up is received.
+   * Called when a touch motion is received.
+   */
+  static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
+  {
+    Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
+    EventHandler* handler( (EventHandler*)data );
+
+    if ( touchEvent->window == handler->mImpl->mWindow )
+    {
+      TouchPoint point( touchEvent->multi.device, TouchPoint::Motion, touchEvent->x, touchEvent->y );
+      handler->SendEvent( point, touchEvent->timestamp );
+    }
+
+    return ECORE_CALLBACK_PASS_ON;
+  }
+
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // Wheel Callbacks
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+
+  /**
+   * Called when a mouse wheel is received.
    */
   static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
   {
     Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
 
-    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);
+    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 );
 
     EventHandler* handler( (EventHandler*)data );
     if ( mouseWheelEvent->window == handler->mImpl->mWindow )
     {
-      MouseWheelEvent wheelEvent(mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp);
-      handler->SendMouseWheelEvent( wheelEvent );
+      WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
+      handler->SendWheelEvent( wheelEvent );
     }
     return ECORE_CALLBACK_PASS_ON;
   }
 
   /**
-   * Called when a touch motion is received.
+   * Called when a custom wheel is received.
    */
-  static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
+  static Eina_Bool EcoreEventCustomWheel( void* data, int type, void* event )
   {
-    Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
+    Ecore_X_Event_Generic *genericEvent( (Ecore_X_Event_Generic*)event );
     EventHandler* handler( (EventHandler*)data );
 
-    if ( touchEvent->window == handler->mImpl->mWindow )
+    switch( genericEvent->evtype )
     {
-      TouchPoint point( touchEvent->multi.device, TouchPoint::Motion, touchEvent->x, touchEvent->y );
-      handler->SendEvent( point, touchEvent->timestamp );
+      case XI_RawMotion:
+      {
+        XIRawEvent* xiRawEvent = static_cast< XIRawEvent* >( genericEvent->data );
+        unsigned int timeStamp = 0;
+
+        if( xiRawEvent->deviceid != handler->mImpl->mXiDeviceId )
+        {
+          return ECORE_CALLBACK_PASS_ON;
+        }
+
+        // X(0): rotate: NOT USED
+        // Y(1): timestamp
+        // Z(2): direction
+
+        double* value = xiRawEvent->raw_values;
+
+        if( XIMaskIsSet( xiRawEvent->valuators.mask, 1) )
+        {
+          timeStamp = static_cast< unsigned int >( *(value + 1) );
+        }
+
+        if( XIMaskIsSet( xiRawEvent->valuators.mask, 2) )
+        {
+          // if z == 1, clockwise
+          // otherwise counter-clockwise
+          int z = static_cast< int >( *(value + 2) );
+
+          // In DALi, positive value means clockwise, and negative value means counter-clockwise
+          if( z == 0 )
+          {
+            z = -1;
+          }
+
+          DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventCustomWheel: z: %d\n", z );
+
+          WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), z, timeStamp );
+          handler->SendWheelEvent( wheelEvent );
+        }
+        break;
+      }
+      default:
+      {
+        break;
+      }
     }
 
     return ECORE_CALLBACK_PASS_ON;
@@ -1077,6 +1212,7 @@ struct EventHandler::Impl
   EventHandler* mHandler;
   std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
   Ecore_X_Window mWindow;
+  int mXiDeviceId;
 };
 
 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
@@ -1163,10 +1299,10 @@ void EventHandler::SendEvent(KeyEvent& keyEvent)
   mCoreEventInterface.ProcessCoreEvents();
 }
 
-void EventHandler::SendMouseWheelEvent( MouseWheelEvent& wheelEvent )
+void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
 {
-  // Create MouseWheelEvent and send to Core.
-  Integration::MouseWheelEvent event(wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp);
+  // Create WheelEvent and send to Core.
+  Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
   mCoreEventInterface.QueueCoreEvent( event );
   mCoreEventInterface.ProcessCoreEvents();
 }
@@ -1203,9 +1339,9 @@ void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
   SendEvent(point, timeStamp);
 }
 
-void EventHandler::FeedWheelEvent( MouseWheelEvent& wheelEvent )
+void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
 {
-  SendMouseWheelEvent( wheelEvent );
+  SendWheelEvent( wheelEvent );
 }
 
 void EventHandler::FeedKeyEvent( KeyEvent& event )
index 8483389..fb584a2 100644 (file)
@@ -86,6 +86,7 @@ BuildRequires:  pkgconfig(ecore-wayland)
 BuildRequires:  pkgconfig(wayland-egl)
 BuildRequires:  pkgconfig(wayland-client)
 %else
+BuildRequires:  pkgconfig(xext)
 BuildRequires:  pkgconfig(xi)
 BuildRequires:  pkgconfig(xfixes)
 BuildRequires:  pkgconfig(xdamage)