fix nested frameless windows & other minor tweaks

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2023-01-18 13:43:51 +08:00
parent 4896869123
commit 378aa7db12
6 changed files with 24 additions and 20 deletions

View File

@ -56,10 +56,10 @@ QT_END_NAMESPACE
#endif #endif
#if defined(Q_OS_WIN) && !defined(Q_OS_WINDOWS) #if defined(Q_OS_WIN) && !defined(Q_OS_WINDOWS)
# define Q_OS_WINDOWS # define Q_OS_WINDOWS // Since 5.14
#endif #endif
#ifndef Q_DISABLE_COPY_MOVE #ifndef Q_DISABLE_COPY_MOVE // Since 5.13
# define Q_DISABLE_COPY_MOVE(Class) \ # define Q_DISABLE_COPY_MOVE(Class) \
Q_DISABLE_COPY(Class) \ Q_DISABLE_COPY(Class) \
Class(Class &&) = delete; \ Class(Class &&) = delete; \
@ -68,8 +68,6 @@ QT_END_NAMESPACE
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0)) #if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
using QStringView = const QString &; using QStringView = const QString &;
#else
# include <QtCore/qstringview.h>
#endif #endif
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
@ -77,6 +75,7 @@ QT_END_NAMESPACE
# define Q_NAMESPACE_EXPORT(...) Q_NAMESPACE # define Q_NAMESPACE_EXPORT(...) Q_NAMESPACE
#endif #endif
// MOC can't handle C++ attributes before 5.15.
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
# define Q_NODISCARD [[nodiscard]] # define Q_NODISCARD [[nodiscard]]
# define Q_MAYBE_UNUSED [[maybe_unused]] # define Q_MAYBE_UNUSED [[maybe_unused]]
@ -108,7 +107,7 @@ QT_END_NAMESPACE
#endif #endif
#if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0))
using namespace Qt::StringLiterals; using namespace Qt::Literals::StringLiterals;
#endif #endif
#ifndef FRAMELESSHELPER_BYTEARRAY_LITERAL #ifndef FRAMELESSHELPER_BYTEARRAY_LITERAL
@ -131,6 +130,14 @@ QT_END_NAMESPACE
# endif # endif
#endif #endif
#ifndef Q_UNREACHABLE_RETURN // Since 6.5
# define Q_UNREACHABLE_RETURN(...) \
do { \
Q_UNREACHABLE(); \
return __VA_ARGS__; \
} while (false)
#endif
#ifndef FRAMELESSHELPER_BYTEARRAY_CONSTANT2 #ifndef FRAMELESSHELPER_BYTEARRAY_CONSTANT2
# define FRAMELESSHELPER_BYTEARRAY_CONSTANT2(name, ba) \ # define FRAMELESSHELPER_BYTEARRAY_CONSTANT2(name, ba) \
[[maybe_unused]] static const auto k##name = FRAMELESSHELPER_BYTEARRAY_LITERAL(ba); [[maybe_unused]] static const auto k##name = FRAMELESSHELPER_BYTEARRAY_LITERAL(ba);

View File

