Get rid of private QHighDpi usage

This commit is contained in:
Ilya Fedin 2022-05-19 15:43:44 +04:00 committed by John Preston
parent e1ec6a38be
commit a812ae65a4
4 changed files with 59 additions and 33 deletions

View file

@ -208,7 +208,7 @@ std::optional<uint> XCBWindowWorkspace(xcb_window_t window) {
std::optional<bool> XCBIsOverlapped( std::optional<bool> XCBIsOverlapped(
not_null<QWidget*> widget, not_null<QWidget*> widget,
const QRect &rect) { const QRect &rect) {
const auto window = widget->window()->winId(); const auto window = widget->winId();
Expects(window != XCB_WINDOW_NONE); Expects(window != XCB_WINDOW_NONE);
const auto connection = base::Platform::XCB::GetConnectionFromQt(); const auto connection = base::Platform::XCB::GetConnectionFromQt();
@ -221,11 +221,8 @@ std::optional<bool> XCBIsOverlapped(
return std::nullopt; return std::nullopt;
} }
const auto windowWorkspace = XCBWindowWorkspace( const auto windowWorkspace = XCBWindowWorkspace(window);
window);
const auto currentWorkspace = XCBCurrentWorkspace(); const auto currentWorkspace = XCBCurrentWorkspace();
if (windowWorkspace.has_value() if (windowWorkspace.has_value()
&& currentWorkspace.has_value() && currentWorkspace.has_value()
&& *windowWorkspace != *currentWorkspace && *windowWorkspace != *currentWorkspace
@ -233,6 +230,17 @@ std::optional<bool> XCBIsOverlapped(
return true; return true;
} }
const auto windowGeometry = XCBWindowGeometry(window);
if (windowGeometry.isNull()) {
return std::nullopt;
}
const auto mappedRect = QRect(
rect.topLeft()
* widget->devicePixelRatioF()
+ windowGeometry.topLeft(),
rect.size() * widget->devicePixelRatioF());
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(
xcb_query_tree_reply(connection, cookie, nullptr)); xcb_query_tree_reply(connection, cookie, nullptr));
@ -255,7 +263,7 @@ std::optional<bool> XCBIsOverlapped(
} }
const auto geometry = XCBWindowGeometry(tree[i]); const auto geometry = XCBWindowGeometry(tree[i]);
if (!rect.intersects(geometry)) { if (!mappedRect.intersects(geometry)) {
continue; continue;
} }

View file

@ -103,18 +103,16 @@ void DisableSystemWindowResize(not_null<QWidget*> widget, QSize ratio) {
std::optional<bool> IsOverlapped( std::optional<bool> IsOverlapped(
not_null<QWidget*> widget, not_null<QWidget*> widget,
const QRect &rect) { const QRect &rect) {
NSWindow *window = [reinterpret_cast<NSView*>(widget->window()->winId()) window]; NSWindow *window = [reinterpret_cast<NSView*>(widget->winId()) window];
Assert(window != nullptr); Assert(window != nullptr);
if (![window isOnActiveSpace]) { if (![window isOnActiveSpace]) {
return true; return true;
} }
const auto nativeRect = CGRectMake( const auto nativeRect = QRect(
rect.x(), widget->mapToGlobal(rect.topLeft()),
rect.y(), rect.size()).toCGRect();
rect.width(),
rect.height());
CGWindowID windowId = (CGWindowID)[window windowNumber]; CGWindowID windowId = (CGWindowID)[window windowNumber];
const CGWindowListOption options = kCGWindowListExcludeDesktopElements const CGWindowListOption options = kCGWindowListExcludeDesktopElements

View file

@ -53,7 +53,7 @@ void IgnoreAllActivation(not_null<QWidget*> widget) {
std::optional<bool> IsOverlapped( std::optional<bool> IsOverlapped(
not_null<QWidget*> widget, not_null<QWidget*> widget,
const QRect &rect) { const QRect &rect) {
const auto handle = reinterpret_cast<HWND>(widget->window()->winId()); const auto handle = HWND(widget->winId());
Expects(handle != nullptr); Expects(handle != nullptr);
ComPtr<IVirtualDesktopManager> virtualDesktopManager; ComPtr<IVirtualDesktopManager> virtualDesktopManager;
@ -73,14 +73,36 @@ std::optional<bool> IsOverlapped(
} }
} }
std::vector<HWND> visited; const auto nativeRect = [&] {
const RECT nativeRect{ const auto topLeft = [&] {
rect.left(), const auto qpoints = rect.topLeft()
rect.top(), * widget->devicePixelRatioF();
rect.right(), POINT result{
rect.bottom(), qpoints.x(),
}; qpoints.y(),
};
ClientToScreen(handle, &result);
return result;
}();
const auto bottomRight = [&] {
const auto qpoints = rect.bottomRight()
* widget->devicePixelRatioF();
POINT result{
qpoints.x(),
qpoints.y(),
};
ClientToScreen(handle, &result);
return result;
}();
return RECT{
topLeft.x,
topLeft.y,
bottomRight.x,
bottomRight.y,
};
}();
std::vector<HWND> visited;
for (auto curHandle = handle; for (auto curHandle = handle;
curHandle != nullptr && !ranges::contains(visited, curHandle); curHandle != nullptr && !ranges::contains(visited, curHandle);
curHandle = GetWindow(curHandle, GW_HWNDPREV)) { curHandle = GetWindow(curHandle, GW_HWNDPREV)) {

View file

@ -14,8 +14,6 @@
#include <QtGui/QtEvents> #include <QtGui/QtEvents>
#include <QWheelEvent> #include <QWheelEvent>
#include <private/qhighdpiscaling_p.h>
#include <array> #include <array>
namespace Ui { namespace Ui {
@ -193,18 +191,18 @@ bool IsContentVisible(
return false; return false;
} }
const auto mappedRect = QHighDpi::toNativePixels( const auto mappedRect = rect.isNull()
rect.isNull() ? QRect(
? QRect( widget->mapTo(widget->window(), QPoint()),
widget->mapToGlobal(QPoint()), widget->size())
widget->mapToGlobal( : QRect(
QPoint(widget->width(), widget->height()))) widget->mapTo(widget->window(), rect.topLeft()),
: QRect( rect.size());
widget->mapToGlobal(rect.topLeft()),
widget->mapToGlobal(rect.bottomRight())), const auto overlapped = Platform::IsOverlapped(
widget->window()->windowHandle()); widget->window(),
mappedRect);
const auto overlapped = Platform::IsOverlapped(widget, mappedRect);
return overlapped.has_value() && !*overlapped; return overlapped.has_value() && !*overlapped;
}(); }();