Commit 78b1d261 authored by Fushan Wen's avatar Fushan Wen 💬 Committed by Nate Graham
Browse files

applet/pager: Divide window size by devicePixelRatio on X11 when it's >1

KWindowInfoPrivateX11::frameGeometry() returns the true geometry of
a window, so dividing the window size by devicePixelRatio is needed to
get the correct size when it's greater than 1.

BUG: 446627
FIXED-IN: 5.24.2


(cherry picked from commit 16d44ae2)
parent 5fc9525a
Pipeline #140663 passed with stage
in 3 minutes and 58 seconds
......@@ -63,19 +63,25 @@ QVariant WindowModel::data(const QModelIndex &index, int role) const
{
if (role == AbstractTasksModel::Geometry) {
QRect windowGeo = TaskFilterProxyModel::data(index, role).toRect();
QList<QScreen *> screens = QGuiApplication::screens();
const QRect desktopGeo = screens.at(0)->virtualGeometry();
const QScreen *const screen = QGuiApplication::screens().constFirst();
const QSize desktopSize = screen->virtualSize();
// KWindowInfoPrivateX11::frameGeometry() returns the true geometry of a window, so devicePixelRatio is needed.
if (const auto ratio = screen->devicePixelRatio(); KWindowSystem::isPlatformX11() && ratio != 1.0) {
windowGeo.setTopLeft(windowGeo.topLeft() / ratio);
windowGeo.setBottomRight(windowGeo.bottomRight() / ratio);
}
if (KWindowSystem::mapViewport()) {
int x = windowGeo.center().x() % desktopGeo.width();
int y = windowGeo.center().y() % desktopGeo.height();
int x = windowGeo.center().x() % desktopSize.width();
int y = windowGeo.center().y() % desktopSize.height();
if (x < 0) {
x = x + desktopGeo.width();
x = x + desktopSize.width();
}
if (y < 0) {
y = y + desktopGeo.height();
y = y + desktopSize.height();
}
const QRect mappedGeo(x - windowGeo.width() / 2, y - windowGeo.height() / 2, windowGeo.width(), windowGeo.height());
......@@ -92,15 +98,15 @@ QVariant WindowModel::data(const QModelIndex &index, int role) const
}
// Clamp to desktop rect.
windowGeo.setX(std::clamp(windowGeo.x(), 0, desktopGeo.width()));
windowGeo.setY(std::clamp(windowGeo.y(), 0, desktopGeo.height()));
windowGeo.setX(std::clamp(windowGeo.x(), 0, desktopSize.width()));
windowGeo.setY(std::clamp(windowGeo.y(), 0, desktopSize.height()));
if ((windowGeo.x() + windowGeo.width()) > desktopGeo.width()) {
windowGeo.setWidth(desktopGeo.width() - windowGeo.x());
if ((windowGeo.x() + windowGeo.width()) > desktopSize.width()) {
windowGeo.setWidth(desktopSize.width() - windowGeo.x());
}
if ((windowGeo.y() + windowGeo.height()) > desktopGeo.height()) {
windowGeo.setHeight(desktopGeo.height() - windowGeo.y());
if ((windowGeo.y() + windowGeo.height()) > desktopSize.height()) {
windowGeo.setHeight(desktopSize.height() - windowGeo.y());
}
return windowGeo;
......
Supports Markdown
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