summaryrefslogtreecommitdiffstats
path: root/src/input_common/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/main.cpp')
-rw-r--r--src/input_common/main.cpp64
1 files changed, 62 insertions, 2 deletions
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index 86deb4c7c..c77fc04ee 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -5,7 +5,6 @@
#include "common/input.h"
#include "common/param_package.h"
#include "input_common/drivers/camera.h"
-#include "input_common/drivers/gc_adapter.h"
#include "input_common/drivers/keyboard.h"
#include "input_common/drivers/mouse.h"
#include "input_common/drivers/tas_input.h"
@@ -19,12 +18,39 @@
#include "input_common/input_mapping.h"
#include "input_common/input_poller.h"
#include "input_common/main.h"
+
+#ifdef HAVE_LIBUSB
+#include "input_common/drivers/gc_adapter.h"
+#endif
#ifdef HAVE_SDL2
+#include "input_common/drivers/joycon.h"
#include "input_common/drivers/sdl_driver.h"
#endif
namespace InputCommon {
+/// Dummy engine to get periodic updates
+class UpdateEngine final : public InputEngine {
+public:
+ explicit UpdateEngine(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
+ PreSetController(identifier);
+ }
+
+ void PumpEvents() {
+ SetButton(identifier, 0, last_state);
+ last_state = !last_state;
+ }
+
+private:
+ static constexpr PadIdentifier identifier = {
+ .guid = Common::UUID{},
+ .port = 0,
+ .pad = 0,
+ };
+
+ bool last_state{};
+};
+
struct InputSubsystem::Impl {
template <typename Engine>
void RegisterEngine(std::string name, std::shared_ptr<Engine>& engine) {
@@ -42,10 +68,13 @@ struct InputSubsystem::Impl {
void Initialize() {
mapping_factory = std::make_shared<MappingFactory>();
+ RegisterEngine("updater", update_engine);
RegisterEngine("keyboard", keyboard);
RegisterEngine("mouse", mouse);
RegisterEngine("touch", touch_screen);
+#ifdef HAVE_LIBUSB
RegisterEngine("gcpad", gcadapter);
+#endif
RegisterEngine("cemuhookudp", udp_client);
RegisterEngine("tas", tas_input);
RegisterEngine("camera", camera);
@@ -53,6 +82,7 @@ struct InputSubsystem::Impl {
RegisterEngine("virtual_gamepad", virtual_gamepad);
#ifdef HAVE_SDL2
RegisterEngine("sdl", sdl);
+ RegisterEngine("joycon", joycon);
#endif
Common::Input::RegisterInputFactory("touch_from_button",
@@ -69,10 +99,13 @@ struct InputSubsystem::Impl {
}
void Shutdown() {
+ UnregisterEngine(update_engine);
UnregisterEngine(keyboard);
UnregisterEngine(mouse);
UnregisterEngine(touch_screen);
+#ifdef HAVE_LIBUSB
UnregisterEngine(gcadapter);
+#endif
UnregisterEngine(udp_client);
UnregisterEngine(tas_input);
UnregisterEngine(camera);
@@ -80,6 +113,7 @@ struct InputSubsystem::Impl {
UnregisterEngine(virtual_gamepad);
#ifdef HAVE_SDL2
UnregisterEngine(sdl);
+ UnregisterEngine(joycon);
#endif
Common::Input::UnregisterInputFactory("touch_from_button");
@@ -95,11 +129,15 @@ struct InputSubsystem::Impl {
devices.insert(devices.end(), keyboard_devices.begin(), keyboard_devices.end());
auto mouse_devices = mouse->GetInputDevices();
devices.insert(devices.end(), mouse_devices.begin(), mouse_devices.end());
+#ifdef HAVE_LIBUSB
auto gcadapter_devices = gcadapter->GetInputDevices();
devices.insert(devices.end(), gcadapter_devices.begin(), gcadapter_devices.end());
+#endif
auto udp_devices = udp_client->GetInputDevices();
devices.insert(devices.end(), udp_devices.begin(), udp_devices.end());
#ifdef HAVE_SDL2
+ auto joycon_devices = joycon->GetInputDevices();
+ devices.insert(devices.end(), joycon_devices.begin(), joycon_devices.end());
auto sdl_devices = sdl->GetInputDevices();
devices.insert(devices.end(), sdl_devices.begin(), sdl_devices.end());
#endif
@@ -119,9 +157,11 @@ struct InputSubsystem::Impl {
if (engine == mouse->GetEngineName()) {
return mouse;
}
+#ifdef HAVE_LIBUSB
if (engine == gcadapter->GetEngineName()) {
return gcadapter;
}
+#endif
if (engine == udp_client->GetEngineName()) {
return udp_client;
}
@@ -129,6 +169,9 @@ struct InputSubsystem::Impl {
if (engine == sdl->GetEngineName()) {
return sdl;
}
+ if (engine == joycon->GetEngineName()) {
+ return joycon;
+ }
#endif
return nullptr;
}
@@ -194,9 +237,11 @@ struct InputSubsystem::Impl {
if (engine == mouse->GetEngineName()) {
return true;
}
+#ifdef HAVE_LIBUSB
if (engine == gcadapter->GetEngineName()) {
return true;
}
+#endif
if (engine == udp_client->GetEngineName()) {
return true;
}
@@ -210,6 +255,9 @@ struct InputSubsystem::Impl {
if (engine == sdl->GetEngineName()) {
return true;
}
+ if (engine == joycon->GetEngineName()) {
+ return true;
+ }
#endif
return false;
}
@@ -217,24 +265,31 @@ struct InputSubsystem::Impl {
void BeginConfiguration() {
keyboard->BeginConfiguration();
mouse->BeginConfiguration();
+#ifdef HAVE_LIBUSB
gcadapter->BeginConfiguration();
+#endif
udp_client->BeginConfiguration();
#ifdef HAVE_SDL2
sdl->BeginConfiguration();
+ joycon->BeginConfiguration();
#endif
}
void EndConfiguration() {
keyboard->EndConfiguration();
mouse->EndConfiguration();
+#ifdef HAVE_LIBUSB
gcadapter->EndConfiguration();
+#endif
udp_client->EndConfiguration();
#ifdef HAVE_SDL2
sdl->EndConfiguration();
+ joycon->EndConfiguration();
#endif
}
void PumpEvents() const {
+ update_engine->PumpEvents();
#ifdef HAVE_SDL2
sdl->PumpEvents();
#endif
@@ -246,9 +301,9 @@ struct InputSubsystem::Impl {
std::shared_ptr<MappingFactory> mapping_factory;
+ std::shared_ptr<UpdateEngine> update_engine;
std::shared_ptr<Keyboard> keyboard;
std::shared_ptr<Mouse> mouse;
- std::shared_ptr<GCAdapter> gcadapter;
std::shared_ptr<TouchScreen> touch_screen;
std::shared_ptr<TasInput::Tas> tas_input;
std::shared_ptr<CemuhookUDP::UDPClient> udp_client;
@@ -256,8 +311,13 @@ struct InputSubsystem::Impl {
std::shared_ptr<VirtualAmiibo> virtual_amiibo;
std::shared_ptr<VirtualGamepad> virtual_gamepad;
+#ifdef HAVE_LIBUSB
+ std::shared_ptr<GCAdapter> gcadapter;
+#endif
+
#ifdef HAVE_SDL2
std::shared_ptr<SDLDriver> sdl;
+ std::shared_ptr<Joycons> joycon;
#endif
};