diff --git a/examples/quick/qml/main.qml b/examples/quick/qml/main.qml index 75ab5d1..42c218b 100644 --- a/examples/quick/qml/main.qml +++ b/examples/quick/qml/main.qml @@ -35,7 +35,7 @@ Window { title: qsTr("Hello, World!") color: "#f0f0f0" - property int _flh_margin: ((window.visibility === Window.Maximized) || (window.visibility === Window.FullScreen)) ? 0 : (1 / Screen.devicePixelRatio) + property real _flh_margin: ((window.visibility === Window.Maximized) || (window.visibility === Window.FullScreen)) ? 0.0 : (1.0 / Screen.devicePixelRatio) FramelessHelper { id: framelessHelper @@ -51,7 +51,7 @@ Window { Rectangle { id: titleBar - height: framelessHelper.titleBarHeight + height: framelessHelper.titleBarHeight + framelessHelper.resizeBorderHeight color: "transparent" anchors { top: parent.top diff --git a/examples/widget/widget.cpp b/examples/widget/widget.cpp index 72fbd71..feb0682 100644 --- a/examples/widget/widget.cpp +++ b/examples/widget/widget.cpp @@ -112,8 +112,9 @@ void Widget::paintEvent(QPaintEvent *event) void Widget::setupUi() { const QWindow *win = windowHandle(); + const int resizeBorderHeight = Utilities::getSystemMetric(win, Utilities::SystemMetric::ResizeBorderHeight, false); const int titleBarHeight = Utilities::getSystemMetric(win, Utilities::SystemMetric::TitleBarHeight, false); - const QSize systemButtonSize = {qRound(titleBarHeight * 1.5), titleBarHeight}; + const QSize systemButtonSize = {qRound(static_cast(titleBarHeight + resizeBorderHeight) * 1.5), titleBarHeight}; m_minimizeButton = new QPushButton(this); m_minimizeButton->setObjectName(QStringLiteral("MinimizeButton")); m_minimizeButton->setFixedSize(systemButtonSize); diff --git a/framelesshelper.cpp b/framelesshelper.cpp index 229baa6..5e7072a 100644 --- a/framelesshelper.cpp +++ b/framelesshelper.cpp @@ -67,34 +67,34 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event) return false; } const auto currentWindow = qobject_cast(object); - const int m_borderWidth = FramelessWindowsManager::getResizeBorderWidth(currentWindow); - const int m_borderHeight = FramelessWindowsManager::getResizeBorderHeight(currentWindow); + const int m_resizeBorderWidth = FramelessWindowsManager::getResizeBorderWidth(currentWindow); + const int m_resizeBorderHeight = FramelessWindowsManager::getResizeBorderHeight(currentWindow); const int m_titleBarHeight = FramelessWindowsManager::getTitleBarHeight(currentWindow); const bool m_resizable = FramelessWindowsManager::getResizable(currentWindow); const auto getWindowEdges = - [m_borderWidth, m_borderHeight](const QPointF &point, const int ww, const int wh) -> Qt::Edges { - if (point.y() <= m_borderHeight) { - if (point.x() <= m_borderWidth) { + [m_resizeBorderWidth, m_resizeBorderHeight](const QPointF &point, const int ww, const int wh) -> Qt::Edges { + if (point.y() <= m_resizeBorderHeight) { + if (point.x() <= m_resizeBorderWidth) { return Qt::Edge::TopEdge | Qt::Edge::LeftEdge; } - if (point.x() >= (ww - m_borderWidth)) { + if (point.x() >= (ww - m_resizeBorderWidth)) { return Qt::Edge::TopEdge | Qt::Edge::RightEdge; } return Qt::Edge::TopEdge; } - if (point.y() >= (wh - m_borderHeight)) { - if (point.x() <= m_borderWidth) { + if (point.y() >= (wh - m_resizeBorderHeight)) { + if (point.x() <= m_resizeBorderWidth) { return Qt::Edge::BottomEdge | Qt::Edge::LeftEdge; } - if (point.x() >= (ww - m_borderWidth)) { + if (point.x() >= (ww - m_resizeBorderWidth)) { return Qt::Edge::BottomEdge | Qt::Edge::RightEdge; } return Qt::Edge::BottomEdge; } - if (point.x() <= m_borderWidth) { + if (point.x() <= m_resizeBorderWidth) { return Qt::Edge::LeftEdge; } - if (point.x() >= (ww - m_borderWidth)) { + if (point.x() >= (ww - m_resizeBorderWidth)) { return Qt::Edge::RightEdge; } return {}; @@ -116,12 +116,13 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event) } return Qt::CursorShape::ArrowCursor; }; - const auto isInTitlebarArea = [m_titleBarHeight](const QPointF &point, const QWindow *window) -> bool { + const auto isInTitlebarArea = [m_resizeBorderHeight, m_titleBarHeight](const QPointF &point, const QWindow *window) -> bool { Q_ASSERT(window); if (!window) { return false; } - return (point.y() <= m_titleBarHeight) && !Utilities::isHitTestVisibleInChrome(window); + return (point.y() > m_resizeBorderHeight) && (point.y() <= (m_titleBarHeight + m_resizeBorderHeight)) + && !Utilities::isHitTestVisibleInChrome(window); }; const auto moveOrResize = [m_resizable, &getWindowEdges, &isInTitlebarArea](const QPointF &point, QWindow *window) { diff --git a/framelesshelper_global.h b/framelesshelper_global.h index b398d86..b9e4982 100644 --- a/framelesshelper_global.h +++ b/framelesshelper_global.h @@ -57,11 +57,18 @@ #define FRAMELESSHELPER_USE_UNIX_VERSION #endif -namespace _flh_global { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) +#define Q_NODISCARD [[nodiscard]] +#else +#define Q_NODISCARD +#endif + +namespace _flh_global +{ [[maybe_unused]] const char _flh_framelessEnabled_flag[] = "_FRAMELESSHELPER_FRAMELESS_MODE_ENABLED"; -[[maybe_unused]] const char _flh_borderWidth_flag[] = "_FRAMELESSHELPER_WINDOW_RESIZE_BORDER_WIDTH"; -[[maybe_unused]] const char _flh_borderHeight_flag[] = "_FRAMELESSHELPER_WINDOW_RESIZE_BORDER_HEIGHT"; +[[maybe_unused]] const char _flh_resizeBorderWidth_flag[] = "_FRAMELESSHELPER_WINDOW_RESIZE_BORDER_WIDTH"; +[[maybe_unused]] const char _flh_resizeBorderHeight_flag[] = "_FRAMELESSHELPER_WINDOW_RESIZE_BORDER_HEIGHT"; [[maybe_unused]] const char _flh_titleBarHeight_flag[] = "_FRAMELESSHELPER_WINDOW_TITLE_BAR_HEIGHT"; [[maybe_unused]] const char _flh_hitTestVisibleInChrome_flag[] = "_FRAMELESSHELPER_HIT_TEST_VISIBLE_IN_CHROME"; [[maybe_unused]] const char _flh_useNativeTitleBar_flag[] = "_FRAMELESSHELPER_USE_NATIVE_TITLE_BAR"; diff --git a/framelesshelper_win32.cpp b/framelesshelper_win32.cpp index d6e42c9..e81819e 100644 --- a/framelesshelper_win32.cpp +++ b/framelesshelper_win32.cpp @@ -109,8 +109,8 @@ static inline void installHelper(QWindow *window, const bool enable) return; } Utilities::updateQtFrameMargins(window, enable); - Utilities::updateFrameMargins(window, !enable); - Utilities::triggerFrameChange(window); + Utilities::updateFrameMargins(window->winId(), !enable); + Utilities::triggerFrameChange(window->winId()); window->setProperty(_flh_global::_flh_framelessEnabled_flag, enable); } @@ -273,13 +273,13 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me // The value of border width and border height should be // identical in most cases, when the scale factor is 1.0, it // should be eight pixels. - const int bh = getSystemMetric(window, Utilities::SystemMetric::ResizeBorderHeight, true); - clientRect->top += bh; + const int rbh = getSystemMetric(window, Utilities::SystemMetric::ResizeBorderHeight, true); + clientRect->top += rbh; if (!shouldHaveWindowFrame()) { - clientRect->bottom -= bh; - const int bw = getSystemMetric(window, Utilities::SystemMetric::ResizeBorderWidth, true); - clientRect->left += bw; - clientRect->right -= bw; + clientRect->bottom -= rbh; + const int rbw = getSystemMetric(window, Utilities::SystemMetric::ResizeBorderWidth, true); + clientRect->left += rbw; + clientRect->right -= rbw; } nonClientAreaExists = true; } @@ -518,10 +518,11 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me POINT winLocalMouse = {qRound(globalMouse.x()), qRound(globalMouse.y())}; ScreenToClient(msg->hwnd, &winLocalMouse); const QPointF localMouse = {static_cast(winLocalMouse.x), static_cast(winLocalMouse.y)}; - const int bh = getSystemMetric(window, Utilities::SystemMetric::ResizeBorderHeight, true); + const int rbh = getSystemMetric(window, Utilities::SystemMetric::ResizeBorderHeight, true); const int tbh = getSystemMetric(window, Utilities::SystemMetric::TitleBarHeight, true); - const bool isTitleBar = (localMouse.y() <= tbh) && !Utilities::isHitTestVisibleInChrome(window); - const bool isTop = localMouse.y() <= bh; + const bool isTitleBar = (localMouse.y() > rbh) && (localMouse.y() <= (rbh + tbh)) + && !Utilities::isHitTestVisibleInChrome(window); + const bool isTop = localMouse.y() <= rbh; if (shouldHaveWindowFrame()) { // This will handle the left, right and bottom parts of the frame // because we didn't change them. @@ -547,23 +548,23 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me return true; } else { const auto getHitTestResult = - [msg, isTitleBar, &localMouse, bh, isTop, window]() -> LRESULT { + [msg, isTitleBar, &localMouse, rbh, isTop, window]() -> LRESULT { RECT clientRect = {0, 0, 0, 0}; GetClientRect(msg->hwnd, &clientRect); const LONG ww = clientRect.right; const LONG wh = clientRect.bottom; - const int bw = getSystemMetric(window, Utilities::SystemMetric::ResizeBorderWidth, true); + const int rbw = getSystemMetric(window, Utilities::SystemMetric::ResizeBorderWidth, true); if (IsMaximized(msg->hwnd)) { if (isTitleBar) { return HTCAPTION; } return HTCLIENT; } - const bool isBottom = (localMouse.y() >= (wh - bh)); + const bool isBottom = (localMouse.y() >= (wh - rbh)); // Make the border a little wider to let the user easy to resize on corners. - const int factor = (isTop || isBottom) ? 2 : 1; - const bool isLeft = (localMouse.x() <= (bw * factor)); - const bool isRight = (localMouse.x() >= (ww - (bw * factor))); + const qreal factor = (isTop || isBottom) ? 2.0 : 1.0; + const bool isLeft = (localMouse.x() <= qRound(static_cast(rbw) * factor)); + const bool isRight = (localMouse.x() >= (ww - qRound(static_cast(rbw) * factor))); const bool fixedSize = Utilities::isWindowFixedSize(window); const auto getBorderValue = [fixedSize](int value) -> int { return fixedSize ? HTCLIENT : value; @@ -613,10 +614,10 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me // Prevent Windows from drawing the default title bar by temporarily // toggling the WS_VISIBLE style. SetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle & ~WS_VISIBLE); - Utilities::triggerFrameChange(window); + Utilities::triggerFrameChange(reinterpret_cast(msg->hwnd)); const LRESULT ret = DefWindowProcW(msg->hwnd, msg->message, msg->wParam, msg->lParam); SetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle); - Utilities::triggerFrameChange(window); + Utilities::triggerFrameChange(reinterpret_cast(msg->hwnd)); *result = ret; return true; } diff --git a/framelessquickhelper.cpp b/framelessquickhelper.cpp index 72d133c..3cce28a 100644 --- a/framelessquickhelper.cpp +++ b/framelessquickhelper.cpp @@ -30,37 +30,37 @@ FramelessQuickHelper::FramelessQuickHelper(QQuickItem *parent) : QQuickItem(pare { } -int FramelessQuickHelper::resizeBorderWidth() const +qreal FramelessQuickHelper::resizeBorderWidth() const { return FramelessWindowsManager::getResizeBorderWidth(window()); } -void FramelessQuickHelper::setResizeBorderWidth(const int val) +void FramelessQuickHelper::setResizeBorderWidth(const qreal val) { - FramelessWindowsManager::setResizeBorderWidth(window(), val); - Q_EMIT resizeBorderWidthChanged(); + FramelessWindowsManager::setResizeBorderWidth(window(), qRound(val)); + Q_EMIT resizeBorderWidthChanged(val); } -int FramelessQuickHelper::resizeBorderHeight() const +qreal FramelessQuickHelper::resizeBorderHeight() const { return FramelessWindowsManager::getResizeBorderHeight(window()); } -void FramelessQuickHelper::setResizeBorderHeight(const int val) +void FramelessQuickHelper::setResizeBorderHeight(const qreal val) { - FramelessWindowsManager::setResizeBorderHeight(window(), val); - Q_EMIT resizeBorderHeightChanged(); + FramelessWindowsManager::setResizeBorderHeight(window(), qRound(val)); + Q_EMIT resizeBorderHeightChanged(val); } -int FramelessQuickHelper::titleBarHeight() const +qreal FramelessQuickHelper::titleBarHeight() const { return FramelessWindowsManager::getTitleBarHeight(window()); } -void FramelessQuickHelper::setTitleBarHeight(const int val) +void FramelessQuickHelper::setTitleBarHeight(const qreal val) { - FramelessWindowsManager::setTitleBarHeight(window(), val); - Q_EMIT titleBarHeightChanged(); + FramelessWindowsManager::setTitleBarHeight(window(), qRound(val)); + Q_EMIT titleBarHeightChanged(val); } bool FramelessQuickHelper::resizable() const @@ -71,7 +71,7 @@ bool FramelessQuickHelper::resizable() const void FramelessQuickHelper::setResizable(const bool val) { FramelessWindowsManager::setResizable(window(), val); - Q_EMIT resizableChanged(); + Q_EMIT resizableChanged(val); } void FramelessQuickHelper::removeWindowFrame() diff --git a/framelessquickhelper.h b/framelessquickhelper.h index 3502d05..98ef01e 100644 --- a/framelessquickhelper.h +++ b/framelessquickhelper.h @@ -34,36 +34,36 @@ class FRAMELESSHELPER_API FramelessQuickHelper : public QQuickItem #ifdef QML_NAMED_ELEMENT QML_NAMED_ELEMENT(FramelessHelper) #endif - Q_PROPERTY(int resizeBorderWidth READ resizeBorderWidth WRITE setResizeBorderWidth NOTIFY resizeBorderWidthChanged) - Q_PROPERTY(int resizeBorderHeight READ resizeBorderHeight WRITE setResizeBorderHeight NOTIFY resizeBorderHeightChanged) - Q_PROPERTY(int titleBarHeight READ titleBarHeight WRITE setTitleBarHeight NOTIFY titleBarHeightChanged) + Q_PROPERTY(qreal resizeBorderWidth READ resizeBorderWidth WRITE setResizeBorderWidth NOTIFY resizeBorderWidthChanged) + Q_PROPERTY(qreal resizeBorderHeight READ resizeBorderHeight WRITE setResizeBorderHeight NOTIFY resizeBorderHeightChanged) + Q_PROPERTY(qreal titleBarHeight READ titleBarHeight WRITE setTitleBarHeight NOTIFY titleBarHeightChanged) Q_PROPERTY(bool resizable READ resizable WRITE setResizable NOTIFY resizableChanged) public: explicit FramelessQuickHelper(QQuickItem *parent = nullptr); ~FramelessQuickHelper() override = default; - [[nodiscard]] int resizeBorderWidth() const; - void setResizeBorderWidth(const int val); + Q_NODISCARD qreal resizeBorderWidth() const; + void setResizeBorderWidth(const qreal val); - [[nodiscard]] int resizeBorderHeight() const; - void setResizeBorderHeight(const int val); + Q_NODISCARD qreal resizeBorderHeight() const; + void setResizeBorderHeight(const qreal val); - [[nodiscard]] int titleBarHeight() const; - void setTitleBarHeight(const int val); + Q_NODISCARD qreal titleBarHeight() const; + void setTitleBarHeight(const qreal val); - [[nodiscard]] bool resizable() const; + Q_NODISCARD bool resizable() const; void setResizable(const bool val); public Q_SLOTS: void removeWindowFrame(); void bringBackWindowFrame(); - [[nodiscard]] bool isWindowFrameless() const; + Q_NODISCARD bool isWindowFrameless() const; void setHitTestVisibleInChrome(QQuickItem *item, const bool visible); Q_SIGNALS: - void resizeBorderWidthChanged(); - void resizeBorderHeightChanged(); - void titleBarHeightChanged(); - void resizableChanged(); + void resizeBorderWidthChanged(qreal); + void resizeBorderHeightChanged(qreal); + void titleBarHeightChanged(qreal); + void resizableChanged(bool); }; diff --git a/framelesswindowsmanager.cpp b/framelesswindowsmanager.cpp index 47ced69..9ea6c55 100644 --- a/framelesswindowsmanager.cpp +++ b/framelesswindowsmanager.cpp @@ -91,7 +91,7 @@ int FramelessWindowsManager::getResizeBorderWidth(const QWindow *window) return 8; } #ifdef FRAMELESSHELPER_USE_UNIX_VERSION - const int value = window->property(_flh_global::_flh_borderWidth_flag).toInt(); + const int value = window->property(_flh_global::_flh_resizeBorderWidth_flag).toInt(); return value <= 0 ? 8 : value; #else return Utilities::getSystemMetric(window, Utilities::SystemMetric::ResizeBorderWidth, false); @@ -104,7 +104,7 @@ void FramelessWindowsManager::setResizeBorderWidth(QWindow *window, const int va if (!window || (value <= 0)) { return; } - window->setProperty(_flh_global::_flh_borderWidth_flag, value); + window->setProperty(_flh_global::_flh_resizeBorderWidth_flag, value); } int FramelessWindowsManager::getResizeBorderHeight(const QWindow *window) @@ -114,7 +114,7 @@ int FramelessWindowsManager::getResizeBorderHeight(const QWindow *window) return 8; } #ifdef FRAMELESSHELPER_USE_UNIX_VERSION - const int value = window->property(_flh_global::_flh_borderHeight_flag).toInt(); + const int value = window->property(_flh_global::_flh_resizeBorderHeight_flag).toInt(); return value <= 0 ? 8 : value; #else return Utilities::getSystemMetric(window, Utilities::SystemMetric::ResizeBorderHeight, false); @@ -127,18 +127,18 @@ void FramelessWindowsManager::setResizeBorderHeight(QWindow *window, const int v if (!window || (value <= 0)) { return; } - window->setProperty(_flh_global::_flh_borderHeight_flag, value); + window->setProperty(_flh_global::_flh_resizeBorderHeight_flag, value); } int FramelessWindowsManager::getTitleBarHeight(const QWindow *window) { Q_ASSERT(window); if (!window) { - return 31; + return 23; } #ifdef FRAMELESSHELPER_USE_UNIX_VERSION const int value = window->property(_flh_global::_flh_titleBarHeight_flag).toInt(); - return value <= 0 ? 31 : value; + return value <= 0 ? 23 : value; #else return Utilities::getSystemMetric(window, Utilities::SystemMetric::TitleBarHeight, false); #endif diff --git a/utilities.h b/utilities.h index 474fdc3..787b2a5 100644 --- a/utilities.h +++ b/utilities.h @@ -49,8 +49,8 @@ enum class SystemMetric [[nodiscard]] FRAMELESSHELPER_API bool isWin8Point1OrGreater(); [[nodiscard]] FRAMELESSHELPER_API bool isWin10OrGreater(); [[nodiscard]] FRAMELESSHELPER_API bool isDwmCompositionAvailable(); -FRAMELESSHELPER_API void triggerFrameChange(const QWindow *window); -FRAMELESSHELPER_API void updateFrameMargins(const QWindow *window, const bool reset); +FRAMELESSHELPER_API void triggerFrameChange(const WId winId); +FRAMELESSHELPER_API void updateFrameMargins(const WId winId, const bool reset); FRAMELESSHELPER_API void updateQtFrameMargins(QWindow *window, const bool enable); #endif diff --git a/utilities_win32.cpp b/utilities_win32.cpp index 336cc3b..51a9c43 100644 --- a/utilities_win32.cpp +++ b/utilities_win32.cpp @@ -47,7 +47,7 @@ Q_DECLARE_METATYPE(QMargins) #endif // The standard values of resize border width, resize border height and title bar height when DPI is 96. -static const int g_defaultResizeBorderWidth = 8, g_defaultResizeBorderHeight = 8, g_defaultTitleBarHeight = 31; +static const int g_defaultResizeBorderWidth = 8, g_defaultResizeBorderHeight = 8, g_defaultTitleBarHeight = 23; bool Utilities::isDwmCompositionAvailable() { @@ -71,9 +71,9 @@ int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric, } switch (metric) { case SystemMetric::ResizeBorderWidth: { - const int bw = window->property(_flh_global::_flh_borderWidth_flag).toInt(); - if ((bw > 0) && !forceSystemValue) { - return qRound(static_cast(bw) * (dpiScale ? window->devicePixelRatio() : 1.0)); + const int rbw = window->property(_flh_global::_flh_resizeBorderWidth_flag).toInt(); + if ((rbw > 0) && !forceSystemValue) { + return qRound(static_cast(rbw) * (dpiScale ? window->devicePixelRatio() : 1.0)); } else { const int result = GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER); if (result > 0) { @@ -92,9 +92,9 @@ int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric, } } case SystemMetric::ResizeBorderHeight: { - const int bh = window->property(_flh_global::_flh_borderHeight_flag).toInt(); - if ((bh > 0) && !forceSystemValue) { - return qRound(static_cast(bh) * (dpiScale ? window->devicePixelRatio() : 1.0)); + const int rbh = window->property(_flh_global::_flh_resizeBorderHeight_flag).toInt(); + if ((rbh > 0) && !forceSystemValue) { + return qRound(static_cast(rbh) * (dpiScale ? window->devicePixelRatio() : 1.0)); } else { // There is no "SM_CYPADDEDBORDER". const int result = GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER); @@ -118,8 +118,7 @@ int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric, if ((tbh > 0) && !forceSystemValue) { return qRound(static_cast(tbh) * (dpiScale ? window->devicePixelRatio() : 1.0)); } else { - // There is no "SM_CYPADDEDBORDER". - const int result = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER); + const int result = GetSystemMetrics(SM_CYCAPTION); if (result > 0) { if (dpiScale) { return result; @@ -139,30 +138,30 @@ int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric, return 0; } -void Utilities::triggerFrameChange(const QWindow *window) +void Utilities::triggerFrameChange(const WId winId) { - Q_ASSERT(window); - if (!window) { + Q_ASSERT(winId); + if (!winId) { return; } - const auto hwnd = reinterpret_cast(window->winId()); + const auto hwnd = reinterpret_cast(winId); if (SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER) == FALSE) { qWarning() << "SetWindowPos() failed."; } } -void Utilities::updateFrameMargins(const QWindow *window, const bool reset) +void Utilities::updateFrameMargins(const WId winId, const bool reset) { // DwmExtendFrameIntoClientArea() will always fail if DWM Composition is disabled. // No need to try in this case. if (!isDwmCompositionAvailable()) { return; } - Q_ASSERT(window); - if (!window) { + Q_ASSERT(winId); + if (!winId) { return; } - const auto hwnd = reinterpret_cast(window->winId()); + const auto hwnd = reinterpret_cast(winId); const MARGINS margins = reset ? MARGINS{0, 0, 0, 0} : MARGINS{1, 1, 1, 1}; if (FAILED(DwmExtendFrameIntoClientArea(hwnd, &margins))) { qWarning() << "DwmExtendFrameIntoClientArea() failed."; @@ -176,9 +175,9 @@ void Utilities::updateQtFrameMargins(QWindow *window, const bool enable) return; } const int tbh = enable ? Utilities::getSystemMetric(window, Utilities::SystemMetric::TitleBarHeight, true, true) : 0; - const int bw = enable ? Utilities::getSystemMetric(window, Utilities::SystemMetric::ResizeBorderWidth, true, true) : 0; - const int bh = enable ? Utilities::getSystemMetric(window, Utilities::SystemMetric::ResizeBorderHeight, true, true) : 0; - const QMargins margins = {-bw, -tbh, -bw, -bh}; // left, top, right, bottom + const int rbw = enable ? Utilities::getSystemMetric(window, Utilities::SystemMetric::ResizeBorderWidth, true, true) : 0; + const int rbh = enable ? Utilities::getSystemMetric(window, Utilities::SystemMetric::ResizeBorderHeight, true, true) : 0; + const QMargins margins = {-rbw, -(rbh + tbh), -rbw, -rbh}; // left, top, right, bottom const QVariant marginsVar = QVariant::fromValue(margins); window->setProperty("_q_windowsCustomMargins", marginsVar); #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))