File indexing completed on 2024-05-19 16:35:19

0001 /*
0002     SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 #pragma once
0007 
0008 #include "kwin_export.h"
0009 
0010 #include <QObject>
0011 #include <QPointF>
0012 #include <memory>
0013 
0014 struct wl_resource;
0015 
0016 namespace KWaylandServer
0017 {
0018 class Display;
0019 class FakeInputDevice;
0020 class FakeInputDevicePrivate;
0021 class FakeInputInterfacePrivate;
0022 
0023 /**
0024  * @brief Represents the Global for org_kde_kwin_fake_input interface.
0025  *
0026  * The fake input interface allows clients to send fake input events to the
0027  * Wayland server. For the actual events it creates a FakeInputDevice. Whenever
0028  * the FakeInputInterface creates a device the signal deviceCreated gets emitted.
0029  *
0030  * Accepting fake input events is a security risk. The server should make a
0031  * dedicated decision about whether it wants to accept fake input events from a
0032  * device. Because of that by default no events are forwarded to the server. The
0033  * device needs to request authentication and the server must explicitly authenticate
0034  * the device. The recommendation is that the server only accepts input for in some
0035  * way trusted clients.
0036  *
0037  * @see FakeInputDevice
0038  */
0039 class KWIN_EXPORT FakeInputInterface : public QObject
0040 {
0041     Q_OBJECT
0042 
0043 public:
0044     explicit FakeInputInterface(Display *display);
0045     ~FakeInputInterface() override;
0046 
0047 Q_SIGNALS:
0048     /**
0049      * Signal emitted whenever a client bound the fake input @p device.
0050      * @param device The created FakeInputDevice
0051      */
0052     void deviceCreated(KWaylandServer::FakeInputDevice *device);
0053 
0054     void deviceDestroyed(KWaylandServer::FakeInputDevice *device);
0055 
0056 private:
0057     std::unique_ptr<FakeInputInterfacePrivate> d;
0058 };
0059 
0060 /**
0061  * @brief Represents the Resource for a org_kde_kwin_fake_input interface.
0062  *
0063  * @see FakeInputInterface
0064  */
0065 class KWIN_EXPORT FakeInputDevice : public QObject
0066 {
0067     Q_OBJECT
0068 public:
0069     ~FakeInputDevice() override;
0070     /**
0071      * @returns the native wl_resource.
0072      */
0073     wl_resource *resource();
0074 
0075     /**
0076      * Authenticate this device to send events. If @p authenticated is @c true events are
0077      * accepted, for @c false events are no longer accepted.
0078      *
0079      * @param authenticated Whether the FakeInputDevice should be considered authenticated
0080      */
0081     void setAuthentication(bool authenticated);
0082     /**
0083      * @returns whether the FakeInputDevice is authenticated and allowed to send events, default is @c false.
0084      */
0085     bool isAuthenticated() const;
0086 
0087 Q_SIGNALS:
0088     /**
0089      * Request for authentication.
0090      *
0091      * The server might use the provided information to make a decision on whether the
0092      * FakeInputDevice should get authenticated. It is recommended to not trust the data
0093      * and to combine it with information from ClientConnection.
0094      *
0095      * @param application A textual description of the application
0096      * @param reason A textual description of the reason why the application wants to send fake input events
0097      */
0098     void authenticationRequested(const QString &application, const QString &reason);
0099     /**
0100      * Request a pointer motion by @p delta.
0101      */
0102     void pointerMotionRequested(const QPointF &delta);
0103     /**
0104      * Request an absolute pointer motion to @p pos.
0105      */
0106     void pointerMotionAbsoluteRequested(const QPointF &pos);
0107     /**
0108      * Requests a pointer button pressed for @p button.
0109      */
0110     void pointerButtonPressRequested(quint32 button);
0111     /**
0112      * Requests a pointer button release for @p button.
0113      */
0114     void pointerButtonReleaseRequested(quint32 button);
0115     /**
0116      * Requests a pointer axis for the given @p orientation by @p delta.
0117      */
0118     void pointerAxisRequested(Qt::Orientation orientation, qreal delta);
0119     /**
0120      * Requests a touch down at @p pos and identified by @p id.
0121      */
0122     void touchDownRequested(quint32 id, const QPointF &pos);
0123     /**
0124      * Requests a touch motion by @p pos and identified by @p id.
0125      */
0126     void touchMotionRequested(quint32 id, const QPointF &pos);
0127     /**
0128      * Requests a touch up identified by @p id.
0129      */
0130     void touchUpRequested(quint32 id);
0131     /**
0132      * Requests a touch cancel event.
0133      */
0134     void touchCancelRequested();
0135     /**
0136      * Requests a touch frame event.
0137      */
0138     void touchFrameRequested();
0139     /**
0140      * Requests a keyboard key pressed for @p key.
0141      */
0142     void keyboardKeyPressRequested(quint32 key);
0143     /**
0144      * Requests a keyboard key release for @p key.
0145      */
0146     void keyboardKeyReleaseRequested(quint32 key);
0147 
0148 private:
0149     friend class FakeInputInterfacePrivate;
0150     FakeInputDevice(FakeInputInterface *parent, wl_resource *resource);
0151     std::unique_ptr<FakeInputDevicePrivate> d;
0152 };
0153 
0154 }
0155 
0156 Q_DECLARE_METATYPE(KWaylandServer::FakeInputDevice *)