diff --git a/src/decorations/decorationrenderer.cpp b/src/decorations/decorationrenderer.cpp index 9a4506ffad..58d12a1100 100644 --- a/src/decorations/decorationrenderer.cpp +++ b/src/decorations/decorationrenderer.cpp @@ -80,7 +80,7 @@ QImage Renderer::renderToImage(const QRect &geo) image.fill(Qt::transparent); QPainter p(&image); p.setRenderHint(QPainter::Antialiasing); - p.setWindow(QRect(geo.topLeft(), geo.size() * dpr)); + p.setWindow(QRect(geo.topLeft(), geo.size() * qPainterEffectiveDevicePixelRatio(&p))); p.setClipRect(geo); renderToPainter(&p, geo); return image; diff --git a/src/plugins/scenes/opengl/scene_opengl.cpp b/src/plugins/scenes/opengl/scene_opengl.cpp index 350701524c..c96e2c21a1 100644 --- a/src/plugins/scenes/opengl/scene_opengl.cpp +++ b/src/plugins/scenes/opengl/scene_opengl.cpp @@ -2644,7 +2644,7 @@ void SceneOpenGLDecorationRenderer::render() QPainter painter(&image); painter.setRenderHint(QPainter::Antialiasing); painter.setViewport(QRect(viewport.topLeft(), viewport.size() * devicePixelRatio)); - painter.setWindow(QRect(geo.topLeft(), geo.size() * devicePixelRatio)); + painter.setWindow(QRect(geo.topLeft(), geo.size() * qPainterEffectiveDevicePixelRatio(&painter))); painter.setClipRect(geo); renderToPainter(&painter, geo); painter.end(); diff --git a/src/plugins/scenes/qpainter/scene_qpainter.cpp b/src/plugins/scenes/qpainter/scene_qpainter.cpp index 6b477b3446..3b75f93808 100644 --- a/src/plugins/scenes/qpainter/scene_qpainter.cpp +++ b/src/plugins/scenes/qpainter/scene_qpainter.cpp @@ -774,7 +774,7 @@ void SceneQPainterDecorationRenderer::render() } QPainter painter(&m_images[index]); painter.setRenderHint(QPainter::Antialiasing); - painter.setWindow(QRect(partRect.topLeft(), partRect.size() * m_images[index].devicePixelRatio())); + painter.setWindow(QRect(partRect.topLeft(), partRect.size() * qPainterEffectiveDevicePixelRatio(&painter))); painter.setClipRect(rect); painter.save(); // clear existing part diff --git a/src/utils.cpp b/src/utils.cpp index adc45ddd86..3a627904d7 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -16,6 +16,7 @@ #include "utils.h" +#include #include #include @@ -195,6 +196,11 @@ Qt::KeyboardModifiers x11ToQtKeyboardModifiers(int state) return ret; } +qreal qPainterEffectiveDevicePixelRatio(const QPainter *painter) +{ + return std::max(qreal(1), painter->device()->devicePixelRatioF()); +} + } // namespace #ifndef KCMRULES diff --git a/src/utils.h b/src/utils.h index c663ff8ad1..50f7e98141 100644 --- a/src/utils.h +++ b/src/utils.h @@ -119,6 +119,15 @@ void KWIN_EXPORT ungrabXServer(); bool KWIN_EXPORT grabXKeyboard(xcb_window_t w = XCB_WINDOW_NONE); void KWIN_EXPORT ungrabXKeyboard(); +/** + * QPainter::setWindow() doesn't work as expected when the device pixel ratio of the paint + * device is less than 1. + * + * QPainter simply doesn't allow the effective scale factor to be less than 1. Use this function + * to determine the effective device pixel ratio by which the window rect has to be scaled. + */ +qreal KWIN_EXPORT qPainterEffectiveDevicePixelRatio(const QPainter *painter); + /** * Small helper class which performs grabXServer in the ctor and * ungrabXServer in the dtor. Use this class to ensure that grab and