File indexing completed on 2024-10-06 13:27:04

0001 /*
0002  * SPDX-FileCopyrightText: 2018 Red Hat Inc
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  *
0006  * SPDX-FileCopyrightText: 2018 Jan Grulich <jgrulich@redhat.com>
0007  */
0008 
0009 #ifndef XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_H
0010 #define XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_H
0011 
0012 #include <QDBusArgument>
0013 #include <QObject>
0014 #include <QPoint>
0015 #include <QScreen>
0016 #include <QSize>
0017 #include <QVariant>
0018 
0019 #include <KWayland/Client/output.h>
0020 #include <screencasting.h>
0021 
0022 namespace KWayland
0023 {
0024 namespace Client
0025 {
0026 class PlasmaWindowManagement;
0027 class ScreencastingSource;
0028 }
0029 }
0030 
0031 class QWindow;
0032 
0033 namespace WaylandIntegration
0034 {
0035 class WaylandOutput
0036 {
0037     Q_GADGET
0038 public:
0039     enum OutputType {
0040         Laptop,
0041         Monitor,
0042         Television,
0043         Workspace,
0044         Virtual,
0045     };
0046     Q_ENUM(OutputType)
0047     QString manufacturer() const
0048     {
0049         return m_output->manufacturer();
0050     }
0051     QString model() const
0052     {
0053         return m_output->model();
0054     }
0055     QPoint globalPosition() const
0056     {
0057         return m_output->globalPosition();
0058     }
0059     QSize resolution() const
0060     {
0061         return m_output->pixelSize();
0062     }
0063     OutputType outputType() const
0064     {
0065         return m_outputType;
0066     }
0067 
0068     QSharedPointer<KWayland::Client::Output> output() const
0069     {
0070         return m_output;
0071     }
0072     void setOutput(const QSharedPointer<KWayland::Client::Output> &output)
0073     {
0074         m_output = output;
0075         setOutputType(output->model());
0076     }
0077 
0078     void setWaylandOutputName(int outputName)
0079     {
0080         m_waylandOutputName = outputName;
0081     }
0082     int waylandOutputName() const
0083     {
0084         return m_waylandOutputName;
0085     }
0086 
0087     void setWaylandOutputVersion(int outputVersion)
0088     {
0089         m_waylandOutputVersion = outputVersion;
0090     }
0091     int waylandOutputVersion() const
0092     {
0093         return m_waylandOutputVersion;
0094     }
0095 
0096 private:
0097     void setOutputType(const QString &model);
0098     OutputType m_outputType = Monitor;
0099     QSharedPointer<KWayland::Client::Output> m_output;
0100 
0101     // Needed for later output binding
0102     int m_waylandOutputName;
0103     int m_waylandOutputVersion;
0104 };
0105 
0106 struct Stream {
0107     ScreencastingStream *stream = nullptr;
0108     uint nodeId;
0109     QVariantMap map;
0110     bool isValid() const
0111     {
0112         return stream != nullptr;
0113     }
0114 
0115     void close();
0116 };
0117 typedef QVector<Stream> Streams;
0118 
0119 class WaylandIntegration : public QObject
0120 {
0121     Q_OBJECT
0122 Q_SIGNALS:
0123     void newBuffer(uint8_t *screenData);
0124     void plasmaWindowManagementInitialized();
0125 };
0126 
0127 bool isStreamingEnabled();
0128 bool isStreamingAvailable();
0129 
0130 void acquireStreamingInput(bool acquire);
0131 Stream startStreamingOutput(quint32 outputName, Screencasting::CursorMode mode);
0132 Stream startStreamingOutput(QScreen *screen, Screencasting::CursorMode mode);
0133 Stream startStreamingWorkspace(Screencasting::CursorMode mode);
0134 Stream startStreamingVirtual(const QString &name, const QSize &size, Screencasting::CursorMode mode);
0135 Stream startStreamingWindow(const QMap<int, QVariant> &win, Screencasting::CursorMode mode);
0136 void stopStreaming(uint node);
0137 
0138 void requestPointerButtonPress(quint32 linuxButton);
0139 void requestPointerButtonRelease(quint32 linuxButton);
0140 void requestPointerMotion(const QSizeF &delta);
0141 void requestPointerMotionAbsolute(uint stream, const QPointF &pos);
0142 void requestPointerAxis(qreal x, qreal y);
0143 void requestPointerAxisDiscrete(Qt::Orientation axis, qreal delta);
0144 
0145 void requestKeyboardKeycode(int keycode, bool state);
0146 void requestKeyboardKeysym(int keysym, bool state);
0147 
0148 void requestTouchDown(quint32 touchPoint, const QPointF &pos);
0149 void requestTouchMotion(quint32 touchPoint, const QPointF &pos);
0150 void requestTouchUp(quint32 touchPoint);
0151 
0152 QMap<quint32, WaylandOutput> screens();
0153 
0154 void setParentWindow(QWindow *window, const QString &parentWindow);
0155 
0156 void init();
0157 
0158 KWayland::Client::PlasmaWindowManagement *plasmaWindowManagement();
0159 
0160 WaylandIntegration *waylandIntegration();
0161 
0162 QDebug operator<<(QDebug dbg, const Stream &c);
0163 
0164 const QDBusArgument &operator<<(QDBusArgument &arg, const Stream &stream);
0165 const QDBusArgument &operator>>(const QDBusArgument &arg, Stream &stream);
0166 }
0167 
0168 Q_DECLARE_METATYPE(WaylandIntegration::Stream)
0169 Q_DECLARE_METATYPE(WaylandIntegration::Streams)
0170 
0171 #endif // XDG_DESKTOP_PORTAL_KDE_WAYLAND_INTEGRATION_H