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 <kscreen/config.h> | ||||
21 | | ||||
22 | #include "kscreen_wayland_export.h" | ||||
23 | | ||||
24 | #include <QEventLoop> | ||||
25 | #include <QObject> | ||||
26 | #include <QVector> | ||||
27 | | ||||
28 | class QThread; | ||||
29 | | ||||
30 | namespace KScreen | ||||
31 | { | ||||
32 | class Output; | ||||
33 | class WaylandOutput; | ||||
34 | class WaylandScreen; | ||||
35 | | ||||
36 | class KSCREEN_WAYLAND_EXPORT WaylandInterface : public QObject | ||||
37 | { | ||||
38 | Q_OBJECT | ||||
39 | | ||||
40 | public: | ||||
41 | ~WaylandInterface() override; | ||||
42 | | ||||
43 | virtual void initConnection(QThread *thread) = 0; | ||||
44 | virtual bool isInitialized() const; | ||||
45 | | ||||
46 | // Compositor side names as keys | ||||
47 | virtual QMap<int, WaylandOutput*> outputMap() const = 0; | ||||
48 | | ||||
49 | virtual void applyConfig(const KScreen::ConfigPtr &newConfig); | ||||
50 | virtual void updateConfig(KScreen::ConfigPtr &config) = 0; | ||||
51 | | ||||
52 | Q_SIGNALS: | ||||
53 | void configChanged(); | ||||
54 | void initialized(); | ||||
55 | void connectionFailed(const QString &socketName); | ||||
56 | void outputsChanged(); | ||||
57 | | ||||
58 | protected: | ||||
59 | explicit WaylandInterface(QObject *parent = nullptr); | ||||
60 | | ||||
61 | virtual void insertOutput(WaylandOutput *output) = 0; | ||||
62 | virtual WaylandOutput* takeOutput(WaylandOutput *output) = 0; | ||||
63 | | ||||
64 | bool signalsBlocked() const; | ||||
65 | void blockSignals(); | ||||
66 | void unblockSignals(); | ||||
67 | | ||||
68 | void checkInitialized(); | ||||
69 | | ||||
70 | void addOutput(WaylandOutput *output); | ||||
71 | virtual void handleDisconnect(); | ||||
72 | | ||||
73 | private: | ||||
74 | void removeOutput(WaylandOutput *output); | ||||
75 | | ||||
76 | /** | ||||
77 | * Finalize: when the output is is initialized, we put it in the known outputs map, | ||||
78 | * remove it from the list of initializing outputs, and emit configChanged(). | ||||
79 | */ | ||||
80 | virtual void initOutput(WaylandOutput *output); | ||||
81 | | ||||
82 | void tryPendingConfig(); | ||||
83 | | ||||
84 | // Compositor side names | ||||
85 | QList<WaylandOutput*> m_initializingOutputs; | ||||
86 | int m_lastOutputId = -1; | ||||
87 | | ||||
88 | bool m_blockSignals; | ||||
89 | KScreen::ConfigPtr m_kscreenConfig; | ||||
90 | WaylandScreen *m_screen; | ||||
91 | }; | ||||
92 | | ||||
93 | class KSCREEN_EXPORT WaylandFactory : public QObject | ||||
94 | { | ||||
95 | Q_OBJECT | ||||
96 | public: | ||||
97 | WaylandFactory(QObject *parent = nullptr) : QObject(parent) {} | ||||
98 | ~WaylandFactory() override = default; | ||||
99 | | ||||
100 | virtual WaylandInterface* createInterface(QObject *parent = nullptr) = 0; | ||||
101 | }; | ||||
102 | | ||||
103 | } | ||||
104 | | ||||
105 | Q_DECLARE_INTERFACE(KScreen::WaylandFactory, "org.kde.libkscreen.waylandinterface") |