WaylandInputDevice: support for Touch point event
authorNobuhiko Tanibata <ntanibata@jp.adit-jv.com>
Thu, 27 Sep 2012 02:36:55 +0000 (11:36 +0900)
committerTimo Lotterbach <timo.lotterbach@bmw-carit.de>
Thu, 22 Nov 2012 10:01:27 +0000 (02:01 -0800)
-WaylandBaseWindowSystem: modification for handling touch point
-WaylandInputDevice: Add implementation to send touch point event via wayland protocol

LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/WaylandInputDevice.h
LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/WaylandBaseWindowSystem.cpp
LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/WaylandInputDevice.cpp

index 94abce4..a989fd1 100644 (file)
@@ -45,6 +45,11 @@ private:
     bool               m_hasTouch;
     int                m_nTp;
 
+    struct wl_surface*  m_wlTouchFocus;
+    struct wl_listener  m_wlTouchFocusListener;
+    struct wl_resource* m_wlTouchFocusResource;
+    struct wl_listener  m_wlTouchFocusResourceListener;
+
     struct {
         struct wl_pointer  wlPointer;
         struct wl_keyboard wlKeyboard;
@@ -83,7 +88,8 @@ public:
     void sendKeyReleaseEvent(struct wl_surface *surface, uint32_t time, uint32_t code);
     void setKeyboardFocus(struct wl_surface *surface);
 
-    void sendTouchPointEvent();
+    void sendTouchPointEvent(struct wl_surface *surface, uint32_t time,
+                             int touchId, int touchState, const Point& touchPos);
     void sendTouchFrameEvent();
     void sendTouchCancelEvent();
 
@@ -98,6 +104,8 @@ private:
                               const Point& localPos,
                               uint32_t time);
 
+    void setTouchFocus(struct wl_surface *surface);
+
     const static struct wl_seat_interface m_seatInterface;
 
     static void bindInputDevice(struct wl_client *client,
index 7538cc8..6a6d421 100644 (file)
@@ -1273,12 +1273,18 @@ void WaylandBaseWindowSystem::manageWLInputEvent(const InputDevice type,
             if (!surface)
                 break;
 
+            nativeSurface = getNativeSurfaceFromSurface(surface);
+            if (!nativeSurface)
+                break;
+
             switch (state){
             case INPUT_STATE_PRESSED:
-                m_inputEvent->inputDevice().sendTouchPointEvent();
-                break;
             case INPUT_STATE_MOTION:
             case INPUT_STATE_RELEASED:
+                m_inputEvent->inputDevice().sendTouchPointEvent(
+                    &nativeSurface->surface, time, wlEvent->touchId,
+                    wlEvent->touchType, ptVec[0]);
+                break;
             case INPUT_STATE_OTHER:
             default:
                 break;
index e36b615..f3d1877 100644 (file)
 
 /////////////////////////////////////////////////////////////////////////////
 
+static struct wl_resource*
+findResourceForClient(struct wl_list *list, struct wl_client *client)
+{
+    struct wl_resource *r;
+    wl_list_for_each(r, list, link){
+        if (r->client == client)
+            return r;
+    }
+    return NULL;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
 WaylandInputDevice::WaylandInputDevice(struct wl_display *display)
 : m_wlDisplay(display)
 , m_hasPointer(false)
@@ -307,18 +320,64 @@ WaylandInputDevice::sendKeyReleaseEvent(struct wl_surface* /*surface*/,
 }
 
 void
-WaylandInputDevice::sendTouchPointEvent()
+WaylandInputDevice::sendTouchPointEvent(struct wl_surface* surface, uint32_t time,
+                                        int touchId, int touchState, const Point& touchPos)
 {
+    switch (touchState){
+    case WL_TOUCH_DOWN:
+        ++m_nTp;
+        if (m_nTp == 1){
+            setTouchFocus(surface);
+        }
+        if (m_wlTouchFocusResource && m_wlTouchFocus){
+            wl_touch_send_down(m_wlTouchFocusResource,
+                               0 /*serial*/, time,
+                               &m_wlTouchFocus->resource, touchId,
+                               wl_fixed_from_double(touchPos.x),
+                               wl_fixed_from_double(touchPos.y));
+        }
+        break;
+    case WL_TOUCH_MOTION:
+        if (!m_wlTouchFocus){
+            break;
+        }
+        if (m_wlTouchFocusResource){
+            wl_touch_send_motion(m_wlTouchFocusResource,
+                                 time, touchId,
+                                 wl_fixed_from_double(touchPos.x),
+                                 wl_fixed_from_double(touchPos.y));
+        }
+        break;
+    case WL_TOUCH_UP:
+        --m_nTp;
+        if (m_wlTouchFocusResource){
+            wl_touch_send_up(m_wlTouchFocusResource, 0 /*serial*/, time, touchId);
+        }
+        if (m_nTp == 0){
+            setTouchFocus(NULL);
+        }
+        break;
+    }
 }
 
 void
 WaylandInputDevice::sendTouchFrameEvent()
 {
+    wl_touch *touch = touchDevice();
+    wl_resource *resource = touch->focus_resource;
+    if (resource){
+        wl_touch_send_frame(resource);
+    }
 }
 
 void
 WaylandInputDevice::sendTouchCancelEvent()
 {
+    wl_touch *touch = touchDevice();
+    wl_resource *resource = touch->focus_resource;
+    if (resource){
+        wl_touch_send_cancel(resource);
+    }
 }
 
 void
@@ -343,3 +402,26 @@ WaylandInputDevice::setKeyboardFocus(struct wl_surface* surface)
 {
     wl_keyboard_set_focus(keyboardDevice(), surface);
 }
+
+void
+WaylandInputDevice::setTouchFocus(struct wl_surface* surface)
+{
+    struct wl_resource* resource = NULL;
+
+    if (m_wlTouchFocus == surface)
+        return;
+
+    if (surface){
+        resource = findResourceForClient(&m_wlSeat.touch->resource_list,
+                                         surface->resource.client);
+        if (!resource){
+            return;
+        }
+        m_wlSeat.touch->focus = surface;
+        m_wlSeat.touch->focus_resource = resource;
+    }
+    else {
+        m_wlSeat.touch->focus = NULL;
+        m_wlSeat.touch->focus_resource = NULL;
+    }
+}