Skip to content

Commit

Permalink
Improved dock detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordonbc committed Jan 16, 2024
1 parent 545815f commit ea7042c
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 35 deletions.
22 changes: 17 additions & 5 deletions HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion HarmonyLinkLib/src/Platform/IPlatformUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 13 additions & 1 deletion HarmonyLinkLib/src/Platform/Unix/UnixUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
6 changes: 5 additions & 1 deletion HarmonyLinkLib/src/Platform/Unix/UnixUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
73 changes: 47 additions & 26 deletions HarmonyLinkLib/src/Platform/Windows/WindowsUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma comment(lib, "XInput.lib")

#include "Platform/WineUtilities.h"
#include <algorithm>

namespace HarmonyLinkLib
{
Expand Down Expand Up @@ -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));

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;
std::vector<RAWINPUTDEVICELIST> devices;

GetRawInputDeviceList(devices.data(), &n_devices, sizeof(RAWINPUTDEVICELIST));

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()
Expand All @@ -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;
}
}
6 changes: 5 additions & 1 deletion HarmonyLinkLib/src/Platform/Windows/WindowsUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
6 changes: 6 additions & 0 deletions HarmonyLinkTest/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit ea7042c

Please sign in to comment.