From 768ab6da4bf4a727a83000ef2ef6a139411cc679 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Mon, 19 Dec 2022 17:39:36 +0800 Subject: [PATCH] win: fix the border color, take 2 Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- .github/workflows/ci.yml | 5 ----- src/core/utils_win.cpp | 28 +++++++++++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf3dddf..87af0c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,11 +56,6 @@ jobs: if: ${{ matrix.platform == 'windows-latest' }} uses: ilammy/msvc-dev-cmd@v1 - - name: Install Linux dependencies - if: ${{ matrix.platform == 'ubuntu-latest' }} - run: | - sudo apt install -y libxcb1-dev libgtk-3-dev - - name: Build library with CMake run: | mkdir ci-test-build diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index b295b90..9971f59 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -718,8 +718,11 @@ QColor Utils::getDwmColorizationColor() if (!registry.isValid()) { return kDefaultDarkGrayColor; } - const DWORD value = registry.value(kColorizationColor).value_or(0); - return QColor::fromRgba(value); + const QVariant value = registry.value(kColorizationColor); + if (!value.isValid()) { + return kDefaultDarkGrayColor; + } + return QColor::fromRgba(qvariant_cast(value)); }; if (!API_DWM_AVAILABLE(DwmGetColorizationColor)) { return resultFromRegistry(); @@ -1229,10 +1232,14 @@ QColor Utils::getFrameBorderColor(const bool active) if (!WindowsVersionHelper::isWin10OrGreater()) { return (active ? kDefaultBlackColor : kDefaultDarkGrayColor); } + const bool dark = shouldAppsUseDarkMode(); if (active) { - return (isFrameBorderColorized() ? getDwmColorizationColor() : kDefaultTransparentColor); + if (isFrameBorderColorized()) { + return getDwmAccentColor(); + } + return (dark ? kDefaultFrameBorderActiveColor : kDefaultTransparentColor); } else { - return (shouldAppsUseDarkMode() ? kDefaultFrameBorderInactiveColorDark : kDefaultFrameBorderInactiveColorLight); + return (dark ? kDefaultFrameBorderInactiveColorDark : kDefaultFrameBorderInactiveColorLight); } } @@ -1901,14 +1908,21 @@ QColor Utils::getDwmAccentColor() // so we'd better also do the same thing. // There's no Windows API to get this value, so we can only read it // directly from the registry. + const QColor alternative = getDwmColorizationColor(); const RegistryKey registry(RegistryRootKey::CurrentUser, dwmRegistryKey()); if (!registry.isValid()) { - return kDefaultDarkGrayColor; + return alternative; + } + const QVariant value = registry.value(kAccentColor); + if (!value.isValid()) { + return alternative; } - const DWORD value = registry.value(kAccentColor).value_or(0); // The retrieved value is in the #AABBGGRR format, we need to // convert it to the #AARRGGBB format that Qt accepts. - const QColor abgr = QColor::fromRgba(value); + const QColor abgr = QColor::fromRgba(qvariant_cast(value)); + if (!abgr.isValid()) { + return alternative; + } return QColor(abgr.blue(), abgr.green(), abgr.red(), abgr.alpha()); }