Changeset View
Changeset View
Standalone View
Standalone View
kded/osdmanager.cpp
Show All 21 Lines | |||||
22 | 22 | | |||
23 | #include <KScreen/Config> | 23 | #include <KScreen/Config> | ||
24 | #include <KScreen/GetConfigOperation> | 24 | #include <KScreen/GetConfigOperation> | ||
25 | #include <KScreen/Output> | 25 | #include <KScreen/Output> | ||
26 | 26 | | |||
27 | #include <QDBusConnection> | 27 | #include <QDBusConnection> | ||
28 | 28 | | |||
29 | #include <QQmlEngine> | 29 | #include <QQmlEngine> | ||
30 | #include <QMetaObject> | ||||
30 | 31 | | |||
31 | namespace KScreen { | 32 | namespace KScreen { | ||
32 | 33 | | |||
33 | class OsdActionImpl : public OsdAction | 34 | class OsdActionImpl : public OsdAction | ||
34 | { | 35 | { | ||
35 | Q_OBJECT | 36 | Q_OBJECT | ||
36 | public: | 37 | public: | ||
37 | OsdActionImpl(QObject *parent = nullptr) | 38 | OsdActionImpl(QObject *parent = nullptr) | ||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 121 | Q_FOREACH (const KScreen::OutputPtr &output, config->outputs()) { | |||
128 | } | 129 | } | ||
129 | osd->showGenericOsd(icon, text); | 130 | osd->showGenericOsd(icon, text); | ||
130 | } | 131 | } | ||
131 | m_cleanupTimer->start(); | 132 | m_cleanupTimer->start(); | ||
132 | } | 133 | } | ||
133 | ); | 134 | ); | ||
134 | } | 135 | } | ||
135 | 136 | | |||
136 | OsdAction *OsdManager::showActionSelector() | 137 | OsdAction *OsdManager::showActionSelector(bool lidIsOpen) | ||
137 | { | 138 | { | ||
138 | hideOsd(); | 139 | hideOsd(); | ||
139 | 140 | | |||
140 | OsdActionImpl *action = new OsdActionImpl(this); | 141 | OsdActionImpl *action = new OsdActionImpl(this); | ||
141 | connect(action, &OsdActionImpl::selected, | 142 | connect(action, &OsdActionImpl::selected, | ||
142 | this, [this]() { | 143 | this, [this]() { | ||
143 | for (auto osd : qAsConst(m_osds)) { | 144 | for (auto osd : qAsConst(m_osds)) { | ||
144 | osd->hideOsd(); | 145 | osd->hideOsd(); | ||
145 | } | 146 | } | ||
146 | }); | 147 | }); | ||
147 | connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, | 148 | connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, | ||
148 | this, [this, action](const KScreen::ConfigOperation *op) { | 149 | this, [this, action, lidIsOpen](const KScreen::ConfigOperation *op) { | ||
149 | if (op->hasError()) { | 150 | if (op->hasError()) { | ||
150 | qCWarning(KSCREEN_KDED) << op->errorString(); | 151 | qCWarning(KSCREEN_KDED) << op->errorString(); | ||
151 | return; | 152 | return; | ||
152 | } | 153 | } | ||
153 | 154 | | |||
154 | // Show selector on alll enabled screens | 155 | // Show selector on alll enabled screens | ||
155 | const auto outputs = op->config()->outputs(); | 156 | const auto outputs = op->config()->outputs(); | ||
156 | KScreen::OutputPtr osdOutput; | 157 | KScreen::OutputPtr osdOutput; | ||
157 | for (const auto &output : outputs) { | 158 | for (const auto &output : outputs) { | ||
158 | if (!output->isConnected() || !output->isEnabled() || !output->currentMode()) { | 159 | if (!output->isConnected() || !output->isEnabled() || !output->currentMode()) { | ||
159 | continue; | 160 | continue; | ||
160 | } | 161 | } | ||
161 | 162 | | |||
162 | // Prefer laptop screen | 163 | // Prefer laptop screen | ||
163 | if (output->type() == KScreen::Output::Panel) { | 164 | if ((output->type() == KScreen::Output::Panel) && lidIsOpen) { | ||
164 | osdOutput = output; | 165 | osdOutput = output; | ||
165 | break; | 166 | break; | ||
166 | } | 167 | } | ||
167 | 168 | | |||
168 | // Fallback to primary | 169 | // Fallback to primary | ||
169 | if (output->isPrimary()) { | 170 | if (output->isPrimary() && lidIsOpen) { | ||
170 | osdOutput = output; | 171 | osdOutput = output; | ||
171 | break; | 172 | break; | ||
172 | } | 173 | } | ||
173 | } | 174 | } | ||
174 | // no laptop or primary screen, just take the first usable one | 175 | | ||
176 | // no laptop (with open lid) or primary screen (with open lid), just take the first usable one (with open lid) | ||||
177 | if (!osdOutput) { | ||||
178 | for (const auto &output : outputs) { | ||||
179 | if ( (output->isConnected() && output->isEnabled() && output->currentMode()) | ||||
180 | && ( ( (output->type() == KScreen::Output::Panel) && lidIsOpen) | ||||
181 | || (output->type() != KScreen::Output::Panel) | ||||
182 | ) | ||||
183 | ) { | ||||
184 | osdOutput = output; | ||||
185 | break; | ||||
186 | } | ||||
187 | } | ||||
188 | } | ||||
189 | | ||||
190 | // nothing up to now, just take the first usable one, even with closed lid | ||||
175 | if (!osdOutput) { | 191 | if (!osdOutput) { | ||
176 | for (const auto &output : outputs) { | 192 | for (const auto &output : outputs) { | ||
177 | if (output->isConnected() && output->isEnabled() && output->currentMode()) { | 193 | if (output->isConnected() && output->isEnabled() && output->currentMode()) { | ||
178 | osdOutput = output; | 194 | osdOutput = output; | ||
179 | break; | 195 | break; | ||
180 | } | 196 | } | ||
181 | } | 197 | } | ||
182 | } | 198 | } | ||
Show All 26 Lines |