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
#if defined(Q_OS_WIN) && !defined(Q_OS_WINDOWS)
# define Q_OS_WINDOWS
# define Q_OS_WINDOWS // Since 5.14
#endif
#ifndef Q_DISABLE_COPY_MOVE
#ifndef Q_DISABLE_COPY_MOVE // Since 5.13
# define Q_DISABLE_COPY_MOVE(Class) \
Q_DISABLE_COPY(Class) \
Class(Class &&) = delete; \
@ -68,8 +68,6 @@ QT_END_NAMESPACE
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
using QStringView = const QString &;
#else
# include <QtCore/qstringview.h>
#endif
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
@ -77,6 +75,7 @@ QT_END_NAMESPACE
# define Q_NAMESPACE_EXPORT(...) Q_NAMESPACE
#endif
// MOC can't handle C++ attributes before 5.15.
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
# define Q_NODISCARD [[nodiscard]]
# define Q_MAYBE_UNUSED [[maybe_unused]]
@ -108,7 +107,7 @@ QT_END_NAMESPACE
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0))
using namespace Qt::StringLiterals;
using namespace Qt::Literals::StringLiterals;
#endif
#ifndef FRAMELESSHELPER_BYTEARRAY_LITERAL
@ -131,6 +130,14 @@ QT_END_NAMESPACE
# 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
# define FRAMELESSHELPER_BYTEARRAY_CONSTANT2(name, 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)) {
switch (buttonType) {
case SystemButtonType::Unknown:
Q_ASSERT(false);
break;
Q_UNREACHABLE_RETURN(HTNOWHERE);
case SystemButtonType::WindowIcon:
return HTSYSMENU;
case SystemButtonType::Help:

View File

@ -197,6 +197,10 @@ void initialize()
Utils::fixupDialogsDpiScaling();
#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))
// Enable high DPI scaling by default, but only for Qt5 applications,
// 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:
return _DWMWCP_ROUND;
}
Q_ASSERT(false);
return _DWMWCP_DEFAULT;
Q_UNREACHABLE_RETURN(_DWMWCP_DEFAULT);
}();
const HRESULT hr = API_CALL_FUNCTION(DwmSetWindowAttribute,
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;
}
Q_ASSERT(false); // Really should NOT go here.
return mode;
Q_UNREACHABLE_RETURN(BlurMode::Default);
}();
if (blurMode == BlurMode::Disable) {
bool result = true;
@ -1849,7 +1847,7 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
} else if (blurMode == BlurMode::Windows_Aero) {
policy.State = ACCENT_ENABLE_BLURBEHIND;
} else {
Q_ASSERT(false); // Really should NOT go here.
Q_UNREACHABLE_RETURN(false);
}
WINDOWCOMPOSITIONATTRIBDATA wcad;
SecureZeroMemory(&wcad, sizeof(wcad));

View File

@ -275,8 +275,7 @@ void FramelessQuickHelperPrivate::setSystemButton(QQuickItem *item, const QuickG
}
switch (buttonType) {
case QuickGlobal::SystemButtonType::Unknown:
Q_ASSERT(false);
break;
Q_UNREACHABLE_RETURN(static_cast<void>(0));
case QuickGlobal::SystemButtonType::WindowIcon:
data->windowIconButton = item;
break;
@ -800,8 +799,7 @@ void FramelessQuickHelperPrivate::setSystemButtonState(const QuickGlobal::System
QQuickAbstractButton *quickButton = nullptr;
switch (button) {
case QuickGlobal::SystemButtonType::Unknown:
Q_ASSERT(false);
break;
Q_UNREACHABLE_RETURN(void(0));
case QuickGlobal::SystemButtonType::WindowIcon:
if (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;
switch (button) {
case SystemButtonType::Unknown:
Q_ASSERT(false);
break;
Q_UNREACHABLE_RETURN(void(0));
case SystemButtonType::WindowIcon:
if (data.windowIconButton) {
widgetButton = data.windowIconButton;
@ -843,8 +842,7 @@ void FramelessWidgetsHelperPrivate::setSystemButton(QWidget *widget, const Syste
}
switch (buttonType) {
case SystemButtonType::Unknown:
Q_ASSERT(false);
break;
Q_UNREACHABLE_RETURN(void(0));
case SystemButtonType::WindowIcon:
data->windowIconButton = widget;
break;