kwin/src/wayland/fakeinput_interface.h

156 lines
4.7 KiB
C
Raw Normal View History

/*
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
2021-03-10 16:08:30 +00:00
#pragma once
#include <QPointF>
#include <QSizeF>
#include <QObject>
2020-04-29 14:56:38 +00:00
#include <KWaylandServer/kwaylandserver_export.h>
struct wl_resource;
2020-04-29 14:56:38 +00:00
namespace KWaylandServer
{
class Display;
class FakeInputDevice;
class FakeInputDevicePrivate;
class FakeInputInterfacePrivate;
2015-09-10 11:36:42 +00:00
/**
* @brief Represents the Global for org_kde_kwin_fake_input interface.
*
* The fake input interface allows clients to send fake input events to the
* Wayland server. For the actual events it creates a FakeInputDevice. Whenever
* the FakeInputInterface creates a device the signal deviceCreated gets emitted.
*
* Accepting fake input events is a security risk. The server should make a
* dedicated decision about whether it wants to accept fake input events from a
* device. Because of that by default no events are forwarded to the server. The
* device needs to request authentication and the server must explicitly authenticate
* the device. The recommendation is that the server only accepts input for in some
* way trusted clients.
*
* @see FakeInputDevice
**/
class KWAYLANDSERVER_EXPORT FakeInputInterface : public QObject
{
Q_OBJECT
public:
explicit FakeInputInterface(Display *display, QObject *parent = nullptr);
~FakeInputInterface() override;
Q_SIGNALS:
2015-09-10 11:36:42 +00:00
/**
* Signal emitted whenever a client bound the fake input @p device.
* @param device The created FakeInputDevice
**/
2020-04-29 14:56:38 +00:00
void deviceCreated(KWaylandServer::FakeInputDevice *device);
private:
QScopedPointer<FakeInputInterfacePrivate> d;
};
2015-09-10 11:36:42 +00:00
/**
* @brief Represents the Resource for a org_kde_kwin_fake_input interface.
*
* @see FakeInputInterface
**/
class KWAYLANDSERVER_EXPORT FakeInputDevice : public QObject
{
Q_OBJECT
public:
~FakeInputDevice() override;
2015-09-10 11:36:42 +00:00
/**
* @returns the native wl_resource.
**/
wl_resource *resource();
2015-09-10 11:36:42 +00:00
/**
* Authenticate this device to send events. If @p authenticated is @c true events are
* accepted, for @c false events are no longer accepted.
*
* @param authenticated Whether the FakeInputDevice should be considered authenticated
**/
void setAuthentication(bool authenticated);
2015-09-10 11:36:42 +00:00
/**
* @returns whether the FakeInputDevice is authenticated and allowed to send events, default is @c false.
**/
bool isAuthenticated() const;
Q_SIGNALS:
2015-09-10 11:36:42 +00:00
/**
* Request for authentication.
*
* The server might use the provided information to make a decision on whether the
* FakeInputDevice should get authenticated. It is recommended to not trust the data
* and to combine it with information from ClientConnection.
*
* @param application A textual description of the application
* @param reason A textual description of the reason why the application wants to send fake input events
**/
void authenticationRequested(const QString &application, const QString &reason);
2015-09-10 11:36:42 +00:00
/**
* Request a pointer motion by @p delta.
**/
void pointerMotionRequested(const QSizeF &delta);
/**
* Request an absolute pointer motion to @p pos.
**/
void pointerMotionAbsoluteRequested(const QPointF &pos);
2015-09-10 11:36:42 +00:00
/**
* Requests a pointer button pressed for @p button.
**/
void pointerButtonPressRequested(quint32 button);
2015-09-10 11:36:42 +00:00
/**
* Requests a pointer button release for @p button.
**/
void pointerButtonReleaseRequested(quint32 button);
2015-09-10 11:36:42 +00:00
/**
* Requests a pointer axis for the given @p orientation by @p delta.
**/
void pointerAxisRequested(Qt::Orientation orientation, qreal delta);
/**
* Requests a touch down at @p pos and identified by @p id.
**/
void touchDownRequested(quint32 id, const QPointF &pos);
/**
* Requests a touch motion by @p pos and identified by @p id.
**/
void touchMotionRequested(quint32 id, const QPointF &pos);
/**
* Requests a touch up identified by @p id.
**/
void touchUpRequested(quint32 id);
/**
* Requests a touch cancel event.
**/
void touchCancelRequested();
/**
* Requests a touch frame event.
**/
void touchFrameRequested();
/**
* Requests a keyboard key pressed for @p key.
**/
void keyboardKeyPressRequested(quint32 key);
/**
* Requests a keyboard key release for @p key.
**/
void keyboardKeyReleaseRequested(quint32 key);
private:
friend class FakeInputInterfacePrivate;
FakeInputDevice(FakeInputInterface *parent, wl_resource *resource);
QScopedPointer<FakeInputDevicePrivate> d;
};
}
2020-04-29 14:56:38 +00:00
Q_DECLARE_METATYPE(KWaylandServer::FakeInputDevice*)