#include "DSWaylandTouch.h"
#include "DSWaylandTouchPrivate.h"
#include "DSWaylandClient.h"
+#include "DSWaylandSeat.h"
+#include "DSWaylandSurface.h"
+#include "DSWaylandCompositor.h"
namespace display_server {
: DSObjectPrivate(touch),
__p_ptr(touch),
__seat(seat),
- __waylandSurface(nullptr)
+ __compositor(seat->getCompositor()),
+ __waylandSurface(nullptr),
+ __wlTouchResource(nullptr)
{
wl_touch();
}
{
}
+void DSWaylandTouchPrivate::setFocus(DSWaylandSurface *waylandSurface)
+{
+ DSLOG_INF("DSWaylandTouchPrivate", "touch focus changed (%p -> %p)", __waylandSurface, waylandSurface);
+
+ __waylandSurface = waylandSurface;
+
+ if (!waylandSurface)
+ 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)
+ {
+ __wlTouchResource = res->handle;
+ break;
+ }
+
+ }
+}
+
+DSWaylandSurface *DSWaylandTouchPrivate::getFocus()
+{
+ return __waylandSurface;
+}
+
void DSWaylandTouchPrivate::touch_bind_resource(Resource *resource)
{
DSLOG_INF("DSWaylandTouchPrivate","");
wl_resource_destroy(resource->handle);
}
+void DSWaylandTouchPrivate::sendDown(int32_t id, int x, int y)
+{
+ if (!__waylandSurface)
+ {
+ DSLOG_INF("DSWaylandTouchPrivate", "no waylandSurface available !");
+ return;
+ }
+
+ wl_fixed_t x_fixed = wl_fixed_from_int(x);
+ wl_fixed_t y_fixed = wl_fixed_from_int(y);
+
+ struct ::wl_resource *surface = __waylandSurface->getWlResource();
+ DS_ASSERT(surface != nullptr);
+
+ send_down(__wlTouchResource, __compositor->nextSerial(), __seat->getCurrentEventTime(), surface, id, x_fixed, y_fixed);
+}
+
+void DSWaylandTouchPrivate::sendUp(int32_t id)
+{
+ send_up(__wlTouchResource, __compositor->nextSerial(), __seat->getCurrentEventTime(), id);
+}
+
+void DSWaylandTouchPrivate::sendMotion(int32_t id, int x, int y)
+{
+ wl_fixed_t x_fixed = wl_fixed_from_int(x);
+ wl_fixed_t y_fixed = wl_fixed_from_int(y);
+
+ send_motion(__wlTouchResource, __seat->getCurrentEventTime(), id, x_fixed, y_fixed);
+}
+
/* Begin Public Class Implementation */
DSWaylandTouch::DSWaylandTouch(DSWaylandSeat *seat)
: DSObject(), _d_ptr(std::make_unique<DSWaylandTouchPrivate>(seat, this))
void DSWaylandTouch::setFocus(DSWaylandSurface *waylandSurface)
{
DS_GET_PRIV(DSWaylandTouch);
- priv->__waylandSurface = waylandSurface;
+ priv->setFocus(waylandSurface);
}
DSWaylandSurface *DSWaylandTouch::getFocus()
{
DS_GET_PRIV(DSWaylandTouch);
- return priv->__waylandSurface;
+ return priv->getFocus();
+}
+
+void DSWaylandTouch::sendDown(int32_t id, int x, int y)
+{
+ DS_GET_PRIV(DSWaylandTouch);
+ priv->sendDown(id, x, y);
+}
+
+void DSWaylandTouch::sendUp(int32_t id)
+{
+ DS_GET_PRIV(DSWaylandTouch);
+ priv->sendUp(id);
+}
+
+void DSWaylandTouch::sendMotion(int32_t id, int x, int y)
+{
+ DS_GET_PRIV(DSWaylandTouch);
+ priv->sendMotion(id, x, y);
}
}
#include "DSCore.h"
#include "DSObjectPrivate.h"
+struct wl_resource;
+
namespace display_server
{
class DSWaylandSeat;
+class DSWaylandCompositor;
+class DSWaylandSurface;
+
class DS_DECL_EXPORT DSWaylandTouchPrivate : public DSObjectPrivate, public DSWaylandServer::wl_touch
{
DS_PIMPL_USE_PUBLIC(DSWaylandTouch);
DSWaylandTouchPrivate(DSWaylandSeat *seat, DSWaylandTouch *touch);
~DSWaylandTouchPrivate() override;
- //TODO
+ void setFocus(DSWaylandSurface *waylandSurface);
+ DSWaylandSurface *getFocus();
protected:
//virtual Resource *touch_allocate();
virtual void touch_release(Resource *resource);
/* APIs must be provided */
+ void sendDown(int32_t id, int x, int y);
+ void sendUp(int32_t id);
+ void sendMotion(int32_t id, int x, int y);
/*
- void sendDown(struct ::wl_client *client, uint32_t serial, uint32_t time, struct ::wl_resource *surface, int32_t id, wl_fixed_t x, wl_fixed_t y);
- void sendUp(struct ::wl_client *client, uint32_t serial, uint32_t time, int32_t id);
- void sendMotion(struct ::wl_client *client, uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y);
- void sendFrame(struct ::wl_client *client);
- void sendCancel(struct ::wl_client *client);
+ void sendFrame(struct ::wl_resource *surface);
+ void sendCancel(struct ::wl_resource *surface);
*/
-
/* APIs don't need to provide */
/*
void send_shape(struct ::wl_resource *resource, int32_t id, wl_fixed_t major, wl_fixed_t minor);
private:
DSWaylandSeat *__seat;
+ DSWaylandCompositor *__compositor;
DSWaylandSurface *__waylandSurface;
+ struct ::wl_resource *__wlTouchResource;
};
}