2014-11-25 12:52:40 +00:00
|
|
|
/********************************************************************
|
|
|
|
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) version 3, or any
|
|
|
|
later version accepted by the membership of KDE e.V. (or its
|
|
|
|
successor approved by the membership of KDE e.V.), which shall
|
|
|
|
act as a proxy defined in Section 6 of version 3 of the license.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "pointer_interface.h"
|
2014-11-26 10:03:32 +00:00
|
|
|
#include "resource_p.h"
|
2014-11-25 12:52:40 +00:00
|
|
|
#include "seat_interface.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "surface_interface.h"
|
|
|
|
// Wayland
|
|
|
|
#include <wayland-server.h>
|
|
|
|
|
|
|
|
namespace KWayland
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace Server
|
|
|
|
{
|
|
|
|
|
2014-11-26 10:03:32 +00:00
|
|
|
class PointerInterface::Private : public Resource::Private
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-11-26 10:03:32 +00:00
|
|
|
Private(SeatInterface *parent, wl_resource *parentResource, PointerInterface *q);
|
2014-11-25 12:52:40 +00:00
|
|
|
|
|
|
|
SeatInterface *seat;
|
2014-11-26 09:34:23 +00:00
|
|
|
SurfaceInterface *focusedSurface = nullptr;
|
2014-11-25 12:52:40 +00:00
|
|
|
QMetaObject::Connection destroyConnection;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// interface
|
|
|
|
static void setCursorCallback(wl_client *client, wl_resource *resource, uint32_t serial,
|
|
|
|
wl_resource *surface, int32_t hotspot_x, int32_t hotspot_y);
|
|
|
|
// since version 3
|
|
|
|
static void releaseCallback(wl_client *client, wl_resource *resource);
|
|
|
|
|
|
|
|
static const struct wl_pointer_interface s_interface;
|
|
|
|
};
|
|
|
|
|
2014-11-26 10:03:32 +00:00
|
|
|
PointerInterface::Private::Private(SeatInterface *parent, wl_resource *parentResource, PointerInterface *q)
|
|
|
|
: Resource::Private(q, parent, parentResource, &wl_pointer_interface, &s_interface)
|
|
|
|
, seat(parent)
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const struct wl_pointer_interface PointerInterface::Private::s_interface = {
|
|
|
|
setCursorCallback,
|
|
|
|
releaseCallback
|
|
|
|
};
|
|
|
|
|
2014-11-26 10:03:32 +00:00
|
|
|
PointerInterface::PointerInterface(SeatInterface *parent, wl_resource *parentResource)
|
|
|
|
: Resource(new Private(parent, parentResource, this), parent)
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
2014-11-26 09:34:23 +00:00
|
|
|
connect(parent, &SeatInterface::pointerPosChanged, [this] {
|
2014-11-26 10:03:32 +00:00
|
|
|
Q_D();
|
2014-11-26 09:34:23 +00:00
|
|
|
if (d->focusedSurface) {
|
|
|
|
const QPointF pos = d->seat->pointerPos() - d->seat->focusedPointerSurfacePosition();
|
|
|
|
wl_pointer_send_motion(d->resource, d->seat->timestamp(),
|
2014-11-25 13:24:52 +00:00
|
|
|
wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()));
|
|
|
|
}
|
|
|
|
});
|
2014-11-25 12:52:40 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 10:03:32 +00:00
|
|
|
PointerInterface::~PointerInterface() = default;
|
2014-11-25 12:52:40 +00:00
|
|
|
|
2014-11-26 09:34:23 +00:00
|
|
|
void PointerInterface::setFocusedSurface(SurfaceInterface *surface, quint32 serial)
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
2014-11-26 10:03:32 +00:00
|
|
|
Q_D();
|
2014-11-26 09:34:23 +00:00
|
|
|
Q_ASSERT(d->resource);
|
|
|
|
if (d->focusedSurface) {
|
|
|
|
wl_pointer_send_leave(d->resource, serial, d->focusedSurface->resource());
|
2014-11-25 12:52:40 +00:00
|
|
|
disconnect(d->destroyConnection);
|
|
|
|
}
|
2014-11-26 09:34:23 +00:00
|
|
|
if (!surface) {
|
|
|
|
d->focusedSurface = nullptr;
|
2014-11-25 12:52:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-11-26 09:34:23 +00:00
|
|
|
d->focusedSurface = surface;
|
2014-11-26 10:03:32 +00:00
|
|
|
d->destroyConnection = connect(d->focusedSurface, &QObject::destroyed, this,
|
|
|
|
[this] {
|
|
|
|
Q_D();
|
|
|
|
d->focusedSurface = nullptr;
|
|
|
|
}
|
|
|
|
);
|
2014-11-25 12:52:40 +00:00
|
|
|
|
2014-11-26 09:34:23 +00:00
|
|
|
const QPointF pos = d->seat->pointerPos() - d->seat->focusedPointerSurfacePosition();
|
|
|
|
wl_pointer_send_enter(d->resource, serial,
|
|
|
|
d->focusedSurface->resource(),
|
|
|
|
wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()));
|
2014-11-25 12:52:40 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 10:50:52 +00:00
|
|
|
void PointerInterface::buttonPressed(quint32 button, quint32 serial)
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
2014-11-26 10:03:32 +00:00
|
|
|
Q_D();
|
2014-11-26 10:50:52 +00:00
|
|
|
Q_ASSERT(d->focusedSurface);
|
2014-11-26 09:34:23 +00:00
|
|
|
wl_pointer_send_button(d->resource, serial, d->seat->timestamp(), button, WL_POINTER_BUTTON_STATE_PRESSED);
|
2014-11-25 12:52:40 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 10:50:52 +00:00
|
|
|
void PointerInterface::buttonReleased(quint32 button, quint32 serial)
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
2014-11-26 10:03:32 +00:00
|
|
|
Q_D();
|
2014-11-26 10:50:52 +00:00
|
|
|
Q_ASSERT(d->focusedSurface);
|
2014-11-26 09:34:23 +00:00
|
|
|
wl_pointer_send_button(d->resource, serial, d->seat->timestamp(), button, WL_POINTER_BUTTON_STATE_RELEASED);
|
2014-11-25 12:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PointerInterface::axis(Qt::Orientation orientation, quint32 delta)
|
|
|
|
{
|
2014-11-26 10:03:32 +00:00
|
|
|
Q_D();
|
2014-11-26 10:50:52 +00:00
|
|
|
Q_ASSERT(d->focusedSurface);
|
2014-11-26 09:34:23 +00:00
|
|
|
wl_pointer_send_axis(d->resource, d->seat->timestamp(),
|
2014-11-25 12:52:40 +00:00
|
|
|
(orientation == Qt::Vertical) ? WL_POINTER_AXIS_VERTICAL_SCROLL : WL_POINTER_AXIS_HORIZONTAL_SCROLL,
|
|
|
|
wl_fixed_from_int(delta));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PointerInterface::Private::setCursorCallback(wl_client *client, wl_resource *resource, uint32_t serial,
|
|
|
|
wl_resource *surface, int32_t hotspot_x, int32_t hotspot_y)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
|
|
|
Q_UNUSED(resource)
|
|
|
|
Q_UNUSED(serial)
|
|
|
|
Q_UNUSED(surface)
|
|
|
|
Q_UNUSED(hotspot_x)
|
|
|
|
Q_UNUSED(hotspot_y)
|
|
|
|
// TODO: implement
|
|
|
|
}
|
|
|
|
|
|
|
|
void PointerInterface::Private::releaseCallback(wl_client *client, wl_resource *resource)
|
|
|
|
{
|
|
|
|
Q_UNUSED(client)
|
|
|
|
unbind(resource);
|
|
|
|
}
|
|
|
|
|
2014-11-26 10:03:32 +00:00
|
|
|
PointerInterface::Private *PointerInterface::d_func() const
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
2014-11-26 10:03:32 +00:00
|
|
|
return reinterpret_cast<Private*>(d.data());
|
2014-11-25 12:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|