Changeset View
Changeset View
Standalone View
Standalone View
kded/daemon.cpp
Show All 14 Lines | |||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
16 | * GNU General Public License for more details. * | 16 | * GNU General Public License for more details. * | ||
17 | * * | 17 | * * | ||
18 | * You should have received a copy of the GNU General Public License * | 18 | * You should have received a copy of the GNU General Public License * | ||
19 | * along with this program; if not, write to the Free Software * | 19 | * along with this program; if not, write to the Free Software * | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * | ||
21 | *************************************************************************************/ | 21 | *************************************************************************************/ | ||
22 | #include "daemon.h" | 22 | #include "daemon.h" | ||
23 | #include "serializer.h" | 23 | #include "config.h" | ||
24 | #include "generator.h" | 24 | #include "generator.h" | ||
25 | #include "device.h" | 25 | #include "device.h" | ||
26 | #include "kscreenadaptor.h" | 26 | #include "kscreenadaptor.h" | ||
27 | #include "kscreen_daemon_debug.h" | 27 | #include "kscreen_daemon_debug.h" | ||
28 | #include "osdmanager.h" | 28 | #include "osdmanager.h" | ||
29 | 29 | | |||
30 | #include <kscreen/log.h> | 30 | #include <kscreen/log.h> | ||
31 | #include <kscreen/output.h> | 31 | #include <kscreen/output.h> | ||
Show All 9 Lines | |||||
41 | #include <QTimer> | 41 | #include <QTimer> | ||
42 | #include <QAction> | 42 | #include <QAction> | ||
43 | #include <QShortcut> | 43 | #include <QShortcut> | ||
44 | 44 | | |||
45 | K_PLUGIN_CLASS_WITH_JSON(KScreenDaemon, "kscreen.json") | 45 | K_PLUGIN_CLASS_WITH_JSON(KScreenDaemon, "kscreen.json") | ||
46 | 46 | | |||
47 | KScreenDaemon::KScreenDaemon(QObject* parent, const QList< QVariant >& ) | 47 | KScreenDaemon::KScreenDaemon(QObject* parent, const QList< QVariant >& ) | ||
48 | : KDEDModule(parent) | 48 | : KDEDModule(parent) | ||
49 | , m_monitoredConfig(nullptr) | | |||
50 | , m_monitoring(false) | 49 | , m_monitoring(false) | ||
51 | , m_changeCompressor(new QTimer(this)) | 50 | , m_changeCompressor(new QTimer(this)) | ||
52 | , m_saveTimer(nullptr) | 51 | , m_saveTimer(nullptr) | ||
53 | , m_lidClosedTimer(new QTimer(this)) | 52 | , m_lidClosedTimer(new QTimer(this)) | ||
54 | 53 | | |||
55 | { | 54 | { | ||
56 | KScreen::Log::instance(); | 55 | KScreen::Log::instance(); | ||
57 | QMetaObject::invokeMethod(this, "getInitialConfig", Qt::QueuedConnection); | 56 | QMetaObject::invokeMethod(this, "getInitialConfig", Qt::QueuedConnection); | ||
58 | } | 57 | } | ||
59 | 58 | | |||
60 | void KScreenDaemon::getInitialConfig() | 59 | void KScreenDaemon::getInitialConfig() | ||
61 | { | 60 | { | ||
62 | connect(new KScreen::GetConfigOperation, &KScreen::GetConfigOperation::finished, | 61 | connect(new KScreen::GetConfigOperation, &KScreen::GetConfigOperation::finished, | ||
63 | this, [this](KScreen::ConfigOperation* op) { | 62 | this, [this](KScreen::ConfigOperation* op) { | ||
64 | if (op->hasError()) { | 63 | if (op->hasError()) { | ||
65 | return; | 64 | return; | ||
66 | } | 65 | } | ||
67 | 66 | | |||
68 | m_monitoredConfig = qobject_cast<KScreen::GetConfigOperation*>(op)->config(); | 67 | m_monitoredConfig = std::unique_ptr<Config>(new Config(qobject_cast<KScreen::GetConfigOperation*>(op)->config())); | ||
69 | qCDebug(KSCREEN_KDED) << "Config" << m_monitoredConfig.data() << "is ready"; | 68 | m_monitoredConfig->setValidityFlags(KScreen::Config::ValidityFlag::RequireAtLeastOneEnabledScreen); | ||
70 | KScreen::ConfigMonitor::instance()->addConfig(m_monitoredConfig); | 69 | qCDebug(KSCREEN_KDED) << "Config" << m_monitoredConfig->data().data() << "is ready"; | ||
70 | KScreen::ConfigMonitor::instance()->addConfig(m_monitoredConfig->data()); | ||||
71 | 71 | | |||
72 | init(); | 72 | init(); | ||
73 | }); | 73 | }); | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | KScreenDaemon::~KScreenDaemon() | 76 | KScreenDaemon::~KScreenDaemon() | ||
77 | { | 77 | { | ||
78 | Generator::destroy(); | 78 | Generator::destroy(); | ||
Show All 35 Lines | 113 | connect(Device::self(), &Device::aboutToSuspend, this, | |||
114 | [&]() { | 114 | [&]() { | ||
115 | qCDebug(KSCREEN_KDED) << "System is going to suspend, won't be changing config (waited for " << (m_lidClosedTimer->interval() - m_lidClosedTimer->remainingTime()) << "ms)"; | 115 | qCDebug(KSCREEN_KDED) << "System is going to suspend, won't be changing config (waited for " << (m_lidClosedTimer->interval() - m_lidClosedTimer->remainingTime()) << "ms)"; | ||
116 | m_lidClosedTimer->stop(); | 116 | m_lidClosedTimer->stop(); | ||
117 | }); | 117 | }); | ||
118 | 118 | | |||
119 | connect(Generator::self(), &Generator::ready, | 119 | connect(Generator::self(), &Generator::ready, | ||
120 | this, &KScreenDaemon::applyConfig); | 120 | this, &KScreenDaemon::applyConfig); | ||
121 | 121 | | |||
122 | Generator::self()->setCurrentConfig(m_monitoredConfig); | 122 | Generator::self()->setCurrentConfig(m_monitoredConfig->data()); | ||
123 | monitorConnectedChange(); | 123 | monitorConnectedChange(); | ||
124 | } | 124 | } | ||
125 | 125 | | |||
126 | void KScreenDaemon::doApplyConfig(const KScreen::ConfigPtr& config) | 126 | void KScreenDaemon::doApplyConfig(const KScreen::ConfigPtr& config) | ||
127 | { | 127 | { | ||
128 | qCDebug(KSCREEN_KDED) << "doApplyConfig()"; | 128 | qCDebug(KSCREEN_KDED) << "Do set and apply specific config"; | ||
129 | auto configWrapper = std::unique_ptr<Config>(new Config(config)); | ||||
130 | configWrapper->setValidityFlags(KScreen::Config::ValidityFlag::RequireAtLeastOneEnabledScreen); | ||||
131 | doApplyConfig(std::move(configWrapper)); | ||||
132 | } | ||||
133 | | ||||
134 | void KScreenDaemon::doApplyConfig(std::unique_ptr<Config> config) | ||||
135 | { | ||||
136 | setMonitorForChanges(false); // TODO: remove? | ||||
137 | m_monitoredConfig = std::move(config); | ||||
138 | refreshConfig(); | ||||
139 | } | ||||
140 | | ||||
141 | void KScreenDaemon::refreshConfig() | ||||
142 | { | ||||
129 | setMonitorForChanges(false); | 143 | setMonitorForChanges(false); | ||
130 | m_monitoredConfig = config; | 144 | KScreen::ConfigMonitor::instance()->addConfig(m_monitoredConfig->data()); | ||
131 | KScreen::ConfigMonitor::instance()->addConfig(m_monitoredConfig); | | |||
132 | 145 | | |||
133 | connect(new KScreen::SetConfigOperation(config), &KScreen::SetConfigOperation::finished, this, | 146 | connect(new KScreen::SetConfigOperation(m_monitoredConfig->data()), &KScreen::SetConfigOperation::finished, this, | ||
134 | [&]() { | 147 | [&]() { | ||
135 | qCDebug(KSCREEN_KDED) << "Config applied"; | 148 | qCDebug(KSCREEN_KDED) << "Config applied"; | ||
136 | setMonitorForChanges(true); | 149 | setMonitorForChanges(true); | ||
137 | }); | 150 | }); | ||
138 | } | 151 | } | ||
139 | 152 | | |||
140 | void KScreenDaemon::applyConfig() | 153 | void KScreenDaemon::applyConfig() | ||
141 | { | 154 | { | ||
142 | qCDebug(KSCREEN_KDED) << "Applying config"; | 155 | qCDebug(KSCREEN_KDED) << "Applying config"; | ||
143 | if (Serializer::configExists(m_monitoredConfig)) { | 156 | if (m_monitoredConfig->fileExists()) { | ||
144 | applyKnownConfig(); | 157 | applyKnownConfig(); | ||
145 | return; | 158 | return; | ||
146 | } | 159 | } | ||
147 | | ||||
148 | applyIdealConfig(); | 160 | applyIdealConfig(); | ||
149 | } | 161 | } | ||
150 | 162 | | |||
151 | void KScreenDaemon::applyKnownConfig() | 163 | void KScreenDaemon::applyKnownConfig() | ||
152 | { | 164 | { | ||
153 | const QString configId = Serializer::configId(m_monitoredConfig); | 165 | qCDebug(KSCREEN_KDED) << "Applying known config"; | ||
154 | qCDebug(KSCREEN_KDED) << "Applying known config" << configId; | | |||
155 | 166 | | |||
156 | // We may look for a config that has been set when the lid was closed, Bug: 353029 | 167 | std::unique_ptr<Config> readInConfig = m_monitoredConfig->readFile(); | ||
157 | if (Device::self()->isLaptop() && !Device::self()->isLidClosed()) { | 168 | if (readInConfig) { | ||
158 | Serializer::moveConfig(configId + QLatin1String("_lidOpened"), configId); | 169 | doApplyConfig(std::move(readInConfig)); | ||
159 | } | 170 | } else { | ||
160 | 171 | // loading not succesful, fall back to ideal config | |||
161 | KScreen::ConfigPtr config = Serializer::loadConfig(m_monitoredConfig, configId); | | |||
162 | // It's possible that the Serializer returned a nullptr | | |||
163 | if (!config || !KScreen::Config::canBeApplied(config, KScreen::Config::ValidityFlag::RequireAtLeastOneEnabledScreen)) { | | |||
164 | applyIdealConfig(); | 172 | applyIdealConfig(); | ||
165 | return; | | |||
166 | } | 173 | } | ||
167 | doApplyConfig(config); | | |||
168 | } | 174 | } | ||
169 | 175 | | |||
170 | void KScreenDaemon::applyLayoutPreset(const QString &presetName) | 176 | void KScreenDaemon::applyLayoutPreset(const QString &presetName) | ||
171 | { | 177 | { | ||
172 | const QMetaEnum actionEnum = QMetaEnum::fromType<KScreen::OsdAction::Action>(); | 178 | const QMetaEnum actionEnum = QMetaEnum::fromType<KScreen::OsdAction::Action>(); | ||
173 | Q_ASSERT(actionEnum.isValid()); | 179 | Q_ASSERT(actionEnum.isValid()); | ||
174 | 180 | | |||
175 | bool ok; | 181 | bool ok; | ||
Show All 32 Lines | 212 | case KScreen::OsdAction::Clone: | |||
208 | doApplyConfig(Generator::self()->displaySwitch(Generator::Clone)); | 214 | doApplyConfig(Generator::self()->displaySwitch(Generator::Clone)); | ||
209 | return; | 215 | return; | ||
210 | } | 216 | } | ||
211 | Q_UNREACHABLE(); | 217 | Q_UNREACHABLE(); | ||
212 | } | 218 | } | ||
213 | 219 | | |||
214 | void KScreenDaemon::applyIdealConfig() | 220 | void KScreenDaemon::applyIdealConfig() | ||
215 | { | 221 | { | ||
216 | if (m_monitoredConfig->connectedOutputs().count() < 2) { | 222 | if (m_monitoredConfig->data()->connectedOutputs().count() < 2) { | ||
217 | m_osdManager->hideOsd(); | 223 | m_osdManager->hideOsd(); | ||
218 | doApplyConfig(Generator::self()->idealConfig(m_monitoredConfig)); | 224 | doApplyConfig(Generator::self()->idealConfig(m_monitoredConfig->data())); | ||
219 | } else { | 225 | } else { | ||
220 | qCDebug(KSCREEN_KDED) << "Getting ideal config from user via OSD..."; | 226 | qCDebug(KSCREEN_KDED) << "Getting ideal config from user via OSD..."; | ||
221 | auto action = m_osdManager->showActionSelector(); | 227 | auto action = m_osdManager->showActionSelector(); | ||
222 | connect(action, &KScreen::OsdAction::selected, | 228 | connect(action, &KScreen::OsdAction::selected, | ||
223 | this, &KScreenDaemon::applyOsdAction); | 229 | this, &KScreenDaemon::applyOsdAction); | ||
224 | } | 230 | } | ||
225 | } | 231 | } | ||
226 | 232 | | |||
227 | void logConfig(const KScreen::ConfigPtr &config) | | |||
228 | { | | |||
229 | if (config) { | | |||
230 | foreach (auto o, config->outputs()) { | | |||
231 | if (o->isConnected()) { | | |||
232 | qCDebug(KSCREEN_KDED) << o; | | |||
233 | } | | |||
234 | } | | |||
235 | } | | |||
236 | } | | |||
237 | | ||||
238 | void KScreenDaemon::configChanged() | 233 | void KScreenDaemon::configChanged() | ||
239 | { | 234 | { | ||
240 | qCDebug(KSCREEN_KDED) << "Change detected"; | 235 | qCDebug(KSCREEN_KDED) << "Change detected"; | ||
241 | logConfig(m_monitoredConfig); | 236 | m_monitoredConfig->log(); | ||
242 | 237 | | |||
243 | // Modes may have changed, fix-up current mode id | 238 | // Modes may have changed, fix-up current mode id | ||
244 | bool changed = false; | 239 | bool changed = false; | ||
245 | Q_FOREACH(const KScreen::OutputPtr &output, m_monitoredConfig->outputs()) { | 240 | Q_FOREACH(const KScreen::OutputPtr &output, m_monitoredConfig->data()->outputs()) { | ||
246 | if (output->isConnected() && output->isEnabled() && (output->currentMode().isNull() || (output->followPreferredMode() && output->currentModeId() != output->preferredModeId()))) { | 241 | if (output->isConnected() && output->isEnabled() && (output->currentMode().isNull() || (output->followPreferredMode() && output->currentModeId() != output->preferredModeId()))) { | ||
247 | qCDebug(KSCREEN_KDED) << "Current mode was" << output->currentModeId() << ", setting preferred mode" << output->preferredModeId(); | 242 | qCDebug(KSCREEN_KDED) << "Current mode was" << output->currentModeId() << ", setting preferred mode" << output->preferredModeId(); | ||
248 | output->setCurrentModeId(output->preferredModeId()); | 243 | output->setCurrentModeId(output->preferredModeId()); | ||
249 | changed = true; | 244 | changed = true; | ||
250 | } | 245 | } | ||
251 | } | 246 | } | ||
252 | if (changed) { | 247 | if (changed) { | ||
253 | doApplyConfig(m_monitoredConfig); | 248 | refreshConfig(); | ||
254 | } | 249 | } | ||
255 | 250 | | |||
256 | // Reset timer, delay the writeback | 251 | // Reset timer, delay the writeback | ||
257 | if (!m_saveTimer) { | 252 | if (!m_saveTimer) { | ||
258 | m_saveTimer = new QTimer(this); | 253 | m_saveTimer = new QTimer(this); | ||
259 | m_saveTimer->setInterval(300); | 254 | m_saveTimer->setInterval(300); | ||
260 | m_saveTimer->setSingleShot(true); | 255 | m_saveTimer->setSingleShot(true); | ||
261 | connect(m_saveTimer, &QTimer::timeout, this, &KScreenDaemon::saveCurrentConfig); | 256 | connect(m_saveTimer, &QTimer::timeout, this, &KScreenDaemon::saveCurrentConfig); | ||
262 | } | 257 | } | ||
263 | m_saveTimer->start(); | 258 | m_saveTimer->start(); | ||
264 | } | 259 | } | ||
265 | 260 | | |||
266 | void KScreenDaemon::saveCurrentConfig() | 261 | void KScreenDaemon::saveCurrentConfig() | ||
267 | { | 262 | { | ||
268 | qCDebug(KSCREEN_KDED) << "Saving current config to file"; | 263 | qCDebug(KSCREEN_KDED) << "Saving current config to file"; | ||
269 | 264 | | |||
270 | // We assume the config is valid, since it's what we got, but we are interested | 265 | // We assume the config is valid, since it's what we got, but we are interested | ||
271 | // in the "at least one enabled screen" check | 266 | // in the "at least one enabled screen" check | ||
272 | 267 | | |||
273 | const bool valid = KScreen::Config::canBeApplied(m_monitoredConfig, KScreen::Config::ValidityFlag::RequireAtLeastOneEnabledScreen); | 268 | if (m_monitoredConfig->canBeApplied()) { | ||
274 | if (valid) { | 269 | m_monitoredConfig->writeFile(); | ||
275 | Serializer::saveConfig(m_monitoredConfig, Serializer::configId(m_monitoredConfig)); | 270 | m_monitoredConfig->log(); | ||
276 | logConfig(m_monitoredConfig); | | |||
277 | } else { | 271 | } else { | ||
278 | qCWarning(KSCREEN_KDED) << "Config does not have at least one screen enabled, WILL NOT save this config, this is not what user wants."; | 272 | qCWarning(KSCREEN_KDED) << "Config does not have at least one screen enabled, WILL NOT save this config, this is not what user wants."; | ||
279 | logConfig(m_monitoredConfig); | 273 | m_monitoredConfig->log(); | ||
280 | } | 274 | } | ||
281 | } | 275 | } | ||
282 | 276 | | |||
283 | void KScreenDaemon::showOsd(const QString &icon, const QString &text) | 277 | void KScreenDaemon::showOsd(const QString &icon, const QString &text) | ||
284 | { | 278 | { | ||
285 | QDBusMessage msg = QDBusMessage::createMethodCall( | 279 | QDBusMessage msg = QDBusMessage::createMethodCall( | ||
286 | QLatin1Literal("org.kde.plasmashell"), | 280 | QLatin1Literal("org.kde.plasmashell"), | ||
287 | QLatin1Literal("/org/kde/osdService"), | 281 | QLatin1Literal("/org/kde/osdService"), | ||
Show All 17 Lines | 295 | { | |||
305 | connect(action, &KScreen::OsdAction::selected, | 299 | connect(action, &KScreen::OsdAction::selected, | ||
306 | this, &KScreenDaemon::applyOsdAction); | 300 | this, &KScreenDaemon::applyOsdAction); | ||
307 | } | 301 | } | ||
308 | 302 | | |||
309 | void KScreenDaemon::lidClosedChanged(bool lidIsClosed) | 303 | void KScreenDaemon::lidClosedChanged(bool lidIsClosed) | ||
310 | { | 304 | { | ||
311 | // Ignore this when we don't have any external monitors, we can't turn off our | 305 | // Ignore this when we don't have any external monitors, we can't turn off our | ||
312 | // only screen | 306 | // only screen | ||
313 | if (m_monitoredConfig->connectedOutputs().count() == 1) { | 307 | if (m_monitoredConfig->data()->connectedOutputs().count() == 1) { | ||
314 | return; | 308 | return; | ||
315 | } | 309 | } | ||
316 | 310 | | |||
317 | if (lidIsClosed) { | 311 | if (lidIsClosed) { | ||
318 | // Lid is closed, now we wait for couple seconds to find out whether it | 312 | // Lid is closed, now we wait for couple seconds to find out whether it | ||
319 | // will trigger a suspend (see Device::aboutToSuspend), or whether we should | 313 | // will trigger a suspend (see Device::aboutToSuspend), or whether we should | ||
320 | // turn off the screen | 314 | // turn off the screen | ||
321 | qCDebug(KSCREEN_KDED) << "Lid closed, waiting to see if the computer goes to sleep..."; | 315 | qCDebug(KSCREEN_KDED) << "Lid closed, waiting to see if the computer goes to sleep..."; | ||
322 | m_lidClosedTimer->start(); | 316 | m_lidClosedTimer->start(); | ||
323 | return; | 317 | return; | ||
324 | } else { | 318 | } else { | ||
325 | qCDebug(KSCREEN_KDED) << "Lid opened!"; | 319 | qCDebug(KSCREEN_KDED) << "Lid opened!"; | ||
326 | // We should have a config with "_lidOpened" suffix lying around. If not, | 320 | // We should have a config with "_lidOpened" suffix lying around. If not, | ||
327 | // then the configuration has changed while the lid was closed and we just | 321 | // then the configuration has changed while the lid was closed and we just | ||
328 | // use applyConfig() and see what we can do ... | 322 | // use applyConfig() and see what we can do ... | ||
329 | 323 | if (auto openCfg = m_monitoredConfig->readOpenLidFile()) { | |||
330 | const QString openConfigId = Serializer::configId(m_monitoredConfig) + QLatin1String("_lidOpened"); | 324 | doApplyConfig(std::move(openCfg)); | ||
331 | if (Serializer::configExists(openConfigId)) { | | |||
332 | const KScreen::ConfigPtr openedConfig = Serializer::loadConfig(m_monitoredConfig, openConfigId); | | |||
333 | Serializer::removeConfig(openConfigId); | | |||
334 | | ||||
335 | doApplyConfig(openedConfig); | | |||
336 | } | 325 | } | ||
337 | } | 326 | } | ||
338 | } | 327 | } | ||
339 | 328 | | |||
340 | void KScreenDaemon::lidClosedTimeout() | 329 | void KScreenDaemon::lidClosedTimeout() | ||
341 | { | 330 | { | ||
342 | // Make sure nothing has changed in the past second... :-) | 331 | // Make sure nothing has changed in the past second... :-) | ||
343 | if (!Device::self()->isLidClosed()) { | 332 | if (!Device::self()->isLidClosed()) { | ||
344 | return; | 333 | return; | ||
345 | } | 334 | } | ||
346 | 335 | | |||
347 | // If we are here, it means that closing the lid did not result in suspend | 336 | // If we are here, it means that closing the lid did not result in suspend | ||
348 | // action. | 337 | // action. | ||
349 | // FIXME: This could be because the suspend took longer than m_lidClosedTimer | 338 | // FIXME: This could be because the suspend took longer than m_lidClosedTimer | ||
350 | // timeout. Ideally we need to be able to look into PowerDevil config to see | 339 | // timeout. Ideally we need to be able to look into PowerDevil config to see | ||
351 | // what's the configured action for lid events, but there's no API to do that | 340 | // what's the configured action for lid events, but there's no API to do that | ||
352 | // and I'm not parsing PowerDevil's configs... | 341 | // and I'm not parsing PowerDevil's configs... | ||
353 | 342 | | |||
354 | qCDebug(KSCREEN_KDED) << "Lid closed without system going to suspend -> turning off the screen"; | 343 | qCDebug(KSCREEN_KDED) << "Lid closed without system going to suspend -> turning off the screen"; | ||
355 | for (KScreen::OutputPtr &output : m_monitoredConfig->outputs()) { | 344 | for (KScreen::OutputPtr &output : m_monitoredConfig->data()->outputs()) { | ||
356 | if (output->type() == KScreen::Output::Panel) { | 345 | if (output->type() == KScreen::Output::Panel) { | ||
357 | if (output->isConnected() && output->isEnabled()) { | 346 | if (output->isConnected() && output->isEnabled()) { | ||
358 | // Save the current config with opened lid, just so that we know | 347 | // Save the current config with opened lid, just so that we know | ||
359 | // how to restore it later | 348 | // how to restore it later | ||
360 | const QString configId = Serializer::configId(m_monitoredConfig) + QLatin1String("_lidOpened"); | 349 | m_monitoredConfig->writeOpenLidFile(); | ||
361 | Serializer::saveConfig(m_monitoredConfig, configId); | 350 | disableOutput(output); | ||
362 | disableOutput(m_monitoredConfig, output); | 351 | refreshConfig(); | ||
363 | doApplyConfig(m_monitoredConfig); | | |||
364 | return; | 352 | return; | ||
365 | } | 353 | } | ||
366 | } | 354 | } | ||
367 | } | 355 | } | ||
368 | } | 356 | } | ||
369 | 357 | | |||
370 | 358 | | |||
371 | void KScreenDaemon::outputConnectedChanged() | 359 | void KScreenDaemon::outputConnectedChanged() | ||
372 | { | 360 | { | ||
373 | if (!m_changeCompressor->isActive()) { | 361 | if (!m_changeCompressor->isActive()) { | ||
374 | m_changeCompressor->start(); | 362 | m_changeCompressor->start(); | ||
375 | } | 363 | } | ||
376 | 364 | | |||
377 | KScreen::Output *output = qobject_cast<KScreen::Output*>(sender()); | 365 | KScreen::Output *output = qobject_cast<KScreen::Output*>(sender()); | ||
378 | qCDebug(KSCREEN_KDED) << "outputConnectedChanged():" << output->name(); | 366 | qCDebug(KSCREEN_KDED) << "outputConnectedChanged():" << output->name(); | ||
379 | 367 | | |||
380 | if (output->isConnected()) { | 368 | if (output->isConnected()) { | ||
381 | Q_EMIT outputConnected(output->name()); | 369 | Q_EMIT outputConnected(output->name()); | ||
382 | 370 | | |||
383 | if (!Serializer::configExists(m_monitoredConfig)) { | 371 | if (!m_monitoredConfig->fileExists()) { | ||
384 | Q_EMIT unknownOutputConnected(output->name()); | 372 | Q_EMIT unknownOutputConnected(output->name()); | ||
385 | } | 373 | } | ||
386 | } | 374 | } | ||
387 | } | 375 | } | ||
388 | 376 | | |||
389 | void KScreenDaemon::monitorConnectedChange() | 377 | void KScreenDaemon::monitorConnectedChange() | ||
390 | { | 378 | { | ||
391 | KScreen::OutputList outputs = m_monitoredConfig->outputs(); | 379 | KScreen::OutputList outputs = m_monitoredConfig->data()->outputs(); | ||
392 | Q_FOREACH(const KScreen::OutputPtr &output, outputs) { | 380 | Q_FOREACH(const KScreen::OutputPtr &output, outputs) { | ||
393 | connect(output.data(), &KScreen::Output::isConnectedChanged, | 381 | connect(output.data(), &KScreen::Output::isConnectedChanged, | ||
394 | this, &KScreenDaemon::outputConnectedChanged, | 382 | this, &KScreenDaemon::outputConnectedChanged, | ||
395 | Qt::UniqueConnection); | 383 | Qt::UniqueConnection); | ||
396 | } | 384 | } | ||
397 | connect(m_monitoredConfig.data(), &KScreen::Config::outputAdded, this, | 385 | connect(m_monitoredConfig->data().data(), &KScreen::Config::outputAdded, this, | ||
398 | [this] (const KScreen::OutputPtr output) { | 386 | [this] (const KScreen::OutputPtr output) { | ||
399 | if (output->isConnected()) { | 387 | if (output->isConnected()) { | ||
400 | m_changeCompressor->start(); | 388 | m_changeCompressor->start(); | ||
401 | } | 389 | } | ||
402 | connect(output.data(), &KScreen::Output::isConnectedChanged, | 390 | connect(output.data(), &KScreen::Output::isConnectedChanged, | ||
403 | this, &KScreenDaemon::outputConnectedChanged, | 391 | this, &KScreenDaemon::outputConnectedChanged, | ||
404 | Qt::UniqueConnection); | 392 | Qt::UniqueConnection); | ||
405 | }, Qt::UniqueConnection | 393 | }, Qt::UniqueConnection | ||
406 | ); | 394 | ); | ||
407 | connect(m_monitoredConfig.data(), &KScreen::Config::outputRemoved, | 395 | connect(m_monitoredConfig->data().data(), &KScreen::Config::outputRemoved, | ||
408 | this, &KScreenDaemon::applyConfig, | 396 | this, &KScreenDaemon::applyConfig, | ||
409 | static_cast<Qt::ConnectionType>(Qt::QueuedConnection | Qt::UniqueConnection)); | 397 | static_cast<Qt::ConnectionType>(Qt::QueuedConnection | Qt::UniqueConnection)); | ||
410 | } | 398 | } | ||
411 | 399 | | |||
412 | void KScreenDaemon::setMonitorForChanges(bool enabled) | 400 | void KScreenDaemon::setMonitorForChanges(bool enabled) | ||
413 | { | 401 | { | ||
414 | if (m_monitoring == enabled) { | 402 | if (m_monitoring == enabled) { | ||
415 | return; | 403 | return; | ||
416 | } | 404 | } | ||
417 | 405 | | |||
418 | qCDebug(KSCREEN_KDED) << "Monitor for changes: " << enabled; | 406 | qCDebug(KSCREEN_KDED) << "Monitor for changes: " << enabled; | ||
419 | m_monitoring = enabled; | 407 | m_monitoring = enabled; | ||
420 | if (m_monitoring) { | 408 | if (m_monitoring) { | ||
421 | connect(KScreen::ConfigMonitor::instance(), &KScreen::ConfigMonitor::configurationChanged, | 409 | connect(KScreen::ConfigMonitor::instance(), &KScreen::ConfigMonitor::configurationChanged, | ||
422 | this, &KScreenDaemon::configChanged, Qt::UniqueConnection); | 410 | this, &KScreenDaemon::configChanged, Qt::UniqueConnection); | ||
423 | } else { | 411 | } else { | ||
424 | disconnect(KScreen::ConfigMonitor::instance(), &KScreen::ConfigMonitor::configurationChanged, | 412 | disconnect(KScreen::ConfigMonitor::instance(), &KScreen::ConfigMonitor::configurationChanged, | ||
425 | this, &KScreenDaemon::configChanged); | 413 | this, &KScreenDaemon::configChanged); | ||
426 | } | 414 | } | ||
427 | } | 415 | } | ||
428 | 416 | | |||
429 | void KScreenDaemon::disableOutput(KScreen::ConfigPtr &config, KScreen::OutputPtr &output) | 417 | void KScreenDaemon::disableOutput(KScreen::OutputPtr &output) | ||
430 | { | 418 | { | ||
431 | const QRect geom = output->geometry(); | 419 | const QRect geom = output->geometry(); | ||
432 | qCDebug(KSCREEN_KDED) << "Laptop geometry:" << geom << output->pos() << (output->currentMode() ? output->currentMode()->size() : QSize()); | 420 | qCDebug(KSCREEN_KDED) << "Laptop geometry:" << geom << output->pos() << (output->currentMode() ? output->currentMode()->size() : QSize()); | ||
433 | 421 | | |||
434 | // Move all outputs right from the @p output to left | 422 | // Move all outputs right from the @p output to left | ||
435 | for (KScreen::OutputPtr &otherOutput : config->outputs()) { | 423 | for (KScreen::OutputPtr &otherOutput : m_monitoredConfig->data()->outputs()) { | ||
436 | if (otherOutput == output || !otherOutput->isConnected() || !otherOutput->isEnabled()) { | 424 | if (otherOutput == output || !otherOutput->isConnected() || !otherOutput->isEnabled()) { | ||
437 | continue; | 425 | continue; | ||
438 | } | 426 | } | ||
439 | 427 | | |||
440 | QPoint otherPos = otherOutput->pos(); | 428 | QPoint otherPos = otherOutput->pos(); | ||
441 | if (otherPos.x() >= geom.right() && otherPos.y() >= geom.top() && otherPos.y() <= geom.bottom()) { | 429 | if (otherPos.x() >= geom.right() && otherPos.y() >= geom.top() && otherPos.y() <= geom.bottom()) { | ||
442 | otherPos.setX(otherPos.x() - geom.width()); | 430 | otherPos.setX(otherPos.x() - geom.width()); | ||
443 | } | 431 | } | ||
Show All 10 Lines |