Changeset View
Changeset View
Standalone View
Standalone View
kded/daemon.cpp
Show All 13 Lines | |||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
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 | | ||||
23 | #include "daemon.h" | 22 | #include "daemon.h" | ||
24 | #include "serializer.h" | 23 | #include "serializer.h" | ||
25 | #include "generator.h" | 24 | #include "generator.h" | ||
26 | #include "device.h" | 25 | #include "device.h" | ||
27 | #include "kscreenadaptor.h" | 26 | #include "kscreenadaptor.h" | ||
28 | #include "kscreen_daemon_debug.h" | 27 | #include "kscreen_daemon_debug.h" | ||
29 | #include "osdmanager.h" | 28 | #include "osdmanager.h" | ||
30 | 29 | | |||
31 | #include <QTimer> | 30 | #include <kscreen/log.h> | ||
32 | #include <QAction> | 31 | #include <kscreen/output.h> | ||
33 | #include <QShortcut> | 32 | #include <kscreen/configmonitor.h> | ||
34 | #include <QLoggingCategory> | 33 | #include <kscreen/getconfigoperation.h> | ||
34 | #include <kscreen/setconfigoperation.h> | ||||
35 | 35 | | |||
36 | #include <KLocalizedString> | 36 | #include <KLocalizedString> | ||
37 | #include <KActionCollection> | 37 | #include <KActionCollection> | ||
38 | #include <KPluginFactory> | 38 | #include <KPluginFactory> | ||
39 | #include <KGlobalAccel> | 39 | #include <KGlobalAccel> | ||
40 | 40 | | |||
41 | #include <kscreen/log.h> | 41 | #include <QTimer> | ||
42 | #include <kscreen/config.h> | 42 | #include <QAction> | ||
43 | #include <kscreen/output.h> | 43 | #include <QShortcut> | ||
44 | #include <kscreen/configmonitor.h> | | |||
45 | #include <kscreen/getconfigoperation.h> | | |||
46 | #include <kscreen/setconfigoperation.h> | | |||
47 | 44 | | |||
48 | K_PLUGIN_FACTORY_WITH_JSON(KScreenDaemonFactory, | 45 | K_PLUGIN_FACTORY_WITH_JSON(KScreenDaemonFactory, | ||
49 | "kscreen.json", | 46 | "kscreen.json", | ||
50 | registerPlugin<KScreenDaemon>();) | 47 | registerPlugin<KScreenDaemon>();) | ||
51 | 48 | | |||
52 | KScreenDaemon::KScreenDaemon(QObject* parent, const QList< QVariant >& ) | 49 | KScreenDaemon::KScreenDaemon(QObject* parent, const QList< QVariant >& ) | ||
53 | : KDEDModule(parent) | 50 | : KDEDModule(parent) | ||
54 | , m_monitoredConfig(nullptr) | 51 | , m_monitoredConfig(nullptr) | ||
55 | , m_monitoring(false) | 52 | , m_monitoring(false) | ||
56 | , m_changeCompressor(new QTimer(this)) | 53 | , m_changeCompressor(new QTimer(this)) | ||
57 | , m_saveTimer(nullptr) | 54 | , m_saveTimer(nullptr) | ||
58 | , m_lidClosedTimer(new QTimer(this)) | 55 | , m_lidClosedTimer(new QTimer(this)) | ||
59 | 56 | | |||
60 | { | 57 | { | ||
61 | KScreen::Log::instance(); | 58 | KScreen::Log::instance(); | ||
62 | QMetaObject::invokeMethod(this, "requestConfig", Qt::QueuedConnection); | 59 | QMetaObject::invokeMethod(this, "getInitialConfig", Qt::QueuedConnection); | ||
63 | } | 60 | } | ||
64 | 61 | | |||
65 | void KScreenDaemon::requestConfig() | 62 | void KScreenDaemon::getInitialConfig() | ||
66 | { | 63 | { | ||
67 | connect(new KScreen::GetConfigOperation, &KScreen::GetConfigOperation::finished, | 64 | connect(new KScreen::GetConfigOperation, &KScreen::GetConfigOperation::finished, | ||
68 | this, [this](KScreen::ConfigOperation* op) { | 65 | this, [this](KScreen::ConfigOperation* op) { | ||
69 | if (op->hasError()) { | 66 | if (op->hasError()) { | ||
70 | return; | 67 | return; | ||
71 | } | 68 | } | ||
72 | 69 | | |||
73 | m_monitoredConfig = qobject_cast<KScreen::GetConfigOperation*>(op)->config(); | 70 | m_monitoredConfig = qobject_cast<KScreen::GetConfigOperation*>(op)->config(); | ||
Show All 26 Lines | 85 | { | |||
100 | m_changeCompressor->setInterval(10); | 97 | m_changeCompressor->setInterval(10); | ||
101 | m_changeCompressor->setSingleShot(true); | 98 | m_changeCompressor->setSingleShot(true); | ||
102 | connect(m_changeCompressor, &QTimer::timeout, this, &KScreenDaemon::applyConfig); | 99 | connect(m_changeCompressor, &QTimer::timeout, this, &KScreenDaemon::applyConfig); | ||
103 | 100 | | |||
104 | m_lidClosedTimer->setInterval(1000); | 101 | m_lidClosedTimer->setInterval(1000); | ||
105 | m_lidClosedTimer->setSingleShot(true); | 102 | m_lidClosedTimer->setSingleShot(true); | ||
106 | connect(m_lidClosedTimer, &QTimer::timeout, this, &KScreenDaemon::lidClosedTimeout); | 103 | connect(m_lidClosedTimer, &QTimer::timeout, this, &KScreenDaemon::lidClosedTimeout); | ||
107 | 104 | | |||
108 | | ||||
109 | connect(Device::self(), &Device::lidClosedChanged, this, &KScreenDaemon::lidClosedChanged); | 105 | connect(Device::self(), &Device::lidClosedChanged, this, &KScreenDaemon::lidClosedChanged); | ||
110 | connect(Device::self(), &Device::resumingFromSuspend, this, | 106 | connect(Device::self(), &Device::resumingFromSuspend, this, | ||
111 | [&]() { | 107 | [&]() { | ||
112 | KScreen::Log::instance()->setContext(QStringLiteral("resuming")); | 108 | KScreen::Log::instance()->setContext(QStringLiteral("resuming")); | ||
113 | qCDebug(KSCREEN_KDED) << "Resumed from suspend, checking for screen changes"; | 109 | qCDebug(KSCREEN_KDED) << "Resumed from suspend, checking for screen changes"; | ||
114 | // We don't care about the result, we just want to force the backend | 110 | // We don't care about the result, we just want to force the backend | ||
115 | // to query XRandR so that it will detect possible changes that happened | 111 | // to query XRandR so that it will detect possible changes that happened | ||
116 | // while the computer was suspended, and will emit the change events. | 112 | // while the computer was suspended, and will emit the change events. | ||
117 | new KScreen::GetConfigOperation(KScreen::GetConfigOperation::NoEDID, this); | 113 | new KScreen::GetConfigOperation(KScreen::GetConfigOperation::NoEDID, this); | ||
118 | }); | 114 | }); | ||
119 | connect(Device::self(), &Device::aboutToSuspend, this, | 115 | connect(Device::self(), &Device::aboutToSuspend, this, | ||
120 | [&]() { | 116 | [&]() { | ||
121 | qCDebug(KSCREEN_KDED) << "System is going to suspend, won't be changing config (waited for " << (m_lidClosedTimer->interval() - m_lidClosedTimer->remainingTime()) << "ms)"; | 117 | qCDebug(KSCREEN_KDED) << "System is going to suspend, won't be changing config (waited for " << (m_lidClosedTimer->interval() - m_lidClosedTimer->remainingTime()) << "ms)"; | ||
122 | m_lidClosedTimer->stop(); | 118 | m_lidClosedTimer->stop(); | ||
123 | }); | 119 | }); | ||
124 | 120 | | |||
125 | | ||||
126 | connect(Generator::self(), &Generator::ready, | 121 | connect(Generator::self(), &Generator::ready, | ||
127 | this, &KScreenDaemon::applyConfig); | 122 | this, &KScreenDaemon::applyConfig); | ||
128 | 123 | | |||
129 | Generator::self()->setCurrentConfig(m_monitoredConfig); | 124 | Generator::self()->setCurrentConfig(m_monitoredConfig); | ||
130 | monitorConnectedChange(); | 125 | monitorConnectedChange(); | ||
131 | } | 126 | } | ||
132 | 127 | | |||
133 | void KScreenDaemon::doApplyConfig(const KScreen::ConfigPtr& config) | 128 | void KScreenDaemon::doApplyConfig(const KScreen::ConfigPtr& config) | ||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 204 | case KScreen::OsdAction::ExtendRight: | |||
210 | qCDebug(KSCREEN_KDED) << "OSD: extend right"; | 205 | qCDebug(KSCREEN_KDED) << "OSD: extend right"; | ||
211 | doApplyConfig(Generator::self()->displaySwitch(Generator::ExtendToRight)); | 206 | doApplyConfig(Generator::self()->displaySwitch(Generator::ExtendToRight)); | ||
212 | return; | 207 | return; | ||
213 | case KScreen::OsdAction::Clone: | 208 | case KScreen::OsdAction::Clone: | ||
214 | qCDebug(KSCREEN_KDED) << "OSD: clone"; | 209 | qCDebug(KSCREEN_KDED) << "OSD: clone"; | ||
215 | doApplyConfig(Generator::self()->displaySwitch(Generator::Clone)); | 210 | doApplyConfig(Generator::self()->displaySwitch(Generator::Clone)); | ||
216 | return; | 211 | return; | ||
217 | } | 212 | } | ||
218 | | ||||
219 | Q_UNREACHABLE(); | 213 | Q_UNREACHABLE(); | ||
220 | } | 214 | } | ||
221 | 215 | | |||
222 | void KScreenDaemon::applyIdealConfig() | 216 | void KScreenDaemon::applyIdealConfig() | ||
223 | { | 217 | { | ||
224 | if (m_monitoredConfig->connectedOutputs().count() < 2) { | 218 | if (m_monitoredConfig->connectedOutputs().count() < 2) { | ||
225 | m_osdManager->hideOsd(); | 219 | m_osdManager->hideOsd(); | ||
226 | doApplyConfig(Generator::self()->idealConfig(m_monitoredConfig)); | 220 | doApplyConfig(Generator::self()->idealConfig(m_monitoredConfig)); | ||
227 | } else { | 221 | } else { | ||
228 | qCDebug(KSCREEN_KDED) << "Getting ideal config from user via OSD..."; | 222 | qCDebug(KSCREEN_KDED) << "Getting ideal config from user via OSD..."; | ||
229 | auto action = m_osdManager->showActionSelector(); | 223 | auto action = m_osdManager->showActionSelector(); | ||
230 | connect(action, &KScreen::OsdAction::selected, | 224 | connect(action, &KScreen::OsdAction::selected, | ||
231 | this, &KScreenDaemon::applyOsdAction); | 225 | this, &KScreenDaemon::applyOsdAction); | ||
232 | } | 226 | } | ||
233 | } | 227 | } | ||
234 | 228 | | |||
235 | void logConfig(const KScreen::ConfigPtr &config) { | 229 | void logConfig(const KScreen::ConfigPtr &config) | ||
230 | { | ||||
236 | if (config) { | 231 | if (config) { | ||
237 | foreach (auto o, config->outputs()) { | 232 | foreach (auto o, config->outputs()) { | ||
238 | if (o->isConnected()) { | 233 | if (o->isConnected()) { | ||
239 | qCDebug(KSCREEN_KDED) << o; | 234 | qCDebug(KSCREEN_KDED) << o; | ||
240 | } | 235 | } | ||
241 | } | 236 | } | ||
242 | } | 237 | } | ||
243 | } | 238 | } | ||
▲ Show 20 Lines • Show All 217 Lines • Show Last 20 Lines |