Add initial score-based dock detection
This is early development & untested code specifically targeting the steam deck for now until further finalised
This commit is contained in:
parent
470f4a318f
commit
545815fd6d
8 changed files with 336 additions and 150 deletions
|
@ -17,79 +17,140 @@
|
|||
#include <sstream>
|
||||
#include <Windows.h>
|
||||
|
||||
#include <XInput.h>
|
||||
#pragma comment(lib, "XInput.lib")
|
||||
|
||||
#include "Platform/WineUtilities.h"
|
||||
|
||||
namespace HarmonyLinkLib
|
||||
{
|
||||
std::shared_ptr<FBattery> WindowsUtilities::get_battery_status()
|
||||
{
|
||||
if (is_linux())
|
||||
{
|
||||
return WineUtilities::get_battery_status();
|
||||
}
|
||||
FBattery result;
|
||||
|
||||
SYSTEM_POWER_STATUS status;
|
||||
if (GetSystemPowerStatus(&status)) {
|
||||
result.has_battery = status.BatteryFlag != 128; // 128 indicates no battery
|
||||
result.is_connected_to_ac = status.ACLineStatus == 1;
|
||||
result.battery_percent = result.has_battery ? status.BatteryLifePercent : 0;
|
||||
} else {
|
||||
std::wcout << "Failed to get power statistics.\n";
|
||||
}
|
||||
|
||||
return std::make_shared<FBattery>(result);
|
||||
}
|
||||
|
||||
std::shared_ptr<FCPUInfo> WindowsUtilities::get_cpu_info()
|
||||
{
|
||||
if (is_linux())
|
||||
{
|
||||
return WineUtilities::get_cpu_info();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<FOSVerInfo> WindowsUtilities::get_os_version()
|
||||
{
|
||||
if (is_linux())
|
||||
{
|
||||
return WineUtilities::get_linux_info();
|
||||
}
|
||||
|
||||
OSVERSIONINFOEX os_version_info;
|
||||
ZeroMemory(&os_version_info, sizeof(OSVERSIONINFOEX));
|
||||
os_version_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
||||
|
||||
if (!GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&os_version_info))) {
|
||||
// Handle error if needed
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FOSVerInfo os_version;
|
||||
|
||||
HKEY h_key;
|
||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), 0, KEY_READ, &h_key) == ERROR_SUCCESS)
|
||||
{
|
||||
DWORD dw_size;
|
||||
DWORD dw_type;
|
||||
char sz_product_name[256];
|
||||
dw_size = sizeof(sz_product_name);
|
||||
if (RegQueryValueEx(h_key, TEXT("ProductName"), nullptr, &dw_type, reinterpret_cast<LPBYTE>(sz_product_name), &dw_size) == ERROR_SUCCESS)
|
||||
if (is_linux())
|
||||
{
|
||||
os_version.pretty_name = sz_product_name;
|
||||
return WineUtilities::get_battery_status();
|
||||
}
|
||||
RegCloseKey(h_key);
|
||||
FBattery result;
|
||||
|
||||
SYSTEM_POWER_STATUS status;
|
||||
if (GetSystemPowerStatus(&status)) {
|
||||
result.has_battery = status.BatteryFlag != 128; // 128 indicates no battery
|
||||
result.is_connected_to_ac = status.ACLineStatus == 1;
|
||||
result.battery_percent = result.has_battery ? status.BatteryLifePercent : 0;
|
||||
} else {
|
||||
std::wcout << "Failed to get power statistics.\n";
|
||||
}
|
||||
|
||||
return std::make_shared<FBattery>(result);
|
||||
}
|
||||
|
||||
std::stringstream version;
|
||||
version << os_version_info.dwMajorVersion << "." << os_version_info.dwMinorVersion;
|
||||
os_version.version_id = version.str();
|
||||
std::shared_ptr<FCPUInfo> WindowsUtilities::get_cpu_info()
|
||||
{
|
||||
if (is_linux())
|
||||
{
|
||||
return WineUtilities::get_cpu_info();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
os_version.name = "Windows";
|
||||
os_version.version = os_version_info.dwBuildNumber; // Build number as the version
|
||||
std::shared_ptr<FOSVerInfo> WindowsUtilities::get_os_version()
|
||||
{
|
||||
if (is_linux())
|
||||
{
|
||||
return WineUtilities::get_linux_info();
|
||||
}
|
||||
|
||||
OSVERSIONINFOEX os_version_info;
|
||||
ZeroMemory(&os_version_info, sizeof(OSVERSIONINFOEX));
|
||||
os_version_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
||||
|
||||
return std::make_shared<FOSVerInfo>(os_version);
|
||||
}
|
||||
if (!GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&os_version_info))) {
|
||||
// Handle error if needed
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FOSVerInfo os_version;
|
||||
|
||||
HKEY h_key;
|
||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), 0, KEY_READ, &h_key) == ERROR_SUCCESS)
|
||||
{
|
||||
DWORD dw_size;
|
||||
DWORD dw_type;
|
||||
char sz_product_name[256];
|
||||
dw_size = sizeof(sz_product_name);
|
||||
if (RegQueryValueEx(h_key, TEXT("ProductName"), nullptr, &dw_type, reinterpret_cast<LPBYTE>(sz_product_name), &dw_size) == ERROR_SUCCESS)
|
||||
{
|
||||
os_version.pretty_name = sz_product_name;
|
||||
}
|
||||
RegCloseKey(h_key);
|
||||
}
|
||||
|
||||
std::stringstream version;
|
||||
version << os_version_info.dwMajorVersion << "." << os_version_info.dwMinorVersion;
|
||||
os_version.version_id = version.str();
|
||||
|
||||
os_version.name = "Windows";
|
||||
os_version.version = os_version_info.dwBuildNumber; // Build number as the version
|
||||
|
||||
return std::make_shared<FOSVerInfo>(os_version);
|
||||
}
|
||||
|
||||
bool WindowsUtilities::get_is_external_monitor_connected()
|
||||
{
|
||||
// SM_CMONITORS returns the count of all display monitors.
|
||||
const int monitorCount = GetSystemMetrics(SM_CMONITORS);
|
||||
|
||||
// More than one monitor implies an external monitor is connected.
|
||||
return monitorCount > 1;
|
||||
}
|
||||
|
||||
bool WindowsUtilities::get_mouse_keyboard_detected()
|
||||
{
|
||||
UINT n_devices;
|
||||
GetRawInputDeviceList(nullptr, &n_devices, sizeof(RAWINPUTDEVICELIST));
|
||||
|
||||
if (n_devices > 0) {
|
||||
bool mouse_detected = false;
|
||||
bool keyboard_detected = false;
|
||||
|
||||
std::vector<RAWINPUTDEVICELIST> devices(n_devices);
|
||||
GetRawInputDeviceList(devices.data(), &n_devices, sizeof(RAWINPUTDEVICELIST));
|
||||
|
||||
for (const auto& device : devices) {
|
||||
switch (device.dwType)
|
||||
{
|
||||
case RIM_TYPEMOUSE:
|
||||
mouse_detected = true;
|
||||
break;
|
||||
case RIM_TYPEKEYBOARD:
|
||||
keyboard_detected = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return mouse_detected && keyboard_detected;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WindowsUtilities::get_external_controller_detected()
|
||||
{
|
||||
static_assert(XUSER_MAX_COUNT <= UINT8_MAX, "XUSER_MAX_COUNT exceeds uint8_t size");
|
||||
|
||||
uint8_t connectedGamepads = 0;
|
||||
|
||||
for (DWORD i = 0; i < XUSER_MAX_COUNT; ++i) {
|
||||
XINPUT_STATE state;
|
||||
ZeroMemory(&state, sizeof(XINPUT_STATE));
|
||||
|
||||
if (XInputGetState(i, &state) == ERROR_SUCCESS) {
|
||||
connectedGamepads++;
|
||||
}
|
||||
}
|
||||
|
||||
return connectedGamepads > 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue