Changeset View
Changeset View
Standalone View
Standalone View
backends/kwayland/plugins/kwayland/kwayland_output.cpp
- This file was copied from backends/kwayland/waylandoutput.cpp.
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 | #include "waylandoutput.h" | 18 | **************************************************************************/ | ||
19 | #include "kwayland_output.h" | ||||
20 | | ||||
19 | #include "waylandbackend.h" | 21 | #include "waylandbackend.h" | ||
20 | #include "waylandconfig.h" | 22 | #include "waylandconfig.h" | ||
21 | #include "../utils.h" | 23 | #include "../utils.h" | ||
22 | 24 | | |||
23 | #include <mode.h> | 25 | #include <mode.h> | ||
24 | #include <edid.h> | 26 | #include <edid.h> | ||
25 | 27 | | |||
28 | #include "../../wayland_logging.h" | ||||
29 | | ||||
26 | #include <KWayland/Client/outputconfiguration.h> | 30 | #include <KWayland/Client/outputconfiguration.h> | ||
27 | #include <KWayland/Client/outputdevice.h> | 31 | #include <KWayland/Client/outputdevice.h> | ||
28 | 32 | | |||
29 | using namespace KScreen; | 33 | using namespace KScreen; | ||
30 | namespace Wl = KWayland::Client; | 34 | namespace Wl = KWayland::Client; | ||
31 | 35 | | |||
32 | const QMap<Wl::OutputDevice::Transform, Output::Rotation> | 36 | const QMap<Wl::OutputDevice::Transform, Output::Rotation> | ||
33 | s_rotationMap = { | 37 | s_rotationMap = { | ||
Show All 13 Lines | 49 | { | |||
47 | return it.value(); | 51 | return it.value(); | ||
48 | } | 52 | } | ||
49 | 53 | | |||
50 | Wl::OutputDevice::Transform toKWaylandTransform(const Output::Rotation rotation) | 54 | Wl::OutputDevice::Transform toKWaylandTransform(const Output::Rotation rotation) | ||
51 | { | 55 | { | ||
52 | return s_rotationMap.key(rotation); | 56 | return s_rotationMap.key(rotation); | ||
53 | } | 57 | } | ||
54 | 58 | | |||
55 | WaylandOutput::WaylandOutput(quint32 id, WaylandConfig *parent) | 59 | KWaylandOutput::KWaylandOutput(quint32 id, QObject *parent) | ||
56 | : QObject(parent) | 60 | : WaylandOutput(id, parent) | ||
57 | , m_id(id) | | |||
58 | , m_device(nullptr) | 61 | , m_device(nullptr) | ||
59 | { | 62 | { | ||
60 | } | 63 | } | ||
61 | 64 | | |||
62 | quint32 WaylandOutput::id() const | 65 | bool KWaylandOutput::enabled() const | ||
63 | { | 66 | { | ||
64 | Q_ASSERT(m_device); | 67 | return m_device != nullptr; | ||
65 | return m_id; | | |||
66 | } | 68 | } | ||
67 | 69 | | |||
68 | bool WaylandOutput::enabled() const | 70 | QByteArray KWaylandOutput::edid() const | ||
69 | { | 71 | { | ||
70 | return m_device != nullptr; | 72 | return m_device->edid(); | ||
71 | } | 73 | } | ||
72 | 74 | | |||
73 | Wl::OutputDevice* WaylandOutput::outputDevice() const | 75 | QRectF KWaylandOutput::geometry() const | ||
76 | { | ||||
77 | return m_device->geometry(); | ||||
78 | } | ||||
79 | | ||||
80 | Wl::OutputDevice* KWaylandOutput::outputDevice() const | ||||
74 | { | 81 | { | ||
75 | return m_device; | 82 | return m_device; | ||
76 | } | 83 | } | ||
77 | 84 | | |||
78 | void WaylandOutput::createOutputDevice(Wl::Registry *registry, quint32 name, quint32 version) | 85 | void KWaylandOutput::createOutputDevice(Wl::Registry *registry, quint32 name, quint32 version) | ||
79 | { | 86 | { | ||
80 | Q_ASSERT(!m_device); | 87 | Q_ASSERT(!m_device); | ||
81 | m_device = registry->createOutputDevice(name, version); | 88 | m_device = registry->createOutputDevice(name, version); | ||
82 | 89 | | |||
83 | connect(m_device, &Wl::OutputDevice::removed, this, &WaylandOutput::deviceRemoved); | 90 | connect(m_device, &Wl::OutputDevice::removed, this, &KWaylandOutput::removed); | ||
84 | connect(m_device, &Wl::OutputDevice::done, this, [this]() { | 91 | connect(m_device, &Wl::OutputDevice::done, this, [this]() { | ||
85 | Q_EMIT complete(); | 92 | Q_EMIT dataReceived(); | ||
86 | connect(m_device, &Wl::OutputDevice::changed, this, &WaylandOutput::changed); | 93 | connect(m_device, &Wl::OutputDevice::changed, this, &KWaylandOutput::changed); | ||
87 | }); | 94 | }); | ||
88 | } | 95 | } | ||
89 | 96 | | |||
90 | OutputPtr WaylandOutput::toKScreenOutput() | 97 | void KWaylandOutput::updateKScreenOutput(OutputPtr &output) | ||
91 | { | | |||
92 | OutputPtr output(new Output()); | | |||
93 | output->setId(m_id); | | |||
94 | updateKScreenOutput(output); | | |||
95 | return output; | | |||
96 | } | | |||
97 | | ||||
98 | void WaylandOutput::updateKScreenOutput(OutputPtr &output) | | |||
99 | { | 98 | { | ||
100 | // Initialize primary output | 99 | // Initialize primary output | ||
101 | output->setId(m_id); | | |||
102 | output->setEnabled(m_device->enabled() == Wl::OutputDevice::Enablement::Enabled); | 100 | output->setEnabled(m_device->enabled() == Wl::OutputDevice::Enablement::Enabled); | ||
103 | output->setConnected(true); | 101 | output->setConnected(true); | ||
104 | output->setPrimary(true); // FIXME: wayland doesn't have the concept of a primary display | 102 | output->setPrimary(true); // FIXME: wayland doesn't have the concept of a primary display | ||
105 | output->setName(name()); | 103 | output->setName(name()); | ||
106 | output->setSizeMm(m_device->physicalSize()); | 104 | output->setSizeMm(m_device->physicalSize()); | ||
107 | output->setPos(m_device->globalPosition()); | 105 | output->setPos(m_device->globalPosition()); | ||
108 | output->setRotation(s_rotationMap[m_device->transform()]); | 106 | output->setRotation(s_rotationMap[m_device->transform()]); | ||
109 | 107 | | |||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
152 | 150 | | |||
153 | output->setCurrentModeId(currentModeId); | 151 | output->setCurrentModeId(currentModeId); | ||
154 | output->setPreferredModes(preferredModeIds); | 152 | output->setPreferredModes(preferredModeIds); | ||
155 | output->setModes(modeList); | 153 | output->setModes(modeList); | ||
156 | output->setScale(m_device->scaleF()); | 154 | output->setScale(m_device->scaleF()); | ||
157 | output->setType(Utils::guessOutputType(m_device->model(), m_device->model())); | 155 | output->setType(Utils::guessOutputType(m_device->model(), m_device->model())); | ||
158 | } | 156 | } | ||
159 | 157 | | |||
160 | bool WaylandOutput::setWlConfig(Wl::OutputConfiguration *wlConfig, | 158 | bool KWaylandOutput::setWlConfig(Wl::OutputConfiguration *wlConfig, | ||
161 | const KScreen::OutputPtr &output) | 159 | const KScreen::OutputPtr &output) | ||
162 | { | 160 | { | ||
163 | bool changed = false; | 161 | bool changed = false; | ||
164 | 162 | | |||
165 | // enabled? | 163 | // enabled? | ||
166 | if ((m_device->enabled() == Wl::OutputDevice::Enablement::Enabled) | 164 | if ((m_device->enabled() == Wl::OutputDevice::Enablement::Enabled) | ||
167 | != output->isEnabled()) { | 165 | != output->isEnabled()) { | ||
168 | changed = true; | 166 | changed = true; | ||
Show All 29 Lines | 191 | if (m_modeIdMap.contains(output->currentModeId())) { | |||
198 | } | 196 | } | ||
199 | } else { | 197 | } else { | ||
200 | qCWarning(KSCREEN_WAYLAND) << "Invalid kscreen mode id:" << output->currentModeId() | 198 | qCWarning(KSCREEN_WAYLAND) << "Invalid kscreen mode id:" << output->currentModeId() | ||
201 | << "\n\n" << m_modeIdMap; | 199 | << "\n\n" << m_modeIdMap; | ||
202 | } | 200 | } | ||
203 | return changed; | 201 | return changed; | ||
204 | } | 202 | } | ||
205 | 203 | | |||
206 | QString WaylandOutput::modeName(const Wl::OutputDevice::Mode &m) const | 204 | QString KWaylandOutput::modeName(const Wl::OutputDevice::Mode &m) const | ||
207 | { | 205 | { | ||
208 | return QString::number(m.size.width()) + QLatin1Char('x') + | 206 | return QString::number(m.size.width()) + QLatin1Char('x') + | ||
209 | QString::number(m.size.height()) + QLatin1Char('@') + | 207 | QString::number(m.size.height()) + QLatin1Char('@') + | ||
210 | QString::number(qRound(m.refreshRate/1000.0)); | 208 | QString::number(qRound(m.refreshRate/1000.0)); | ||
211 | } | 209 | } | ||
212 | 210 | | |||
213 | QString WaylandOutput::name() const | 211 | QString KWaylandOutput::name() const | ||
214 | { | 212 | { | ||
215 | Q_ASSERT(m_device); | 213 | Q_ASSERT(m_device); | ||
216 | return QStringLiteral("%1 %2").arg(m_device->manufacturer(), m_device->model()); | 214 | return QStringLiteral("%1 %2").arg(m_device->manufacturer(), m_device->model()); | ||
217 | } | 215 | } | ||
218 | 216 | | |||
219 | QDebug operator<<(QDebug dbg, const WaylandOutput *output) | 217 | QDebug operator<<(QDebug dbg, const KWaylandOutput *output) | ||
220 | { | 218 | { | ||
221 | dbg << "WaylandOutput(Id:" << output->id() <<", Name:" << \ | 219 | dbg << "KWaylandOutput(Id:" << output->id() <<", Name:" << \ | ||
222 | QString(output->outputDevice()->manufacturer() + QLatin1Char(' ') + \ | 220 | QString(output->outputDevice()->manufacturer() + QLatin1Char(' ') + \ | ||
223 | output->outputDevice()->model()) << ")"; | 221 | output->outputDevice()->model()) << ")"; | ||
224 | return dbg; | 222 | return dbg; | ||
225 | } | 223 | } |