Commit 731a1908 authored by Tranter Madi's avatar Tranter Madi

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
parent a8299642
......@@ -104,8 +104,6 @@ View::View(QWindow *)
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::resetScreenPos()
void View::positionOnScreen()
{
if (!m_requestedVisible) {
return;
}
QScreen *shownOnScreen = QGuiApplication::primaryScreen();
const auto screens = QGuiApplication::screens();
......@@ -229,42 +231,55 @@ void View::positionOnScreen()
}
}
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<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();
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 @@ void View::writeHistory()
{
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;
public Q_SLOTS:
void setVisible(bool visible);
void display();
void displaySingleRunner(const QString &runnerName);
void displayWithClipboardContents();
......@@ -96,6 +97,7 @@ private:
KConfigGroup m_config;
qreal m_offset;
bool m_floating : 1;
bool m_requestedVisible = false;
QStringList m_history;
};
......
......@@ -58,6 +58,11 @@ QRect StrutManager::availableScreenRect(int id) const
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);
......
......@@ -39,6 +39,8 @@ class StrutManager : public QObject
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<QRect> &rects);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment