Improved dock detection

This commit is contained in:
Jordon Brooks 2024-01-16 02:04:22 +00:00
parent 545815fd6d
commit ea7042c9ad
No known key found for this signature in database
GPG key ID: 83964894E5D98D57
7 changed files with 95 additions and 34 deletions

View file

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

View file

@ -43,8 +43,10 @@ namespace HarmonyLinkLib
virtual std::shared_ptr<FBattery> get_battery_status() = 0;
virtual std::shared_ptr<FOSVerInfo> 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;

View file

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

View file

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

View file

@ -21,6 +21,7 @@
#pragma comment(lib, "XInput.lib")
#include "Platform/WineUtilities.h"
#include <algorithm>
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<RAWINPUTDEVICELIST> devices;
GetRawInputDeviceList(devices.data(), &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;
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<RAWINPUTDEVICELIST> 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;
}
}

View file

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