From f0fac0c7fb6f7dd9fe81747b3369767c8c9e7d01 Mon Sep 17 00:00:00 2001 From: Morph Date: Wed, 22 Jul 2020 10:39:53 -0400 Subject: Project Mjölnir: Part 1 Co-authored-by: James Rowe Co-authored-by: Its-Rei --- src/input_common/main.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'src/input_common/main.cpp') diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index b9d5d0ec3..b8725e9af 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -44,7 +44,6 @@ void Init() { #ifdef HAVE_SDL2 sdl = SDL::Init(); #endif - udp = CemuhookUDP::Init(); } @@ -103,6 +102,55 @@ std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, return circle_pad_param.Serialize(); } +std::vector GetInputDevices() { + std::vector devices = { + Common::ParamPackage{{"display", "Any"}, {"class", "any"}}, + Common::ParamPackage{{"display", "Keyboard"}, {"class", "key"}}, + }; +#ifdef HAVE_SDL2 + auto sdl_devices = sdl->GetInputDevices(); + devices.insert(devices.end(), sdl_devices.begin(), sdl_devices.end()); +#endif + auto udp_devices = udp->GetInputDevices(); + devices.insert(devices.end(), udp_devices.begin(), udp_devices.end()); + return devices; +} + +std::unordered_map GetButtonMappingForDevice( + const Common::ParamPackage& params) { + std::unordered_map mappings{}; + if (!params.Has("class") || params.Get("class", "") == "any") { + return mappings; + } + if (params.Get("class", "") == "key") { + // TODO consider returning the SDL key codes for the default keybindings + } +#ifdef HAVE_SDL2 + if (params.Get("class", "") == "sdl") { + return sdl->GetButtonMappingForDevice(params); + } +#endif + return mappings; +} + +std::unordered_map GetAnalogMappingForDevice( + const Common::ParamPackage& params) { + std::unordered_map mappings{}; + if (!params.Has("class") || params.Get("class", "") == "any") { + return mappings; + } + if (params.Get("class", "") == "key") { + // TODO consider returning the SDL key codes for the default keybindings + return mappings; + } +#ifdef HAVE_SDL2 + if (params.Get("class", "") == "sdl") { + return sdl->GetAnalogMappingForDevice(params); + } +#endif + return mappings; +} + namespace Polling { std::vector> GetPollers(DeviceType type) { -- cgit v1.2.3 From efa0b7a056b73dffb8789c95ebf8a9c09e55f539 Mon Sep 17 00:00:00 2001 From: Morph Date: Sat, 15 Aug 2020 15:26:29 -0400 Subject: Address feedback --- src/input_common/main.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/input_common/main.cpp') 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 GetInputDevices() { std::unordered_map GetButtonMappingForDevice( const Common::ParamPackage& params) { - std::unordered_map mappings{}; + std::unordered_map mappings; if (!params.Has("class") || params.Get("class", "") == "any") { - return mappings; + return {}; } if (params.Get("class", "") == "key") { // TODO consider returning the SDL key codes for the default keybindings + return {}; } #ifdef HAVE_SDL2 if (params.Get("class", "") == "sdl") { return sdl->GetButtonMappingForDevice(params); } #endif - return mappings; + return {}; } std::unordered_map GetAnalogMappingForDevice( const Common::ParamPackage& params) { - std::unordered_map mappings{}; + std::unordered_map mappings; if (!params.Has("class") || params.Get("class", "") == "any") { - return mappings; + return {}; } if (params.Get("class", "") == "key") { // TODO consider returning the SDL key codes for the default keybindings - return mappings; + return {}; } #ifdef HAVE_SDL2 if (params.Get("class", "") == "sdl") { return sdl->GetAnalogMappingForDevice(params); } #endif - return mappings; + return {}; } namespace Polling { -- cgit v1.2.3 From 8ffc491546c8fa449e23463585e4b55498dcb307 Mon Sep 17 00:00:00 2001 From: Morph Date: Wed, 26 Aug 2020 22:41:51 -0400 Subject: input_common/main: Add "/Mouse" to the display name --- src/input_common/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/input_common/main.cpp') diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 7bad2c45b..8e67a7437 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -105,7 +105,7 @@ std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, std::vector GetInputDevices() { std::vector devices = { Common::ParamPackage{{"display", "Any"}, {"class", "any"}}, - Common::ParamPackage{{"display", "Keyboard"}, {"class", "key"}}, + Common::ParamPackage{{"display", "Keyboard/Mouse"}, {"class", "key"}}, }; #ifdef HAVE_SDL2 auto sdl_devices = sdl->GetInputDevices(); -- cgit v1.2.3