Changeset View
Changeset View
Standalone View
Standalone View
backends/kwayland/wayland_interface.h
- This file was added.
1 | /************************************************************************* | ||||
---|---|---|---|---|---|
2 | Copyright © 2020 Roman Gilg <subdiff@gmail.com> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Lesser General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Lesser General Public | ||||
15 | License along with this library; if not, write to the Free Software | ||||
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||||
17 | **************************************************************************/ | ||||
18 | #pragma once | ||||
19 | | ||||
20 | #include "config.h" | ||||
21 | | ||||
22 | #include <QEventLoop> | ||||
23 | #include <QObject> | ||||
24 | #include <QVector> | ||||
25 | | ||||
26 | class QThread; | ||||
27 | | ||||
28 | namespace KScreen | ||||
29 | { | ||||
30 | class Output; | ||||
31 | class WaylandOutput; | ||||
32 | class WaylandScreen; | ||||
33 | | ||||
34 | class WaylandInterface : public QObject | ||||
35 | { | ||||
36 | Q_OBJECT | ||||
37 | | ||||
38 | public: | ||||
39 | enum class Type { | ||||
40 | KWayland = 0, | ||||
41 | }; | ||||
42 | | ||||
43 | ~WaylandInterface() override; | ||||
44 | | ||||
45 | virtual void initConnection(QThread *thread) = 0; | ||||
46 | virtual bool isInitialized() const; | ||||
47 | | ||||
48 | // Compositor side names as keys | ||||
49 | virtual QMap<int, WaylandOutput*> outputMap() const = 0; | ||||
50 | | ||||
51 | virtual void applyConfig(const KScreen::ConfigPtr &newConfig); | ||||
52 | virtual void updateConfig(KScreen::ConfigPtr &config) = 0; | ||||
53 | | ||||
54 | Q_SIGNALS: | ||||
55 | void configChanged(); | ||||
56 | void initialized(); | ||||
57 | void connectionFailed(const QString &socketName); | ||||
58 | void outputsChanged(); | ||||
59 | | ||||
60 | protected: | ||||
61 | explicit WaylandInterface(QObject *parent = nullptr); | ||||
62 | | ||||
63 | virtual void insertOutput(WaylandOutput *output) = 0; | ||||
64 | virtual WaylandOutput* takeOutput(WaylandOutput *output) = 0; | ||||
65 | | ||||
66 | bool signalsBlocked() const; | ||||
67 | void blockSignals(); | ||||
68 | void unblockSignals(); | ||||
69 | | ||||
70 | void checkInitialized(); | ||||
71 | | ||||
72 | void addOutput(WaylandOutput *output); | ||||
73 | virtual void handleDisconnect(); | ||||
74 | | ||||
75 | private: | ||||
76 | void removeOutput(WaylandOutput *output); | ||||
77 | | ||||
78 | /** | ||||
79 | * Finalize: when the output is is initialized, we put it in the known outputs map, | ||||
80 | * remove it from the list of initializing outputs, and emit configChanged(). | ||||
81 | */ | ||||
82 | virtual void initOutput(WaylandOutput *output); | ||||
83 | | ||||
84 | void tryPendingConfig(); | ||||
85 | | ||||
86 | // Compositor side names | ||||
87 | QList<WaylandOutput*> m_initializingOutputs; | ||||
88 | int m_lastOutputId = -1; | ||||
89 | | ||||
90 | bool m_blockSignals; | ||||
91 | KScreen::ConfigPtr m_kscreenConfig; | ||||
92 | WaylandScreen *m_screen; | ||||
93 | }; | ||||
94 | | ||||
95 | class WaylandFactory : public QObject | ||||
96 | { | ||||
97 | Q_OBJECT | ||||
98 | public: | ||||
99 | WaylandFactory(QObject *parent = nullptr) : QObject(parent) {} | ||||
100 | ~WaylandFactory() override = default; | ||||
101 | | ||||
102 | virtual WaylandInterface* createInterface(QObject *parent = nullptr) = 0; | ||||
103 | }; | ||||
104 | | ||||
105 | } | ||||
106 | | ||||
107 | Q_DECLARE_INTERFACE(KScreen::WaylandFactory, "org.kde.libkscreen.waylandinterface") |