Adapt for Qt 6.4 device pixel ratio changes

QWidget::devicePixelRatioF represents backing store ratio and it's no more equal to native surface ratio
This commit is contained in:
Ilya Fedin 2022-07-14 12:54:15 +04:00 committed by John Preston
parent e91cfd55c2
commit ba7e3667d6
4 changed files with 17 additions and 10 deletions

View file

@ -21,6 +21,7 @@
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION #endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
#include <QtCore/QPoint> #include <QtCore/QPoint>
#include <QtGui/QWindow>
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
namespace Ui { namespace Ui {
@ -236,9 +237,9 @@ std::optional<bool> XCBIsOverlapped(
const auto mappedRect = QRect( const auto mappedRect = QRect(
rect.topLeft() rect.topLeft()
* widget->devicePixelRatioF() * widget->windowHandle()->devicePixelRatio()
+ windowGeometry.topLeft(), + windowGeometry.topLeft(),
rect.size() * widget->devicePixelRatioF()); rect.size() * widget->windowHandle()->devicePixelRatio());
const auto cookie = xcb_query_tree(connection, *root); const auto cookie = xcb_query_tree(connection, *root);
const auto reply = base::Platform::XCB::MakeReplyPointer( const auto reply = base::Platform::XCB::MakeReplyPointer(
@ -304,7 +305,9 @@ void SetXCBFrameExtents(not_null<QWidget*> widget, const QMargins &extents) {
return; return;
} }
const auto nativeExtents = extents * widget->devicePixelRatioF(); const auto nativeExtents = extents
* widget->windowHandle()->devicePixelRatio();
const auto extentsVector = std::vector<uint>{ const auto extentsVector = std::vector<uint>{
uint(nativeExtents.left()), uint(nativeExtents.left()),
uint(nativeExtents.right()), uint(nativeExtents.right()),
@ -368,7 +371,7 @@ void ShowXCBWindowMenu(not_null<QWidget*> widget, const QPoint &point) {
} }
const auto globalPos = point const auto globalPos = point
* widget->devicePixelRatioF() * widget->windowHandle()->devicePixelRatio()
+ windowGeometry.topLeft(); + windowGeometry.topLeft();
xcb_client_message_event_t xev; xcb_client_message_event_t xev;

View file

@ -9,6 +9,7 @@
#include "base/platform/win/base_windows_h.h" #include "base/platform/win/base_windows_h.h"
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
#include <QtGui/QWindow>
#include <wrl/client.h> #include <wrl/client.h>
#include <Shobjidl.h> #include <Shobjidl.h>
@ -75,7 +76,7 @@ std::optional<bool> IsOverlapped(
const auto nativeRect = [&] { const auto nativeRect = [&] {
const auto topLeft = [&] { const auto topLeft = [&] {
const auto qpoints = rect.topLeft() const auto qpoints = rect.topLeft()
* widget->devicePixelRatioF(); * widget->windowHandle()->devicePixelRatio();
POINT result{ POINT result{
qpoints.x(), qpoints.x(),
qpoints.y(), qpoints.y(),
@ -85,7 +86,7 @@ std::optional<bool> IsOverlapped(
}(); }();
const auto bottomRight = [&] { const auto bottomRight = [&] {
const auto qpoints = rect.bottomRight() const auto qpoints = rect.bottomRight()
* widget->devicePixelRatioF(); * widget->windowHandle()->devicePixelRatio();
POINT result{ POINT result{
qpoints.x(), qpoints.x(),
qpoints.y(), qpoints.y(),
@ -122,7 +123,7 @@ std::optional<bool> IsOverlapped(
void ShowWindowMenu(not_null<QWidget*> widget, const QPoint &point) { void ShowWindowMenu(not_null<QWidget*> widget, const QPoint &point) {
const auto handle = HWND(widget->winId()); const auto handle = HWND(widget->winId());
const auto mapped = point * widget->devicePixelRatioF(); const auto mapped = point * widget->windowHandle()->devicePixelRatio();
POINT p{ mapped.x(), mapped.y() }; POINT p{ mapped.x(), mapped.y() };
ClientToScreen(handle, &p); ClientToScreen(handle, &p);
SendMessage( SendMessage(

View file

@ -205,7 +205,8 @@ void TitleWidget::refreshAdditionalPaddings(
return -1; return -1;
} }
const auto pixels = (factor + 50) / 100; const auto pixels = (factor + 50) / 100;
return int(base::SafeRound(pixels / window()->devicePixelRatioF())); return int(base::SafeRound(
pixels / window()->windowHandle()->devicePixelRatio()));
}(); }();
if (padding < 0) { if (padding < 0) {
return; return;

View file

@ -455,7 +455,8 @@ bool WindowHelper::handleNativeEvent(
} }
POINT p{ GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; POINT p{ GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
ScreenToClient(_handle, &p); ScreenToClient(_handle, &p);
const auto mapped = QPoint(p.x, p.y) / window()->devicePixelRatioF(); const auto mapped = QPoint(p.x, p.y)
/ window()->windowHandle()->devicePixelRatio();
ShowWindowMenu(window(), mapped); ShowWindowMenu(window(), mapped);
if (result) *result = 0; if (result) *result = 0;
} return true; } return true;
@ -547,7 +548,8 @@ bool WindowHelper::handleNativeEvent(
POINT p{ GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; POINT p{ GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
ScreenToClient(_handle, &p); ScreenToClient(_handle, &p);
const auto mapped = QPoint(p.x, p.y) / window()->devicePixelRatioF(); const auto mapped = QPoint(p.x, p.y)
/ window()->windowHandle()->devicePixelRatio();
*result = [&] { *result = [&] {
if (!window()->rect().contains(mapped)) { if (!window()->rect().contains(mapped)) {
return HTTRANSPARENT; return HTTRANSPARENT;