Changeset View
Changeset View
Standalone View
Standalone View
backends/kwayland/wayland_interface.cpp
- 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 | #include "wayland_interface.h" | ||||
19 | | ||||
20 | #include "waylandbackend.h" | ||||
21 | #include "waylandoutput.h" | ||||
22 | #include "waylandscreen.h" | ||||
23 | | ||||
24 | #include <configmonitor.h> | ||||
25 | #include <mode.h> | ||||
26 | | ||||
27 | #include "../../wayland_logging.h" | ||||
28 | | ||||
29 | #include <QThread> | ||||
30 | #include <QTimer> | ||||
31 | | ||||
32 | using namespace KScreen; | ||||
33 | | ||||
34 | WaylandInterface::WaylandInterface(QObject *parent) | ||||
35 | : QObject(parent) | ||||
36 | , m_blockSignals(true) | ||||
37 | , m_kscreenConfig(new Config) | ||||
38 | { | ||||
39 | } | ||||
40 | | ||||
41 | WaylandInterface::~WaylandInterface() = default; | ||||
42 | | ||||
43 | bool WaylandInterface::signalsBlocked() const | ||||
44 | { | ||||
45 | return m_blockSignals; | ||||
46 | } | ||||
47 | | ||||
48 | void WaylandInterface::blockSignals() | ||||
49 | { | ||||
50 | Q_ASSERT(m_blockSignals == false); | ||||
51 | m_blockSignals = true; | ||||
52 | } | ||||
53 | | ||||
54 | void WaylandInterface::unblockSignals() | ||||
55 | { | ||||
56 | Q_ASSERT(m_blockSignals == true); | ||||
57 | m_blockSignals = false; | ||||
58 | } | ||||
59 | | ||||
60 | void WaylandInterface::handleDisconnect() | ||||
61 | { | ||||
62 | qCWarning(KSCREEN_WAYLAND) << "Wayland disconnected, cleaning up."; | ||||
63 | Q_EMIT configChanged(); | ||||
64 | } | ||||
65 | | ||||
66 | void WaylandInterface::addOutput(WaylandOutput *output) | ||||
67 | { | ||||
68 | m_initializingOutputs << output; | ||||
69 | | ||||
70 | connect(output, &WaylandOutput::removed, | ||||
71 | this, [this, output]() { removeOutput(output); }); | ||||
72 | connect(output, &WaylandOutput::dataReceived, | ||||
73 | this, [this, output]() { initOutput(output); }); | ||||
74 | } | ||||
75 | | ||||
76 | void WaylandInterface::initOutput(WaylandOutput *output) | ||||
77 | { | ||||
78 | insertOutput(output); | ||||
79 | m_initializingOutputs.removeOne(output); | ||||
80 | checkInitialized(); | ||||
81 | | ||||
82 | if (!signalsBlocked() && m_initializingOutputs.empty()) { | ||||
83 | Q_EMIT outputsChanged(); | ||||
84 | Q_EMIT configChanged(); | ||||
85 | } | ||||
86 | | ||||
87 | connect(output, &WaylandOutput::changed, this, [this]() { | ||||
88 | if (!signalsBlocked()) { | ||||
89 | Q_EMIT configChanged(); | ||||
90 | } | ||||
91 | }); | ||||
92 | } | ||||
93 | | ||||
94 | void WaylandInterface::removeOutput(WaylandOutput *output) | ||||
95 | { | ||||
96 | if (m_initializingOutputs.removeOne(output)) { | ||||
97 | // Output was not yet fully initialized, just remove here and return. | ||||
98 | delete output; | ||||
99 | return; | ||||
100 | } | ||||
101 | | ||||
102 | // remove the output from output mapping | ||||
103 | const auto removedOutput = takeOutput(output); | ||||
104 | Q_ASSERT(removedOutput == output); Q_UNUSED(removedOutput); | ||||
105 | Q_EMIT outputsChanged(); | ||||
106 | delete output; | ||||
107 | | ||||
108 | if (!m_blockSignals) { | ||||
109 | Q_EMIT configChanged(); | ||||
110 | } | ||||
111 | } | ||||
112 | | ||||
113 | void WaylandInterface::checkInitialized() | ||||
114 | { | ||||
115 | if (isInitialized()) { | ||||
116 | Q_EMIT initialized(); | ||||
117 | } | ||||
118 | } | ||||
119 | | ||||
120 | bool WaylandInterface::isInitialized() const | ||||
121 | { | ||||
122 | return !m_blockSignals && m_initializingOutputs.isEmpty(); | ||||
123 | } | ||||
124 | | ||||
125 | void WaylandInterface::applyConfig(const KScreen::ConfigPtr &newConfig) | ||||
126 | { | ||||
127 | Q_UNUSED(newConfig) | ||||
128 | } |