Changeset View
Changeset View
Standalone View
Standalone View
backends/kwayland/waylandconfig.h
1 | /************************************************************************************* | 1 | /************************************************************************* | ||
---|---|---|---|---|---|
2 | * Copyright 2014-2015 Sebastian Kügler <sebas@kde.org> * | 2 | Copyright © 2014-2015 Sebastian Kügler <sebas@kde.org> | ||
3 | * * | 3 | Copyright © 2019-2020 Roman Gilg <subdiff@gmail.com> | ||
4 | * This library is free software; you can redistribute it and/or * | 4 | | ||
5 | * modify it under the terms of the GNU Lesser General Public * | 5 | This library is free software; you can redistribute it and/or | ||
6 | * License as published by the Free Software Foundation; either * | 6 | modify it under the terms of the GNU Lesser General Public | ||
7 | * version 2.1 of the License, or (at your option) any later version. * | 7 | License as published by the Free Software Foundation; either | ||
8 | * * | 8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | * This library is distributed in the hope that it will be useful, * | 9 | | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 10 | This library is distributed in the hope that it will be useful, | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * Lesser General Public License for more details. * | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * * | 13 | Lesser General Public License for more details. | ||
14 | * You should have received a copy of the GNU Lesser General Public * | 14 | | ||
15 | * License along with this library; if not, write to the Free Software * | 15 | You should have received a copy of the GNU Lesser General Public | ||
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | 16 | License along with this library; if not, write to the Free Software | ||
17 | *************************************************************************************/ | 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | **************************************************************************/ | ||||
18 | #pragma once | 19 | #pragma once | ||
19 | 20 | | |||
20 | #include "abstractbackend.h" | 21 | #include "abstractbackend.h" | ||
21 | #include "config.h" | 22 | #include "config.h" | ||
22 | 23 | | |||
23 | #include <QDir> | | |||
24 | #include <QEventLoop> | 24 | #include <QEventLoop> | ||
25 | #include <QLoggingCategory> | 25 | #include <QPointer> | ||
26 | #include <QSize> | | |||
27 | #include <QScreen> | | |||
28 | #include <QSocketNotifier> | | |||
29 | #include <QThread> | | |||
30 | 26 | | |||
31 | namespace KWayland | 27 | #include <vector> | ||
32 | { | 28 | | ||
33 | namespace Client | 29 | class KPluginMetaData; | ||
34 | { | | |||
35 | class ConnectionThread; | | |||
36 | class EventQueue; | | |||
37 | class Registry; | | |||
38 | class OutputManagement; | | |||
39 | } | | |||
40 | } | | |||
41 | 30 | | |||
42 | namespace KScreen | 31 | namespace KScreen | ||
43 | { | 32 | { | ||
44 | class Output; | 33 | class Output; | ||
34 | class WaylandInterface; | ||||
45 | class WaylandOutput; | 35 | class WaylandOutput; | ||
46 | class WaylandScreen; | 36 | class WaylandScreen; | ||
47 | 37 | | |||
48 | /** | 38 | /** | ||
49 | * @class WaylandConfig | 39 | * @class WaylandConfig | ||
50 | * | 40 | * | ||
51 | * This class holds the basic skeleton of the configuration and takes care of | 41 | * This class holds the basic skeleton of the configuration and takes care of | ||
52 | * fetching the information from the Wayland server and synchronizing the | 42 | * fetching the information from the Wayland server and synchronizing the | ||
53 | * configuration out to the "clients" that receive the config from the backend. | 43 | * configuration out to the "clients" that receive the config from the backend. | ||
54 | * We initialize a wayland connection, using a threaded event queue when | 44 | * We initialize a wayland connection, using a threaded event queue when | ||
55 | * querying the wayland server for data. | 45 | * querying the wayland server for data. | ||
56 | * Initially, the creation of a WaylandConfig blocks until all data has been | 46 | * Initially, the creation of a WaylandConfig blocks until all data has been | ||
57 | * received, signalled by the initialized() signal. This means that the | 47 | * received, signalled by the initialized() signal. This means that the | ||
58 | * wayland client has received information about all interfaces, and that all | 48 | * wayland client has received information about all interfaces, and that all | ||
59 | * outputs are completely initialized. From then on, we properly notifyUpdate(). | 49 | * outputs are completely initialized. From then on, we properly notifyUpdate(). | ||
60 | */ | 50 | */ | ||
61 | class WaylandConfig : public QObject | 51 | class WaylandConfig : public QObject | ||
62 | { | 52 | { | ||
63 | Q_OBJECT | 53 | Q_OBJECT | ||
64 | 54 | | |||
65 | public: | 55 | public: | ||
66 | explicit WaylandConfig(QObject *parent = nullptr); | 56 | explicit WaylandConfig(QObject *parent = nullptr); | ||
67 | ~WaylandConfig() override; | 57 | ~WaylandConfig() override; | ||
68 | 58 | | |||
69 | KScreen::ConfigPtr currentConfig(); | 59 | virtual KScreen::ConfigPtr currentConfig(); | ||
70 | QMap<int, WaylandOutput*> outputMap() const; | 60 | virtual QMap<int, WaylandOutput*> outputMap() const; | ||
71 | 61 | | |||
72 | void applyConfig(const KScreen::ConfigPtr &newConfig); | 62 | void applyConfig(const KScreen::ConfigPtr &newConfig); | ||
73 | 63 | | |||
74 | bool isInitialized() const; | 64 | bool isInitialized() const; | ||
75 | 65 | | |||
76 | Q_SIGNALS: | 66 | Q_SIGNALS: | ||
77 | void configChanged(); | 67 | void configChanged(); | ||
78 | void initialized(); | 68 | void initialized(); | ||
79 | 69 | | |||
80 | private: | 70 | private: | ||
81 | void setupRegistry(); | 71 | struct PendingInterface { | ||
82 | void checkInitialized(); | 72 | bool operator ==(const PendingInterface &other) { | ||
83 | void disconnected(); | 73 | return name == other.name; | ||
74 | } | ||||
75 | QString name; | ||||
76 | WaylandInterface *interface; | ||||
77 | QThread *thread; | ||||
78 | }; | ||||
84 | 79 | | |||
85 | void initKWinTabletMode(); | 80 | void initKWinTabletMode(); | ||
86 | void initConnection(); | 81 | void setScreenOutputs(); | ||
87 | | ||||
88 | void addOutput(quint32 name, quint32 version); | | |||
89 | void removeOutput(WaylandOutput *output); | | |||
90 | 82 | | |||
91 | void blockSignals(); | 83 | void queryInterfaces(); | ||
92 | void unblockSignals(); | 84 | void queryInterface(KPluginMetaData *plugin); | ||
93 | void tryPendingConfig(); | 85 | void takeInterface(const PendingInterface &pending); | ||
86 | void rejectInterface(const PendingInterface &pending); | ||||
94 | 87 | | |||
95 | KWayland::Client::ConnectionThread *m_connection; | | |||
96 | KWayland::Client::EventQueue *m_queue; | | |||
97 | QThread *m_thread; | | |||
98 | | ||||
99 | KWayland::Client::Registry *m_registry; | | |||
100 | KWayland::Client::OutputManagement *m_outputManagement; | | |||
101 | | ||||
102 | // KWayland names as keys | | |||
103 | QMap<int, WaylandOutput*> m_outputMap; | | |||
104 | | ||||
105 | // KWayland names | | |||
106 | QList<WaylandOutput*> m_initializingOutputs; | | |||
107 | int m_lastOutputId = -1; | | |||
108 | | ||||
109 | bool m_registryInitialized; | | |||
110 | bool m_blockSignals; | | |||
111 | QEventLoop m_syncLoop; | | |||
112 | KScreen::ConfigPtr m_kscreenConfig; | 88 | KScreen::ConfigPtr m_kscreenConfig; | ||
113 | KScreen::ConfigPtr m_kscreenPendingConfig; | | |||
114 | WaylandScreen *m_screen; | 89 | WaylandScreen *m_screen; | ||
90 | QPointer<WaylandInterface> m_interface; | ||||
115 | 91 | | |||
116 | bool m_tabletModeAvailable; | 92 | bool m_tabletModeAvailable; | ||
117 | bool m_tabletModeEngaged; | 93 | bool m_tabletModeEngaged; | ||
94 | | ||||
95 | QEventLoop m_syncLoop; | ||||
96 | | ||||
97 | std::vector<PendingInterface> m_pendingInterfaces; | ||||
118 | }; | 98 | }; | ||
119 | 99 | | |||
120 | } | 100 | } |