Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Jan 19, 2025
1 parent d7cc987 commit 0984dc0
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 91 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
cd docs
npm install
npm run docs:build
cp index.html .vitepress/dist
cd ..
- uses: actions/upload-pages-artifact@v3
with:
Expand Down
5 changes: 2 additions & 3 deletions cpp/winsharedutils/AreoAcrylic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include <dwmapi.h>

#include "osversion.hpp"
typedef enum _WINDOWCOMPOSITIONATTRIB
{
CA_UNDEFINED = 0,
Expand Down Expand Up @@ -142,12 +142,11 @@ DECLARE_API bool clearEffect(HWND hwnd)
return false;
#endif
}
uint32_t GetOSversion() noexcept;

DECLARE_API bool setbackdropX(HWND hwnd, bool good, bool dark)
{
#ifndef WINXP
if (GetOSversion() <= 6)
if (GetOSVersion().IsWin7or8())
return false;

DWORD corner_ = good ? DWMWCP_ROUND : DWMWCP_DEFAULT;
Expand Down
62 changes: 62 additions & 0 deletions cpp/winsharedutils/osversion.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

struct OSVersion
{
bool Is20H1OrNewer() const noexcept
{
return version.dwBuildNumber >= 19041;
}

// 下面为 Win11
// 不考虑代号相同的 Win10

bool IsWin11() const noexcept
{
return Is21H2OrNewer();
}

bool Is21H2OrNewer() const noexcept
{
return version.dwBuildNumber >= 22000;
}

bool Is22H2OrNewer() const noexcept
{
return version.dwBuildNumber >= 22621;
}
bool IsWin7or8() const noexcept
{
return version.dwMajorVersion <= 6;
}
RTL_OSVERSIONINFOW version;
};
namespace
{
RTL_OSVERSIONINFOW _GetOSversion() noexcept
{
HMODULE hNtDll = GetModuleHandle(L"ntdll.dll");
if (!hNtDll)
{
return {};
}

auto rtlGetVersion = (LONG(WINAPI *)(PRTL_OSVERSIONINFOW))GetProcAddress(hNtDll, "RtlGetVersion");
if (rtlGetVersion == nullptr)
{
// assert(false);
return {};
}

RTL_OSVERSIONINFOW version{};
version.dwOSVersionInfoSize = sizeof(version);
rtlGetVersion(&version);

return version;
}
}
static OSVersion GetOSVersion()
{
{
static OSVersion version = {_GetOSversion()};
return version;
}
}
92 changes: 4 additions & 88 deletions cpp/winsharedutils/theme.cpp
Original file line number Diff line number Diff line change
@@ -1,90 +1,6 @@

// https://github.com/Blinue/Xaml-Islands-Cpp/blob/main/src/XamlIslandsCpp/XamlWindow.h

uint32_t GetOSversion() noexcept
{
HMODULE hNtDll = GetModuleHandle(L"ntdll.dll");
if (!hNtDll)
{
return 0;
}

auto rtlGetVersion = (LONG(WINAPI *)(PRTL_OSVERSIONINFOW))GetProcAddress(hNtDll, "RtlGetVersion");
if (rtlGetVersion == nullptr)
{
// assert(false);
return 0;
}

RTL_OSVERSIONINFOW version{};
version.dwOSVersionInfoSize = sizeof(version);
rtlGetVersion(&version);

return version.dwMajorVersion;
}

static uint32_t GetOSBuild() noexcept
{
HMODULE hNtDll = GetModuleHandle(L"ntdll.dll");
if (!hNtDll)
{
return 0;
}

auto rtlGetVersion = (LONG(WINAPI *)(PRTL_OSVERSIONINFOW))GetProcAddress(hNtDll, "RtlGetVersion");
if (rtlGetVersion == nullptr)
{
// assert(false);
return 0;
}

RTL_OSVERSIONINFOW version{};
version.dwOSVersionInfoSize = sizeof(version);
rtlGetVersion(&version);

return version.dwBuildNumber;
}
struct Win32Helper
{
struct OSVersion
{
constexpr OSVersion(uint32_t build) : _build(build) {}

bool Is20H1OrNewer() const noexcept
{
return _build >= 19041;
}

// 下面为 Win11
// 不考虑代号相同的 Win10

bool IsWin11() const noexcept
{
return Is21H2OrNewer();
}

bool Is21H2OrNewer() const noexcept
{
return _build >= 22000;
}

bool Is22H2OrNewer() const noexcept
{
return _build >= 22621;
}

private:
uint32_t _build = 0;
};

static OSVersion GetOSVersion() noexcept;
};
Win32Helper::OSVersion Win32Helper::GetOSVersion() noexcept
{
static OSVersion version = GetOSBuild();
return version;
}

#include "osversion.hpp"
enum class PreferredAppMode
{
Default,
Expand Down Expand Up @@ -144,7 +60,7 @@ static void SetWindowTheme(HWND hWnd, bool darkBorder, bool darkMenu) noexcept
BOOL value = darkBorder;
DwmSetWindowAttribute(
hWnd,
Win32Helper::GetOSVersion().Is20H1OrNewer() ? DWMWA_USE_IMMERSIVE_DARK_MODE : DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1,
GetOSVersion().Is20H1OrNewer() ? DWMWA_USE_IMMERSIVE_DARK_MODE : DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1,
&value,
sizeof(value));

Expand All @@ -168,7 +84,7 @@ DECLARE_API void _SetTheme(
{
#ifndef WINXP
// printf("%d %d\n",GetOSversion(),GetOSBuild());
if (GetOSversion() <= 6) // win7 x32 DwmSetWindowAttribute会崩,直接禁了反正没用。不知道win8怎么样。
if (GetOSVersion().IsWin7or8()) // win7 x32 DwmSetWindowAttribute会崩,直接禁了反正没用。不知道win8怎么样。
return;

auto value1 = rect ? DWMWCP_DONOTROUND : DWMWCP_DEFAULT;
Expand All @@ -183,7 +99,7 @@ DECLARE_API void _SetTheme(
// Win10 中即使在亮色主题下我们也使用暗色边框,这也是 UWP 窗口的行为
SetWindowTheme(
_hWnd,
Win32Helper::GetOSVersion().IsWin11() ? dark : true,
GetOSVersion().IsWin11() ? dark : true,
dark);

// if (!Win32Helper::GetOSVersion().Is22H2OrNewer())
Expand Down
2 changes: 2 additions & 0 deletions docs/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npm run docs:build
cp index.html .vitepress/dist
12 changes: 12 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>

<head>
<link rel="icon" href="https://image.lunatranslator.org/luna.ico" type="image/x-icon">
<script>
let lang = window.localStorage.currentlang ? window.localStorage.currentlang : browserlang()
window.location.pathname = `/${lang}/`
</script>
</head>

</html>

0 comments on commit 0984dc0

Please sign in to comment.