From 5b63fe4ccec1f681749cc3e8ce546db26fe40d8e Mon Sep 17 00:00:00 2001 From: Mars Date: Sat, 1 Feb 2025 15:32:28 -0500 Subject: [PATCH] good enough methinks --- .clang-tidy | 1 + meson.build | 4 +- src/os/windows.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++- src/util/macros.h | 4 +- 4 files changed, 109 insertions(+), 4 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index f5d7e7a..7648077 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -10,6 +10,7 @@ Checks: > -cert-env33-c, -concurrency-mt-unsafe, -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-macro-usage, -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-type-member-init, -cppcoreguidelines-pro-type-vararg, diff --git a/meson.build b/meson.build index cb8ef88..ca66fc9 100644 --- a/meson.build +++ b/meson.build @@ -104,7 +104,7 @@ if host_machine.system() == 'darwin' objc_args += ['-fobjc-arc'] elif host_machine.system() == 'windows' windows_sdk_lib_dir = 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22621.0/um/x64' - link_args += ['-L' + windows_sdk_lib_dir, '-lwindowsapp', '-static'] + link_args += ['-L' + windows_sdk_lib_dir, '-lwindowsapp', '-ldwmapi', '-static'] endif executable( @@ -113,4 +113,4 @@ executable( objc_args: objc_args, link_args: link_args, dependencies: deps, -) +) \ No newline at end of file diff --git a/src/os/windows.cpp b/src/os/windows.cpp index 9b8b5ec..bfaa619 100644 --- a/src/os/windows.cpp +++ b/src/os/windows.cpp @@ -1,6 +1,5 @@ #ifdef __WIN32__ -#include #include #include #include @@ -8,6 +7,14 @@ #include #include +// clang-format off +#include +#include +#include +#include +#include +// clang-format on + #include "os.h" using RtlGetVersionPtr = NTSTATUS(WINAPI*)(PRTL_OSVERSIONINFOW); @@ -38,6 +45,33 @@ namespace { return value; } + + // Add these function implementations + fn GetRunningProcesses() -> std::vector { + std::vector processes; + HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (hSnapshot == INVALID_HANDLE_VALUE) + return processes; + + PROCESSENTRY32 pe32; + pe32.dwSize = sizeof(PROCESSENTRY32); + + if (!Process32First(hSnapshot, &pe32)) { + CloseHandle(hSnapshot); + return processes; + } + + while (Process32Next(hSnapshot, &pe32)) { processes.emplace_back(pe32.szExeFile); } + + CloseHandle(hSnapshot); + return processes; + } + + fn IsProcessRunning(const std::vector& processes, const string& name) -> bool { + return std::ranges::any_of(processes, [&name](const string& proc) { + return _stricmp(proc.c_str(), name.c_str()) == 0; + }); + } } fn GetMemInfo() -> u64 { @@ -135,4 +169,72 @@ fn GetKernelVersion() -> string { return versionStream.str(); } +fn GetWindowManager() -> string { + const std::vector processes = GetRunningProcesses(); + string windowManager; + + // Check for third-party WMs + if (IsProcessRunning(processes, "glazewm.exe")) { + windowManager = "GlazeWM"; + } else if (IsProcessRunning(processes, "fancywm.exe")) { + windowManager = "FancyWM"; + } else if (IsProcessRunning(processes, "komorebi.exe") || IsProcessRunning(processes, "komorebic.exe")) { + windowManager = "Komorebi"; + } + + // Fallback to DWM detection + if (windowManager.empty()) { + BOOL compositionEnabled = FALSE; + if (SUCCEEDED(DwmIsCompositionEnabled(&compositionEnabled))) { + windowManager = compositionEnabled ? "Desktop Window Manager" : "Windows Manager (Basic)"; + } else { + windowManager = "Windows Manager"; + } + } + + return windowManager; +} + +fn GetDesktopEnvironment() -> string { + // Get version information from registry + const string buildStr = + GetRegistryValue(HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "CurrentBuildNumber"); + + if (buildStr.empty()) + return "Unknown"; + + try { + const i32 build = stoi(buildStr); + + // Windows 11+ (Fluent) + if (build >= 22000) + return "Fluent (Windows 11)"; + + // Windows 10 Fluent Era + if (build >= 15063) + return "Fluent (Windows 10)"; + + // Windows 8.1/10 Metro Era + if (build >= 9200) { // Windows 8+ + // Distinguish between Windows 8 and 10 + const string productName = + GetRegistryValue(HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "ProductName"); + + if (productName.find("Windows 10") != string::npos) + return "Metro (Windows 10)"; + + if (build >= 9600) + return "Metro (Windows 8.1)"; + return "Metro (Windows 8)"; + } + + // Windows 7 Aero + if (build >= 7600) + return "Aero (Windows 7)"; + + // Older versions + return "Classic"; + } catch (...) { return "Unknown"; } +} + #endif diff --git a/src/util/macros.h b/src/util/macros.h index 43f8229..6212a4d 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -57,7 +57,8 @@ void LogImpl(LogLevel level, const std::source_location& loc, fmt::format_string fmt::print("\n"); } -// Minimal macros to capture source_location at call site +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-macros" #ifdef NDEBUG #define DEBUG_LOG(...) (void)0 #else @@ -67,3 +68,4 @@ void LogImpl(LogLevel level, const std::source_location& loc, fmt::format_string #define INFO_LOG(...) LogImpl(LogLevel::INFO, std::source_location::current(), __VA_ARGS__) #define WARN_LOG(...) LogImpl(LogLevel::WARN, std::source_location::current(), __VA_ARGS__) #define ERROR_LOG(...) LogImpl(LogLevel::ERROR, std::source_location::current(), __VA_ARGS__) +#pragma clang diagnostic pop