Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use QOperatingSystemVersion #567

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ui/darkthemeapplier_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <QApplication>
#include <QGuiApplication>
#include <QOperatingSystemVersion>
#include <QPalette>
#include <QToolTip>
#include <QStyle>
Expand Down Expand Up @@ -90,7 +91,7 @@ namespace tremotesf {
}

void applyDarkThemeToTitleBar(QWindow* window) {
if (isRunningOnWindows11OrGreater()) {
if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows11) {
debug().log("Setting DWMWA_CAPTION_COLOR on {}", *window);
const auto qcolor = QGuiApplication::palette().color(QPalette::Window);
const auto color = RGB(qcolor.red(), qcolor.green(), qcolor.blue());
Expand All @@ -110,7 +111,7 @@ namespace tremotesf {
} else {
debug().log("Setting DWMWA_USE_IMMERSIVE_DARK_MODE on {}", *window);
const auto attribute = []() -> DWORD {
if (isRunningOnWindows10_2004OrGreater()) {
if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10_2004) {
return DWMWINDOWATTRIBUTE_compat::DWMWA_USE_IMMERSIVE_DARK_MODE_SINCE_2004;
}
return DWMWINDOWATTRIBUTE_compat::DWMWA_USE_IMMERSIVE_DARK_MODE_1809_UNTIL_2004;
Expand Down
38 changes: 0 additions & 38 deletions src/windowshelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,6 @@

namespace tremotesf {
namespace {
bool isWindowsVersionOrGreater(DWORD major, DWORD minor, DWORD build) {
debug().log(
"isWindowsVersionOrGreater() called with: major = {}, minor = {}, build = {}",
major,
minor,
build
);
OSVERSIONINFOEXW info{};
info.dwOSVersionInfoSize = sizeof(info);
info.dwMajorVersion = major;
info.dwMinorVersion = minor;
info.dwBuildNumber = build;
const auto conditionMask = VerSetConditionMask(
VerSetConditionMask(
VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL),
VER_MINORVERSION,
VER_GREATER_EQUAL
),
VER_BUILDNUMBER,
VER_GREATER_EQUAL
);
const auto ret =
VerifyVersionInfoW(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER, conditionMask) !=
FALSE;
debug().log("isWindowsVersionOrGreater: returning {}", ret);
return ret;
}

/**
* @brief std::error_category for Win32 errors (returned by GetLastError())
* Returns UTF-8 strings
Expand Down Expand Up @@ -78,16 +50,6 @@ namespace tremotesf {
};
}

bool isRunningOnWindows10_2004OrGreater() {
static const bool is = isWindowsVersionOrGreater(10, 0, 19041);
return is;
}

bool isRunningOnWindows11OrGreater() {
static const bool is = isWindowsVersionOrGreater(10, 0, 22000);
return is;
}

void checkWin32Bool(int win32BoolResult, std::string_view functionName) {
if (win32BoolResult != FALSE) return;
// Don't use winrt::check_bool because it doesn't preserve Win32 error code
Expand Down
3 changes: 0 additions & 3 deletions src/windowshelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include <QString>

namespace tremotesf {
bool isRunningOnWindows10_2004OrGreater();
bool isRunningOnWindows11OrGreater();

/**
* @brief checkWin32Bool
* @param win32BoolResult BOOL returned from Win32 function
Expand Down
Loading