From eeda750a61696561c5d209e1019d7c25480456ae Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Wed, 21 Sep 2022 13:22:03 +0800 Subject: [PATCH] finalize api update Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- .../Core/framelesshelper_windows.h | 56 +++++++++++++++---- include/FramelessHelper/Core/utils.h | 2 +- .../Quick/framelessquickhelper.h | 5 +- .../Quick/private/framelessquickhelper_p.h | 4 +- .../Widgets/framelesswidgetshelper.h | 5 +- .../private/framelesswidgetshelper_p.h | 2 +- src/core/framelesshelper_win.cpp | 4 +- src/core/utils_win.cpp | 53 +++++++++++------- src/quick/framelessquickhelper.cpp | 23 ++++---- src/quick/framelessquickwindow.cpp | 2 +- src/widgets/framelessdialog.cpp | 2 +- src/widgets/framelessmainwindow.cpp | 2 +- src/widgets/framelesswidget.cpp | 2 +- src/widgets/framelesswidgetshelper.cpp | 15 ++--- src/widgets/widgetssharedhelper.cpp | 2 +- 15 files changed, 111 insertions(+), 68 deletions(-) diff --git a/include/FramelessHelper/Core/framelesshelper_windows.h b/include/FramelessHelper/Core/framelesshelper_windows.h index 6099dd5..f9eec7a 100644 --- a/include/FramelessHelper/Core/framelesshelper_windows.h +++ b/include/FramelessHelper/Core/framelesshelper_windows.h @@ -154,49 +154,69 @@ #endif #ifndef HKEY_CLASSES_ROOT -# define HKEY_CLASSES_ROOT ((HKEY)(ULONG_PTR)((LONG)0x80000000)) +# define HKEY_CLASSES_ROOT (reinterpret_cast(static_cast(static_cast(0x80000000)))) #endif #ifndef HKEY_CURRENT_USER -# define HKEY_CURRENT_USER ((HKEY)(ULONG_PTR)((LONG)0x80000001)) +# define HKEY_CURRENT_USER (reinterpret_cast(static_cast(static_cast(0x80000001)))) #endif #ifndef HKEY_LOCAL_MACHINE -# define HKEY_LOCAL_MACHINE ((HKEY)(ULONG_PTR)((LONG)0x80000002)) +# define HKEY_LOCAL_MACHINE (reinterpret_cast(static_cast(static_cast(0x80000002)))) #endif #ifndef HKEY_USERS -# define HKEY_USERS ((HKEY)(ULONG_PTR)((LONG)0x80000003)) +# define HKEY_USERS (reinterpret_cast(static_cast(static_cast(0x80000003)))) #endif #ifndef HKEY_PERFORMANCE_DATA -# define HKEY_PERFORMANCE_DATA ((HKEY)(ULONG_PTR)((LONG)0x80000004)) +# define HKEY_PERFORMANCE_DATA (reinterpret_cast(static_cast(static_cast(0x80000004)))) #endif #ifndef HKEY_CURRENT_CONFIG -# define HKEY_CURRENT_CONFIG ((HKEY)(ULONG_PTR)((LONG)0x80000005)) +# define HKEY_CURRENT_CONFIG (reinterpret_cast(static_cast(static_cast(0x80000005)))) #endif #ifndef HKEY_DYN_DATA -# define HKEY_DYN_DATA ((HKEY)(ULONG_PTR)((LONG)0x80000006)) +# define HKEY_DYN_DATA (reinterpret_cast(static_cast(static_cast(0x80000006)))) #endif #ifndef HKEY_CURRENT_USER_LOCAL_SETTINGS -# define HKEY_CURRENT_USER_LOCAL_SETTINGS ((HKEY)(ULONG_PTR)((LONG)0x80000007)) +# define HKEY_CURRENT_USER_LOCAL_SETTINGS (reinterpret_cast(static_cast(static_cast(0x80000007)))) #endif #ifndef HKEY_PERFORMANCE_TEXT -# define HKEY_PERFORMANCE_TEXT ((HKEY)(ULONG_PTR)((LONG)0x80000050)) +# define HKEY_PERFORMANCE_TEXT (reinterpret_cast(static_cast(static_cast(0x80000050)))) #endif #ifndef HKEY_PERFORMANCE_NLSTEXT -# define HKEY_PERFORMANCE_NLSTEXT ((HKEY)(ULONG_PTR)((LONG)0x80000060)) +# define HKEY_PERFORMANCE_NLSTEXT (reinterpret_cast(static_cast(static_cast(0x80000060)))) #endif #ifndef STATUS_SUCCESS # define STATUS_SUCCESS (static_cast(0x00000000L)) #endif +#ifndef WTNCA_NODRAWCAPTION +# define WTNCA_NODRAWCAPTION (0x00000001) // don't draw the window caption +#endif + +#ifndef WTNCA_NODRAWICON +# define WTNCA_NODRAWICON (0x00000002) // don't draw the system icon +#endif + +#ifndef WTNCA_NOSYSMENU +# define WTNCA_NOSYSMENU (0x00000004) // don't expose the system menu icon functionality +#endif + +#ifndef WTNCA_NOMIRRORHELP +# define WTNCA_NOMIRRORHELP (0x00000008) // don't mirror the question mark, even in RTL layout +#endif + +#ifndef WTNCA_VALIDBITS +# define WTNCA_VALIDBITS (WTNCA_NODRAWCAPTION | WTNCA_NODRAWICON | WTNCA_NOSYSMENU | WTNCA_NOMIRRORHELP) +#endif + #ifndef EXTERN_C # define EXTERN_C extern "C" #endif @@ -349,7 +369,7 @@ using WINDOWCOMPOSITIONATTRIBDATA = struct WINDOWCOMPOSITIONATTRIBDATA { WINDOWCOMPOSITIONATTRIB Attrib; PVOID pvData; - SIZE_T cbData; + DWORD cbData; }; using PWINDOWCOMPOSITIONATTRIBDATA = WINDOWCOMPOSITIONATTRIBDATA *; using NPWINDOWCOMPOSITIONATTRIBDATA = WINDOWCOMPOSITIONATTRIBDATA NEAR *; @@ -358,6 +378,18 @@ using LPWINDOWCOMPOSITIONATTRIBDATA = WINDOWCOMPOSITIONATTRIBDATA FAR *; using GetWindowCompositionAttributePtr = BOOL(WINAPI *)(HWND, PWINDOWCOMPOSITIONATTRIBDATA); using SetWindowCompositionAttributePtr = BOOL(WINAPI *)(HWND, PWINDOWCOMPOSITIONATTRIBDATA); +using _WINDOWTHEMEATTRIBUTETYPE = enum _WINDOWTHEMEATTRIBUTETYPE +{ + _WTA_NONCLIENT = 1 +}; + +using WTA_OPTIONS2 = struct WTA_OPTIONS2 +{ + DWORD dwFlags; // Values for each style option specified in the bitmask. + DWORD dwMask; // Bitmask for flags that are changing. +}; +using PWTA_OPTIONS2 = WTA_OPTIONS2 *; + EXTERN_C_START DECLSPEC_IMPORT MMRESULT WINAPI @@ -397,7 +429,7 @@ GetSystemMetricsForDpi( DECLSPEC_IMPORT UINT WINAPI GetDpiForWindow( - _In_ HWND hwnd + _In_ HWND hWnd ); DECLSPEC_IMPORT UINT WINAPI diff --git a/include/FramelessHelper/Core/utils.h b/include/FramelessHelper/Core/utils.h index 54b1651..3b99561 100644 --- a/include/FramelessHelper/Core/utils.h +++ b/include/FramelessHelper/Core/utils.h @@ -99,7 +99,7 @@ FRAMELESSHELPER_CORE_API void showSystemMenu( const bool scaled); [[nodiscard]] FRAMELESSHELPER_CORE_API QColor getFrameBorderColor(const bool active); FRAMELESSHELPER_CORE_API void updateWindowFrameBorderColor(const WId windowId, const bool dark); -FRAMELESSHELPER_CORE_API void fixupQtInternals(const WId windowId); +FRAMELESSHELPER_CORE_API void maybeFixupQtInternals(const WId windowId); [[nodiscard]] FRAMELESSHELPER_CORE_API bool isWindowFrameBorderVisible(); [[nodiscard]] FRAMELESSHELPER_CORE_API bool isFrameBorderColorized(); FRAMELESSHELPER_CORE_API void installSystemMenuHook( diff --git a/include/FramelessHelper/Quick/framelessquickhelper.h b/include/FramelessHelper/Quick/framelessquickhelper.h index 360070f..473fa82 100644 --- a/include/FramelessHelper/Quick/framelessquickhelper.h +++ b/include/FramelessHelper/Quick/framelessquickhelper.h @@ -50,7 +50,7 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickHelper : public QQuickItem Q_PROPERTY(bool windowFixedSize READ isWindowFixedSize WRITE setWindowFixedSize NOTIFY windowFixedSizeChanged FINAL) Q_PROPERTY(bool blurBehindWindowEnabled READ isBlurBehindWindowEnabled WRITE setBlurBehindWindowEnabled NOTIFY blurBehindWindowEnabledChanged FINAL) Q_PROPERTY(QQuickWindow* window READ window NOTIFY windowChanged2 FINAL) - Q_PROPERTY(bool extendsContentIntoTitleBar READ isContentExtendedIntoTitleBar WRITE setContentExtendedIntoTitleBar NOTIFY extendsContentIntoTitleBarChanged FINAL) + Q_PROPERTY(bool extendsContentIntoTitleBar READ isContentExtendedIntoTitleBar WRITE extendsContentIntoTitleBar NOTIFY extendsContentIntoTitleBarChanged FINAL) public: explicit FramelessQuickHelper(QQuickItem *parent = nullptr); @@ -65,8 +65,7 @@ public: Q_NODISCARD bool isContentExtendedIntoTitleBar() const; public Q_SLOTS: - [[deprecated("Use the extendsContentIntoTitleBar property instead.")]] void extendsContentIntoTitleBar(); - void setContentExtendedIntoTitleBar(const bool value); + void extendsContentIntoTitleBar(const bool value = true); void setTitleBarItem(QQuickItem *value); void setSystemButton(QQuickItem *item, const QuickGlobal::SystemButtonType buttonType); diff --git a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h index 35c15ed..6f7c855 100644 --- a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h @@ -28,6 +28,7 @@ #include "framelessquickhelper.h" #include #include +#include QT_BEGIN_NAMESPACE class QQuickItem; @@ -51,7 +52,7 @@ public: Q_NODISCARD static const FramelessQuickHelperPrivate *get(const FramelessQuickHelper *pub); Q_NODISCARD bool isContentExtendedIntoTitleBar() const; - void setContentExtendedIntoTitleBar(const bool value); + void extendsContentIntoTitleBar(const bool value); Q_NODISCARD QQuickItem *getTitleBarItem() const; void setTitleBarItem(QQuickItem *value); @@ -95,6 +96,7 @@ private: QPointer q_ptr = nullptr; QColor m_savedWindowBackgroundColor = {}; bool m_blurBehindWindowEnabled = false; + std::optional m_extendIntoTitleBar = std::nullopt; }; FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Widgets/framelesswidgetshelper.h b/include/FramelessHelper/Widgets/framelesswidgetshelper.h index b1e1550..40c6b9d 100644 --- a/include/FramelessHelper/Widgets/framelesswidgetshelper.h +++ b/include/FramelessHelper/Widgets/framelesswidgetshelper.h @@ -44,7 +44,7 @@ class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelper : public QObject Q_PROPERTY(bool windowFixedSize READ isWindowFixedSize WRITE setWindowFixedSize NOTIFY windowFixedSizeChanged FINAL) Q_PROPERTY(bool blurBehindWindowEnabled READ isBlurBehindWindowEnabled WRITE setBlurBehindWindowEnabled NOTIFY blurBehindWindowEnabledChanged FINAL) Q_PROPERTY(QWidget* window READ window NOTIFY windowChanged FINAL) - Q_PROPERTY(bool extendsContentIntoTitleBar READ isContentExtendedIntoTitleBar WRITE setContentExtendedIntoTitleBar NOTIFY extendsContentIntoTitleBarChanged FINAL) + Q_PROPERTY(bool extendsContentIntoTitleBar READ isContentExtendedIntoTitleBar WRITE extendsContentIntoTitleBar NOTIFY extendsContentIntoTitleBarChanged FINAL) public: explicit FramelessWidgetsHelper(QObject *parent = nullptr); @@ -59,8 +59,7 @@ public: Q_NODISCARD bool isContentExtendedIntoTitleBar() const; public Q_SLOTS: - [[deprecated("Use the extendsContentIntoTitleBar property instead.")]] void extendsContentIntoTitleBar(); - void setContentExtendedIntoTitleBar(const bool value); + void extendsContentIntoTitleBar(const bool value = true); void setTitleBarWidget(QWidget *widget); void setSystemButton(QWidget *widget, const Global::SystemButtonType buttonType); diff --git a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h index b9b7445..12528d9 100644 --- a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h +++ b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h @@ -47,7 +47,7 @@ public: Q_NODISCARD static const FramelessWidgetsHelperPrivate *get(const FramelessWidgetsHelper *pub); Q_NODISCARD bool isContentExtendedIntoTitleBar() const; - void setContentExtendedIntoTitleBar(const bool value); + void extendsContentIntoTitleBar(const bool value); Q_NODISCARD QWidget *getTitleBarWidget() const; void setTitleBarWidget(QWidget *widget); diff --git a/src/core/framelesshelper_win.cpp b/src/core/framelesshelper_win.cpp index d39dab6..04090b8 100644 --- a/src/core/framelesshelper_win.cpp +++ b/src/core/framelesshelper_win.cpp @@ -512,7 +512,7 @@ void FramelessHelperWin::addWindow(const SystemParameters ¶ms) } g_win32Helper()->mutex.unlock(); // Some Qt internals have to be corrected. - Utils::fixupQtInternals(windowId); + Utils::maybeFixupQtInternals(windowId); // Qt maintains a frame margin internally, we need to update it accordingly // otherwise we'll get lots of warning messages when we change the window // geometry, it will also affect the final window geometry because QPA will @@ -520,6 +520,8 @@ void FramelessHelperWin::addWindow(const SystemParameters ¶ms) Utils::updateInternalWindowFrameMargins(params.getWindowHandle(), true); // Tell DWM our preferred frame margin. Utils::updateWindowFrameMargins(windowId, false); + // Tell DWM we don't use the window icon/caption/sysmenu, don't draw them. + Utils::disableOriginalTitleBarFunctionalities(windowId); static const bool isWin10RS1OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607); if (isWin10RS1OrGreater) { // Tell DWM we may need dark theme non-client area (title bar & frame border). diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index 8a83898..0c4b983 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -45,6 +45,34 @@ #include #include +EXTERN_C [[nodiscard]] FRAMELESSHELPER_CORE_API HRESULT WINAPI +SetWindowThemeAttribute2(const HWND hWnd, const _WINDOWTHEMEATTRIBUTETYPE attrib, + PVOID pvData, const DWORD cbData +) +{ + Q_ASSERT(hWnd); + Q_ASSERT(pvData); + if (!hWnd || !pvData) { + return E_INVALIDARG; + } + FRAMELESSHELPER_STRING_CONSTANT(uxtheme) + FRAMELESSHELPER_STRING_CONSTANT(SetWindowThemeAttribute) + const auto loader = FRAMELESSHELPER_PREPEND_NAMESPACE(SysApiLoader)::instance(); + if (!loader->isAvailable(kuxtheme, kSetWindowThemeAttribute)) { + return E_NOTIMPL; + } + return (loader->get(kSetWindowThemeAttribute))(hWnd, attrib, pvData, cbData); +} + +EXTERN_C [[nodiscard]] FRAMELESSHELPER_CORE_API HRESULT WINAPI +SetWindowThemeNonClientAttributes2(const HWND hWnd, const DWORD dwMask, const DWORD dwAttributes) +{ + WTA_OPTIONS2 options = {}; + options.dwFlags = dwAttributes; + options.dwMask = dwMask; + return SetWindowThemeAttribute2(hWnd, _WTA_NONCLIENT, &options, sizeof(options)); +} + Q_DECLARE_METATYPE(QMargins) FRAMELESSHELPER_BEGIN_NAMESPACE @@ -1145,7 +1173,7 @@ void Utils::updateWindowFrameBorderColor(const WId windowId, const bool dark) } } -void Utils::fixupQtInternals(const WId windowId) +void Utils::maybeFixupQtInternals(const WId windowId) { Q_ASSERT(windowId); if (!windowId) { @@ -1167,8 +1195,7 @@ void Utils::fixupQtInternals(const WId windowId) static constexpr const DWORD badClassStyle = (CS_HREDRAW | CS_VREDRAW); if (classStyle & badClassStyle) { SetLastError(ERROR_SUCCESS); - if (SetClassLongPtrW(hwnd, GCL_STYLE, - static_cast(classStyle & ~badClassStyle)) == 0) { + if (SetClassLongPtrW(hwnd, GCL_STYLE, (classStyle & ~badClassStyle)) == 0) { WARNING << getSystemErrorMessage(kSetClassLongPtrW); } else { shouldUpdateFrame = true; @@ -1191,8 +1218,7 @@ void Utils::fixupQtInternals(const WId windowId) (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME); if (!(windowStyle & goodWindowStyle)) { SetLastError(ERROR_SUCCESS); - if (SetWindowLongPtrW(hwnd, GWL_STYLE, - static_cast((windowStyle & ~WS_POPUP) | goodWindowStyle)) == 0) { + if (SetWindowLongPtrW(hwnd, GWL_STYLE, ((windowStyle & ~WS_POPUP) | goodWindowStyle)) == 0) { WARNING << getSystemErrorMessage(kSetWindowLongPtrW); } else { shouldUpdateFrame = true; @@ -1802,28 +1828,17 @@ bool Utils::isBlurBehindWindowSupported() void Utils::disableOriginalTitleBarFunctionalities(const WId windowId, const bool disable) { -#if 0 Q_ASSERT(windowId); if (!windowId) { return; } - if (!API_THEME_AVAILABLE(SetWindowThemeAttribute)) { - return; - } const auto hwnd = reinterpret_cast(windowId); - WTA_OPTIONS options; - SecureZeroMemory(&options, sizeof(options)); - options.dwFlags = options.dwMask = (disable ? - (WTNCA_NODRAWCAPTION | WTNCA_NODRAWICON | WTNCA_NOSYSMENU) : 0); - const HRESULT hr = API_CALL_FUNCTION(SetWindowThemeAttribute, - hwnd, WTA_NONCLIENT, &options, sizeof(options)); + static constexpr const DWORD validBits = (WTNCA_NODRAWCAPTION | WTNCA_NODRAWICON | WTNCA_NOSYSMENU); + const DWORD mask = (disable ? validBits : 0); + const HRESULT hr = SetWindowThemeNonClientAttributes2(hwnd, mask, mask); if (FAILED(hr)) { WARNING << __getSystemErrorMessage(kSetWindowThemeAttribute, hr); } -#else - Q_UNUSED(windowId); - Q_UNUSED(disable); -#endif } void Utils::setQtDarkModeAwareEnabled(const bool enable) diff --git a/src/quick/framelessquickhelper.cpp b/src/quick/framelessquickhelper.cpp index 1c555d1..a837941 100644 --- a/src/quick/framelessquickhelper.cpp +++ b/src/quick/framelessquickhelper.cpp @@ -103,7 +103,8 @@ FramelessQuickHelperPrivate::FramelessQuickHelperPrivate(FramelessQuickHelper *q FramelessQuickHelperPrivate::~FramelessQuickHelperPrivate() { - detach(); + extendsContentIntoTitleBar(false); + m_extendIntoTitleBar = std::nullopt; } FramelessQuickHelperPrivate *FramelessQuickHelperPrivate::get(FramelessQuickHelper *pub) @@ -129,7 +130,7 @@ bool FramelessQuickHelperPrivate::isContentExtendedIntoTitleBar() const return getWindowData().ready; } -void FramelessQuickHelperPrivate::setContentExtendedIntoTitleBar(const bool value) +void FramelessQuickHelperPrivate::extendsContentIntoTitleBar(const bool value) { if (isContentExtendedIntoTitleBar() == value) { return; @@ -139,6 +140,7 @@ void FramelessQuickHelperPrivate::setContentExtendedIntoTitleBar(const bool valu } else { detach(); } + m_extendIntoTitleBar = value; emitSignalForAllInstances(FRAMELESSHELPER_BYTEARRAY_LITERAL("extendsContentIntoTitleBarChanged")); } @@ -570,7 +572,7 @@ bool FramelessQuickHelperPrivate::eventFilter(QObject *object, QEvent *event) } else { const auto changeEvent = static_cast(event); if (Utils::windowStatesToWindowState(changeEvent->oldState()) == Qt::WindowFullScreen) { - Utils::fixupQtInternals(windowId); + Utils::maybeFixupQtInternals(windowId); if (isWin11OrGreater && roundCorner) { Utils::forceSquareCornersForWindow(windowId, false); } @@ -864,7 +866,7 @@ FramelessQuickHelper *FramelessQuickHelper::get(QObject *object) instance->setParentItem(parentItem); instance->setParent(parent); // No need to do this here, we'll do it once the item has been assigned to a specific window. - //instance->d_func()->attach(); + //instance->extendsContentIntoTitleBar(); } return instance; } @@ -902,15 +904,10 @@ bool FramelessQuickHelper::isContentExtendedIntoTitleBar() const return d->isContentExtendedIntoTitleBar(); } -void FramelessQuickHelper::extendsContentIntoTitleBar() -{ - setContentExtendedIntoTitleBar(true); -} - -void FramelessQuickHelper::setContentExtendedIntoTitleBar(const bool value) +void FramelessQuickHelper::extendsContentIntoTitleBar(const bool value) { Q_D(FramelessQuickHelper); - d->setContentExtendedIntoTitleBar(value); + d->extendsContentIntoTitleBar(value); } void FramelessQuickHelper::setTitleBarItem(QQuickItem *value) @@ -1020,7 +1017,9 @@ void FramelessQuickHelper::itemChange(const ItemChange change, const ItemChangeD } } Q_D(FramelessQuickHelper); - d->attach(); + if (d->m_extendIntoTitleBar.value_or(true)) { + extendsContentIntoTitleBar(); + } } } diff --git a/src/quick/framelessquickwindow.cpp b/src/quick/framelessquickwindow.cpp index 6669458..4c9c48d 100644 --- a/src/quick/framelessquickwindow.cpp +++ b/src/quick/framelessquickwindow.cpp @@ -162,7 +162,7 @@ void FramelessQuickWindowPrivate::initialize() { Q_Q(FramelessQuickWindow); QQuickItem * const rootItem = q->contentItem(); - FramelessQuickHelper::get(rootItem)->setContentExtendedIntoTitleBar(true); + FramelessQuickHelper::get(rootItem)->extendsContentIntoTitleBar(); m_topBorderRectangle.reset(new QQuickRectangle(rootItem)); m_topBorderRectangle->setZ(999); // Make sure the frame border stays on top of eveything. m_topBorderRectangle->setColor(kDefaultTransparentColor); diff --git a/src/widgets/framelessdialog.cpp b/src/widgets/framelessdialog.cpp index 333b0f2..6966772 100644 --- a/src/widgets/framelessdialog.cpp +++ b/src/widgets/framelessdialog.cpp @@ -71,7 +71,7 @@ const FramelessDialogPrivate *FramelessDialogPrivate::get(const FramelessDialog void FramelessDialogPrivate::initialize() { Q_Q(FramelessDialog); - FramelessWidgetsHelper::get(q)->setContentExtendedIntoTitleBar(true); + FramelessWidgetsHelper::get(q)->extendsContentIntoTitleBar(); m_helper.reset(new WidgetsSharedHelper(this)); m_helper->setup(q); } diff --git a/src/widgets/framelessmainwindow.cpp b/src/widgets/framelessmainwindow.cpp index fdf35a5..ea99f37 100644 --- a/src/widgets/framelessmainwindow.cpp +++ b/src/widgets/framelessmainwindow.cpp @@ -71,7 +71,7 @@ const FramelessMainWindowPrivate *FramelessMainWindowPrivate::get(const Frameles void FramelessMainWindowPrivate::initialize() { Q_Q(FramelessMainWindow); - FramelessWidgetsHelper::get(q)->setContentExtendedIntoTitleBar(true); + FramelessWidgetsHelper::get(q)->extendsContentIntoTitleBar(); m_helper.reset(new WidgetsSharedHelper(this)); m_helper->setup(q); } diff --git a/src/widgets/framelesswidget.cpp b/src/widgets/framelesswidget.cpp index f7bc502..f028c87 100644 --- a/src/widgets/framelesswidget.cpp +++ b/src/widgets/framelesswidget.cpp @@ -71,7 +71,7 @@ const FramelessWidgetPrivate *FramelessWidgetPrivate::get(const FramelessWidget void FramelessWidgetPrivate::initialize() { Q_Q(FramelessWidget); - FramelessWidgetsHelper::get(q)->setContentExtendedIntoTitleBar(true); + FramelessWidgetsHelper::get(q)->extendsContentIntoTitleBar(); m_helper.reset(new WidgetsSharedHelper(this)); m_helper->setup(q); } diff --git a/src/widgets/framelesswidgetshelper.cpp b/src/widgets/framelesswidgetshelper.cpp index 592b56f..6ac5634 100644 --- a/src/widgets/framelesswidgetshelper.cpp +++ b/src/widgets/framelesswidgetshelper.cpp @@ -109,7 +109,7 @@ FramelessWidgetsHelperPrivate::FramelessWidgetsHelperPrivate(FramelessWidgetsHel FramelessWidgetsHelperPrivate::~FramelessWidgetsHelperPrivate() { - detach(); + extendsContentIntoTitleBar(false); } FramelessWidgetsHelperPrivate *FramelessWidgetsHelperPrivate::get(FramelessWidgetsHelper *pub) @@ -438,7 +438,7 @@ void FramelessWidgetsHelperPrivate::detach() emitSignalForAllInstances(FRAMELESSHELPER_BYTEARRAY_LITERAL("windowChanged")); } -void FramelessWidgetsHelperPrivate::setContentExtendedIntoTitleBar(const bool value) +void FramelessWidgetsHelperPrivate::extendsContentIntoTitleBar(const bool value) { if (isContentExtendedIntoTitleBar() == value) { return; @@ -821,7 +821,7 @@ FramelessWidgetsHelper *FramelessWidgetsHelper::get(QObject *object) FramelessWidgetsHelper *instance = parent->findChild(); if (!instance) { instance = new FramelessWidgetsHelper(parent); - instance->d_func()->attach(); + instance->extendsContentIntoTitleBar(); } return instance; } @@ -856,15 +856,10 @@ bool FramelessWidgetsHelper::isContentExtendedIntoTitleBar() const return d->isContentExtendedIntoTitleBar(); } -void FramelessWidgetsHelper::extendsContentIntoTitleBar() -{ - setContentExtendedIntoTitleBar(true); -} - -void FramelessWidgetsHelper::setContentExtendedIntoTitleBar(const bool value) +void FramelessWidgetsHelper::extendsContentIntoTitleBar(const bool value) { Q_D(FramelessWidgetsHelper); - d->setContentExtendedIntoTitleBar(value); + d->extendsContentIntoTitleBar(value); } void FramelessWidgetsHelper::setTitleBarWidget(QWidget *widget) diff --git a/src/widgets/widgetssharedhelper.cpp b/src/widgets/widgetssharedhelper.cpp index bb07546..114fcbb 100644 --- a/src/widgets/widgetssharedhelper.cpp +++ b/src/widgets/widgetssharedhelper.cpp @@ -168,7 +168,7 @@ void WidgetsSharedHelper::changeEventHandler(QEvent *event) } else { const auto changeEvent = static_cast(event); if (Utils::windowStatesToWindowState(changeEvent->oldState()) == Qt::WindowFullScreen) { - Utils::fixupQtInternals(windowId); + Utils::maybeFixupQtInternals(windowId); if (isWin11OrGreater && roundCorner) { Utils::forceSquareCornersForWindow(windowId, false); }