#include "DSWaylandPointer.h"
#include "DSWaylandPointerPrivate.h"
#include "DSWaylandClient.h"
+#include "DSWaylandSeat.h"
+#include "DSWaylandSurface.h"
+#include "DSWaylandCompositor.h"
namespace display_server
{
: DSObjectPrivate(pointer),
__p_ptr(pointer),
__seat(seat),
- __waylandSurface(nullptr)
+ __compositor(seat->getCompositor()),
+ __waylandSurface(nullptr),
+ __wlPointerResource(nullptr)
{
wl_pointer();
}
{
}
+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","");
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))
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);
}
}
#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);
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;
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);
private:
DSWaylandSeat *__seat;
+ DSWaylandCompositor *__compositor;
DSWaylandSurface *__waylandSurface;
+ struct ::wl_resource *__wlPointerResource;
};
}