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 | | ||||
24 | #include "../common/orientation_sensor.h" | ||||
23 | #include "config.h" | 25 | #include "config.h" | ||
24 | #include "generator.h" | 26 | #include "generator.h" | ||
25 | #include "device.h" | 27 | #include "device.h" | ||
26 | #include "kscreenadaptor.h" | 28 | #include "kscreenadaptor.h" | ||
27 | #include "kscreen_daemon_debug.h" | 29 | #include "kscreen_daemon_debug.h" | ||
28 | #include "osdmanager.h" | 30 | #include "osdmanager.h" | ||
29 | 31 | | |||
30 | #include <kscreen/log.h> | 32 | #include <kscreen/log.h> | ||
Show All 14 Lines | |||||
45 | K_PLUGIN_CLASS_WITH_JSON(KScreenDaemon, "kscreen.json") | 47 | K_PLUGIN_CLASS_WITH_JSON(KScreenDaemon, "kscreen.json") | ||
46 | 48 | | |||
47 | KScreenDaemon::KScreenDaemon(QObject* parent, const QList< QVariant >& ) | 49 | KScreenDaemon::KScreenDaemon(QObject* parent, const QList< QVariant >& ) | ||
48 | : KDEDModule(parent) | 50 | : KDEDModule(parent) | ||
49 | , m_monitoring(false) | 51 | , m_monitoring(false) | ||
50 | , m_changeCompressor(new QTimer(this)) | 52 | , m_changeCompressor(new QTimer(this)) | ||
51 | , m_saveTimer(nullptr) | 53 | , m_saveTimer(nullptr) | ||
52 | , m_lidClosedTimer(new QTimer(this)) | 54 | , m_lidClosedTimer(new QTimer(this)) | ||
53 | 55 | , m_orientationSensor(nullptr) | |||
54 | { | 56 | { | ||
55 | KScreen::Log::instance(); | 57 | KScreen::Log::instance(); | ||
56 | QMetaObject::invokeMethod(this, "getInitialConfig", Qt::QueuedConnection); | 58 | QMetaObject::invokeMethod(this, "getInitialConfig", Qt::QueuedConnection); | ||
57 | } | 59 | } | ||
58 | 60 | | |||
59 | void KScreenDaemon::getInitialConfig() | 61 | void KScreenDaemon::getInitialConfig() | ||
60 | { | 62 | { | ||
61 | connect(new KScreen::GetConfigOperation, &KScreen::GetConfigOperation::finished, | 63 | connect(new KScreen::GetConfigOperation, &KScreen::GetConfigOperation::finished, | ||
Show All 33 Lines | 85 | { | |||
95 | m_changeCompressor->setInterval(10); | 97 | m_changeCompressor->setInterval(10); | ||
96 | m_changeCompressor->setSingleShot(true); | 98 | m_changeCompressor->setSingleShot(true); | ||
97 | connect(m_changeCompressor, &QTimer::timeout, this, &KScreenDaemon::applyConfig); | 99 | connect(m_changeCompressor, &QTimer::timeout, this, &KScreenDaemon::applyConfig); | ||
98 | 100 | | |||
99 | m_lidClosedTimer->setInterval(1000); | 101 | m_lidClosedTimer->setInterval(1000); | ||
100 | m_lidClosedTimer->setSingleShot(true); | 102 | m_lidClosedTimer->setSingleShot(true); | ||
101 | connect(m_lidClosedTimer, &QTimer::timeout, this, &KScreenDaemon::lidClosedTimeout); | 103 | connect(m_lidClosedTimer, &QTimer::timeout, this, &KScreenDaemon::lidClosedTimeout); | ||
102 | 104 | | |||
105 | if (m_monitoredConfig->data()->supportedFeatures() | ||||
106 | & (KScreen::Config::Feature::AutoRotation | ||||
107 | | KScreen::Config::Feature::TabletMode)) { | ||||
108 | m_orientationSensor = new OrientationSensor(this); | ||||
109 | | ||||
110 | connect(m_orientationSensor, &OrientationSensor::availableChanged, | ||||
111 | this, &KScreenDaemon::updateOrientation); | ||||
112 | connect(m_orientationSensor, &OrientationSensor::valueChanged, | ||||
113 | this, &KScreenDaemon::updateOrientation); | ||||
114 | } | ||||
115 | | ||||
103 | connect(Device::self(), &Device::lidClosedChanged, this, &KScreenDaemon::lidClosedChanged); | 116 | connect(Device::self(), &Device::lidClosedChanged, this, &KScreenDaemon::lidClosedChanged); | ||
104 | connect(Device::self(), &Device::resumingFromSuspend, this, | 117 | connect(Device::self(), &Device::resumingFromSuspend, this, | ||
105 | [&]() { | 118 | [&]() { | ||
106 | KScreen::Log::instance()->setContext(QStringLiteral("resuming")); | 119 | KScreen::Log::instance()->setContext(QStringLiteral("resuming")); | ||
107 | qCDebug(KSCREEN_KDED) << "Resumed from suspend, checking for screen changes"; | 120 | qCDebug(KSCREEN_KDED) << "Resumed from suspend, checking for screen changes"; | ||
108 | // We don't care about the result, we just want to force the backend | 121 | // We don't care about the result, we just want to force the backend | ||
109 | // to query XRandR so that it will detect possible changes that happened | 122 | // to query XRandR so that it will detect possible changes that happened | ||
110 | // while the computer was suspended, and will emit the change events. | 123 | // while the computer was suspended, and will emit the change events. | ||
Show All 9 Lines | 132 | connect(Generator::self(), &Generator::ready, this, [this] { | |||
120 | applyConfig(); | 133 | applyConfig(); | ||
121 | m_startingUp = false; | 134 | m_startingUp = false; | ||
122 | }); | 135 | }); | ||
123 | 136 | | |||
124 | Generator::self()->setCurrentConfig(m_monitoredConfig->data()); | 137 | Generator::self()->setCurrentConfig(m_monitoredConfig->data()); | ||
125 | monitorConnectedChange(); | 138 | monitorConnectedChange(); | ||
126 | } | 139 | } | ||
127 | 140 | | |||
141 | void KScreenDaemon::updateOrientation() | ||||
142 | { | ||||
143 | using Orientation = Globals::DeviceOrientation; | ||||
144 | | ||||
145 | if (!m_monitoredConfig) { | ||||
146 | return; | ||||
147 | } | ||||
148 | Q_ASSERT(m_monitoredConfig->data()->supportedFeatures() | ||||
149 | & (KScreen::Config::Feature::AutoRotation | ||||
150 | | KScreen::Config::Feature::TabletMode)); | ||||
151 | | ||||
152 | if (!m_orientationSensor->available() || !m_orientationSensor->enabled()) { | ||||
153 | return; | ||||
154 | } | ||||
155 | | ||||
156 | const auto orientation = m_orientationSensor->value(); | ||||
157 | if (orientation == Orientation::Undefined) { | ||||
158 | // Orientation sensor went off. Do not change current orientation. | ||||
159 | return; | ||||
160 | } | ||||
161 | if (orientation == Orientation::FaceUp || | ||||
162 | orientation == Orientation::FaceDown) { | ||||
163 | // We currently don't do anything with FaceUp/FaceDown, but in the future we could use them | ||||
164 | // to shut off and switch on again a display when display is facing downwards/upwards. | ||||
165 | return; | ||||
166 | } | ||||
167 | | ||||
168 | m_monitoredConfig->setDeviceOrientation(orientation); | ||||
169 | if (m_monitoring) { | ||||
170 | doApplyConfig(m_monitoredConfig->data()); | ||||
171 | } else { | ||||
172 | m_configDirty = true; | ||||
173 | } | ||||
174 | } | ||||
175 | | ||||
128 | void KScreenDaemon::doApplyConfig(const KScreen::ConfigPtr& config) | 176 | void KScreenDaemon::doApplyConfig(const KScreen::ConfigPtr& config) | ||
129 | { | 177 | { | ||
130 | qCDebug(KSCREEN_KDED) << "Do set and apply specific config"; | 178 | qCDebug(KSCREEN_KDED) << "Do set and apply specific config"; | ||
131 | auto configWrapper = std::unique_ptr<Config>(new Config(config)); | 179 | auto configWrapper = std::unique_ptr<Config>(new Config(config)); | ||
132 | configWrapper->setValidityFlags(KScreen::Config::ValidityFlag::RequireAtLeastOneEnabledScreen); | 180 | configWrapper->setValidityFlags(KScreen::Config::ValidityFlag::RequireAtLeastOneEnabledScreen); | ||
133 | configWrapper->activateControlWatching(); | 181 | configWrapper->activateControlWatching(); | ||
134 | connect(configWrapper.get(), &Config::controlChanged, this, [this]() { | | |||
135 | // TODO | | |||
136 | }); | | |||
137 | doApplyConfig(std::move(configWrapper)); | 182 | doApplyConfig(std::move(configWrapper)); | ||
138 | } | 183 | } | ||
139 | 184 | | |||
140 | void KScreenDaemon::doApplyConfig(std::unique_ptr<Config> config) | 185 | void KScreenDaemon::doApplyConfig(std::unique_ptr<Config> config) | ||
141 | { | 186 | { | ||
142 | setMonitorForChanges(false); // TODO: remove? | | |||
143 | m_monitoredConfig = std::move(config); | 187 | m_monitoredConfig = std::move(config); | ||
188 | | ||||
189 | m_orientationSensor->setEnabled(m_monitoredConfig->autoRotationRequested()); | ||||
190 | connect(m_monitoredConfig.get(), &Config::controlChanged, this, [this]() { | ||||
191 | m_orientationSensor->setEnabled(m_monitoredConfig->autoRotationRequested()); | ||||
192 | updateOrientation(); | ||||
193 | }); | ||||
194 | | ||||
144 | refreshConfig(); | 195 | refreshConfig(); | ||
145 | } | 196 | } | ||
146 | 197 | | |||
147 | void KScreenDaemon::refreshConfig() | 198 | void KScreenDaemon::refreshConfig() | ||
148 | { | 199 | { | ||
149 | setMonitorForChanges(false); | 200 | setMonitorForChanges(false); | ||
201 | m_configDirty = false; | ||||
150 | KScreen::ConfigMonitor::instance()->addConfig(m_monitoredConfig->data()); | 202 | KScreen::ConfigMonitor::instance()->addConfig(m_monitoredConfig->data()); | ||
151 | 203 | | |||
152 | connect(new KScreen::SetConfigOperation(m_monitoredConfig->data()), &KScreen::SetConfigOperation::finished, this, | 204 | connect(new KScreen::SetConfigOperation(m_monitoredConfig->data()), | ||
153 | [&]() { | 205 | &KScreen::SetConfigOperation::finished, | ||
206 | this, [this]() { | ||||
154 | qCDebug(KSCREEN_KDED) << "Config applied"; | 207 | qCDebug(KSCREEN_KDED) << "Config applied"; | ||
208 | if (m_configDirty) { | ||||
209 | // Config changed in the meantime again, apply. | ||||
210 | doApplyConfig(m_monitoredConfig->data()); | ||||
211 | } else { | ||||
155 | setMonitorForChanges(true); | 212 | setMonitorForChanges(true); | ||
213 | } | ||||
156 | }); | 214 | }); | ||
157 | } | 215 | } | ||
158 | 216 | | |||
159 | void KScreenDaemon::applyConfig() | 217 | void KScreenDaemon::applyConfig() | ||
160 | { | 218 | { | ||
161 | qCDebug(KSCREEN_KDED) << "Applying config"; | 219 | qCDebug(KSCREEN_KDED) << "Applying config"; | ||
162 | if (m_monitoredConfig->fileExists()) { | 220 | if (m_monitoredConfig->fileExists()) { | ||
163 | applyKnownConfig(); | 221 | applyKnownConfig(); | ||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |