Improved dock detection
This commit is contained in:
parent
545815fd6d
commit
ea7042c9ad
7 changed files with 95 additions and 34 deletions
|
@ -76,10 +76,12 @@ namespace HarmonyLinkLib
|
||||||
bool IPlatformUtilities::is_docked()
|
bool IPlatformUtilities::is_docked()
|
||||||
{
|
{
|
||||||
static constexpr uint8_t CHARGING_SCORE = 3;
|
static constexpr uint8_t CHARGING_SCORE = 3;
|
||||||
static constexpr uint8_t EXTERNAL_MONITOR_SCORE = 3;
|
static constexpr uint8_t EXTERNAL_MONITOR_SCORE = 4;
|
||||||
static constexpr uint8_t KEYBOARD_DETECTION_SCORE = 2;
|
static constexpr uint8_t STEAM_DECK_RESOLUTION_SCORE = 3;
|
||||||
static constexpr uint8_t CONTROLLER_DETECTION_SCORE = 2;
|
static constexpr uint8_t KEYBOARD_DETECTION_SCORE = 1;
|
||||||
static constexpr uint8_t FINAL_TARGET_DETECTION_SCORE = 6;
|
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();
|
const std::shared_ptr<FDevice> device = get_device();
|
||||||
|
@ -108,11 +110,21 @@ namespace HarmonyLinkLib
|
||||||
score += EXTERNAL_MONITOR_SCORE;
|
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;
|
score += KEYBOARD_DETECTION_SCORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (get_mouse_detected())
|
||||||
|
{
|
||||||
|
score += MOUSE_DETECTION_SCORE;
|
||||||
|
}
|
||||||
|
|
||||||
if (get_external_controller_detected())
|
if (get_external_controller_detected())
|
||||||
{
|
{
|
||||||
score += CONTROLLER_DETECTION_SCORE;
|
score += CONTROLLER_DETECTION_SCORE;
|
||||||
|
|
|
@ -43,8 +43,10 @@ namespace HarmonyLinkLib
|
||||||
virtual std::shared_ptr<FBattery> get_battery_status() = 0;
|
virtual std::shared_ptr<FBattery> get_battery_status() = 0;
|
||||||
virtual std::shared_ptr<FOSVerInfo> get_os_version() = 0;
|
virtual std::shared_ptr<FOSVerInfo> get_os_version() = 0;
|
||||||
virtual bool get_is_external_monitor_connected() = 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_external_controller_detected() = 0;
|
||||||
|
virtual bool get_is_steam_deck_native_resolution() = 0;
|
||||||
//virtual bool get_is_ethernet_connected() = 0;
|
//virtual bool get_is_ethernet_connected() = 0;
|
||||||
//virtual bool get_is_external_input_detected() = 0;
|
//virtual bool get_is_external_input_detected() = 0;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,13 @@ namespace HarmonyLinkLib
|
||||||
return false;
|
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";
|
std::wcout << "This feature is not supported on unix-based systems yet.\n";
|
||||||
return false;
|
return false;
|
||||||
|
@ -57,4 +63,10 @@ namespace HarmonyLinkLib
|
||||||
std::wcout << "This feature is not supported on unix-based systems yet.\n";
|
std::wcout << "This feature is not supported on unix-based systems yet.\n";
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -29,9 +29,13 @@ namespace HarmonyLinkLib
|
||||||
|
|
||||||
bool get_is_external_monitor_connected() override;
|
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_external_controller_detected() override;
|
||||||
|
|
||||||
|
bool get_is_steam_deck_native_resolution() override;
|
||||||
|
|
||||||
// Implementation for other Unix/Linux-specific functions
|
// Implementation for other Unix/Linux-specific functions
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#pragma comment(lib, "XInput.lib")
|
#pragma comment(lib, "XInput.lib")
|
||||||
|
|
||||||
#include "Platform/WineUtilities.h"
|
#include "Platform/WineUtilities.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace HarmonyLinkLib
|
namespace HarmonyLinkLib
|
||||||
{
|
{
|
||||||
|
@ -105,35 +106,40 @@ namespace HarmonyLinkLib
|
||||||
return monitorCount > 1;
|
return monitorCount > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowsUtilities::get_mouse_keyboard_detected()
|
bool WindowsUtilities::get_keyboard_detected()
|
||||||
{
|
{
|
||||||
UINT n_devices;
|
UINT n_devices;
|
||||||
GetRawInputDeviceList(nullptr, &n_devices, sizeof(RAWINPUTDEVICELIST));
|
std::vector<RAWINPUTDEVICELIST> devices;
|
||||||
|
|
||||||
|
GetRawInputDeviceList(devices.data(), &n_devices, sizeof(RAWINPUTDEVICELIST));
|
||||||
|
|
||||||
if (n_devices > 0) {
|
if (n_devices == 0)
|
||||||
bool mouse_detected = false;
|
{
|
||||||
bool keyboard_detected = false;
|
return 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;
|
|
||||||
|
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()
|
bool WindowsUtilities::get_external_controller_detected()
|
||||||
|
@ -153,4 +159,19 @@ namespace HarmonyLinkLib
|
||||||
|
|
||||||
return connectedGamepads > 1;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,12 @@ namespace HarmonyLinkLib
|
||||||
|
|
||||||
bool get_is_external_monitor_connected() override;
|
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_external_controller_detected() override;
|
||||||
|
|
||||||
|
bool get_is_steam_deck_native_resolution() override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,6 +128,12 @@ int main()
|
||||||
battery->free();
|
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));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue