Changeset View
Changeset View
Standalone View
Standalone View
krunner/view.cpp
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | 54 | { | |||
---|---|---|---|---|---|
99 | for(QScreen* s : screens) { | 99 | for(QScreen* s : screens) { | ||
100 | screenAdded(s); | 100 | screenAdded(s); | ||
101 | } | 101 | } | ||
102 | connect(qGuiApp, &QGuiApplication::screenAdded, this, screenAdded); | 102 | connect(qGuiApp, &QGuiApplication::screenAdded, this, screenAdded); | ||
103 | connect(qGuiApp, &QGuiApplication::screenRemoved, this, screenRemoved); | 103 | connect(qGuiApp, &QGuiApplication::screenRemoved, this, screenRemoved); | ||
104 | 104 | | |||
105 | connect(KWindowSystem::self(), &KWindowSystem::workAreaChanged, this, &View::resetScreenPos); | 105 | connect(KWindowSystem::self(), &KWindowSystem::workAreaChanged, this, &View::resetScreenPos); | ||
106 | 106 | | |||
107 | connect(this, &View::visibleChanged, this, &View::resetScreenPos); | | |||
108 | | ||||
109 | KDirWatch::self()->addFile(m_config.name()); | 107 | KDirWatch::self()->addFile(m_config.name()); | ||
110 | 108 | | |||
111 | // Catch both, direct changes to the config file ... | 109 | // Catch both, direct changes to the config file ... | ||
112 | connect(KDirWatch::self(), &KDirWatch::dirty, this, &View::reloadConfig); | 110 | connect(KDirWatch::self(), &KDirWatch::dirty, this, &View::reloadConfig); | ||
113 | connect(KDirWatch::self(), &KDirWatch::created, this, &View::reloadConfig); | 111 | connect(KDirWatch::self(), &KDirWatch::created, this, &View::reloadConfig); | ||
114 | 112 | | |||
115 | if (m_floating) { | 113 | if (m_floating) { | ||
116 | setLocation(Plasma::Types::Floating); | 114 | setLocation(Plasma::Types::Floating); | ||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | |||||
214 | { | 212 | { | ||
215 | if (isVisible() && !m_floating) { | 213 | if (isVisible() && !m_floating) { | ||
216 | positionOnScreen(); | 214 | positionOnScreen(); | ||
217 | } | 215 | } | ||
218 | } | 216 | } | ||
219 | 217 | | |||
220 | void View::positionOnScreen() | 218 | void View::positionOnScreen() | ||
221 | { | 219 | { | ||
220 | if (!m_requestedVisible) { | ||||
221 | return; | ||||
222 | } | ||||
223 | | ||||
222 | QScreen *shownOnScreen = QGuiApplication::primaryScreen(); | 224 | QScreen *shownOnScreen = QGuiApplication::primaryScreen(); | ||
223 | 225 | | |||
224 | const auto screens = QGuiApplication::screens(); | 226 | const auto screens = QGuiApplication::screens(); | ||
225 | for (QScreen* screen : screens) { | 227 | for (QScreen* screen : screens) { | ||
226 | if (screen->geometry().contains(QCursor::pos(screen))) { | 228 | if (screen->geometry().contains(QCursor::pos(screen))) { | ||
227 | shownOnScreen = screen; | 229 | shownOnScreen = screen; | ||
228 | break; | 230 | break; | ||
229 | } | 231 | } | ||
230 | } | 232 | } | ||
231 | 233 | | |||
234 | // in wayland, QScreen::availableGeometry() returns QScreen::geometry() | ||||
235 | // we could get a better value from plasmashell | ||||
236 | // BUG: 386114 | ||||
237 | QDBusInterface strutManager("org.kde.plasmashell", "/StrutManager", "org.kde.PlasmaShell.StrutManager"); | ||||
238 | QDBusPendingCall async = strutManager.asyncCall("availableScreenRect", shownOnScreen->name()); | ||||
239 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); | ||||
240 | | ||||
apol: This is a blocking call, it would be ideal to find a way around this... | |||||
241 | QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [=]() { | ||||
242 | QDBusPendingReply<QRect> reply = *watcher; | ||||
243 | | ||||
232 | setScreen(shownOnScreen); | 244 | setScreen(shownOnScreen); | ||
233 | const QRect r = shownOnScreen->availableGeometry(); | 245 | const QRect r = reply.isValid() ? reply.value() : shownOnScreen->availableGeometry(); | ||
234 | 246 | | |||
235 | if (m_floating && !m_customPos.isNull()) { | 247 | if (m_floating && !m_customPos.isNull()) { | ||
236 | int x = qBound(r.left(), m_customPos.x(), r.right() - width()); | 248 | int x = qBound(r.left(), m_customPos.x(), r.right() - width()); | ||
237 | int y = qBound(r.top(), m_customPos.y(), r.bottom() - height()); | 249 | int y = qBound(r.top(), m_customPos.y(), r.bottom() - height()); | ||
238 | setPosition(x, y); | 250 | setPosition(x, y); | ||
239 | show(); | 251 | PlasmaQuick::Dialog::setVisible(true); | ||
240 | return; | 252 | return; | ||
241 | } | 253 | } | ||
242 | 254 | | |||
243 | const int w = width(); | 255 | const int w = width(); | ||
244 | int x = r.left() + (r.width() * m_offset) - (w / 2); | 256 | int x = r.left() + (r.width() * m_offset) - (w / 2); | ||
245 | 257 | | |||
246 | int y = r.top(); | 258 | int y = r.top(); | ||
247 | if (m_floating) { | 259 | if (m_floating) { | ||
248 | y += r.height() / 3; | 260 | y += r.height() / 3; | ||
249 | } | 261 | } | ||
250 | 262 | | |||
251 | x = qBound(r.left(), x, r.right() - width()); | 263 | x = qBound(r.left(), x, r.right() - width()); | ||
252 | y = qBound(r.top(), y, r.bottom() - height()); | 264 | y = qBound(r.top(), y, r.bottom() - height()); | ||
253 | 265 | | |||
254 | setPosition(x, y); | 266 | setPosition(x, y); | ||
267 | PlasmaQuick::Dialog::setVisible(true); | ||||
255 | 268 | | |||
256 | if (m_floating) { | 269 | if (m_floating) { | ||
257 | KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop()); | 270 | KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop()); | ||
258 | KWindowSystem::setType(winId(), NET::Normal); | 271 | KWindowSystem::setType(winId(), NET::Normal); | ||
259 | //Turn the sliding effect off | 272 | //Turn the sliding effect off | ||
260 | KWindowEffects::slideWindow(winId(), KWindowEffects::NoEdge, 0); | 273 | KWindowEffects::slideWindow(winId(), KWindowEffects::NoEdge, 0); | ||
261 | } else { | 274 | } else { | ||
262 | KWindowSystem::setOnAllDesktops(winId(), true); | 275 | KWindowSystem::setOnAllDesktops(winId(), true); | ||
263 | KWindowEffects::slideWindow(winId(), KWindowEffects::TopEdge, 0); | 276 | KWindowEffects::slideWindow(winId(), KWindowEffects::TopEdge, 0); | ||
264 | } | 277 | } | ||
265 | 278 | | |||
266 | KWindowSystem::forceActiveWindow(winId()); | 279 | KWindowSystem::forceActiveWindow(winId()); | ||
267 | //qDebug() << "moving to" << m_screenPos[screen]; | 280 | watcher->deleteLater(); | ||
281 | | ||||
282 | }); | ||||
268 | } | 283 | } | ||
269 | 284 | | |||
270 | void View::displayOrHide() | 285 | void View::displayOrHide() | ||
271 | { | 286 | { | ||
272 | if (isVisible() && !QGuiApplication::focusWindow()) { | 287 | if (isVisible() && !QGuiApplication::focusWindow()) { | ||
273 | KWindowSystem::forceActiveWindow(winId()); | 288 | KWindowSystem::forceActiveWindow(winId()); | ||
274 | return; | 289 | return; | ||
275 | } | 290 | } | ||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | 393 | { | |||
385 | 400 | | |||
386 | writeHistory(); | 401 | writeHistory(); | ||
387 | } | 402 | } | ||
388 | 403 | | |||
389 | void View::writeHistory() | 404 | void View::writeHistory() | ||
390 | { | 405 | { | ||
391 | m_config.writeEntry("history", m_history); | 406 | m_config.writeEntry("history", m_history); | ||
392 | } | 407 | } | ||
408 | | ||||
409 | void View::setVisible(bool visible) | ||||
410 | { | ||||
411 | m_requestedVisible = visible; | ||||
this is a very confusing name. It refers to the visible state krunner has set, but most importantly NOT the state of the QWindow (which is arguably the real state) davidedmundson: this is a very confusing name.
It refers to the visible state krunner has set, but most… | |||||
412 | | ||||
413 | if (visible && !m_floating) { | ||||
414 | positionOnScreen(); | ||||
415 | } else { | ||||
416 | PlasmaQuick::Dialog::setVisible(visible); | ||||
417 | } | ||||
418 | } |
This is a blocking call, it would be ideal to find a way around this...