Set a better position for Krunner in wayland

Summary:
In wayland, QScreen::availableGeometry() returns QScreen::geometry(), we could get a better value from plasmashell

BUG: 386114

Test Plan: Krunner isn't overlapped by a top panel in all cases

Reviewers: #plasma, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: meven, apol, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D27458
wilder-portage-prov
Tranter Madi 6 years ago
parent a8299642d7
commit 731a190810
  1. 90
      krunner/view.cpp
  2. 2
      krunner/view.h
  3. 5
      shell/strutmanager.cpp
  4. 2
      shell/strutmanager.h

@ -104,8 +104,6 @@ View::View(QWindow *)
connect(KWindowSystem::self(), &KWindowSystem::workAreaChanged, this, &View::resetScreenPos); connect(KWindowSystem::self(), &KWindowSystem::workAreaChanged, this, &View::resetScreenPos);
connect(this, &View::visibleChanged, this, &View::resetScreenPos);
KDirWatch::self()->addFile(m_config.name()); KDirWatch::self()->addFile(m_config.name());
// Catch both, direct changes to the config file ... // Catch both, direct changes to the config file ...
@ -219,6 +217,10 @@ void View::resetScreenPos()
void View::positionOnScreen() void View::positionOnScreen()
{ {
if (!m_requestedVisible) {
return;
}
QScreen *shownOnScreen = QGuiApplication::primaryScreen(); QScreen *shownOnScreen = QGuiApplication::primaryScreen();
const auto screens = QGuiApplication::screens(); const auto screens = QGuiApplication::screens();
@ -229,42 +231,55 @@ void View::positionOnScreen()
} }
} }
setScreen(shownOnScreen); // in wayland, QScreen::availableGeometry() returns QScreen::geometry()
const QRect r = shownOnScreen->availableGeometry(); // we could get a better value from plasmashell
// BUG: 386114
if (m_floating && !m_customPos.isNull()) { QDBusInterface strutManager("org.kde.plasmashell", "/StrutManager", "org.kde.PlasmaShell.StrutManager");
int x = qBound(r.left(), m_customPos.x(), r.right() - width()); QDBusPendingCall async = strutManager.asyncCall("availableScreenRect", shownOnScreen->name());
int y = qBound(r.top(), m_customPos.y(), r.bottom() - height()); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this);
setPosition(x, y);
show(); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [=]() {
return; QDBusPendingReply<QRect> 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(); const int w = width();
int x = r.left() + (r.width() * m_offset) - (w / 2); int x = r.left() + (r.width() * m_offset) - (w / 2);
int y = r.top(); int y = r.top();
if (m_floating) { if (m_floating) {
y += r.height() / 3; y += r.height() / 3;
} }
x = qBound(r.left(), x, r.right() - width()); x = qBound(r.left(), x, r.right() - width());
y = qBound(r.top(), y, r.bottom() - height()); 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::forceActiveWindow(winId());
KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop()); watcher->deleteLater();
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()); });
//qDebug() << "moving to" << m_screenPos[screen];
} }
void View::displayOrHide() void View::displayOrHide()
@ -390,3 +405,14 @@ void View::writeHistory()
{ {
m_config.writeEntry("history", m_history); m_config.writeEntry("history", m_history);
} }
void View::setVisible(bool visible)
{
m_requestedVisible = visible;
if (visible && !m_floating) {
positionOnScreen();
} else {
PlasmaQuick::Dialog::setVisible(visible);
}
}

@ -73,6 +73,7 @@ protected:
void showEvent(QShowEvent *event) override; void showEvent(QShowEvent *event) override;
public Q_SLOTS: public Q_SLOTS:
void setVisible(bool visible);
void display(); void display();
void displaySingleRunner(const QString &runnerName); void displaySingleRunner(const QString &runnerName);
void displayWithClipboardContents(); void displayWithClipboardContents();
@ -96,6 +97,7 @@ private:
KConfigGroup m_config; KConfigGroup m_config;
qreal m_offset; qreal m_offset;
bool m_floating : 1; bool m_floating : 1;
bool m_requestedVisible = false;
QStringList m_history; QStringList m_history;
}; };

@ -58,6 +58,11 @@ QRect StrutManager::availableScreenRect(int id) const
return r; return r;
} }
QRect StrutManager::availableScreenRect(const QString &screenName) const
{
return availableScreenRect(m_plasmashellCorona->screenPool()->id(screenName));
}
QRegion StrutManager::availableScreenRegion(int id) const QRegion StrutManager::availableScreenRegion(int id) const
{ {
QRegion r = m_plasmashellCorona->_availableScreenRegion(id); QRegion r = m_plasmashellCorona->_availableScreenRegion(id);

@ -39,6 +39,8 @@ class StrutManager : public QObject
QRegion availableScreenRegion(int id) const; QRegion availableScreenRegion(int id) const;
public Q_SLOTS: public Q_SLOTS:
QRect availableScreenRect(const QString &screenName) const;
void setAvailableScreenRect(const QString &service, const QString &screenName, const QRect &rect); void setAvailableScreenRect(const QString &service, const QString &screenName, const QRect &rect);
void setAvailableScreenRegion(const QString &service, const QString &screenName, const QList<QRect> &rects); void setAvailableScreenRegion(const QString &service, const QString &screenName, const QList<QRect> &rects);

Loading…
Cancel
Save