@ -206,8 +206,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper)
if (data.params.isInsideSystemButtons(qtScenePos, &buttonType)) { if (data.params.isInsideSystemButtons(qtScenePos, &buttonType)) {
switch (buttonType) { switch (buttonType) {
case SystemButtonType::Unknown: case SystemButtonType::Unknown:
Q_ASSERT(false); Q_UNREACHABLE_RETURN(HTNOWHERE);
break;
case SystemButtonType::WindowIcon: case SystemButtonType::WindowIcon:
return HTSYSMENU; return HTSYSMENU;
case SystemButtonType::Help: case SystemButtonType::Help:

View File

@ -197,6 +197,10 @@ void initialize()
Utils::fixupDialogsDpiScaling(); Utils::fixupDialogsDpiScaling();
#endif #endif
// We need this flag to enable nested frameless windows, however,
// this flag is known to be __NOT__ compatible with QGLWidget.
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
// Enable high DPI scaling by default, but only for Qt5 applications, // Enable high DPI scaling by default, but only for Qt5 applications,
// because this has become the default setting since Qt6 and it can't // because this has become the default setting since Qt6 and it can't

View File

@ -1681,8 +1681,7 @@ void Utils::setCornerStyleForWindow(const WId windowId, const WindowCornerStyle
case WindowCornerStyle::Round: case WindowCornerStyle::Round:
return _DWMWCP_ROUND; return _DWMWCP_ROUND;
} }
Q_ASSERT(false); Q_UNREACHABLE_RETURN(_DWMWCP_DEFAULT);
return _DWMWCP_DEFAULT;
}(); }();
const HRESULT hr = API_CALL_FUNCTION(DwmSetWindowAttribute, const HRESULT hr = API_CALL_FUNCTION(DwmSetWindowAttribute,
hwnd, _DWMWA_WINDOW_CORNER_PREFERENCE, &wcp, sizeof(wcp)); hwnd, _DWMWA_WINDOW_CORNER_PREFERENCE, &wcp, sizeof(wcp));
@ -1739,8 +1738,7 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
} }
return BlurMode::Windows_Aero; return BlurMode::Windows_Aero;
} }
Q_ASSERT(false); // Really should NOT go here. Q_UNREACHABLE_RETURN(BlurMode::Default);
return mode;
}(); }();
if (blurMode == BlurMode::Disable) { if (blurMode == BlurMode::Disable) {
bool result = true; bool result = true;
@ -1849,7 +1847,7 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
} else if (blurMode == BlurMode::Windows_Aero) { } else if (blurMode == BlurMode::Windows_Aero) {
policy.State = ACCENT_ENABLE_BLURBEHIND; policy.State = ACCENT_ENABLE_BLURBEHIND;
} else { } else {
Q_ASSERT(false); // Really should NOT go here. Q_UNREACHABLE_RETURN(false);
} }
WINDOWCOMPOSITIONATTRIBDATA wcad; WINDOWCOMPOSITIONATTRIBDATA wcad;
SecureZeroMemory(&wcad, sizeof(wcad)); SecureZeroMemory(&wcad, sizeof(wcad));

View File

@ -275,8 +275,7 @@ void FramelessQuickHelperPrivate::setSystemButton(QQuickItem *item, const QuickG
} }
switch (buttonType) { switch (buttonType) {
case QuickGlobal::SystemButtonType::Unknown: case QuickGlobal::SystemButtonType::Unknown:
Q_ASSERT(false); Q_UNREACHABLE_RETURN(static_cast<void>(0));
break;
case QuickGlobal::SystemButtonType::WindowIcon: case QuickGlobal::SystemButtonType::WindowIcon:
data->windowIconButton = item; data->windowIconButton = item;
break; break;
@ -800,8 +799,7 @@ void FramelessQuickHelperPrivate::setSystemButtonState(const QuickGlobal::System
QQuickAbstractButton *quickButton = nullptr; QQuickAbstractButton *quickButton = nullptr;
switch (button) { switch (button) {
case QuickGlobal::SystemButtonType::Unknown: case QuickGlobal::SystemButtonType::Unknown:
Q_ASSERT(false); Q_UNREACHABLE_RETURN(void(0));
break;
case QuickGlobal::SystemButtonType::WindowIcon: case QuickGlobal::SystemButtonType::WindowIcon:
if (data.windowIconButton) { if (data.windowIconButton) {
if (const auto btn = qobject_cast<QQuickAbstractButton *>(data.windowIconButton)) { if (const auto btn = qobject_cast<QQuickAbstractButton *>(data.windowIconButton)) {

View File

@ -689,8 +689,7 @@ void FramelessWidgetsHelperPrivate::setSystemButtonState(const SystemButtonType
QWidget *widgetButton = nullptr; QWidget *widgetButton = nullptr;
switch (button) { switch (button) {
case SystemButtonType::Unknown: case SystemButtonType::Unknown:
Q_ASSERT(false); Q_UNREACHABLE_RETURN(void(0));
break;
case SystemButtonType::WindowIcon: case SystemButtonType::WindowIcon:
if (data.windowIconButton) { if (data.windowIconButton) {
widgetButton = data.windowIconButton; widgetButton = data.windowIconButton;
@ -843,8 +842,7 @@ void FramelessWidgetsHelperPrivate::setSystemButton(QWidget *widget, const Syste
} }
switch (buttonType) { switch (buttonType) {
case SystemButtonType::Unknown: case SystemButtonType::Unknown:
Q_ASSERT(false); Q_UNREACHABLE_RETURN(void(0));
break;
case SystemButtonType::WindowIcon: case SystemButtonType::WindowIcon:
data->windowIconButton = widget; data->windowIconButton = widget;
break; break;