summaryrefslogtreecommitdiff
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/main.cpp15
-rw-r--r--src/input_common/main.h2
-rw-r--r--src/input_common/sdl/sdl_impl.cpp52
-rw-r--r--src/input_common/udp/udp.cpp5
-rw-r--r--src/input_common/udp/udp.h2
5 files changed, 32 insertions, 44 deletions
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index b8725e9af..7bad2c45b 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -118,37 +118,38 @@ std::vector<Common::ParamPackage> GetInputDevices() {
118 118
119std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage> GetButtonMappingForDevice( 119std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage> GetButtonMappingForDevice(
120 const Common::ParamPackage& params) { 120 const Common::ParamPackage& params) {
121 std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage> mappings{}; 121 std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage> mappings;
122 if (!params.Has("class") || params.Get("class", "") == "any") { 122 if (!params.Has("class") || params.Get("class", "") == "any") {
123 return mappings; 123 return {};
124 } 124 }
125 if (params.Get("class", "") == "key") { 125 if (params.Get("class", "") == "key") {
126 // TODO consider returning the SDL key codes for the default keybindings 126 // TODO consider returning the SDL key codes for the default keybindings
127 return {};
127 } 128 }
128#ifdef HAVE_SDL2 129#ifdef HAVE_SDL2
129 if (params.Get("class", "") == "sdl") { 130 if (params.Get("class", "") == "sdl") {
130 return sdl->GetButtonMappingForDevice(params); 131 return sdl->GetButtonMappingForDevice(params);
131 } 132 }
132#endif 133#endif
133 return mappings; 134 return {};
134} 135}
135 136
136std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage> GetAnalogMappingForDevice( 137std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage> GetAnalogMappingForDevice(
137 const Common::ParamPackage& params) { 138 const Common::ParamPackage& params) {
138 std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage> mappings{}; 139 std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage> mappings;
139 if (!params.Has("class") || params.Get("class", "") == "any") { 140 if (!params.Has("class") || params.Get("class", "") == "any") {
140 return mappings; 141 return {};
141 } 142 }
142 if (params.Get("class", "") == "key") { 143 if (params.Get("class", "") == "key") {
143 // TODO consider returning the SDL key codes for the default keybindings 144 // TODO consider returning the SDL key codes for the default keybindings
144 return mappings; 145 return {};
145 } 146 }
146#ifdef HAVE_SDL2 147#ifdef HAVE_SDL2
147 if (params.Get("class", "") == "sdl") { 148 if (params.Get("class", "") == "sdl") {
148 return sdl->GetAnalogMappingForDevice(params); 149 return sdl->GetAnalogMappingForDevice(params);
149 } 150 }
150#endif 151#endif
151 return mappings; 152 return {};
152} 153}
153 154
154namespace Polling { 155namespace Polling {
diff --git a/src/input_common/main.h b/src/input_common/main.h
index ebc7f9533..e706c3750 100644
--- a/src/input_common/main.h
+++ b/src/input_common/main.h
@@ -76,7 +76,7 @@ public:
76 /// Setup and start polling for inputs, should be called before GetNextInput 76 /// Setup and start polling for inputs, should be called before GetNextInput
77 /// If a device_id is provided, events should be filtered to only include events from this 77 /// If a device_id is provided, events should be filtered to only include events from this
78 /// device id 78 /// device id
79 virtual void Start(std::string device_id = "") = 0; 79 virtual void Start(const std::string& device_id = "") = 0;
80 /// Stop polling 80 /// Stop polling
81 virtual void Stop() = 0; 81 virtual void Stop() = 0;
82 /** 82 /**
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index 35a9d45ec..dec7540e2 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -545,17 +545,16 @@ SDLState::~SDLState() {
545 545
546std::vector<Common::ParamPackage> SDLState::GetInputDevices() { 546std::vector<Common::ParamPackage> SDLState::GetInputDevices() {
547 std::scoped_lock lock(joystick_map_mutex); 547 std::scoped_lock lock(joystick_map_mutex);
548 std::vector<Common::ParamPackage> devices = {}; 548 std::vector<Common::ParamPackage> devices;
549 for (const auto& [key, value] : joystick_map) { 549 for (const auto& [key, value] : joystick_map) {
550 for (const auto& joystick : value) { 550 for (const auto& joystick : value) {
551 auto controller = joystick->GetSDLGameController();
552 auto joy = joystick->GetSDLJoystick(); 551 auto joy = joystick->GetSDLJoystick();
553 if (controller) { 552 if (auto controller = joystick->GetSDLGameController()) {
554 std::string name = 553 std::string name =
555 fmt::format("{} {}", SDL_GameControllerName(controller), joystick->GetPort()); 554 fmt::format("{} {}", SDL_GameControllerName(controller), joystick->GetPort());
556 devices.emplace_back(Common::ParamPackage{ 555 devices.emplace_back(Common::ParamPackage{
557 {"class", "sdl"}, 556 {"class", "sdl"},
558 {"display", name}, 557 {"display", std::move(name)},
559 {"guid", joystick->GetGUID()}, 558 {"guid", joystick->GetGUID()},
560 {"port", std::to_string(joystick->GetPort())}, 559 {"port", std::to_string(joystick->GetPort())},
561 }); 560 });
@@ -563,7 +562,7 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() {
563 std::string name = fmt::format("{} {}", SDL_JoystickName(joy), joystick->GetPort()); 562 std::string name = fmt::format("{} {}", SDL_JoystickName(joy), joystick->GetPort());
564 devices.emplace_back(Common::ParamPackage{ 563 devices.emplace_back(Common::ParamPackage{
565 {"class", "sdl"}, 564 {"class", "sdl"},
566 {"display", name}, 565 {"display", std::move(name)},
567 {"guid", joystick->GetGUID()}, 566 {"guid", joystick->GetGUID()},
568 {"port", std::to_string(joystick->GetPort())}, 567 {"port", std::to_string(joystick->GetPort())},
569 }); 568 });
@@ -624,54 +623,43 @@ Common::ParamPackage BuildHatParamPackageForButton(int port, std::string guid, u
624} 623}
625 624
626Common::ParamPackage SDLEventToButtonParamPackage(SDLState& state, const SDL_Event& event) { 625Common::ParamPackage SDLEventToButtonParamPackage(SDLState& state, const SDL_Event& event) {
627 Common::ParamPackage params{};
628
629 switch (event.type) { 626 switch (event.type) {
630 case SDL_JOYAXISMOTION: { 627 case SDL_JOYAXISMOTION: {
631 const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); 628 const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which);
632 params = BuildAnalogParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), 629 return BuildAnalogParamPackageForButton(joystick->GetPort(), joystick->GetGUID(),
633 event.jaxis.axis, event.jaxis.value); 630 event.jaxis.axis, event.jaxis.value);
634 break;
635 } 631 }
636 case SDL_JOYBUTTONUP: { 632 case SDL_JOYBUTTONUP: {
637 const auto joystick = state.GetSDLJoystickBySDLID(event.jbutton.which); 633 const auto joystick = state.GetSDLJoystickBySDLID(event.jbutton.which);
638 params = BuildButtonParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), 634 return BuildButtonParamPackageForButton(joystick->GetPort(), joystick->GetGUID(),
639 event.jbutton.button); 635 event.jbutton.button);
640 break;
641 } 636 }
642 case SDL_JOYHATMOTION: { 637 case SDL_JOYHATMOTION: {
643 const auto joystick = state.GetSDLJoystickBySDLID(event.jhat.which); 638 const auto joystick = state.GetSDLJoystickBySDLID(event.jhat.which);
644 params = BuildHatParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), 639 return BuildHatParamPackageForButton(joystick->GetPort(), joystick->GetGUID(),
645 event.jhat.hat, event.jhat.value); 640 event.jhat.hat, event.jhat.value);
646 break;
647 } 641 }
648 } 642 }
649 return params; 643 return {};
650} 644}
651 645
652Common::ParamPackage BuildParamPackageForBinding(int port, const std::string& guid, 646Common::ParamPackage BuildParamPackageForBinding(int port, const std::string& guid,
653 const SDL_GameControllerButtonBind& binding) { 647 const SDL_GameControllerButtonBind& binding) {
654 Common::ParamPackage out{};
655 switch (binding.bindType) { 648 switch (binding.bindType) {
656 case SDL_CONTROLLER_BINDTYPE_AXIS: 649 case SDL_CONTROLLER_BINDTYPE_AXIS:
657 out = BuildAnalogParamPackageForButton(port, guid, binding.value.axis); 650 return BuildAnalogParamPackageForButton(port, guid, binding.value.axis);
658 break;
659 case SDL_CONTROLLER_BINDTYPE_BUTTON: 651 case SDL_CONTROLLER_BINDTYPE_BUTTON:
660 out = BuildButtonParamPackageForButton(port, guid, binding.value.button); 652 return BuildButtonParamPackageForButton(port, guid, binding.value.button);
661 break;
662 case SDL_CONTROLLER_BINDTYPE_HAT: 653 case SDL_CONTROLLER_BINDTYPE_HAT:
663 out = BuildHatParamPackageForButton(port, guid, binding.value.hat.hat, 654 return BuildHatParamPackageForButton(port, guid, binding.value.hat.hat,
664 binding.value.hat.hat_mask); 655 binding.value.hat.hat_mask);
665 break;
666 default:
667 break;
668 } 656 }
669 return out; 657 return {};
670}; 658}
671 659
672Common::ParamPackage BuildParamPackageForAnalog(int port, const std::string& guid, int axis_x, 660Common::ParamPackage BuildParamPackageForAnalog(int port, const std::string& guid, int axis_x,
673 int axis_y) { 661 int axis_y) {
674 Common::ParamPackage params{}; 662 Common::ParamPackage params;
675 params.Set("engine", "sdl"); 663 params.Set("engine", "sdl");
676 params.Set("port", port); 664 params.Set("port", port);
677 params.Set("guid", guid); 665 params.Set("guid", guid);
@@ -769,7 +757,7 @@ class SDLPoller : public InputCommon::Polling::DevicePoller {
769public: 757public:
770 explicit SDLPoller(SDLState& state_) : state(state_) {} 758 explicit SDLPoller(SDLState& state_) : state(state_) {}
771 759
772 void Start(std::string device_id) override { 760 void Start(const std::string& device_id) override {
773 state.event_queue.Clear(); 761 state.event_queue.Clear();
774 state.polling = true; 762 state.polling = true;
775 } 763 }
@@ -821,7 +809,7 @@ public:
821 explicit SDLAnalogPreferredPoller(SDLState& state_) 809 explicit SDLAnalogPreferredPoller(SDLState& state_)
822 : SDLPoller(state_), button_poller(state_) {} 810 : SDLPoller(state_), button_poller(state_) {}
823 811
824 void Start(std::string device_id) override { 812 void Start(const std::string& device_id) override {
825 SDLPoller::Start(device_id); 813 SDLPoller::Start(device_id);
826 // Load the game controller 814 // Load the game controller
827 // Reset stored axes 815 // Reset stored axes
diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp
index 60cf47123..4b347e47e 100644
--- a/src/input_common/udp/udp.cpp
+++ b/src/input_common/udp/udp.cpp
@@ -89,10 +89,9 @@ State::~State() {
89 Input::UnregisterFactory<Input::MotionDevice>("cemuhookudp"); 89 Input::UnregisterFactory<Input::MotionDevice>("cemuhookudp");
90} 90}
91 91
92std::vector<Common::ParamPackage> State::GetInputDevices() { 92std::vector<Common::ParamPackage> State::GetInputDevices() const {
93 std::vector<Common::ParamPackage> devices = {};
94 // TODO support binding udp devices 93 // TODO support binding udp devices
95 return devices; 94 return {};
96} 95}
97 96
98void State::ReloadUDPClient() { 97void State::ReloadUDPClient() {
diff --git a/src/input_common/udp/udp.h b/src/input_common/udp/udp.h
index 24f6e0857..672a5c812 100644
--- a/src/input_common/udp/udp.h
+++ b/src/input_common/udp/udp.h
@@ -19,7 +19,7 @@ public:
19 State(); 19 State();
20 ~State(); 20 ~State();
21 void ReloadUDPClient(); 21 void ReloadUDPClient();
22 std::vector<Common::ParamPackage> GetInputDevices(); 22 std::vector<Common::ParamPackage> GetInputDevices() const;
23 23
24private: 24private:
25 std::unique_ptr<Client> client; 25 std::unique_ptr<Client> client;