2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2021-02-12 22:29:45 +00:00
|
|
|
SPDX-FileCopyrightText: 2020 Adrien Faveraux <ad1rie3@hotmail.fr>
|
|
|
|
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2014-11-25 12:52:40 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2021-02-12 22:29:45 +00:00
|
|
|
|
2014-11-25 12:52:40 +00:00
|
|
|
#include "pointer_interface.h"
|
2021-02-12 22:29:45 +00:00
|
|
|
#include "clientconnection.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "logging.h"
|
2016-04-06 09:27:42 +00:00
|
|
|
#include "pointer_interface_p.h"
|
2020-11-03 17:24:57 +00:00
|
|
|
#include "pointergestures_v1_interface_p.h"
|
2020-11-03 16:24:03 +00:00
|
|
|
#include "relativepointer_v1_interface_p.h"
|
2014-11-25 12:52:40 +00:00
|
|
|
#include "seat_interface.h"
|
|
|
|
#include "surface_interface.h"
|
2021-02-12 22:29:45 +00:00
|
|
|
#include "surfacerole_p.h"
|
|
|
|
#include "utils.h"
|
2014-11-25 12:52:40 +00:00
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
namespace KWaylandServer
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
class CursorPrivate
|
2015-02-27 16:36:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-02-12 22:29:45 +00:00
|
|
|
CursorPrivate(Cursor *q, PointerInterface *pointer);
|
|
|
|
|
|
|
|
Cursor *q;
|
2015-02-27 16:36:43 +00:00
|
|
|
PointerInterface *pointer;
|
|
|
|
quint32 enteredSerial = 0;
|
|
|
|
QPoint hotspot;
|
|
|
|
QPointer<SurfaceInterface> surface;
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void update(SurfaceInterface *surface, quint32 serial, const QPoint &hotspot);
|
2015-02-27 16:36:43 +00:00
|
|
|
};
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
PointerInterfacePrivate *PointerInterfacePrivate::get(PointerInterface *pointer)
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
return pointer->d.data();
|
2014-11-25 12:52:40 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
PointerInterfacePrivate::PointerInterfacePrivate(PointerInterface *q, SeatInterface *seat)
|
|
|
|
: q(q)
|
|
|
|
, seat(seat)
|
|
|
|
, relativePointersV1(new RelativePointerV1Interface(q))
|
|
|
|
, swipeGesturesV1(new PointerSwipeGestureV1Interface(q))
|
|
|
|
, pinchGesturesV1(new PointerPinchGestureV1Interface(q))
|
2015-02-27 16:36:43 +00:00
|
|
|
{
|
|
|
|
}
|
2014-11-25 12:52:40 +00:00
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
PointerInterfacePrivate::~PointerInterfacePrivate()
|
2016-04-06 07:52:13 +00:00
|
|
|
{
|
2020-11-03 16:24:03 +00:00
|
|
|
}
|
2016-10-26 08:27:14 +00:00
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
QList<PointerInterfacePrivate::Resource *> PointerInterfacePrivate::pointersForClient(ClientConnection *client) const
|
2016-10-26 08:27:14 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
return resourceMap().values(client->client());
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
void PointerInterfacePrivate::pointer_set_cursor(Resource *resource, uint32_t serial, ::wl_resource *surface_resource, int32_t hotspot_x, int32_t hotspot_y)
|
2016-10-26 08:27:14 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
SurfaceInterface *surface = nullptr;
|
2020-11-03 17:24:57 +00:00
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
if (!focusedSurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (focusedSurface->client()->client() != resource->client()) {
|
|
|
|
qCDebug(KWAYLAND_SERVER, "Denied set_cursor request from unfocused client");
|
|
|
|
return;
|
|
|
|
}
|
2020-11-03 17:24:57 +00:00
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
if (surface_resource) {
|
|
|
|
surface = SurfaceInterface::get(surface_resource);
|
|
|
|
if (!surface) {
|
2021-08-29 05:11:06 +00:00
|
|
|
wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT, "invalid surface");
|
2021-02-12 22:29:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-10-26 08:27:14 +00:00
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
const SurfaceRole *surfaceRole = SurfaceRole::get(surface);
|
|
|
|
if (surfaceRole) {
|
2021-08-29 05:11:06 +00:00
|
|
|
wl_resource_post_error(resource->handle, error_role, "the wl_surface already has a role assigned %s", surfaceRole->name().constData());
|
2021-02-12 22:29:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-04-06 07:52:13 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
if (!cursor) { // TODO: Assign the cursor surface role.
|
|
|
|
cursor = new Cursor(q);
|
|
|
|
cursor->d->update(surface, serial, QPoint(hotspot_x, hotspot_y));
|
|
|
|
QObject::connect(cursor, &Cursor::changed, q, &PointerInterface::cursorChanged);
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->cursorChanged();
|
2021-02-12 22:29:45 +00:00
|
|
|
} else {
|
|
|
|
cursor->d->update(surface, serial, QPoint(hotspot_x, hotspot_y));
|
2016-04-06 07:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void PointerInterfacePrivate::pointer_release(Resource *resource)
|
2016-10-26 08:27:14 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
wl_resource_destroy(resource->handle);
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void PointerInterfacePrivate::pointer_bind_resource(Resource *resource)
|
2016-10-26 08:27:14 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
const ClientConnection *focusedClient = focusedSurface ? focusedSurface->client() : nullptr;
|
|
|
|
|
|
|
|
if (focusedClient && focusedClient->client() == resource->client()) {
|
|
|
|
const quint32 serial = seat->display()->nextSerial();
|
2021-08-29 05:11:06 +00:00
|
|
|
send_enter(resource->handle, serial, focusedSurface->resource(), wl_fixed_from_double(lastPosition.x()), wl_fixed_from_double(lastPosition.y()));
|
2021-02-12 22:29:45 +00:00
|
|
|
if (resource->version() >= WL_POINTER_FRAME_SINCE_VERSION) {
|
|
|
|
send_frame(resource->handle);
|
|
|
|
}
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void PointerInterfacePrivate::sendLeave(quint32 serial)
|
2016-10-26 08:27:14 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
const QList<Resource *> pointerResources = pointersForClient(focusedSurface->client());
|
|
|
|
for (Resource *resource : pointerResources) {
|
|
|
|
send_leave(resource->handle, serial, focusedSurface->resource());
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void PointerInterfacePrivate::sendEnter(const QPointF &position, quint32 serial)
|
2016-10-26 08:27:14 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
const QList<Resource *> pointerResources = pointersForClient(focusedSurface->client());
|
|
|
|
for (Resource *resource : pointerResources) {
|
2021-08-29 05:11:06 +00:00
|
|
|
send_enter(resource->handle, serial, focusedSurface->resource(), wl_fixed_from_double(position.x()), wl_fixed_from_double(position.y()));
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void PointerInterfacePrivate::sendFrame()
|
2016-10-26 08:27:14 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
const QList<Resource *> pointerResources = pointersForClient(focusedSurface->client());
|
|
|
|
for (Resource *resource : pointerResources) {
|
|
|
|
if (resource->version() >= WL_POINTER_FRAME_SINCE_VERSION) {
|
|
|
|
send_frame(resource->handle);
|
|
|
|
}
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
PointerInterface::PointerInterface(SeatInterface *seat)
|
|
|
|
: d(new PointerInterfacePrivate(this, seat))
|
2016-10-26 08:27:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
PointerInterface::~PointerInterface()
|
2016-10-26 08:27:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
SurfaceInterface *PointerInterface::focusedSurface() const
|
2016-10-26 08:27:14 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
return d->focusedSurface;
|
2016-10-26 08:27:14 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void PointerInterface::setFocusedSurface(SurfaceInterface *surface, const QPointF &position, quint32 serial)
|
2018-02-01 16:46:53 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
if (d->focusedSurface == surface) {
|
2018-02-01 16:46:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
if (d->focusedSurface) {
|
|
|
|
d->sendLeave(serial);
|
|
|
|
if (!surface || d->focusedSurface->client() != surface->client()) {
|
2019-02-06 08:26:43 +00:00
|
|
|
d->sendFrame();
|
2014-11-25 13:24:52 +00:00
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
disconnect(d->destroyConnection);
|
2014-11-25 12:52:40 +00:00
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
2014-11-26 09:34:23 +00:00
|
|
|
d->focusedSurface = surface;
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
if (d->focusedSurface) {
|
|
|
|
d->destroyConnection = connect(d->focusedSurface, &SurfaceInterface::aboutToBeDestroyed, this, [this]() {
|
|
|
|
d->sendLeave(d->seat->display()->nextSerial());
|
2018-02-01 16:46:53 +00:00
|
|
|
d->sendFrame();
|
2014-11-26 10:03:32 +00:00
|
|
|
d->focusedSurface = nullptr;
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT focusedSurfaceChanged();
|
2021-02-12 22:29:45 +00:00
|
|
|
});
|
|
|
|
d->sendEnter(position, serial);
|
|
|
|
d->sendFrame();
|
|
|
|
d->lastPosition = position;
|
2016-04-06 07:52:13 +00:00
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT focusedSurfaceChanged();
|
2014-11-25 12:52:40 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 17:58:39 +00:00
|
|
|
void PointerInterface::sendButton(quint32 button, PointerButtonState state, quint32 serial)
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
if (!d->focusedSurface) {
|
2015-04-20 07:09:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
const auto pointerResources = d->pointersForClient(d->focusedSurface->client());
|
|
|
|
for (PointerInterfacePrivate::Resource *resource : pointerResources) {
|
2021-03-15 17:58:39 +00:00
|
|
|
d->send_button(resource->handle, serial, d->seat->timestamp(), button, quint32(state));
|
2021-02-12 22:29:45 +00:00
|
|
|
}
|
2014-11-25 12:52:40 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void PointerInterface::sendAxis(Qt::Orientation orientation, qreal delta, qint32 discreteDelta, PointerAxisSource source)
|
2019-02-11 16:35:23 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
if (!d->focusedSurface) {
|
2019-02-11 16:35:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
const auto pointerResources = d->pointersForClient(d->focusedSurface->client());
|
|
|
|
for (PointerInterfacePrivate::Resource *resource : pointerResources) {
|
|
|
|
const quint32 version = resource->version();
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
const auto wlOrientation =
|
|
|
|
(orientation == Qt::Vertical) ? PointerInterfacePrivate::axis_vertical_scroll : PointerInterfacePrivate::axis_horizontal_scroll;
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
if (source != PointerAxisSource::Unknown && version >= WL_POINTER_AXIS_SOURCE_SINCE_VERSION) {
|
|
|
|
PointerInterfacePrivate::axis_source wlSource;
|
|
|
|
switch (source) {
|
|
|
|
case PointerAxisSource::Wheel:
|
|
|
|
wlSource = PointerInterfacePrivate::axis_source_wheel;
|
|
|
|
break;
|
|
|
|
case PointerAxisSource::Finger:
|
|
|
|
wlSource = PointerInterfacePrivate::axis_source_finger;
|
|
|
|
break;
|
|
|
|
case PointerAxisSource::Continuous:
|
|
|
|
wlSource = PointerInterfacePrivate::axis_source_continuous;
|
|
|
|
break;
|
|
|
|
case PointerAxisSource::WheelTilt:
|
|
|
|
wlSource = PointerInterfacePrivate::axis_source_wheel_tilt;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
d->send_axis_source(resource->handle, wlSource);
|
2019-02-11 16:35:23 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
if (delta != 0.0) {
|
|
|
|
if (discreteDelta && version >= WL_POINTER_AXIS_DISCRETE_SINCE_VERSION) {
|
|
|
|
d->send_axis_discrete(resource->handle, wlOrientation, discreteDelta);
|
|
|
|
}
|
|
|
|
d->send_axis(resource->handle, d->seat->timestamp(), wlOrientation, wl_fixed_from_double(delta));
|
|
|
|
} else if (version >= WL_POINTER_AXIS_STOP_SINCE_VERSION) {
|
|
|
|
d->send_axis_stop(resource->handle, d->seat->timestamp(), wlOrientation);
|
2019-02-11 16:35:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void PointerInterface::sendMotion(const QPointF &position)
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
d->lastPosition = position;
|
|
|
|
|
|
|
|
if (!d->focusedSurface) {
|
2015-04-20 07:09:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
const auto pointerResources = d->pointersForClient(d->focusedSurface->client());
|
|
|
|
for (PointerInterfacePrivate::Resource *resource : pointerResources) {
|
2021-08-29 05:11:06 +00:00
|
|
|
d->send_motion(resource->handle, d->seat->timestamp(), wl_fixed_from_double(position.x()), wl_fixed_from_double(position.y()));
|
2021-02-12 22:29:45 +00:00
|
|
|
}
|
2014-11-25 12:52:40 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void PointerInterface::sendFrame()
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
if (d->focusedSurface) {
|
|
|
|
d->sendFrame();
|
|
|
|
}
|
2014-11-25 12:52:40 +00:00
|
|
|
}
|
|
|
|
|
2015-02-27 16:36:43 +00:00
|
|
|
Cursor *PointerInterface::cursor() const
|
|
|
|
{
|
|
|
|
return d->cursor;
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
SeatInterface *PointerInterface::seat() const
|
2014-11-25 12:52:40 +00:00
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
return d->seat;
|
2014-11-25 12:52:40 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 07:07:34 +00:00
|
|
|
PointerInterface *PointerInterface::get(wl_resource *native)
|
|
|
|
{
|
2021-02-12 22:29:45 +00:00
|
|
|
if (PointerInterfacePrivate *pointerPrivate = resource_cast<PointerInterfacePrivate *>(native)) {
|
|
|
|
return pointerPrivate->q;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2016-10-07 07:07:34 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
CursorPrivate::CursorPrivate(Cursor *q, PointerInterface *pointer)
|
|
|
|
: q(q)
|
|
|
|
, pointer(pointer)
|
2015-02-27 16:36:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
void CursorPrivate::update(SurfaceInterface *s, quint32 serial, const QPoint &p)
|
2015-02-27 16:36:43 +00:00
|
|
|
{
|
|
|
|
bool emitChanged = false;
|
|
|
|
if (enteredSerial != serial) {
|
|
|
|
enteredSerial = serial;
|
|
|
|
emitChanged = true;
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->enteredSerialChanged();
|
2015-02-27 16:36:43 +00:00
|
|
|
}
|
|
|
|
if (hotspot != p) {
|
|
|
|
hotspot = p;
|
|
|
|
emitChanged = true;
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->hotspotChanged();
|
2015-02-27 16:36:43 +00:00
|
|
|
}
|
|
|
|
if (surface != s) {
|
|
|
|
if (!surface.isNull()) {
|
|
|
|
QObject::disconnect(surface.data(), &SurfaceInterface::damaged, q, &Cursor::changed);
|
|
|
|
}
|
|
|
|
surface = s;
|
|
|
|
if (!surface.isNull()) {
|
|
|
|
QObject::connect(surface.data(), &SurfaceInterface::damaged, q, &Cursor::changed);
|
|
|
|
}
|
|
|
|
emitChanged = true;
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->surfaceChanged();
|
2015-02-27 16:36:43 +00:00
|
|
|
}
|
|
|
|
if (emitChanged) {
|
2021-05-13 09:33:08 +00:00
|
|
|
Q_EMIT q->changed();
|
2015-02-27 16:36:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Cursor::Cursor(PointerInterface *parent)
|
|
|
|
: QObject(parent)
|
2021-02-12 22:29:45 +00:00
|
|
|
, d(new CursorPrivate(this, parent))
|
2015-02-27 16:36:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
Cursor::~Cursor()
|
|
|
|
{
|
|
|
|
}
|
2015-02-27 16:36:43 +00:00
|
|
|
|
|
|
|
quint32 Cursor::enteredSerial() const
|
|
|
|
{
|
|
|
|
return d->enteredSerial;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint Cursor::hotspot() const
|
|
|
|
{
|
|
|
|
return d->hotspot;
|
|
|
|
}
|
|
|
|
|
|
|
|
PointerInterface *Cursor::pointer() const
|
|
|
|
{
|
|
|
|
return d->pointer;
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
SurfaceInterface *Cursor::surface() const
|
2015-02-27 16:36:43 +00:00
|
|
|
{
|
|
|
|
return d->surface;
|
|
|
|
}
|
|
|
|
|
2021-02-23 08:58:13 +00:00
|
|
|
} // namespace KWaylandServer
|