Changeset View
Changeset View
Standalone View
Standalone View
backends/kwayland/waylandoutput.cpp
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
50 | Wl::OutputDevice::Transform toKWaylandTransform(const Output::Rotation rotation) | 50 | Wl::OutputDevice::Transform toKWaylandTransform(const Output::Rotation rotation) | ||
51 | { | 51 | { | ||
52 | return s_rotationMap.key(rotation); | 52 | return s_rotationMap.key(rotation); | ||
53 | } | 53 | } | ||
54 | 54 | | |||
55 | WaylandOutput::WaylandOutput(quint32 id, WaylandConfig *parent) | 55 | WaylandOutput::WaylandOutput(quint32 id, WaylandConfig *parent) | ||
56 | : QObject(parent) | 56 | : QObject(parent) | ||
57 | , m_id(id) | 57 | , m_id(id) | ||
58 | , m_output(nullptr) | 58 | , m_device(nullptr) | ||
59 | { | 59 | { | ||
60 | } | 60 | } | ||
61 | 61 | | |||
62 | quint32 WaylandOutput::id() const | 62 | quint32 WaylandOutput::id() const | ||
63 | { | 63 | { | ||
64 | Q_ASSERT(m_output); | 64 | Q_ASSERT(m_device); | ||
65 | return m_id; | 65 | return m_id; | ||
66 | } | 66 | } | ||
67 | 67 | | |||
68 | bool WaylandOutput::enabled() const | 68 | bool WaylandOutput::enabled() const | ||
69 | { | 69 | { | ||
70 | return m_output != nullptr; | 70 | return m_device != nullptr; | ||
71 | } | 71 | } | ||
72 | 72 | | |||
73 | Wl::OutputDevice* WaylandOutput::outputDevice() const | 73 | Wl::OutputDevice* WaylandOutput::outputDevice() const | ||
74 | { | 74 | { | ||
75 | return m_output; | 75 | return m_device; | ||
76 | } | 76 | } | ||
77 | 77 | | |||
78 | void WaylandOutput::createOutputDevice(Wl::Registry *registry, quint32 name, quint32 version) | 78 | void WaylandOutput::createOutputDevice(Wl::Registry *registry, quint32 name, quint32 version) | ||
79 | { | 79 | { | ||
80 | Q_ASSERT(!m_output); | 80 | Q_ASSERT(!m_device); | ||
81 | m_output = registry->createOutputDevice(name, version); | 81 | m_device = registry->createOutputDevice(name, version); | ||
82 | 82 | | |||
83 | connect(m_output, &Wl::OutputDevice::removed, this, &WaylandOutput::deviceRemoved); | 83 | connect(m_device, &Wl::OutputDevice::removed, this, &WaylandOutput::deviceRemoved); | ||
84 | connect(m_output, &Wl::OutputDevice::done, this, [this]() { | 84 | connect(m_device, &Wl::OutputDevice::done, this, [this]() { | ||
85 | Q_EMIT complete(); | 85 | Q_EMIT complete(); | ||
86 | connect(m_output, &Wl::OutputDevice::changed, this, &WaylandOutput::changed); | 86 | connect(m_device, &Wl::OutputDevice::changed, this, &WaylandOutput::changed); | ||
87 | }); | 87 | }); | ||
88 | } | 88 | } | ||
89 | 89 | | |||
90 | OutputPtr WaylandOutput::toKScreenOutput() | 90 | OutputPtr WaylandOutput::toKScreenOutput() | ||
91 | { | 91 | { | ||
92 | OutputPtr output(new Output()); | 92 | OutputPtr output(new Output()); | ||
93 | output->setId(m_id); | 93 | output->setId(m_id); | ||
94 | updateKScreenOutput(output); | 94 | updateKScreenOutput(output); | ||
95 | return output; | 95 | return output; | ||
96 | } | 96 | } | ||
97 | 97 | | |||
98 | void WaylandOutput::updateKScreenOutput(OutputPtr &output) | 98 | void WaylandOutput::updateKScreenOutput(OutputPtr &output) | ||
99 | { | 99 | { | ||
100 | // Initialize primary output | 100 | // Initialize primary output | ||
101 | output->setId(m_id); | 101 | output->setId(m_id); | ||
102 | output->setEnabled(m_output->enabled() == Wl::OutputDevice::Enablement::Enabled); | 102 | output->setEnabled(m_device->enabled() == Wl::OutputDevice::Enablement::Enabled); | ||
103 | output->setConnected(true); | 103 | output->setConnected(true); | ||
104 | output->setPrimary(true); // FIXME: wayland doesn't have the concept of a primary display | 104 | output->setPrimary(true); // FIXME: wayland doesn't have the concept of a primary display | ||
105 | output->setName(name()); | 105 | output->setName(name()); | ||
106 | output->setSizeMm(m_output->physicalSize()); | 106 | output->setSizeMm(m_device->physicalSize()); | ||
107 | output->setPos(m_output->globalPosition()); | 107 | output->setPos(m_device->globalPosition()); | ||
108 | output->setRotation(s_rotationMap[m_output->transform()]); | 108 | output->setRotation(s_rotationMap[m_device->transform()]); | ||
109 | 109 | | |||
110 | ModeList modeList; | 110 | ModeList modeList; | ||
111 | QStringList preferredModeIds; | 111 | QStringList preferredModeIds; | ||
112 | m_modeIdMap.clear(); | 112 | m_modeIdMap.clear(); | ||
113 | QString currentModeId = QStringLiteral("-1"); | 113 | QString currentModeId = QStringLiteral("-1"); | ||
114 | 114 | | |||
115 | for (const Wl::OutputDevice::Mode &wlMode : m_output->modes()) { | 115 | for (const Wl::OutputDevice::Mode &wlMode : m_device->modes()) { | ||
116 | ModePtr mode(new Mode()); | 116 | ModePtr mode(new Mode()); | ||
117 | const QString name = modeName(wlMode); | 117 | const QString name = modeName(wlMode); | ||
118 | 118 | | |||
119 | QString modeId = QString::number(wlMode.id); | 119 | QString modeId = QString::number(wlMode.id); | ||
120 | if (modeId.isEmpty()) { | 120 | if (modeId.isEmpty()) { | ||
121 | qCDebug(KSCREEN_WAYLAND) << "Could not create mode id from" | 121 | qCDebug(KSCREEN_WAYLAND) << "Could not create mode id from" | ||
122 | << wlMode.id << ", using" << name << "instead."; | 122 | << wlMode.id << ", using" << name << "instead."; | ||
123 | modeId = name; | 123 | modeId = name; | ||
Show All 24 Lines | |||||
148 | 148 | | |||
149 | if (currentModeId == QLatin1String("-1")) { | 149 | if (currentModeId == QLatin1String("-1")) { | ||
150 | qCWarning(KSCREEN_WAYLAND) << "Could not find the current mode id" << modeList; | 150 | qCWarning(KSCREEN_WAYLAND) << "Could not find the current mode id" << modeList; | ||
151 | } | 151 | } | ||
152 | 152 | | |||
153 | output->setCurrentModeId(currentModeId); | 153 | output->setCurrentModeId(currentModeId); | ||
154 | output->setPreferredModes(preferredModeIds); | 154 | output->setPreferredModes(preferredModeIds); | ||
155 | output->setModes(modeList); | 155 | output->setModes(modeList); | ||
156 | output->setScale(m_output->scale()); | 156 | output->setScale(m_device->scale()); | ||
157 | output->setType(Utils::guessOutputType(m_output->model(), m_output->model())); | 157 | output->setType(Utils::guessOutputType(m_device->model(), m_device->model())); | ||
158 | } | 158 | } | ||
159 | 159 | | |||
160 | bool WaylandOutput::setWlConfig(Wl::OutputConfiguration *wlConfig, | 160 | bool WaylandOutput::setWlConfig(Wl::OutputConfiguration *wlConfig, | ||
161 | const KScreen::OutputPtr &output) | 161 | const KScreen::OutputPtr &output) | ||
162 | { | 162 | { | ||
163 | bool changed = false; | 163 | bool changed = false; | ||
164 | 164 | | |||
165 | // enabled? | 165 | // enabled? | ||
166 | if ((m_output->enabled() == Wl::OutputDevice::Enablement::Enabled) | 166 | if ((m_device->enabled() == Wl::OutputDevice::Enablement::Enabled) | ||
167 | != output->isEnabled()) { | 167 | != output->isEnabled()) { | ||
168 | changed = true; | 168 | changed = true; | ||
169 | const auto enablement = output->isEnabled() ? Wl::OutputDevice::Enablement::Enabled : | 169 | const auto enablement = output->isEnabled() ? Wl::OutputDevice::Enablement::Enabled : | ||
170 | Wl::OutputDevice::Enablement::Disabled; | 170 | Wl::OutputDevice::Enablement::Disabled; | ||
171 | wlConfig->setEnabled(m_output, enablement); | 171 | wlConfig->setEnabled(m_device, enablement); | ||
172 | } | 172 | } | ||
173 | 173 | | |||
174 | // position | 174 | // position | ||
175 | if (m_output->globalPosition() != output->pos()) { | 175 | if (m_device->globalPosition() != output->pos()) { | ||
176 | changed = true; | 176 | changed = true; | ||
177 | wlConfig->setPosition(m_output, output->pos()); | 177 | wlConfig->setPosition(m_device, output->pos()); | ||
178 | } | 178 | } | ||
179 | 179 | | |||
180 | // scale | 180 | // scale | ||
181 | if (!qFuzzyCompare(m_output->scaleF(), output->scale())) { | 181 | if (!qFuzzyCompare(m_device->scaleF(), output->scale())) { | ||
182 | changed = true; | 182 | changed = true; | ||
183 | wlConfig->setScaleF(m_output, output->scale()); | 183 | wlConfig->setScaleF(m_device, output->scale()); | ||
184 | } | 184 | } | ||
185 | 185 | | |||
186 | // rotation | 186 | // rotation | ||
187 | if (toKScreenRotation(m_output->transform()) != output->rotation()) { | 187 | if (toKScreenRotation(m_device->transform()) != output->rotation()) { | ||
188 | changed = true; | 188 | changed = true; | ||
189 | wlConfig->setTransform(m_output, toKWaylandTransform(output->rotation())); | 189 | wlConfig->setTransform(m_device, toKWaylandTransform(output->rotation())); | ||
190 | } | 190 | } | ||
191 | 191 | | |||
192 | // mode | 192 | // mode | ||
193 | if (m_modeIdMap.contains(output->currentModeId())) { | 193 | if (m_modeIdMap.contains(output->currentModeId())) { | ||
194 | const int newModeId = m_modeIdMap.value(output->currentModeId(), -1); | 194 | const int newModeId = m_modeIdMap.value(output->currentModeId(), -1); | ||
195 | if (newModeId != m_output->currentMode().id) { | 195 | if (newModeId != m_device->currentMode().id) { | ||
196 | changed = true; | 196 | changed = true; | ||
197 | wlConfig->setMode(m_output, newModeId); | 197 | wlConfig->setMode(m_device, newModeId); | ||
198 | } | 198 | } | ||
199 | } else { | 199 | } else { | ||
200 | qCWarning(KSCREEN_WAYLAND) << "Invalid kscreen mode id:" << output->currentModeId() | 200 | qCWarning(KSCREEN_WAYLAND) << "Invalid kscreen mode id:" << output->currentModeId() | ||
201 | << "\n\n" << m_modeIdMap; | 201 | << "\n\n" << m_modeIdMap; | ||
202 | } | 202 | } | ||
203 | return changed; | 203 | return changed; | ||
204 | } | 204 | } | ||
205 | 205 | | |||
206 | QString WaylandOutput::modeName(const Wl::OutputDevice::Mode &m) const | 206 | QString WaylandOutput::modeName(const Wl::OutputDevice::Mode &m) const | ||
207 | { | 207 | { | ||
208 | return QString::number(m.size.width()) + QLatin1Char('x') + | 208 | return QString::number(m.size.width()) + QLatin1Char('x') + | ||
209 | QString::number(m.size.height()) + QLatin1Char('@') + | 209 | QString::number(m.size.height()) + QLatin1Char('@') + | ||
210 | QString::number(qRound(m.refreshRate/1000.0)); | 210 | QString::number(qRound(m.refreshRate/1000.0)); | ||
211 | } | 211 | } | ||
212 | 212 | | |||
213 | QString WaylandOutput::name() const | 213 | QString WaylandOutput::name() const | ||
214 | { | 214 | { | ||
215 | Q_ASSERT(m_output); | 215 | Q_ASSERT(m_device); | ||
216 | return QStringLiteral("%1 %2").arg(m_output->manufacturer(), m_output->model()); | 216 | return QStringLiteral("%1 %2").arg(m_device->manufacturer(), m_device->model()); | ||
217 | } | 217 | } | ||
218 | 218 | | |||
219 | QDebug operator<<(QDebug dbg, const WaylandOutput *output) | 219 | QDebug operator<<(QDebug dbg, const WaylandOutput *output) | ||
220 | { | 220 | { | ||
221 | dbg << "WaylandOutput(Id:" << output->id() <<", Name:" << \ | 221 | dbg << "WaylandOutput(Id:" << output->id() <<", Name:" << \ | ||
222 | QString(output->outputDevice()->manufacturer() + QLatin1Char(' ') + \ | 222 | QString(output->outputDevice()->manufacturer() + QLatin1Char(' ') + \ | ||
223 | output->outputDevice()->model()) << ")"; | 223 | output->outputDevice()->model()) << ")"; | ||
224 | return dbg; | 224 | return dbg; | ||
225 | } | 225 | } |