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