summaryrefslogtreecommitdiff
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/drivers/joycon.cpp49
-rw-r--r--src/input_common/drivers/joycon.h1
-rw-r--r--src/input_common/drivers/sdl_driver.cpp18
-rw-r--r--src/input_common/helpers/joycon_driver.cpp3
4 files changed, 67 insertions, 4 deletions
diff --git a/src/input_common/drivers/joycon.cpp b/src/input_common/drivers/joycon.cpp
index 4fcfb4510..afc33db57 100644
--- a/src/input_common/drivers/joycon.cpp
+++ b/src/input_common/drivers/joycon.cpp
@@ -16,7 +16,7 @@ namespace InputCommon {
16 16
17Joycons::Joycons(const std::string& input_engine_) : InputEngine(input_engine_) { 17Joycons::Joycons(const std::string& input_engine_) : InputEngine(input_engine_) {
18 // Avoid conflicting with SDL driver 18 // Avoid conflicting with SDL driver
19 if (!Settings::values.enable_joycon_driver) { 19 if (!Settings::values.enable_joycon_driver && !Settings::values.enable_procon_driver) {
20 return; 20 return;
21 } 21 }
22 LOG_INFO(Input, "Joycon driver Initialization started"); 22 LOG_INFO(Input, "Joycon driver Initialization started");
@@ -46,6 +46,12 @@ void Joycons::Reset() {
46 } 46 }
47 device->Stop(); 47 device->Stop();
48 } 48 }
49 for (const auto& device : pro_controller) {
50 if (!device) {
51 continue;
52 }
53 device->Stop();
54 }
49 SDL_hid_exit(); 55 SDL_hid_exit();
50} 56}
51 57
@@ -61,6 +67,11 @@ void Joycons::Setup() {
61 PreSetController(GetIdentifier(port, Joycon::ControllerType::Right)); 67 PreSetController(GetIdentifier(port, Joycon::ControllerType::Right));
62 device = std::make_shared<Joycon::JoyconDriver>(port++); 68 device = std::make_shared<Joycon::JoyconDriver>(port++);
63 } 69 }
70 port = 0;
71 for (auto& device : pro_controller) {
72 PreSetController(GetIdentifier(port, Joycon::ControllerType::Pro));
73 device = std::make_shared<Joycon::JoyconDriver>(port++);
74 }
64 75
65 scan_thread = std::jthread([this](std::stop_token stop_token) { ScanThread(stop_token); }); 76 scan_thread = std::jthread([this](std::stop_token stop_token) { ScanThread(stop_token); });
66} 77}
@@ -116,6 +127,9 @@ bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const {
116 // Check if device already exist 127 // Check if device already exist
117 switch (type) { 128 switch (type) {
118 case Joycon::ControllerType::Left: 129 case Joycon::ControllerType::Left:
130 if (!Settings::values.enable_joycon_driver) {
131 return false;
132 }
119 for (const auto& device : left_joycons) { 133 for (const auto& device : left_joycons) {
120 if (is_handle_identical(device)) { 134 if (is_handle_identical(device)) {
121 return false; 135 return false;
@@ -123,12 +137,25 @@ bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const {
123 } 137 }
124 break; 138 break;
125 case Joycon::ControllerType::Right: 139 case Joycon::ControllerType::Right:
140 if (!Settings::values.enable_joycon_driver) {
141 return false;
142 }
126 for (const auto& device : right_joycons) { 143 for (const auto& device : right_joycons) {
127 if (is_handle_identical(device)) { 144 if (is_handle_identical(device)) {
128 return false; 145 return false;
129 } 146 }
130 } 147 }
131 break; 148 break;
149 case Joycon::ControllerType::Pro:
150 if (!Settings::values.enable_procon_driver) {
151 return false;
152 }
153 for (const auto& device : pro_controller) {
154 if (is_handle_identical(device)) {
155 return false;
156 }
157 }
158 break;
132 default: 159 default:
133 return false; 160 return false;
134 } 161 }
@@ -199,6 +226,14 @@ std::shared_ptr<Joycon::JoyconDriver> Joycons::GetNextFreeHandle(
199 return *unconnected_device; 226 return *unconnected_device;
200 } 227 }
201 } 228 }
229 if (type == Joycon::ControllerType::Pro) {
230 const auto unconnected_device = std::ranges::find_if(
231 pro_controller, [](auto& device) { return !device->IsConnected(); });
232
233 if (unconnected_device != pro_controller.end()) {
234 return *unconnected_device;
235 }
236 }
202 return nullptr; 237 return nullptr;
203} 238}
204 239
@@ -409,6 +444,15 @@ std::shared_ptr<Joycon::JoyconDriver> Joycons::GetHandle(PadIdentifier identifie
409 } 444 }
410 } 445 }
411 446
447 if (type == Joycon::ControllerType::Pro) {
448 const auto matching_device = std::ranges::find_if(
449 pro_controller, [is_handle_active](auto& device) { return is_handle_active(device); });
450
451 if (matching_device != pro_controller.end()) {
452 return *matching_device;
453 }
454 }
455
412 return nullptr; 456 return nullptr;
413} 457}
414 458
@@ -455,6 +499,9 @@ std::vector<Common::ParamPackage> Joycons::GetInputDevices() const {
455 for (const auto& controller : right_joycons) { 499 for (const auto& controller : right_joycons) {
456 add_entry(controller); 500 add_entry(controller);
457 } 501 }
502 for (const auto& controller : pro_controller) {
503 add_entry(controller);
504 }
458 505
459 // List dual joycon pairs 506 // List dual joycon pairs
460 for (std::size_t i = 0; i < MaxSupportedControllers; i++) { 507 for (std::size_t i = 0; i < MaxSupportedControllers; i++) {
diff --git a/src/input_common/drivers/joycon.h b/src/input_common/drivers/joycon.h
index 2149ab7fd..473ba1b9e 100644
--- a/src/input_common/drivers/joycon.h
+++ b/src/input_common/drivers/joycon.h
@@ -106,6 +106,7 @@ private:
106 // Joycon types are split by type to ease supporting dualjoycon configurations 106 // Joycon types are split by type to ease supporting dualjoycon configurations
107 std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> left_joycons{}; 107 std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> left_joycons{};
108 std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> right_joycons{}; 108 std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> right_joycons{};
109 std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> pro_controller{};
109}; 110};
110 111
111} // namespace InputCommon 112} // namespace InputCommon
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index d975eb815..88cacd615 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -343,6 +343,14 @@ void SDLDriver::InitJoystick(int joystick_index) {
343 } 343 }
344 } 344 }
345 345
346 if (Settings::values.enable_procon_driver) {
347 if (guid.uuid[5] == 0x05 && guid.uuid[4] == 0x7e && guid.uuid[8] == 0x09) {
348 LOG_WARNING(Input, "Preferring joycon driver for device index {}", joystick_index);
349 SDL_JoystickClose(sdl_joystick);
350 return;
351 }
352 }
353
346 std::scoped_lock lock{joystick_map_mutex}; 354 std::scoped_lock lock{joystick_map_mutex};
347 if (joystick_map.find(guid) == joystick_map.end()) { 355 if (joystick_map.find(guid) == joystick_map.end()) {
348 auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick, sdl_gamecontroller); 356 auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick, sdl_gamecontroller);
@@ -465,13 +473,19 @@ SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_en
465 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1"); 473 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
466 SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); 474 SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
467 475
468 // Disable hidapi drivers for switch controllers when the custom joycon driver is enabled 476 // Disable hidapi drivers for joycon controllers when the custom joycon driver is enabled
469 if (Settings::values.enable_joycon_driver) { 477 if (Settings::values.enable_joycon_driver) {
470 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "0"); 478 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "0");
471 } else { 479 } else {
472 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1"); 480 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1");
473 } 481 }
474 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH, "1"); 482
483 // Disable hidapi drivers for pro controllers when the custom joycon driver is enabled
484 if (Settings::values.enable_procon_driver) {
485 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH, "0");
486 } else {
487 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH, "1");
488 }
475 489
476 // Disable hidapi driver for xbox. Already default on Windows, this causes conflict with native 490 // Disable hidapi driver for xbox. Already default on Windows, this causes conflict with native
477 // driver on Linux. 491 // driver on Linux.
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp
index 8f94c9f45..e65b6b845 100644
--- a/src/input_common/helpers/joycon_driver.cpp
+++ b/src/input_common/helpers/joycon_driver.cpp
@@ -543,9 +543,10 @@ void JoyconDriver::SetCallbacks(const JoyconCallbacks& callbacks) {
543 543
544DriverResult JoyconDriver::GetDeviceType(SDL_hid_device_info* device_info, 544DriverResult JoyconDriver::GetDeviceType(SDL_hid_device_info* device_info,
545 ControllerType& controller_type) { 545 ControllerType& controller_type) {
546 static constexpr std::array<std::pair<u32, ControllerType>, 2> supported_devices{ 546 static constexpr std::array<std::pair<u32, ControllerType>, 6> supported_devices{
547 std::pair<u32, ControllerType>{0x2006, ControllerType::Left}, 547 std::pair<u32, ControllerType>{0x2006, ControllerType::Left},
548 {0x2007, ControllerType::Right}, 548 {0x2007, ControllerType::Right},
549 {0x2009, ControllerType::Pro},
549 }; 550 };
550 constexpr u16 nintendo_vendor_id = 0x057e; 551 constexpr u16 nintendo_vendor_id = 0x057e;
551 552