diff --git a/HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp b/HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp index 8c53695..e5ff858 100644 --- a/HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp +++ b/HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp @@ -76,10 +76,12 @@ namespace HarmonyLinkLib bool IPlatformUtilities::is_docked() { static constexpr uint8_t CHARGING_SCORE = 3; - static constexpr uint8_t EXTERNAL_MONITOR_SCORE = 3; - static constexpr uint8_t KEYBOARD_DETECTION_SCORE = 2; - static constexpr uint8_t CONTROLLER_DETECTION_SCORE = 2; - static constexpr uint8_t FINAL_TARGET_DETECTION_SCORE = 6; + static constexpr uint8_t EXTERNAL_MONITOR_SCORE = 4; + static constexpr uint8_t STEAM_DECK_RESOLUTION_SCORE = 3; + static constexpr uint8_t KEYBOARD_DETECTION_SCORE = 1; + static constexpr uint8_t MOUSE_DETECTION_SCORE = 2; + static constexpr uint8_t CONTROLLER_DETECTION_SCORE = 3; + static constexpr uint8_t FINAL_TARGET_DETECTION_SCORE = 9; const std::shared_ptr device = get_device(); @@ -108,11 +110,21 @@ namespace HarmonyLinkLib score += EXTERNAL_MONITOR_SCORE; } - if (get_mouse_keyboard_detected()) + if (get_is_steam_deck_native_resolution()) + { + score += STEAM_DECK_RESOLUTION_SCORE; + } + + if (get_keyboard_detected()) { score += KEYBOARD_DETECTION_SCORE; } + if (get_mouse_detected()) + { + score += MOUSE_DETECTION_SCORE; + } + if (get_external_controller_detected()) { score += CONTROLLER_DETECTION_SCORE; diff --git a/HarmonyLinkLib/src/Platform/IPlatformUtilities.h b/HarmonyLinkLib/src/Platform/IPlatformUtilities.h index 856e1a4..420edef 100644 --- a/HarmonyLinkLib/src/Platform/IPlatformUtilities.h +++ b/HarmonyLinkLib/src/Platform/IPlatformUtilities.h @@ -43,8 +43,10 @@ namespace HarmonyLinkLib virtual std::shared_ptr get_battery_status() = 0; virtual std::shared_ptr get_os_version() = 0; virtual bool get_is_external_monitor_connected() = 0; - virtual bool get_mouse_keyboard_detected() = 0; + virtual bool get_keyboard_detected() = 0; + virtual bool get_mouse_detected() = 0; virtual bool get_external_controller_detected() = 0; + virtual bool get_is_steam_deck_native_resolution() = 0; //virtual bool get_is_ethernet_connected() = 0; //virtual bool get_is_external_input_detected() = 0; diff --git a/HarmonyLinkLib/src/Platform/Unix/UnixUtilities.cpp b/HarmonyLinkLib/src/Platform/Unix/UnixUtilities.cpp index 63fef64..0d3b777 100644 --- a/HarmonyLinkLib/src/Platform/Unix/UnixUtilities.cpp +++ b/HarmonyLinkLib/src/Platform/Unix/UnixUtilities.cpp @@ -46,7 +46,13 @@ namespace HarmonyLinkLib return false; } - bool UnixUtilities::get_mouse_keyboard_detected() + bool UnixUtilities::get_keyboard_detected() + { + std::wcout << "This feature is not supported on unix-based systems yet.\n"; + return false; + } + + bool UnixUtilities::get_mouse_detected() { std::wcout << "This feature is not supported on unix-based systems yet.\n"; return false; @@ -57,4 +63,10 @@ namespace HarmonyLinkLib std::wcout << "This feature is not supported on unix-based systems yet.\n"; return false; } + + bool UnixUtilities::get_is_steam_deck_native_resolution() + { + std::wcout << "This feature is not supported on unix-based systems yet.\n"; + return false; + } } \ No newline at end of file diff --git a/HarmonyLinkLib/src/Platform/Unix/UnixUtilities.h b/HarmonyLinkLib/src/Platform/Unix/UnixUtilities.h index 7e0fd5a..8a06546 100644 --- a/HarmonyLinkLib/src/Platform/Unix/UnixUtilities.h +++ b/HarmonyLinkLib/src/Platform/Unix/UnixUtilities.h @@ -29,9 +29,13 @@ namespace HarmonyLinkLib bool get_is_external_monitor_connected() override; - bool get_mouse_keyboard_detected() override; + bool get_keyboard_detected() override; + + bool get_mouse_detected() override; bool get_external_controller_detected() override; + + bool get_is_steam_deck_native_resolution() override; // Implementation for other Unix/Linux-specific functions }; diff --git a/HarmonyLinkLib/src/Platform/Windows/WindowsUtilities.cpp b/HarmonyLinkLib/src/Platform/Windows/WindowsUtilities.cpp index f363bd8..dfd7aa8 100644 --- a/HarmonyLinkLib/src/Platform/Windows/WindowsUtilities.cpp +++ b/HarmonyLinkLib/src/Platform/Windows/WindowsUtilities.cpp @@ -21,6 +21,7 @@ #pragma comment(lib, "XInput.lib") #include "Platform/WineUtilities.h" +#include namespace HarmonyLinkLib { @@ -105,35 +106,40 @@ namespace HarmonyLinkLib return monitorCount > 1; } - bool WindowsUtilities::get_mouse_keyboard_detected() + bool WindowsUtilities::get_keyboard_detected() { UINT n_devices; - GetRawInputDeviceList(nullptr, &n_devices, sizeof(RAWINPUTDEVICELIST)); + std::vector devices; + + GetRawInputDeviceList(devices.data(), &n_devices, sizeof(RAWINPUTDEVICELIST)); - if (n_devices > 0) { - bool mouse_detected = false; - bool keyboard_detected = false; - - std::vector 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; + if (n_devices == 0) + { + return false; } - return false; + + return std::any_of(devices.begin(), devices.end(), [](const RAWINPUTDEVICELIST& device) + { + return device.dwType == RIM_TYPEKEYBOARD; + }); + } + + bool WindowsUtilities::get_mouse_detected() + { + UINT n_devices; + std::vector devices; + + GetRawInputDeviceList(devices.data(), &n_devices, sizeof(RAWINPUTDEVICELIST)); + + if (n_devices == 0) + { + return false; + } + + return std::any_of(devices.begin(), devices.end(), [](const RAWINPUTDEVICELIST& device) + { + return device.dwType == RIM_TYPEMOUSE; + }); } bool WindowsUtilities::get_external_controller_detected() @@ -153,4 +159,19 @@ namespace HarmonyLinkLib return connectedGamepads > 1; } + + bool WindowsUtilities::get_is_steam_deck_native_resolution() + { + DEVMODE devMode; + devMode.dmSize = sizeof(DEVMODE); + + // Get the current display settings for the primary monitor + if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devMode)) { + // Check if the resolution is higher than 800p (1280x800) + if (devMode.dmPelsWidth > 1280 || devMode.dmPelsHeight > 800) { + return true; + } + } + return false; + } } diff --git a/HarmonyLinkLib/src/Platform/Windows/WindowsUtilities.h b/HarmonyLinkLib/src/Platform/Windows/WindowsUtilities.h index c51eacb..809b204 100644 --- a/HarmonyLinkLib/src/Platform/Windows/WindowsUtilities.h +++ b/HarmonyLinkLib/src/Platform/Windows/WindowsUtilities.h @@ -29,8 +29,12 @@ namespace HarmonyLinkLib bool get_is_external_monitor_connected() override; - bool get_mouse_keyboard_detected() override; + bool get_keyboard_detected() override; + + bool get_mouse_detected() override; bool get_external_controller_detected() override; + + bool get_is_steam_deck_native_resolution() override; }; } diff --git a/HarmonyLinkTest/src/main.cpp b/HarmonyLinkTest/src/main.cpp index 69c0957..e9eaf87 100644 --- a/HarmonyLinkTest/src/main.cpp +++ b/HarmonyLinkTest/src/main.cpp @@ -128,6 +128,12 @@ int main() battery->free(); } + const bool is_docked = HarmonyLinkLib::get_is_docked(); + + const char* dock_check_string = is_docked ? "is" : "isn't"; + + wprintf(L"Device %hs docked\n", dock_check_string); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); }