From 42e73547eb9135ca9a93399e7300f49a5a0620f1 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Tue, 11 Jun 2024 19:13:54 -0500 Subject: [PATCH] ControllerInterface: Adjust sort priorities to ensure default keyboard-mouse device is first. --- Source/Core/InputCommon/ControllerInterface/CoreDevice.h | 2 ++ .../ControllerInterface/DInput/DInputKeyboardMouse.cpp | 2 +- .../ControllerInterface/Quartz/QuartzKeyboardAndMouse.h | 1 + .../ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm | 5 +++++ Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp | 5 +++++ Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h | 1 + 6 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Source/Core/InputCommon/ControllerInterface/CoreDevice.h b/Source/Core/InputCommon/ControllerInterface/CoreDevice.h index 5c7a8ed568..8dbbccf4b5 100644 --- a/Source/Core/InputCommon/ControllerInterface/CoreDevice.h +++ b/Source/Core/InputCommon/ControllerInterface/CoreDevice.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include #include #include @@ -147,6 +148,7 @@ public: // A higher priority means it will be one of the first ones (smaller index), making it more // likely to be index 0, which is automatically set as the default device when there isn't one. // Every platform should have at least one device with priority >= 0. + static constexpr int DEFAULT_DEVICE_SORT_PRIORITY = std::numeric_limits::max(); virtual int GetSortPriority() const { return 0; } const std::vector& Inputs() const { return m_inputs; } diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 3c6a82dcd8..ac6406509b 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -271,7 +271,7 @@ std::string KeyboardMouse::GetSource() const // Give this device a higher priority to make sure it shows first int KeyboardMouse::GetSortPriority() const { - return 5; + return DEFAULT_DEVICE_SORT_PRIORITY; } bool KeyboardMouse::IsVirtualDevice() const diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h index 07292f9039..7f526a07dd 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.h @@ -69,6 +69,7 @@ public: std::string GetName() const override; std::string GetSource() const override; + int GetSortPriority() const override; private: void MainThreadInitialization(void* view); diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm index 55f212900d..f36cc86245 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm @@ -283,6 +283,11 @@ std::string KeyboardAndMouse::GetSource() const return Quartz::GetSourceName(); } +int KeyboardAndMouse::GetSortPriority() const +{ + return DEFAULT_DEVICE_SORT_PRIORITY; +} + ControlState KeyboardAndMouse::Cursor::GetState() const { return std::max(0.0, ControlState(m_axis) / (m_positive ? 1.0 : -1.0)); diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp index e4b717e3af..383dd66f1c 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp @@ -414,6 +414,11 @@ std::string KeyboardMouse::GetSource() const return std::string(SOURCE_NAME); } +int KeyboardMouse::GetSortPriority() const +{ + return DEFAULT_DEVICE_SORT_PRIORITY; +} + KeyboardMouse::Key::Key(Display* const display, KeyCode keycode, const char* keyboard) : m_display(display), m_keyboard(keyboard), m_keycode(keycode) { diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h index 427c81b18a..f6fc108e10 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.h @@ -120,6 +120,7 @@ public: std::string GetName() const override; std::string GetSource() const override; + int GetSortPriority() const override; private: Window m_window;