good enough methinks

This commit is contained in:
Mars 2025-02-01 15:32:28 -05:00
parent bf449d91fc
commit 5b63fe4cce
4 changed files with 109 additions and 4 deletions

View file

@ -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,

View file

@ -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(

View file

@ -1,6 +1,5 @@
#ifdef __WIN32__
#include <exception>
#include <iostream>
#include <windows.h>
#include <winrt/Windows.Foundation.h>
@ -8,6 +7,14 @@
#include <winrt/base.h>
#include <winrt/impl/Windows.Media.Control.2.h>
// clang-format off
#include <dwmapi.h>
#include <tlhelp32.h>
#include <algorithm>
#include <vector>
#include <cstring>
// 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<string> {
std::vector<string> 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<string>& 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<string> 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

View file

@ -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