DSWaylandPointer: add set/getFocus(), send event APIs 34/241834/1
authorSung-Jin Park <sj76.park@samsung.com>
Fri, 14 Aug 2020 11:51:50 +0000 (20:51 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 10:11:54 +0000 (19:11 +0900)
Change-Id: I056f8ab50aa47cd173850dad47218579e99c2ab5
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
src/DSWaylandServer/DSWaylandPointer.cpp
src/DSWaylandServer/DSWaylandPointer.h
src/DSWaylandServer/DSWaylandPointerPrivate.h

index 6a04cfa..dea562f 100644 (file)
@@ -24,6 +24,9 @@
 #include "DSWaylandPointer.h"
 #include "DSWaylandPointerPrivate.h"
 #include "DSWaylandClient.h"
+#include "DSWaylandSeat.h"
+#include "DSWaylandSurface.h"
+#include "DSWaylandCompositor.h"
 
 namespace display_server
 {
@@ -33,7 +36,9 @@ DSWaylandPointerPrivate::DSWaylandPointerPrivate(DSWaylandSeat *seat, DSWaylandP
        : DSObjectPrivate(pointer),
          __p_ptr(pointer),
          __seat(seat),
-         __waylandSurface(nullptr)
+         __compositor(seat->getCompositor()),
+         __waylandSurface(nullptr),
+         __wlPointerResource(nullptr)
 {
        wl_pointer();
 }
@@ -42,6 +47,60 @@ DSWaylandPointerPrivate::~DSWaylandPointerPrivate()
 {
 }
 
+void DSWaylandPointerPrivate::setFocus(DSWaylandSurface *waylandSurface)
+{
+       DSLOG_INF("DSWaylandPointerPrivate", "pointer focus changed (%p -> %p)", __waylandSurface, waylandSurface);
+
+#if 0
+       if (__waylandSurface)
+       {
+               DSLOG_INF("DSWaylandPointerPrivate", "send leave to %p", __waylandSurface);
+               send_leave(__wlPointerResource, __waylandSurface->getWlResource());
+       }
+#endif
+
+       __waylandSurface = waylandSurface;
+
+       if (!waylandSurface)
+       {
+               __wlPointerResource = nullptr;
+               DSLOG_INF("DSWaylandPointerPrivate", "wlPointerResource has been set to null.");
+               return;
+       }
+
+       struct ::wl_resource *surface = waylandSurface->getWlResource();
+       auto client = wl_resource_get_client(surface);
+
+       std::multimap<struct ::wl_client*, Resource*>::iterator iter;
+       std::multimap<struct ::wl_client*, Resource*> resMap = resourceMap();
+
+       for (iter = resMap.begin(); iter != resMap.end(); iter++)
+       {
+               Resource *res = (*iter).second;
+               if (res->client() == client)
+               {
+                       __wlPointerResource = res->handle;
+                       break;
+               }
+
+       }
+
+       if (!__wlPointerResource)
+       {
+               DSLOG_INF("DSWaylandPointerPrivate", "no wlPointerResource available");
+               return;
+       }
+#if 0
+       DSLOG_INF("DSWaylandPointerPrivate", "send enter to %p", __waylandSurface);
+       sendEnter(__wlPointerResource, __waylandSurface->getWlResource(), surface_x, surface_y);
+#endif
+}
+
+DSWaylandSurface *DSWaylandPointerPrivate::getFocus()
+{
+       return __waylandSurface;
+}
+
 void DSWaylandPointerPrivate::pointer_bind_resource(Resource *resource)
 {
        DSLOG_INF("DSWaylandPointerPrivate","");
@@ -63,6 +122,32 @@ void DSWaylandPointerPrivate::pointer_release(Resource *resource)
        wl_resource_destroy(resource->handle);
 }
 
+void DSWaylandPointerPrivate::sendEnter(struct ::wl_resource *wlResource, struct ::wl_resource *surface, int surface_x, int surface_y)
+{
+       wl_fixed_t surface_x_fixed = wl_fixed_from_int(surface_x);
+       wl_fixed_t surface_y_fixed = wl_fixed_from_int(surface_y);
+
+       send_enter(__wlPointerResource, __compositor->nextSerial(), surface, surface_x_fixed, surface_y_fixed);
+}
+
+void DSWaylandPointerPrivate::sendLeave(struct ::wl_resource *wlResource, struct ::wl_resource *surface)
+{
+       send_leave(__wlPointerResource, __compositor->nextSerial(), surface);
+}
+
+void DSWaylandPointerPrivate::sendMotion(int surface_x, int surface_y)
+{
+       wl_fixed_t surface_x_fixed = wl_fixed_from_int(surface_x);
+       wl_fixed_t surface_y_fixed = wl_fixed_from_int(surface_y);
+
+       send_motion(__wlPointerResource, __seat->getCurrentEventTime(), surface_x_fixed, surface_y_fixed);
+}
+
+void DSWaylandPointerPrivate::sendButton(uint32_t button, uint32_t state)
+{
+       send_button(__wlPointerResource, __compositor->nextSerial(), __seat->getCurrentEventTime(), button, state);
+}
+
 /* Begin Public Class Implementation */
 DSWaylandPointer::DSWaylandPointer(DSWaylandSeat *seat)
        : DSObject(), _d_ptr(std::make_unique<DSWaylandPointerPrivate>(seat, this))
@@ -94,13 +179,43 @@ void DSWaylandPointer::addClient(DSWaylandClient *client, uint32_t id, int versi
 void DSWaylandPointer::setFocus(DSWaylandSurface *waylandSurface)
 {
        DS_GET_PRIV(DSWaylandPointer);
-       priv->__waylandSurface = waylandSurface;
+       priv->setFocus(waylandSurface);
 }
 
 DSWaylandSurface *DSWaylandPointer::getFocus()
 {
        DS_GET_PRIV(DSWaylandPointer);
-       return priv->__waylandSurface;
+       return priv->getFocus();
+}
+
+void DSWaylandPointer::sendEnter(int surface_x, int surface_y)
+{
+       DS_GET_PRIV(DSWaylandPointer);
+       priv->sendEnter(priv->__wlPointerResource, priv->__waylandSurface->getWlResource(), surface_x, surface_y);
+}
+
+void DSWaylandPointer::sendLeave()
+{
+       DS_GET_PRIV(DSWaylandPointer);
+       priv->sendLeave(priv->__wlPointerResource, priv->__waylandSurface->getWlResource());
+}
+
+void DSWaylandPointer::sendMotion(int surface_x, int surface_y)
+{
+       DS_GET_PRIV(DSWaylandPointer);
+       priv->sendMotion(surface_x, surface_y);
+}
+
+void DSWaylandPointer::sendButtonDown(uint32_t button)
+{
+       DS_GET_PRIV(DSWaylandPointer);
+       priv->sendButton(button, WL_POINTER_BUTTON_STATE_PRESSED);
+}
+
+void DSWaylandPointer::sendButtonUp(uint32_t button)
+{
+       DS_GET_PRIV(DSWaylandPointer);
+       priv->sendButton(button, WL_POINTER_BUTTON_STATE_RELEASED);
 }
 
 }
index d2f468a..7a1f832 100644 (file)
@@ -48,6 +48,12 @@ public:
        void setFocus(DSWaylandSurface *waylandSurface);
        DSWaylandSurface *getFocus();
 
+       void sendEnter(int surface_x, int surface_y);
+       void sendLeave(void);
+       void sendMotion(int surface_x, int surface_y);
+       void sendButtonDown(uint32_t button);
+       void sendButtonUp(uint32_t button);
+
 protected:
 
 private:
index a53bece..aa0809a 100644 (file)
 #include "DSCore.h"
 #include "DSObjectPrivate.h"
 
+struct wl_resource;
+
 namespace display_server
 {
 
 class DSWaylandSeat;
+class DSWaylandCompositor;
+class DSWaylandSurface;
+
 class DS_DECL_EXPORT DSWaylandPointerPrivate : public DSObjectPrivate, public DSWaylandServer::wl_pointer
 {
        DS_PIMPL_USE_PUBLIC(DSWaylandPointer);
@@ -40,6 +45,9 @@ public:
        DSWaylandPointerPrivate(DSWaylandSeat *seat, DSWaylandPointer *pointer);
        ~DSWaylandPointerPrivate() override;
 
+       void setFocus(DSWaylandSurface *waylandSurface);
+       DSWaylandSurface *getFocus();
+
 protected:
        //virtual Resource *pointer_allocate();
        void pointer_bind_resource(Resource *resource) override;
@@ -48,13 +56,10 @@ protected:
        void pointer_release(Resource *resource) override;
 
        /* APIs must be provided */
-       /*
-       void sendEnter(struct ::wl_client *client, uint32_t serial, struct ::wl_resource *surface, wl_fixed_t surface_x, wl_fixed_t surface_y);
-       void sendLeave(struct ::wl_client *client, uint32_t serial, struct ::wl_resource *surface);
-       void sendMotion(struct ::wl_client *client, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y);
-       void sendButton(struct ::wl_client *client, uint32_t serial, uint32_t time, uint32_t button, uint32_t state);
-       */
-
+       void sendEnter(struct ::wl_resource *wlResource, struct ::wl_resource *surface, int surface_x, int surface_y);
+       void sendLeave(struct ::wl_resource *wlResource, struct ::wl_resource *surface);
+       void sendMotion(int surface_x, int surface_y);
+       void sendButton(uint32_t button, uint32_t state);
        /* APIs don't need to provide */
        /*
        void sendAxis(struct ::wl_resource *resource, uint32_t time, uint32_t axis, wl_fixed_t value);
@@ -66,7 +71,9 @@ protected:
 
 private:
        DSWaylandSeat *__seat;
+       DSWaylandCompositor *__compositor;
        DSWaylandSurface *__waylandSurface;
+       struct ::wl_resource *__wlPointerResource;
 };
 
 }