diff --git a/krunner/view.h b/krunner/view.h --- a/krunner/view.h +++ b/krunner/view.h @@ -73,6 +73,7 @@ void showEvent(QShowEvent *event) override; public Q_SLOTS: + void setVisible(bool visible); void display(); void displaySingleRunner(const QString &runnerName); void displayWithClipboardContents(); @@ -96,6 +97,7 @@ KConfigGroup m_config; qreal m_offset; bool m_floating : 1; + bool m_requestedVisible = false; QStringList m_history; }; diff --git a/krunner/view.cpp b/krunner/view.cpp --- a/krunner/view.cpp +++ b/krunner/view.cpp @@ -104,8 +104,6 @@ connect(KWindowSystem::self(), &KWindowSystem::workAreaChanged, this, &View::resetScreenPos); - connect(this, &View::visibleChanged, this, &View::resetScreenPos); - KDirWatch::self()->addFile(m_config.name()); // Catch both, direct changes to the config file ... @@ -219,6 +217,10 @@ void View::positionOnScreen() { + if (!m_requestedVisible) { + return; + } + QScreen *shownOnScreen = QGuiApplication::primaryScreen(); const auto screens = QGuiApplication::screens(); @@ -229,42 +231,55 @@ } } - setScreen(shownOnScreen); - const QRect r = shownOnScreen->availableGeometry(); - - if (m_floating && !m_customPos.isNull()) { - int x = qBound(r.left(), m_customPos.x(), r.right() - width()); - int y = qBound(r.top(), m_customPos.y(), r.bottom() - height()); - setPosition(x, y); - show(); - return; - } + // in wayland, QScreen::availableGeometry() returns QScreen::geometry() + // we could get a better value from plasmashell + // BUG: 386114 + QDBusInterface strutManager("org.kde.plasmashell", "/StrutManager", "org.kde.PlasmaShell.StrutManager"); + QDBusPendingCall async = strutManager.asyncCall("availableScreenRect", shownOnScreen->name()); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); + + QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [=]() { + QDBusPendingReply reply = *watcher; + + setScreen(shownOnScreen); + const QRect r = reply.isValid() ? reply.value() : shownOnScreen->availableGeometry(); + + if (m_floating && !m_customPos.isNull()) { + int x = qBound(r.left(), m_customPos.x(), r.right() - width()); + int y = qBound(r.top(), m_customPos.y(), r.bottom() - height()); + setPosition(x, y); + PlasmaQuick::Dialog::setVisible(true); + return; + } - const int w = width(); - int x = r.left() + (r.width() * m_offset) - (w / 2); + const int w = width(); + int x = r.left() + (r.width() * m_offset) - (w / 2); - int y = r.top(); - if (m_floating) { - y += r.height() / 3; - } + int y = r.top(); + if (m_floating) { + y += r.height() / 3; + } - x = qBound(r.left(), x, r.right() - width()); - y = qBound(r.top(), y, r.bottom() - height()); + x = qBound(r.left(), x, r.right() - width()); + y = qBound(r.top(), y, r.bottom() - height()); - setPosition(x, y); + setPosition(x, y); + PlasmaQuick::Dialog::setVisible(true); + + if (m_floating) { + KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop()); + KWindowSystem::setType(winId(), NET::Normal); + //Turn the sliding effect off + KWindowEffects::slideWindow(winId(), KWindowEffects::NoEdge, 0); + } else { + KWindowSystem::setOnAllDesktops(winId(), true); + KWindowEffects::slideWindow(winId(), KWindowEffects::TopEdge, 0); + } - if (m_floating) { - KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop()); - KWindowSystem::setType(winId(), NET::Normal); - //Turn the sliding effect off - KWindowEffects::slideWindow(winId(), KWindowEffects::NoEdge, 0); - } else { - KWindowSystem::setOnAllDesktops(winId(), true); - KWindowEffects::slideWindow(winId(), KWindowEffects::TopEdge, 0); - } + KWindowSystem::forceActiveWindow(winId()); + watcher->deleteLater(); - KWindowSystem::forceActiveWindow(winId()); - //qDebug() << "moving to" << m_screenPos[screen]; + }); } void View::displayOrHide() @@ -390,3 +405,14 @@ { m_config.writeEntry("history", m_history); } + +void View::setVisible(bool visible) +{ + m_requestedVisible = visible; + + if (visible && !m_floating) { + positionOnScreen(); + } else { + PlasmaQuick::Dialog::setVisible(visible); + } +} diff --git a/shell/strutmanager.h b/shell/strutmanager.h --- a/shell/strutmanager.h +++ b/shell/strutmanager.h @@ -39,6 +39,8 @@ QRegion availableScreenRegion(int id) const; public Q_SLOTS: + QRect availableScreenRect(const QString &screenName) const; + void setAvailableScreenRect(const QString &service, const QString &screenName, const QRect &rect); void setAvailableScreenRegion(const QString &service, const QString &screenName, const QList &rects); diff --git a/shell/strutmanager.cpp b/shell/strutmanager.cpp --- a/shell/strutmanager.cpp +++ b/shell/strutmanager.cpp @@ -58,6 +58,11 @@ return r; } +QRect StrutManager::availableScreenRect(const QString &screenName) const +{ + return availableScreenRect(m_plasmashellCorona->screenPool()->id(screenName)); +} + QRegion StrutManager::availableScreenRegion(int id) const { QRegion r = m_plasmashellCorona->_availableScreenRegion(id);