Changeset View
Changeset View
Standalone View
Standalone View
kded/daemon.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | 44 | | |||
45 | K_PLUGIN_FACTORY_WITH_JSON(KScreenDaemonFactory, | 45 | K_PLUGIN_FACTORY_WITH_JSON(KScreenDaemonFactory, | ||
46 | "kscreen.json", | 46 | "kscreen.json", | ||
47 | registerPlugin<KScreenDaemon>();) | 47 | registerPlugin<KScreenDaemon>();) | ||
48 | 48 | | |||
49 | KScreenDaemon::KScreenDaemon(QObject* parent, const QList< QVariant >& ) | 49 | KScreenDaemon::KScreenDaemon(QObject* parent, const QList< QVariant >& ) | ||
50 | : KDEDModule(parent) | 50 | : KDEDModule(parent) | ||
51 | , m_monitoredConfig(nullptr) | 51 | , m_monitoredConfig(nullptr) | ||
52 | , m_iteration(Generator::None) | | |||
53 | , m_monitoring(false) | 52 | , m_monitoring(false) | ||
54 | , m_changeCompressor(new QTimer(this)) | 53 | , m_changeCompressor(new QTimer(this)) | ||
55 | , m_buttonTimer(new QTimer(this)) | | |||
56 | , m_saveTimer(new QTimer(this)) | 54 | , m_saveTimer(new QTimer(this)) | ||
57 | , m_lidClosedTimer(new QTimer(this)) | 55 | , m_lidClosedTimer(new QTimer(this)) | ||
58 | 56 | | |||
59 | { | 57 | { | ||
60 | KScreen::Log::instance(); | 58 | KScreen::Log::instance(); | ||
61 | QMetaObject::invokeMethod(this, "requestConfig", Qt::QueuedConnection); | 59 | QMetaObject::invokeMethod(this, "requestConfig", Qt::QueuedConnection); | ||
62 | } | 60 | } | ||
63 | 61 | | |||
Show All 30 Lines | 88 | { | |||
94 | QList<QKeySequence> switchDisplayShortcuts({Qt::Key_Display, Qt::MetaModifier + Qt::Key_P}); | 92 | QList<QKeySequence> switchDisplayShortcuts({Qt::Key_Display, Qt::MetaModifier + Qt::Key_P}); | ||
95 | KGlobalAccel::self()->setGlobalShortcut(action, switchDisplayShortcuts); | 93 | KGlobalAccel::self()->setGlobalShortcut(action, switchDisplayShortcuts); | ||
96 | connect(action, &QAction::triggered, [&](bool) { displayButton(); }); | 94 | connect(action, &QAction::triggered, [&](bool) { displayButton(); }); | ||
97 | 95 | | |||
98 | new KScreenAdaptor(this); | 96 | new KScreenAdaptor(this); | ||
99 | // Initialize OSD manager to register its dbus interface | 97 | // Initialize OSD manager to register its dbus interface | ||
100 | KScreen::OsdManager::self(); | 98 | KScreen::OsdManager::self(); | ||
101 | 99 | | |||
102 | m_buttonTimer->setInterval(300); | | |||
103 | m_buttonTimer->setSingleShot(true); | | |||
104 | connect(m_buttonTimer, &QTimer::timeout, this, &KScreenDaemon::applyGenericConfig); | | |||
105 | | ||||
106 | m_saveTimer->setInterval(300); | 100 | m_saveTimer->setInterval(300); | ||
107 | m_saveTimer->setSingleShot(true); | 101 | m_saveTimer->setSingleShot(true); | ||
108 | connect(m_saveTimer, &QTimer::timeout, this, &KScreenDaemon::saveCurrentConfig); | 102 | connect(m_saveTimer, &QTimer::timeout, this, &KScreenDaemon::saveCurrentConfig); | ||
109 | 103 | | |||
110 | m_changeCompressor->setInterval(10); | 104 | m_changeCompressor->setInterval(10); | ||
111 | m_changeCompressor->setSingleShot(true); | 105 | m_changeCompressor->setSingleShot(true); | ||
112 | connect(m_changeCompressor, &QTimer::timeout, this, &KScreenDaemon::applyConfig); | 106 | connect(m_changeCompressor, &QTimer::timeout, this, &KScreenDaemon::applyConfig); | ||
113 | 107 | | |||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Line(s) | |||||
289 | { | 283 | { | ||
290 | KScreen::OsdManager::self()->showOutputIdentifiers(); | 284 | KScreen::OsdManager::self()->showOutputIdentifiers(); | ||
291 | } | 285 | } | ||
292 | 286 | | |||
293 | void KScreenDaemon::displayButton() | 287 | void KScreenDaemon::displayButton() | ||
294 | { | 288 | { | ||
295 | qCDebug(KSCREEN_KDED) << "displayBtn triggered"; | 289 | qCDebug(KSCREEN_KDED) << "displayBtn triggered"; | ||
296 | 290 | | |||
297 | QString message = i18nc("OSD text after XF86Display button press", "No External Display"); | 291 | auto action = KScreen::OsdManager::self()->showActionSelector(); | ||
298 | if (m_monitoredConfig && m_monitoredConfig->connectedOutputs().count() > 1) { | 292 | connect(action, &KScreen::OsdAction::selected, | ||
299 | message = i18nc("OSD text after XF86Display button press", "Changing Screen Layout"); | 293 | this, &KScreenDaemon::applyOsdAction); | ||
300 | } | | |||
301 | | ||||
302 | if (m_buttonTimer->isActive()) { | | |||
303 | qCDebug(KSCREEN_KDED) << "Too fast, cowboy"; | | |||
304 | return; | | |||
305 | } | | |||
306 | | ||||
307 | m_buttonTimer->start(); | | |||
308 | } | | |||
309 | | ||||
310 | void KScreenDaemon::resetDisplaySwitch() | | |||
311 | { | | |||
312 | qCDebug(KSCREEN_KDED) << "resetDisplaySwitch()"; | | |||
313 | m_iteration = Generator::None; | | |||
314 | } | | |||
315 | | ||||
316 | void KScreenDaemon::applyGenericConfig() | | |||
317 | { | | |||
318 | if (m_iteration == Generator::ExtendToRight) { | | |||
319 | m_iteration = Generator::None; | | |||
320 | } | | |||
321 | | ||||
322 | m_iteration = Generator::DisplaySwitchAction(static_cast<int>(m_iteration) + 1); | | |||
323 | qCDebug(KSCREEN_KDED) << "displayButton: " << m_iteration; | | |||
324 | | ||||
325 | static QHash<Generator::DisplaySwitchAction, QString> actionMessages({ | | |||
326 | {Generator::DisplaySwitchAction::None, i18nc("osd when displaybutton is pressed", "No Action")}, | | |||
327 | {Generator::DisplaySwitchAction::Clone, i18nc("osd when displaybutton is pressed", "Cloned Display")}, | | |||
328 | {Generator::DisplaySwitchAction::ExtendToLeft, i18nc("osd when displaybutton is pressed", "Extend Left")}, | | |||
329 | {Generator::DisplaySwitchAction::TurnOffEmbedded, i18nc("osd when displaybutton is pressed", "External Only")}, | | |||
330 | {Generator::DisplaySwitchAction::TurnOffExternal, i18nc("osd when displaybutton is pressed", "Internal Only")}, | | |||
331 | {Generator::DisplaySwitchAction::ExtendToRight, i18nc("osd when displaybutton is pressed", "Extended Right")} | | |||
332 | }); | | |||
333 | const QString &message = actionMessages.value(m_iteration); | | |||
334 | | ||||
335 | // We delay the OSD for two seconds and hope that X and hardware are done setting everything up. | | |||
336 | QTimer::singleShot(2000, | | |||
337 | [message]() { | | |||
338 | KScreen::OsdManager::self()->showOsd(QStringLiteral("preferences-desktop-display-randr"), message); | | |||
339 | } | | |||
340 | ); | | |||
341 | | ||||
342 | doApplyConfig(Generator::self()->displaySwitch(m_iteration)); | | |||
343 | } | 294 | } | ||
344 | 295 | | |||
345 | void KScreenDaemon::lidClosedChanged(bool lidIsClosed) | 296 | void KScreenDaemon::lidClosedChanged(bool lidIsClosed) | ||
346 | { | 297 | { | ||
347 | // Ignore this when we don't have any external monitors, we can't turn off our | 298 | // Ignore this when we don't have any external monitors, we can't turn off our | ||
348 | // only screen | 299 | // only screen | ||
349 | if (m_monitoredConfig->connectedOutputs().count() == 1) { | 300 | if (m_monitoredConfig->connectedOutputs().count() == 1) { | ||
350 | return; | 301 | return; | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | |||||
405 | 356 | | |||
406 | 357 | | |||
407 | void KScreenDaemon::outputConnectedChanged() | 358 | void KScreenDaemon::outputConnectedChanged() | ||
408 | { | 359 | { | ||
409 | if (!m_changeCompressor->isActive()) { | 360 | if (!m_changeCompressor->isActive()) { | ||
410 | m_changeCompressor->start(); | 361 | m_changeCompressor->start(); | ||
411 | } | 362 | } | ||
412 | 363 | | |||
413 | resetDisplaySwitch(); | | |||
414 | | ||||
415 | KScreen::Output *output = qobject_cast<KScreen::Output*>(sender()); | 364 | KScreen::Output *output = qobject_cast<KScreen::Output*>(sender()); | ||
416 | qCDebug(KSCREEN_KDED) << "outputConnectedChanged():" << output->name(); | 365 | qCDebug(KSCREEN_KDED) << "outputConnectedChanged():" << output->name(); | ||
417 | 366 | | |||
418 | if (output->isConnected()) { | 367 | if (output->isConnected()) { | ||
419 | Q_EMIT outputConnected(output->name()); | 368 | Q_EMIT outputConnected(output->name()); | ||
420 | 369 | | |||
421 | if (!Serializer::configExists(m_monitoredConfig)) { | 370 | if (!Serializer::configExists(m_monitoredConfig)) { | ||
422 | Q_EMIT unknownOutputConnected(output->name()); | 371 | Q_EMIT unknownOutputConnected(output->name()); | ||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |