Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-03-15 14:21:15 +08:00
parent d46ec0c1b6
commit 578458f35d
3 changed files with 10 additions and 10 deletions

View File

@ -66,8 +66,8 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper)
return {qreal(GET_X_LPARAM(lParam)), qreal(GET_Y_LPARAM(lParam))}; return {qreal(GET_X_LPARAM(lParam)), qreal(GET_Y_LPARAM(lParam))};
}; };
const auto getGlobalPosFromKeyboard = [hWnd, winId]() -> QPointF { const auto getGlobalPosFromKeyboard = [hWnd, winId]() -> QPointF {
RECT rect = {}; RECT windowPos = {};
if (GetWindowRect(hWnd, &rect) == FALSE) { if (GetWindowRect(hWnd, &windowPos) == FALSE) {
qWarning() << Utilities::getSystemErrorMessage(QStringLiteral("GetWindowRect")); qWarning() << Utilities::getSystemErrorMessage(QStringLiteral("GetWindowRect"));
return {}; return {};
} }
@ -77,7 +77,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper)
const int titleBarHeight = Utilities::getTitleBarHeight(winId, true); const int titleBarHeight = Utilities::getTitleBarHeight(winId, true);
const int horizontalOffset = ((maxOrFull || !Utilities::isWindowFrameBorderVisible()) ? 0 : frameSizeX); const int horizontalOffset = ((maxOrFull || !Utilities::isWindowFrameBorderVisible()) ? 0 : frameSizeX);
const int verticalOffset = (maxOrFull ? titleBarHeight : (titleBarHeight - frameSizeY)); const int verticalOffset = (maxOrFull ? titleBarHeight : (titleBarHeight - frameSizeY));
return {qreal(rect.left + horizontalOffset), qreal(rect.top + verticalOffset)}; return {qreal(windowPos.left + horizontalOffset), qreal(windowPos.top + verticalOffset)};
}; };
bool shouldShowSystemMenu = false; bool shouldShowSystemMenu = false;
QPointF globalPos = {}; QPointF globalPos = {};

View File

@ -132,7 +132,9 @@
[[maybe_unused]] static const QString kDwmRegistryKey = QStringLiteral(R"(Software\Microsoft\Windows\DWM)"); [[maybe_unused]] static const QString kDwmRegistryKey = QStringLiteral(R"(Software\Microsoft\Windows\DWM)");
[[maybe_unused]] static const QString kPersonalizeRegistryKey = QStringLiteral(R"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)"); [[maybe_unused]] static const QString kPersonalizeRegistryKey = QStringLiteral(R"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)");
[[maybe_unused]] static const QString kThemeSettingChangeEventName = QStringLiteral("ImmersiveColorSet"); [[maybe_unused]] static const QString kThemeSettingChangeEventName = QStringLiteral("ImmersiveColorSet");
[[maybe_unused]] static const QString kDwmColorKeyName = QStringLiteral("ColorPrevalence");
[[maybe_unused]] static constexpr const DWORD _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19; [[maybe_unused]] static constexpr const DWORD _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19;
[[maybe_unused]] static constexpr const DWORD _DWMWA_USE_IMMERSIVE_DARK_MODE = 20; [[maybe_unused]] static constexpr const DWORD _DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
[[maybe_unused]] static constexpr const DWORD _DWMWA_WINDOW_CORNER_PREFERENCE = 33;
[[maybe_unused]] static constexpr const DWORD _DWMWA_VISIBLE_FRAME_BORDER_THICKNESS = 37; [[maybe_unused]] static constexpr const DWORD _DWMWA_VISIBLE_FRAME_BORDER_THICKNESS = 37;

View File

@ -369,11 +369,10 @@ DwmColorizationArea Utilities::getDwmColorizationArea()
if (!isWin10OrGreater()) { if (!isWin10OrGreater()) {
return DwmColorizationArea::None; return DwmColorizationArea::None;
} }
const QString keyName = QStringLiteral("ColorPrevalence");
const QWinRegistryKey themeRegistry(HKEY_CURRENT_USER, kPersonalizeRegistryKey); const QWinRegistryKey themeRegistry(HKEY_CURRENT_USER, kPersonalizeRegistryKey);
const auto themeValue = themeRegistry.dwordValue(keyName); const auto themeValue = themeRegistry.dwordValue(kDwmColorKeyName);
const QWinRegistryKey dwmRegistry(HKEY_CURRENT_USER, kDwmRegistryKey); const QWinRegistryKey dwmRegistry(HKEY_CURRENT_USER, kDwmRegistryKey);
const auto dwmValue = dwmRegistry.dwordValue(keyName); const auto dwmValue = dwmRegistry.dwordValue(kDwmColorKeyName);
const bool theme = themeValue.second && (themeValue.first != 0); const bool theme = themeValue.second && (themeValue.first != 0);
const bool dwm = dwmValue.second && (dwmValue.first != 0); const bool dwm = dwmValue.second && (dwmValue.first != 0);
if (theme && dwm) { if (theme && dwm) {
@ -405,9 +404,8 @@ void Utilities::showSystemMenu(const WId winId, const QPointF &pos)
mii.fMask = MIIM_STATE; mii.fMask = MIIM_STATE;
mii.fType = MFT_STRING; mii.fType = MFT_STRING;
const auto setState = [&mii, menu](const UINT item, const bool enabled, const bool highlight) -> bool { const auto setState = [&mii, menu](const UINT item, const bool enabled, const bool highlight) -> bool {
mii.fState = ((enabled ? MFS_ENABLED : MFS_DISABLED) | (highlight ? MFS_HILITE : 0)); mii.fState = ((enabled ? MFS_ENABLED : MFS_DISABLED) | (highlight ? MFS_HILITE : MFS_UNHILITE));
if (SetMenuItemInfoW(menu, item, FALSE, &mii) == FALSE) { if (SetMenuItemInfoW(menu, item, FALSE, &mii) == FALSE) {
Q_ASSERT(false);
qWarning() << getSystemErrorMessage(QStringLiteral("SetMenuItemInfoW")); qWarning() << getSystemErrorMessage(QStringLiteral("SetMenuItemInfoW"));
return false; return false;
} }
@ -437,7 +435,7 @@ void Utilities::showSystemMenu(const WId winId, const QPointF &pos)
return; return;
} }
const QPoint roundedPos = pos.toPoint(); const QPoint roundedPos = pos.toPoint();
const auto ret = TrackPopupMenu(menu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() const int ret = TrackPopupMenu(menu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft()
? TPM_RIGHTALIGN : TPM_LEFTALIGN)), roundedPos.x(), roundedPos.y(), 0, hWnd, nullptr); ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), roundedPos.x(), roundedPos.y(), 0, hWnd, nullptr);
if (ret != 0) { if (ret != 0) {
if (PostMessageW(hWnd, WM_SYSCOMMAND, ret, 0) == FALSE) { if (PostMessageW(hWnd, WM_SYSCOMMAND, ret, 0) == FALSE) {
@ -819,7 +817,7 @@ void Utilities::fixupQtInternals(const WId winId)
qWarning() << getSystemErrorMessage(QStringLiteral("GetWindowLongPtrW")); qWarning() << getSystemErrorMessage(QStringLiteral("GetWindowLongPtrW"));
return; return;
} }
const DWORD newWindowStyle = (oldWindowStyle & ~WS_POPUP) | WS_OVERLAPPED; const DWORD newWindowStyle = ((oldWindowStyle & ~WS_POPUP) | WS_OVERLAPPED);
SetLastError(ERROR_SUCCESS); SetLastError(ERROR_SUCCESS);
if (SetWindowLongPtrW(hwnd, GWL_STYLE, static_cast<LONG_PTR>(newWindowStyle)) == 0) { if (SetWindowLongPtrW(hwnd, GWL_STYLE, static_cast<LONG_PTR>(newWindowStyle)) == 0) {
qWarning() << getSystemErrorMessage(QStringLiteral("SetWindowLongPtrW")); qWarning() << getSystemErrorMessage(QStringLiteral("SetWindowLongPtrW"));