Changeset View
Changeset View
Standalone View
Standalone View
kded/daemon.cpp
Show First 20 Lines • Show All 147 Lines • ▼ Show 20 Line(s) | 141 | { | |||
---|---|---|---|---|---|
148 | applyIdealConfig(); | 148 | applyIdealConfig(); | ||
149 | } | 149 | } | ||
150 | 150 | | |||
151 | void KScreenDaemon::applyKnownConfig() | 151 | void KScreenDaemon::applyKnownConfig() | ||
152 | { | 152 | { | ||
153 | const QString configId = Serializer::configId(m_monitoredConfig); | 153 | const QString configId = Serializer::configId(m_monitoredConfig); | ||
154 | qCDebug(KSCREEN_KDED) << "Applying known config" << configId; | 154 | qCDebug(KSCREEN_KDED) << "Applying known config" << configId; | ||
155 | 155 | | |||
156 | // We may look for a config that has been set when the lid was closed, Bug: 353029 | | |||
157 | if (Device::self()->isLaptop() && !Device::self()->isLidClosed()) { | | |||
158 | Serializer::moveConfig(configId + QLatin1String("_lidOpened"), configId); | | |||
159 | } | | |||
160 | | ||||
161 | KScreen::ConfigPtr config = Serializer::loadConfig(m_monitoredConfig, configId); | 156 | KScreen::ConfigPtr config = Serializer::loadConfig(m_monitoredConfig, configId); | ||
162 | // It's possible that the Serializer returned a nullptr | 157 | // It's possible that the Serializer returned a nullptr | ||
163 | if (!config || !KScreen::Config::canBeApplied(config, KScreen::Config::ValidityFlag::RequireAtLeastOneEnabledScreen)) { | 158 | if (!config || !KScreen::Config::canBeApplied(config, KScreen::Config::ValidityFlag::RequireAtLeastOneEnabledScreen)) { | ||
164 | applyIdealConfig(); | 159 | applyIdealConfig(); | ||
165 | return; | 160 | return; | ||
166 | } | 161 | } | ||
167 | doApplyConfig(config); | 162 | doApplyConfig(config); | ||
168 | } | 163 | } | ||
Show All 39 Lines | 201 | case KScreen::OsdAction::Clone: | |||
208 | doApplyConfig(Generator::self()->displaySwitch(Generator::Clone)); | 203 | doApplyConfig(Generator::self()->displaySwitch(Generator::Clone)); | ||
209 | return; | 204 | return; | ||
210 | } | 205 | } | ||
211 | Q_UNREACHABLE(); | 206 | Q_UNREACHABLE(); | ||
212 | } | 207 | } | ||
213 | 208 | | |||
214 | void KScreenDaemon::applyIdealConfig() | 209 | void KScreenDaemon::applyIdealConfig() | ||
215 | { | 210 | { | ||
216 | if (m_monitoredConfig->connectedOutputs().count() < 2) { | | |||
217 | m_osdManager->hideOsd(); | 211 | m_osdManager->hideOsd(); | ||
212 | | ||||
213 | if (m_monitoredConfig->connectedOutputs().count() < 2) { | ||||
218 | doApplyConfig(Generator::self()->idealConfig(m_monitoredConfig)); | 214 | doApplyConfig(Generator::self()->idealConfig(m_monitoredConfig)); | ||
219 | } else { | 215 | } else { | ||
216 | bool lidIsOpen = !Device::self()->isLaptop() | ||||
217 | || (Device::self()->isLaptop() && !Device::self()->isLidClosed()); | ||||
218 | | ||||
219 | if (!lidIsOpen) { | ||||
220 | for (KScreen::OutputPtr &output : m_monitoredConfig->outputs()) { | ||||
221 | if (output->type() == KScreen::Output::Panel) { | ||||
222 | if (output->isConnected() && output->isEnabled()) { | ||||
223 | disableOutput(m_monitoredConfig, output); | ||||
224 | doApplyConfig(m_monitoredConfig); | ||||
225 | break; | ||||
226 | } | ||||
227 | } | ||||
228 | } | ||||
229 | } | ||||
230 | else { | ||||
231 | for (KScreen::OutputPtr &output : m_monitoredConfig->outputs()) { | ||||
232 | if (output->type() == KScreen::Output::Panel) { | ||||
233 | if (output->isConnected() && !output->isEnabled()) { | ||||
234 | output->setEnabled(true); | ||||
235 | doApplyConfig(m_monitoredConfig); | ||||
236 | break; | ||||
237 | } | ||||
238 | } | ||||
239 | } | ||||
240 | } | ||||
241 | | ||||
242 | if ( (m_monitoredConfig->connectedOutputs().count() > 2) | ||||
243 | || (m_monitoredConfig->connectedOutputs().count() == 2 && lidIsOpen) ) { | ||||
220 | qCDebug(KSCREEN_KDED) << "Getting ideal config from user via OSD..."; | 244 | qCDebug(KSCREEN_KDED) << "Getting ideal config from user via OSD..."; | ||
221 | auto action = m_osdManager->showActionSelector(); | 245 | auto action = m_osdManager->showActionSelector(lidIsOpen); | ||
222 | connect(action, &KScreen::OsdAction::selected, | 246 | connect(action, &KScreen::OsdAction::selected, | ||
223 | this, &KScreenDaemon::applyOsdAction); | 247 | this, &KScreenDaemon::applyOsdAction); | ||
224 | } | 248 | } | ||
225 | } | 249 | } | ||
250 | } | ||||
226 | 251 | | |||
227 | void logConfig(const KScreen::ConfigPtr &config) | 252 | void logConfig(const KScreen::ConfigPtr &config) | ||
228 | { | 253 | { | ||
229 | if (config) { | 254 | if (config) { | ||
230 | foreach (auto o, config->outputs()) { | 255 | foreach (auto o, config->outputs()) { | ||
231 | if (o->isConnected()) { | 256 | if (o->isConnected()) { | ||
232 | qCDebug(KSCREEN_KDED) << o; | 257 | qCDebug(KSCREEN_KDED) << o; | ||
233 | } | 258 | } | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | |||||
296 | { | 321 | { | ||
297 | m_osdManager->showOutputIdentifiers(); | 322 | m_osdManager->showOutputIdentifiers(); | ||
298 | } | 323 | } | ||
299 | 324 | | |||
300 | void KScreenDaemon::displayButton() | 325 | void KScreenDaemon::displayButton() | ||
301 | { | 326 | { | ||
302 | qCDebug(KSCREEN_KDED) << "displayBtn triggered"; | 327 | qCDebug(KSCREEN_KDED) << "displayBtn triggered"; | ||
303 | 328 | | |||
304 | auto action = m_osdManager->showActionSelector(); | 329 | bool lidIsOpen = !Device::self()->isLaptop() | ||
330 | || (Device::self()->isLaptop() && !Device::self()->isLidClosed()); | ||||
331 | | ||||
332 | auto action = m_osdManager->showActionSelector(lidIsOpen); | ||||
305 | connect(action, &KScreen::OsdAction::selected, | 333 | connect(action, &KScreen::OsdAction::selected, | ||
306 | this, &KScreenDaemon::applyOsdAction); | 334 | this, &KScreenDaemon::applyOsdAction); | ||
307 | } | 335 | } | ||
308 | 336 | | |||
309 | void KScreenDaemon::lidClosedChanged(bool lidIsClosed) | 337 | void KScreenDaemon::lidClosedChanged(bool lidIsClosed) | ||
310 | { | 338 | { | ||
311 | // Ignore this when we don't have any external monitors, we can't turn off our | 339 | // Ignore this when we don't have any external monitors, we can't turn off our | ||
312 | // only screen | 340 | // only screen | ||
Show All 12 Lines | 352 | } else { | |||
325 | qCDebug(KSCREEN_KDED) << "Lid opened!"; | 353 | qCDebug(KSCREEN_KDED) << "Lid opened!"; | ||
326 | // We should have a config with "_lidOpened" suffix lying around. If not, | 354 | // 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 | 355 | // then the configuration has changed while the lid was closed and we just | ||
328 | // use applyConfig() and see what we can do ... | 356 | // use applyConfig() and see what we can do ... | ||
329 | 357 | | |||
330 | const QString openConfigId = Serializer::configId(m_monitoredConfig) + QLatin1String("_lidOpened"); | 358 | const QString openConfigId = Serializer::configId(m_monitoredConfig) + QLatin1String("_lidOpened"); | ||
331 | if (Serializer::configExists(openConfigId)) { | 359 | if (Serializer::configExists(openConfigId)) { | ||
332 | const KScreen::ConfigPtr openedConfig = Serializer::loadConfig(m_monitoredConfig, openConfigId); | 360 | const KScreen::ConfigPtr openedConfig = Serializer::loadConfig(m_monitoredConfig, openConfigId); | ||
333 | Serializer::removeConfig(openConfigId); | | |||
334 | 361 | | |||
335 | doApplyConfig(openedConfig); | 362 | doApplyConfig(openedConfig); | ||
336 | } | 363 | } | ||
364 | else { | ||||
365 | applyConfig(); | ||||
366 | } | ||||
337 | } | 367 | } | ||
338 | } | 368 | } | ||
339 | 369 | | |||
340 | void KScreenDaemon::lidClosedTimeout() | 370 | void KScreenDaemon::lidClosedTimeout() | ||
341 | { | 371 | { | ||
342 | // Make sure nothing has changed in the past second... :-) | 372 | // Make sure nothing has changed in the past second... :-) | ||
343 | if (!Device::self()->isLidClosed()) { | 373 | if (!Device::self()->isLidClosed()) { | ||
344 | return; | 374 | return; | ||
345 | } | 375 | } | ||
346 | 376 | | |||
347 | // If we are here, it means that closing the lid did not result in suspend | 377 | // If we are here, it means that closing the lid did not result in suspend | ||
348 | // action. | 378 | // action. | ||
349 | // FIXME: This could be because the suspend took longer than m_lidClosedTimer | 379 | // 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 | 380 | // 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 | 381 | // 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... | 382 | // and I'm not parsing PowerDevil's configs... | ||
353 | 383 | | |||
354 | qCDebug(KSCREEN_KDED) << "Lid closed without system going to suspend -> turning off the screen"; | 384 | qCDebug(KSCREEN_KDED) << "Lid closed without system going to suspend -> turning off the screen"; | ||
355 | for (KScreen::OutputPtr &output : m_monitoredConfig->outputs()) { | 385 | for (KScreen::OutputPtr &output : m_monitoredConfig->outputs()) { | ||
356 | if (output->type() == KScreen::Output::Panel) { | 386 | if (output->type() == KScreen::Output::Panel) { | ||
357 | if (output->isConnected() && output->isEnabled()) { | 387 | if (output->isConnected() && output->isEnabled()) { | ||
358 | // Save the current config with opened lid, just so that we know | 388 | // Save the current config with opened lid, just so that we know | ||
359 | // how to restore it later | 389 | // how to restore it later | ||
360 | const QString configId = Serializer::configId(m_monitoredConfig) + QLatin1String("_lidOpened"); | 390 | const QString configId = Serializer::configId(m_monitoredConfig) + QLatin1String("_lidOpened"); | ||
391 | if (!Serializer::configExists(configId)) { | ||||
361 | Serializer::saveConfig(m_monitoredConfig, configId); | 392 | Serializer::saveConfig(m_monitoredConfig, configId); | ||
393 | } | ||||
362 | disableOutput(m_monitoredConfig, output); | 394 | disableOutput(m_monitoredConfig, output); | ||
363 | doApplyConfig(m_monitoredConfig); | 395 | doApplyConfig(m_monitoredConfig); | ||
396 | applyConfig(); | ||||
364 | return; | 397 | return; | ||
365 | } | 398 | } | ||
366 | } | 399 | } | ||
367 | } | 400 | } | ||
368 | } | 401 | } | ||
369 | 402 | | |||
370 | 403 | | |||
371 | void KScreenDaemon::outputConnectedChanged() | 404 | void KScreenDaemon::outputConnectedChanged() | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 456 | } else { | |||
424 | disconnect(KScreen::ConfigMonitor::instance(), &KScreen::ConfigMonitor::configurationChanged, | 457 | disconnect(KScreen::ConfigMonitor::instance(), &KScreen::ConfigMonitor::configurationChanged, | ||
425 | this, &KScreenDaemon::configChanged); | 458 | this, &KScreenDaemon::configChanged); | ||
426 | } | 459 | } | ||
427 | } | 460 | } | ||
428 | 461 | | |||
429 | void KScreenDaemon::disableOutput(KScreen::ConfigPtr &config, KScreen::OutputPtr &output) | 462 | void KScreenDaemon::disableOutput(KScreen::ConfigPtr &config, KScreen::OutputPtr &output) | ||
430 | { | 463 | { | ||
431 | const QRect geom = output->geometry(); | 464 | const QRect geom = output->geometry(); | ||
465 | const bool disabledWasPrimary = output->isPrimary(); | ||||
466 | bool primaryFound = false; | ||||
467 | KScreen::OutputPtr firstOther = KScreen::OutputPtr(); | ||||
432 | qCDebug(KSCREEN_KDED) << "Laptop geometry:" << geom << output->pos() << (output->currentMode() ? output->currentMode()->size() : QSize()); | 468 | qCDebug(KSCREEN_KDED) << "Laptop geometry:" << geom << output->pos() << (output->currentMode() ? output->currentMode()->size() : QSize()); | ||
433 | 469 | | |||
434 | // Move all outputs right from the @p output to left | 470 | // Move all outputs right from the @p output to left | ||
435 | for (KScreen::OutputPtr &otherOutput : config->outputs()) { | 471 | for (KScreen::OutputPtr &otherOutput : config->outputs()) { | ||
436 | if (otherOutput == output || !otherOutput->isConnected() || !otherOutput->isEnabled()) { | 472 | if (otherOutput == output || !otherOutput->isConnected() || !otherOutput->isEnabled()) { | ||
437 | continue; | 473 | continue; | ||
438 | } | 474 | } | ||
439 | 475 | | |||
440 | QPoint otherPos = otherOutput->pos(); | 476 | QPoint otherPos = otherOutput->pos(); | ||
441 | if (otherPos.x() >= geom.right() && otherPos.y() >= geom.top() && otherPos.y() <= geom.bottom()) { | 477 | if (otherPos.x() >= geom.right() && otherPos.y() >= geom.top() && otherPos.y() <= geom.bottom()) { | ||
442 | otherPos.setX(otherPos.x() - geom.width()); | 478 | otherPos.setX(otherPos.x() - geom.width()); | ||
443 | } | 479 | } | ||
444 | qCDebug(KSCREEN_KDED) << "Moving" << otherOutput->name() << "from" << otherOutput->pos() << "to" << otherPos; | 480 | qCDebug(KSCREEN_KDED) << "Moving" << otherOutput->name() << "from" << otherOutput->pos() << "to" << otherPos; | ||
445 | otherOutput->setPos(otherPos); | 481 | otherOutput->setPos(otherPos); | ||
482 | | ||||
483 | if (otherOutput->isPrimary()) { | ||||
484 | primaryFound = true; | ||||
485 | } | ||||
486 | | ||||
487 | if (!firstOther) { | ||||
488 | firstOther = otherOutput; | ||||
489 | } | ||||
490 | } | ||||
491 | | ||||
492 | if (!primaryFound && disabledWasPrimary && firstOther) { | ||||
493 | firstOther->setPrimary(true); | ||||
446 | } | 494 | } | ||
447 | 495 | | |||
448 | // Disable the output | 496 | // Disable the output | ||
449 | output->setEnabled(false); | 497 | output->setEnabled(false); | ||
450 | } | 498 | } | ||
451 | 499 | | |||
452 | 500 | | |||
453 | #include "daemon.moc" | 501 | #include "daemon.moc" |