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> | ||
31 | #include <kscreen/output.h> | 33 | #include <kscreen/output.h> | ||
32 | #include <kscreen/configmonitor.h> | 34 | #include <kscreen/configmonitor.h> | ||
33 | #include <kscreen/getconfigoperation.h> | 35 | #include <kscreen/getconfigoperation.h> | ||
34 | #include <kscreen/setconfigoperation.h> | 36 | #include <kscreen/setconfigoperation.h> | ||
35 | 37 | | |||
36 | #include <KLocalizedString> | 38 | #include <KLocalizedString> | ||
37 | #include <KActionCollection> | 39 | #include <KActionCollection> | ||
38 | #include <KPluginFactory> | 40 | #include <KPluginFactory> | ||
39 | #include <KGlobalAccel> | 41 | #include <KGlobalAccel> | ||
40 | 42 | | |||
41 | #include <QTimer> | 43 | #include <QTimer> | ||
42 | #include <QAction> | 44 | #include <QAction> | ||
45 | #include <QOrientationReading> | ||||
43 | #include <QShortcut> | 46 | #include <QShortcut> | ||
44 | 47 | | |||
45 | K_PLUGIN_CLASS_WITH_JSON(KScreenDaemon, "kscreen.json") | 48 | K_PLUGIN_CLASS_WITH_JSON(KScreenDaemon, "kscreen.json") | ||
46 | 49 | | |||
47 | KScreenDaemon::KScreenDaemon(QObject* parent, const QList< QVariant >& ) | 50 | KScreenDaemon::KScreenDaemon(QObject* parent, const QList< QVariant >& ) | ||
48 | : KDEDModule(parent) | 51 | : KDEDModule(parent) | ||
49 | , m_monitoring(false) | 52 | , m_monitoring(false) | ||
50 | , m_changeCompressor(new QTimer(this)) | 53 | , m_changeCompressor(new QTimer(this)) | ||
51 | , m_saveTimer(nullptr) | 54 | , m_saveTimer(nullptr) | ||
52 | , m_lidClosedTimer(new QTimer(this)) | 55 | , m_lidClosedTimer(new QTimer(this)) | ||
53 | 56 | , m_orientationSensor(new OrientationSensor(this)) | |||
54 | { | 57 | { | ||
58 | connect(m_orientationSensor, &OrientationSensor::availableChanged, | ||||
59 | this, &KScreenDaemon::updateOrientation); | ||||
60 | connect(m_orientationSensor, &OrientationSensor::valueChanged, | ||||
61 | this, &KScreenDaemon::updateOrientation); | ||||
62 | | ||||
55 | KScreen::Log::instance(); | 63 | KScreen::Log::instance(); | ||
56 | QMetaObject::invokeMethod(this, "getInitialConfig", Qt::QueuedConnection); | 64 | QMetaObject::invokeMethod(this, "getInitialConfig", Qt::QueuedConnection); | ||
57 | } | 65 | } | ||
58 | 66 | | |||
59 | void KScreenDaemon::getInitialConfig() | 67 | void KScreenDaemon::getInitialConfig() | ||
60 | { | 68 | { | ||
61 | connect(new KScreen::GetConfigOperation, &KScreen::GetConfigOperation::finished, | 69 | connect(new KScreen::GetConfigOperation, &KScreen::GetConfigOperation::finished, | ||
62 | this, [this](KScreen::ConfigOperation* op) { | 70 | this, [this](KScreen::ConfigOperation* op) { | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 127 | connect(Generator::self(), &Generator::ready, this, [this] { | |||
120 | applyConfig(); | 128 | applyConfig(); | ||
121 | m_startingUp = false; | 129 | m_startingUp = false; | ||
122 | }); | 130 | }); | ||
123 | 131 | | |||
124 | Generator::self()->setCurrentConfig(m_monitoredConfig->data()); | 132 | Generator::self()->setCurrentConfig(m_monitoredConfig->data()); | ||
125 | monitorConnectedChange(); | 133 | monitorConnectedChange(); | ||
126 | } | 134 | } | ||
127 | 135 | | |||
136 | void KScreenDaemon::updateOrientation() | ||||
137 | { | ||||
138 | if (!m_monitoredConfig) { | ||||
139 | return; | ||||
140 | } | ||||
141 | const auto features = m_monitoredConfig->data()->supportedFeatures(); | ||||
142 | if (!features.testFlag(KScreen::Config::Feature::AutoRotation) | ||||
143 | || !features.testFlag(KScreen::Config::Feature::TabletMode) ) { | ||||
144 | return; | ||||
145 | } | ||||
146 | | ||||
147 | if (!m_orientationSensor->available() || !m_orientationSensor->enabled()) { | ||||
148 | return; | ||||
149 | } | ||||
150 | | ||||
151 | const auto orientation = m_orientationSensor->value(); | ||||
152 | if (orientation == QOrientationReading::Undefined) { | ||||
153 | // Orientation sensor went off. Do not change current orientation. | ||||
154 | return; | ||||
155 | } | ||||
156 | if (orientation == QOrientationReading::FaceUp || | ||||
157 | orientation == QOrientationReading::FaceDown) { | ||||
158 | // We currently don't do anything with FaceUp/FaceDown, but in the future we could use them | ||||
159 | // to shut off and switch on again a display when display is facing downwards/upwards. | ||||
160 | return; | ||||
161 | } | ||||
162 | | ||||
163 | m_monitoredConfig->setDeviceOrientation(orientation); | ||||
164 | if (m_monitoring) { | ||||
165 | doApplyConfig(m_monitoredConfig->data()); | ||||
166 | } else { | ||||
167 | m_configDirty = true; | ||||
168 | } | ||||
169 | } | ||||
170 | | ||||
128 | void KScreenDaemon::doApplyConfig(const KScreen::ConfigPtr& config) | 171 | void KScreenDaemon::doApplyConfig(const KScreen::ConfigPtr& config) | ||
129 | { | 172 | { | ||
130 | qCDebug(KSCREEN_KDED) << "Do set and apply specific config"; | 173 | qCDebug(KSCREEN_KDED) << "Do set and apply specific config"; | ||
131 | auto configWrapper = std::unique_ptr<Config>(new Config(config)); | 174 | auto configWrapper = std::unique_ptr<Config>(new Config(config)); | ||
132 | configWrapper->setValidityFlags(KScreen::Config::ValidityFlag::RequireAtLeastOneEnabledScreen); | 175 | configWrapper->setValidityFlags(KScreen::Config::ValidityFlag::RequireAtLeastOneEnabledScreen); | ||
133 | configWrapper->activateControlWatching(); | 176 | configWrapper->activateControlWatching(); | ||
134 | connect(configWrapper.get(), &Config::controlChanged, this, [this]() { | | |||
135 | // TODO | | |||
136 | }); | | |||
137 | doApplyConfig(std::move(configWrapper)); | 177 | doApplyConfig(std::move(configWrapper)); | ||
138 | } | 178 | } | ||
139 | 179 | | |||
140 | void KScreenDaemon::doApplyConfig(std::unique_ptr<Config> config) | 180 | void KScreenDaemon::doApplyConfig(std::unique_ptr<Config> config) | ||
141 | { | 181 | { | ||
142 | setMonitorForChanges(false); // TODO: remove? | | |||
143 | m_monitoredConfig = std::move(config); | 182 | m_monitoredConfig = std::move(config); | ||
183 | | ||||
184 | m_orientationSensor->setEnabled(m_monitoredConfig->autoRotationRequested()); | ||||
185 | connect(m_monitoredConfig.get(), &Config::controlChanged, this, [this]() { | ||||
186 | m_orientationSensor->setEnabled(m_monitoredConfig->autoRotationRequested()); | ||||
187 | updateOrientation(); | ||||
188 | }); | ||||
189 | | ||||
144 | refreshConfig(); | 190 | refreshConfig(); | ||
145 | } | 191 | } | ||
146 | 192 | | |||
147 | void KScreenDaemon::refreshConfig() | 193 | void KScreenDaemon::refreshConfig() | ||
148 | { | 194 | { | ||
149 | setMonitorForChanges(false); | 195 | setMonitorForChanges(false); | ||
196 | m_configDirty = false; | ||||
150 | KScreen::ConfigMonitor::instance()->addConfig(m_monitoredConfig->data()); | 197 | KScreen::ConfigMonitor::instance()->addConfig(m_monitoredConfig->data()); | ||
151 | 198 | | |||
152 | connect(new KScreen::SetConfigOperation(m_monitoredConfig->data()), &KScreen::SetConfigOperation::finished, this, | 199 | connect(new KScreen::SetConfigOperation(m_monitoredConfig->data()), | ||
153 | [&]() { | 200 | &KScreen::SetConfigOperation::finished, | ||
201 | this, [this]() { | ||||
154 | qCDebug(KSCREEN_KDED) << "Config applied"; | 202 | qCDebug(KSCREEN_KDED) << "Config applied"; | ||
203 | if (m_configDirty) { | ||||
204 | // Config changed in the meantime again, apply. | ||||
205 | doApplyConfig(m_monitoredConfig->data()); | ||||
206 | } else { | ||||
155 | setMonitorForChanges(true); | 207 | setMonitorForChanges(true); | ||
208 | } | ||||
156 | }); | 209 | }); | ||
157 | } | 210 | } | ||
158 | 211 | | |||
159 | void KScreenDaemon::applyConfig() | 212 | void KScreenDaemon::applyConfig() | ||
160 | { | 213 | { | ||
161 | qCDebug(KSCREEN_KDED) << "Applying config"; | 214 | qCDebug(KSCREEN_KDED) << "Applying config"; | ||
162 | if (m_monitoredConfig->fileExists()) { | 215 | if (m_monitoredConfig->fileExists()) { | ||
163 | applyKnownConfig(); | 216 | applyKnownConfig(); | ||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |