From a237fb5f759f15e1e1a8f920118e2189ad6d82e0 Mon Sep 17 00:00:00 2001
From: Morph <39850852+Morph1984@users.noreply.github.com>
Date: Thu, 18 Nov 2021 23:09:28 -0500
Subject: configure_graphics_ui: AMD's -> AMD
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
AMD officially markets FSR as AMD FidelityFX™️ Super Resolution
---
src/yuzu/configuration/configure_graphics.ui | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/yuzu/configuration')
diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui
index 660b68c1c..9241678e4 100644
--- a/src/yuzu/configuration/configure_graphics.ui
+++ b/src/yuzu/configuration/configure_graphics.ui
@@ -429,7 +429,7 @@
-
- AMD's FidelityFX™️ Super Resolution [Vulkan Only]
+ AMD FidelityFX™️ Super Resolution [Vulkan Only]
--
cgit v1.2.3
From 8e3371a5c5aa26e1f3d0c1f944b65ee6b65c3f34 Mon Sep 17 00:00:00 2001
From: Kewlan
Date: Sun, 21 Nov 2021 16:57:00 +0100
Subject: configure_general: Allow framerate cap to be used in custom game
configs
---
src/common/settings.cpp | 1 +
src/common/settings.h | 2 +-
src/yuzu/configuration/config.cpp | 4 +-
src/yuzu/configuration/configure_general.cpp | 20 ++++++
src/yuzu/configuration/configure_general.ui | 99 +++++++++++++++++++++-------
5 files changed, 99 insertions(+), 27 deletions(-)
(limited to 'src/yuzu/configuration')
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 3bcaa072f..6964a8273 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -183,6 +183,7 @@ void RestoreGlobalState(bool is_powered_on) {
values.max_anisotropy.SetGlobal(true);
values.use_speed_limit.SetGlobal(true);
values.speed_limit.SetGlobal(true);
+ values.fps_cap.SetGlobal(true);
values.use_disk_shader_cache.SetGlobal(true);
values.gpu_accuracy.SetGlobal(true);
values.use_asynchronous_gpu_emulation.SetGlobal(true);
diff --git a/src/common/settings.h b/src/common/settings.h
index 42f8b4a7d..fa4aa8747 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -525,7 +525,7 @@ struct Values {
Setting nvdec_emulation{NvdecEmulation::GPU, "nvdec_emulation"};
Setting accelerate_astc{true, "accelerate_astc"};
Setting use_vsync{true, "use_vsync"};
- BasicRangedSetting fps_cap{1000, 1, 1000, "fps_cap"};
+ RangedSetting fps_cap{1000, 1, 1000, "fps_cap"};
BasicSetting disable_fps_limit{false, "disable_fps_limit"};
RangedSetting shader_backend{ShaderBackend::GLASM, ShaderBackend::GLSL,
ShaderBackend::SPIRV, "shader_backend"};
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp
index 8227d06bc..2b670ddfd 100644
--- a/src/yuzu/configuration/config.cpp
+++ b/src/yuzu/configuration/config.cpp
@@ -830,6 +830,7 @@ void Config::ReadRendererValues() {
ReadGlobalSetting(Settings::values.max_anisotropy);
ReadGlobalSetting(Settings::values.use_speed_limit);
ReadGlobalSetting(Settings::values.speed_limit);
+ ReadGlobalSetting(Settings::values.fps_cap);
ReadGlobalSetting(Settings::values.use_disk_shader_cache);
ReadGlobalSetting(Settings::values.gpu_accuracy);
ReadGlobalSetting(Settings::values.use_asynchronous_gpu_emulation);
@@ -844,7 +845,6 @@ void Config::ReadRendererValues() {
ReadGlobalSetting(Settings::values.bg_blue);
if (global) {
- ReadBasicSetting(Settings::values.fps_cap);
ReadBasicSetting(Settings::values.renderer_debug);
ReadBasicSetting(Settings::values.renderer_shader_feedback);
ReadBasicSetting(Settings::values.enable_nsight_aftermath);
@@ -1382,6 +1382,7 @@ void Config::SaveRendererValues() {
WriteGlobalSetting(Settings::values.max_anisotropy);
WriteGlobalSetting(Settings::values.use_speed_limit);
WriteGlobalSetting(Settings::values.speed_limit);
+ WriteGlobalSetting(Settings::values.fps_cap);
WriteGlobalSetting(Settings::values.use_disk_shader_cache);
WriteSetting(QString::fromStdString(Settings::values.gpu_accuracy.GetLabel()),
static_cast(Settings::values.gpu_accuracy.GetValue(global)),
@@ -1405,7 +1406,6 @@ void Config::SaveRendererValues() {
WriteGlobalSetting(Settings::values.bg_blue);
if (global) {
- WriteBasicSetting(Settings::values.fps_cap);
WriteBasicSetting(Settings::values.renderer_debug);
WriteBasicSetting(Settings::values.renderer_shader_feedback);
WriteBasicSetting(Settings::values.enable_nsight_aftermath);
diff --git a/src/yuzu/configuration/configure_general.cpp b/src/yuzu/configuration/configure_general.cpp
index 7af3ea97e..566879317 100644
--- a/src/yuzu/configuration/configure_general.cpp
+++ b/src/yuzu/configuration/configure_general.cpp
@@ -30,6 +30,9 @@ ConfigureGeneral::ConfigureGeneral(const Core::System& system_, QWidget* parent)
connect(ui->button_reset_defaults, &QPushButton::clicked, this,
&ConfigureGeneral::ResetDefaults);
+
+ ui->fps_cap_label->setVisible(Settings::IsConfiguringGlobal());
+ ui->fps_cap_combobox->setVisible(!Settings::IsConfiguringGlobal());
}
ConfigureGeneral::~ConfigureGeneral() = default;
@@ -57,6 +60,11 @@ void ConfigureGeneral::SetConfiguration() {
} else {
ui->speed_limit->setEnabled(Settings::values.use_speed_limit.GetValue() &&
use_speed_limit != ConfigurationShared::CheckState::Global);
+
+ ui->fps_cap_combobox->setCurrentIndex(Settings::values.fps_cap.UsingGlobal() ? 0 : 1);
+ ui->fps_cap->setEnabled(!Settings::values.fps_cap.UsingGlobal());
+ ConfigurationShared::SetHighlight(ui->fps_cap_layout,
+ !Settings::values.fps_cap.UsingGlobal());
}
}
@@ -106,6 +114,13 @@ void ConfigureGeneral::ApplyConfiguration() {
Qt::Checked);
Settings::values.speed_limit.SetValue(ui->speed_limit->value());
}
+
+ if (ui->fps_cap_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
+ Settings::values.fps_cap.SetGlobal(true);
+ } else {
+ Settings::values.fps_cap.SetGlobal(false);
+ Settings::values.fps_cap.SetValue(ui->fps_cap->value());
+ }
}
}
@@ -148,4 +163,9 @@ void ConfigureGeneral::SetupPerGameUI() {
ui->speed_limit->setEnabled(ui->toggle_speed_limit->isChecked() &&
(use_speed_limit != ConfigurationShared::CheckState::Global));
});
+
+ connect(ui->fps_cap_combobox, qOverload(&QComboBox::activated), this, [this](int index) {
+ ui->fps_cap->setEnabled(index == 1);
+ ConfigurationShared::SetHighlight(ui->fps_cap_layout, index == 1);
+ });
}
diff --git a/src/yuzu/configuration/configure_general.ui b/src/yuzu/configuration/configure_general.ui
index f9f0e3ebf..112dc72b3 100644
--- a/src/yuzu/configuration/configure_general.ui
+++ b/src/yuzu/configuration/configure_general.ui
@@ -6,8 +6,8 @@
0
0
- 329
- 407
+ 744
+ 568
@@ -28,34 +28,85 @@
-
-
-
-
-
-
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
-
+
+
+ Use global framerate cap
+
+
+ 0
+
+
-
- Framerate Cap
+ Use global framerate cap
-
- Requires the use of the FPS Limiter Toggle hotkey to take effect.
+
+ -
+
+ Set framerate cap:
+
-
- -
-
-
- x
-
-
- 1
-
-
- 1000
-
-
- 500
-
+
+ -
+
+
+ Requires the use of the FPS Limiter Toggle hotkey to take effect.
+
+
+ Framerate Cap
+
-
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+
+
+ -
+
+
+ x
+
+
+ 1
+
+
+ 1000
+
+
+ 500
+
+
+
+
-
--
cgit v1.2.3
From 5a785ed794fff8c944283271bf25cb835c11700a Mon Sep 17 00:00:00 2001
From: german77
Date: Mon, 20 Sep 2021 17:18:40 -0500
Subject: input_common: Rewrite keyboard
---
src/input_common/CMakeLists.txt | 4 +-
src/input_common/drivers/keyboard.cpp | 35 +++
src/input_common/drivers/keyboard.h | 44 ++++
src/input_common/keyboard.cpp | 121 ----------
src/input_common/keyboard.h | 47 ----
src/input_common/main.cpp | 263 +---------------------
src/input_common/main.h | 89 --------
src/yuzu/bootmanager.cpp | 62 +++--
src/yuzu/bootmanager.h | 2 +-
src/yuzu/configuration/configure_input_player.cpp | 83 +------
src/yuzu/debugger/controller.cpp | 3 +-
src/yuzu/main.cpp | 18 +-
12 files changed, 126 insertions(+), 645 deletions(-)
create mode 100644 src/input_common/drivers/keyboard.cpp
create mode 100644 src/input_common/drivers/keyboard.h
delete mode 100644 src/input_common/keyboard.cpp
delete mode 100644 src/input_common/keyboard.h
(limited to 'src/yuzu/configuration')
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt
index 90e7618ce..0fcf7a9d7 100644
--- a/src/input_common/CMakeLists.txt
+++ b/src/input_common/CMakeLists.txt
@@ -1,6 +1,6 @@
add_library(input_common STATIC
- keyboard.cpp
- keyboard.h
+ drivers/keyboard.cpp
+ drivers/keyboard.h
helpers/stick_from_buttons.cpp
helpers/stick_from_buttons.h
helpers/touch_from_buttons.cpp
diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp
new file mode 100644
index 000000000..b00a4b8d9
--- /dev/null
+++ b/src/input_common/drivers/keyboard.cpp
@@ -0,0 +1,35 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included
+
+#include "common/param_package.h"
+#include "input_common/drivers/keyboard.h"
+
+namespace InputCommon {
+
+Keyboard::Keyboard(const std::string& input_engine_) : InputEngine(input_engine_) {
+ PreSetController(identifier);
+}
+
+void Keyboard::PressKey(int key_code) {
+ SetButton(identifier, key_code, true);
+}
+
+void Keyboard::ReleaseKey(int key_code) {
+ SetButton(identifier, key_code, false);
+}
+
+void Keyboard::ReleaseAllKeys() {
+ ResetButtonState();
+}
+
+std::vector Keyboard::GetInputDevices() const {
+ std::vector devices;
+ devices.emplace_back(Common::ParamPackage{
+ {"engine", "keyboard"},
+ {"display", "Keyboard Only"},
+ });
+ return devices;
+}
+
+} // namespace InputCommon
diff --git a/src/input_common/drivers/keyboard.h b/src/input_common/drivers/keyboard.h
new file mode 100644
index 000000000..a3e0d8a61
--- /dev/null
+++ b/src/input_common/drivers/keyboard.h
@@ -0,0 +1,44 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included
+
+#pragma once
+
+#include "input_common/input_engine.h"
+
+namespace InputCommon {
+
+/**
+ * A button device factory representing a keyboard. It receives keyboard events and forward them
+ * to all button devices it created.
+ */
+class Keyboard final : public InputCommon::InputEngine {
+public:
+ explicit Keyboard(const std::string& input_engine_);
+
+ /**
+ * Sets the status of all buttons bound with the key to pressed
+ * @param key_code the code of the key to press
+ */
+ void PressKey(int key_code);
+
+ /**
+ * Sets the status of all buttons bound with the key to released
+ * @param key_code the code of the key to release
+ */
+ void ReleaseKey(int key_code);
+
+ void ReleaseAllKeys();
+
+ /// Used for automapping features
+ std::vector GetInputDevices() const override;
+
+private:
+ const PadIdentifier identifier = {
+ .guid = Common::UUID{""},
+ .port = 0,
+ .pad = 0,
+ };
+};
+
+} // namespace InputCommon
diff --git a/src/input_common/keyboard.cpp b/src/input_common/keyboard.cpp
deleted file mode 100644
index 8261e76fd..000000000
--- a/src/input_common/keyboard.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright 2017 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include
-#include
-#include
-#include
-#include "input_common/keyboard.h"
-
-namespace InputCommon {
-
-class KeyButton final : public Input::ButtonDevice {
-public:
- explicit KeyButton(std::shared_ptr key_button_list_, bool toggle_)
- : key_button_list(std::move(key_button_list_)), toggle(toggle_) {}
-
- ~KeyButton() override;
-
- bool GetStatus() const override {
- if (toggle) {
- return toggled_status.load(std::memory_order_relaxed);
- }
- return status.load();
- }
-
- void ToggleButton() {
- if (lock) {
- return;
- }
- lock = true;
- const bool old_toggle_status = toggled_status.load();
- toggled_status.store(!old_toggle_status);
- }
-
- void UnlockButton() {
- lock = false;
- }
-
- friend class KeyButtonList;
-
-private:
- std::shared_ptr key_button_list;
- std::atomic status{false};
- std::atomic toggled_status{false};
- bool lock{false};
- const bool toggle;
-};
-
-struct KeyButtonPair {
- int key_code;
- KeyButton* key_button;
-};
-
-class KeyButtonList {
-public:
- void AddKeyButton(int key_code, KeyButton* key_button) {
- std::lock_guard guard{mutex};
- list.push_back(KeyButtonPair{key_code, key_button});
- }
-
- void RemoveKeyButton(const KeyButton* key_button) {
- std::lock_guard guard{mutex};
- list.remove_if(
- [key_button](const KeyButtonPair& pair) { return pair.key_button == key_button; });
- }
-
- void ChangeKeyStatus(int key_code, bool pressed) {
- std::lock_guard guard{mutex};
- for (const KeyButtonPair& pair : list) {
- if (pair.key_code == key_code) {
- pair.key_button->status.store(pressed);
- if (pressed) {
- pair.key_button->ToggleButton();
- } else {
- pair.key_button->UnlockButton();
- }
- pair.key_button->TriggerOnChange();
- }
- }
- }
-
- void ChangeAllKeyStatus(bool pressed) {
- std::lock_guard guard{mutex};
- for (const KeyButtonPair& pair : list) {
- pair.key_button->status.store(pressed);
- }
- }
-
-private:
- std::mutex mutex;
- std::list list;
-};
-
-Keyboard::Keyboard() : key_button_list{std::make_shared()} {}
-
-KeyButton::~KeyButton() {
- key_button_list->RemoveKeyButton(this);
-}
-
-std::unique_ptr Keyboard::Create(const Common::ParamPackage& params) {
- const int key_code = params.Get("code", 0);
- const bool toggle = params.Get("toggle", false);
- std::unique_ptr button = std::make_unique(key_button_list, toggle);
- key_button_list->AddKeyButton(key_code, button.get());
- return button;
-}
-
-void Keyboard::PressKey(int key_code) {
- key_button_list->ChangeKeyStatus(key_code, true);
-}
-
-void Keyboard::ReleaseKey(int key_code) {
- key_button_list->ChangeKeyStatus(key_code, false);
-}
-
-void Keyboard::ReleaseAllKeys() {
- key_button_list->ChangeAllKeyStatus(false);
-}
-
-} // namespace InputCommon
diff --git a/src/input_common/keyboard.h b/src/input_common/keyboard.h
deleted file mode 100644
index 861950472..000000000
--- a/src/input_common/keyboard.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2017 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include
-#include "core/frontend/input.h"
-
-namespace InputCommon {
-
-class KeyButtonList;
-
-/**
- * A button device factory representing a keyboard. It receives keyboard events and forward them
- * to all button devices it created.
- */
-class Keyboard final : public Input::Factory {
-public:
- Keyboard();
-
- /**
- * Creates a button device from a keyboard key
- * @param params contains parameters for creating the device:
- * - "code": the code of the key to bind with the button
- */
- std::unique_ptr Create(const Common::ParamPackage& params) override;
-
- /**
- * Sets the status of all buttons bound with the key to pressed
- * @param key_code the code of the key to press
- */
- void PressKey(int key_code);
-
- /**
- * Sets the status of all buttons bound with the key to released
- * @param key_code the code of the key to release
- */
- void ReleaseKey(int key_code);
-
- void ReleaseAllKeys();
-
-private:
- std::shared_ptr key_button_list;
-};
-
-} // namespace InputCommon
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index 7a5c29b40..da501b6cc 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -6,17 +6,7 @@
#include
#include "common/param_package.h"
#include "common/settings.h"
-#include "input_common/gcadapter/gc_adapter.h"
-#include "input_common/gcadapter/gc_poller.h"
-#include "input_common/keyboard.h"
#include "input_common/main.h"
-#include "input_common/motion_from_button.h"
-#include "input_common/mouse/mouse_input.h"
-#include "input_common/mouse/mouse_poller.h"
-#include "input_common/tas/tas_input.h"
-#include "input_common/tas/tas_poller.h"
-#include "input_common/udp/client.h"
-#include "input_common/udp/udp.h"
#ifdef HAVE_SDL2
#include "input_common/sdl/sdl.h"
#endif
@@ -25,82 +15,9 @@ namespace InputCommon {
struct InputSubsystem::Impl {
void Initialize() {
- gcadapter = std::make_shared();
- gcbuttons = std::make_shared(gcadapter);
- Input::RegisterFactory("gcpad", gcbuttons);
- gcanalog = std::make_shared(gcadapter);
- Input::RegisterFactory("gcpad", gcanalog);
- gcvibration = std::make_shared(gcadapter);
- Input::RegisterFactory("gcpad", gcvibration);
-
- keyboard = std::make_shared();
- Input::RegisterFactory("keyboard", keyboard);
- Input::RegisterFactory("keyboard",
- std::make_shared());
-
-#ifdef HAVE_SDL2
- sdl = SDL::Init();
-#endif
-
- udp = std::make_shared();
- udpmotion = std::make_shared(udp);
- Input::RegisterFactory("cemuhookudp", udpmotion);
- udptouch = std::make_shared(udp);
- Input::RegisterFactory("cemuhookudp", udptouch);
-
- mouse = std::make_shared();
- mousebuttons = std::make_shared(mouse);
- Input::RegisterFactory("mouse", mousebuttons);
- mouseanalog = std::make_shared(mouse);
- Input::RegisterFactory("mouse", mouseanalog);
- mousemotion = std::make_shared(mouse);
- Input::RegisterFactory("mouse", mousemotion);
- mousetouch = std::make_shared(mouse);
- Input::RegisterFactory("mouse", mousetouch);
-
- tas = std::make_shared();
- tasbuttons = std::make_shared(tas);
- Input::RegisterFactory("tas", tasbuttons);
- tasanalog = std::make_shared(tas);
- Input::RegisterFactory("tas", tasanalog);
}
void Shutdown() {
- Input::UnregisterFactory("keyboard");
- Input::UnregisterFactory("keyboard");
- keyboard.reset();
-#ifdef HAVE_SDL2
- sdl.reset();
-#endif
- Input::UnregisterFactory("gcpad");
- Input::UnregisterFactory("gcpad");
- Input::UnregisterFactory("gcpad");
-
- gcbuttons.reset();
- gcanalog.reset();
- gcvibration.reset();
-
- Input::UnregisterFactory("cemuhookudp");
- Input::UnregisterFactory("cemuhookudp");
-
- udpmotion.reset();
- udptouch.reset();
-
- Input::UnregisterFactory("mouse");
- Input::UnregisterFactory("mouse");
- Input::UnregisterFactory("mouse");
- Input::UnregisterFactory("mouse");
-
- mousebuttons.reset();
- mouseanalog.reset();
- mousemotion.reset();
- mousetouch.reset();
-
- Input::UnregisterFactory("tas");
- Input::UnregisterFactory("tas");
-
- tasbuttons.reset();
- tasanalog.reset();
}
[[nodiscard]] std::vector GetInputDevices() const {
@@ -108,19 +25,7 @@ struct InputSubsystem::Impl {
Common::ParamPackage{{"display", "Any"}, {"class", "any"}},
Common::ParamPackage{{"display", "Keyboard/Mouse"}, {"class", "keyboard"}},
};
- if (Settings::values.tas_enable) {
- devices.emplace_back(
- Common::ParamPackage{{"display", "TAS Controller"}, {"class", "tas"}});
- }
-#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());
- auto gcpad_devices = gcadapter->GetInputDevices();
- devices.insert(devices.end(), gcpad_devices.begin(), gcpad_devices.end());
- return devices;
+ return {};
}
[[nodiscard]] AnalogMapping GetAnalogMappingForDevice(
@@ -128,17 +33,6 @@ struct InputSubsystem::Impl {
if (!params.Has("class") || params.Get("class", "") == "any") {
return {};
}
- if (params.Get("class", "") == "gcpad") {
- return gcadapter->GetAnalogMappingForDevice(params);
- }
- if (params.Get("class", "") == "tas") {
- return tas->GetAnalogMappingForDevice(params);
- }
-#ifdef HAVE_SDL2
- if (params.Get("class", "") == "sdl") {
- return sdl->GetAnalogMappingForDevice(params);
- }
-#endif
return {};
}
@@ -147,17 +41,6 @@ struct InputSubsystem::Impl {
if (!params.Has("class") || params.Get("class", "") == "any") {
return {};
}
- if (params.Get("class", "") == "gcpad") {
- return gcadapter->GetButtonMappingForDevice(params);
- }
- if (params.Get("class", "") == "tas") {
- return tas->GetButtonMappingForDevice(params);
- }
-#ifdef HAVE_SDL2
- if (params.Get("class", "") == "sdl") {
- return sdl->GetButtonMappingForDevice(params);
- }
-#endif
return {};
}
@@ -166,37 +49,9 @@ struct InputSubsystem::Impl {
if (!params.Has("class") || params.Get("class", "") == "any") {
return {};
}
- if (params.Get("class", "") == "cemuhookudp") {
- // TODO return the correct motion device
- return {};
- }
-#ifdef HAVE_SDL2
- if (params.Get("class", "") == "sdl") {
- return sdl->GetMotionMappingForDevice(params);
- }
-#endif
return {};
}
- std::shared_ptr keyboard;
-#ifdef HAVE_SDL2
- std::unique_ptr sdl;
-#endif
- std::shared_ptr gcbuttons;
- std::shared_ptr gcanalog;
- std::shared_ptr gcvibration;
- std::shared_ptr udpmotion;
- std::shared_ptr udptouch;
- std::shared_ptr mousebuttons;
- std::shared_ptr mouseanalog;
- std::shared_ptr mousemotion;
- std::shared_ptr mousetouch;
- std::shared_ptr tasbuttons;
- std::shared_ptr tasanalog;
- std::shared_ptr udp;
- std::shared_ptr gcadapter;
- std::shared_ptr mouse;
- std::shared_ptr tas;
};
InputSubsystem::InputSubsystem() : impl{std::make_unique()} {}
@@ -211,30 +66,6 @@ void InputSubsystem::Shutdown() {
impl->Shutdown();
}
-Keyboard* InputSubsystem::GetKeyboard() {
- return impl->keyboard.get();
-}
-
-const Keyboard* InputSubsystem::GetKeyboard() const {
- return impl->keyboard.get();
-}
-
-MouseInput::Mouse* InputSubsystem::GetMouse() {
- return impl->mouse.get();
-}
-
-const MouseInput::Mouse* InputSubsystem::GetMouse() const {
- return impl->mouse.get();
-}
-
-TasInput::Tas* InputSubsystem::GetTas() {
- return impl->tas.get();
-}
-
-const TasInput::Tas* InputSubsystem::GetTas() const {
- return impl->tas.get();
-}
-
std::vector InputSubsystem::GetInputDevices() const {
return impl->GetInputDevices();
}
@@ -251,100 +82,12 @@ MotionMapping InputSubsystem::GetMotionMappingForDevice(const Common::ParamPacka
return impl->GetMotionMappingForDevice(device);
}
-GCAnalogFactory* InputSubsystem::GetGCAnalogs() {
- return impl->gcanalog.get();
-}
-
-const GCAnalogFactory* InputSubsystem::GetGCAnalogs() const {
- return impl->gcanalog.get();
-}
-
-GCButtonFactory* InputSubsystem::GetGCButtons() {
- return impl->gcbuttons.get();
-}
-
-const GCButtonFactory* InputSubsystem::GetGCButtons() const {
- return impl->gcbuttons.get();
-}
-
-UDPMotionFactory* InputSubsystem::GetUDPMotions() {
- return impl->udpmotion.get();
-}
-
-const UDPMotionFactory* InputSubsystem::GetUDPMotions() const {
- return impl->udpmotion.get();
-}
-
-UDPTouchFactory* InputSubsystem::GetUDPTouch() {
- return impl->udptouch.get();
-}
-
-const UDPTouchFactory* InputSubsystem::GetUDPTouch() const {
- return impl->udptouch.get();
-}
-
-MouseButtonFactory* InputSubsystem::GetMouseButtons() {
- return impl->mousebuttons.get();
-}
-
-const MouseButtonFactory* InputSubsystem::GetMouseButtons() const {
- return impl->mousebuttons.get();
-}
-
-MouseAnalogFactory* InputSubsystem::GetMouseAnalogs() {
- return impl->mouseanalog.get();
-}
-
-const MouseAnalogFactory* InputSubsystem::GetMouseAnalogs() const {
- return impl->mouseanalog.get();
-}
-
-MouseMotionFactory* InputSubsystem::GetMouseMotions() {
- return impl->mousemotion.get();
-}
-
-const MouseMotionFactory* InputSubsystem::GetMouseMotions() const {
- return impl->mousemotion.get();
-}
-
-MouseTouchFactory* InputSubsystem::GetMouseTouch() {
- return impl->mousetouch.get();
-}
-
-const MouseTouchFactory* InputSubsystem::GetMouseTouch() const {
- return impl->mousetouch.get();
-}
-
-TasButtonFactory* InputSubsystem::GetTasButtons() {
- return impl->tasbuttons.get();
-}
-
-const TasButtonFactory* InputSubsystem::GetTasButtons() const {
- return impl->tasbuttons.get();
-}
-
-TasAnalogFactory* InputSubsystem::GetTasAnalogs() {
- return impl->tasanalog.get();
-}
-
-const TasAnalogFactory* InputSubsystem::GetTasAnalogs() const {
- return impl->tasanalog.get();
-}
-
void InputSubsystem::ReloadInputDevices() {
- if (!impl->udp) {
- return;
- }
- impl->udp->ReloadSockets();
}
-std::vector> InputSubsystem::GetPollers(
- [[maybe_unused]] Polling::DeviceType type) const {
-#ifdef HAVE_SDL2
- return impl->sdl->GetPollers(type);
-#else
+std::vector> InputSubsystem::GetPollers([
+ [maybe_unused]] Polling::DeviceType type) const {
return {};
-#endif
}
std::string GenerateKeyboardParam(int key_code) {
diff --git a/src/input_common/main.h b/src/input_common/main.h
index eb247e164..b504ebe54 100644
--- a/src/input_common/main.h
+++ b/src/input_common/main.h
@@ -63,18 +63,6 @@ public:
};
} // namespace Polling
-class GCAnalogFactory;
-class GCButtonFactory;
-class UDPMotionFactory;
-class UDPTouchFactory;
-class MouseButtonFactory;
-class MouseAnalogFactory;
-class MouseMotionFactory;
-class MouseTouchFactory;
-class TasButtonFactory;
-class TasAnalogFactory;
-class Keyboard;
-
/**
* Given a ParamPackage for a Device returned from `GetInputDevices`, attempt to get the default
* mapping for the device. This is currently only implemented for the SDL backend devices.
@@ -100,23 +88,6 @@ public:
/// Unregisters all built-in input device factories and shuts them down.
void Shutdown();
- /// Retrieves the underlying keyboard device.
- [[nodiscard]] Keyboard* GetKeyboard();
-
- /// Retrieves the underlying keyboard device.
- [[nodiscard]] const Keyboard* GetKeyboard() const;
-
- /// Retrieves the underlying mouse device.
- [[nodiscard]] MouseInput::Mouse* GetMouse();
-
- /// Retrieves the underlying mouse device.
- [[nodiscard]] const MouseInput::Mouse* GetMouse() const;
-
- /// Retrieves the underlying tas device.
- [[nodiscard]] TasInput::Tas* GetTas();
-
- /// Retrieves the underlying tas device.
- [[nodiscard]] const TasInput::Tas* GetTas() const;
/**
* Returns all available input devices that this Factory can create a new device with.
* Each returned ParamPackage should have a `display` field used for display, a class field for
@@ -134,66 +105,6 @@ public:
/// Retrieves the motion mappings for the given device.
[[nodiscard]] MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& device) const;
- /// Retrieves the underlying GameCube analog handler.
- [[nodiscard]] GCAnalogFactory* GetGCAnalogs();
-
- /// Retrieves the underlying GameCube analog handler.
- [[nodiscard]] const GCAnalogFactory* GetGCAnalogs() const;
-
- /// Retrieves the underlying GameCube button handler.
- [[nodiscard]] GCButtonFactory* GetGCButtons();
-
- /// Retrieves the underlying GameCube button handler.
- [[nodiscard]] const GCButtonFactory* GetGCButtons() const;
-
- /// Retrieves the underlying udp motion handler.
- [[nodiscard]] UDPMotionFactory* GetUDPMotions();
-
- /// Retrieves the underlying udp motion handler.
- [[nodiscard]] const UDPMotionFactory* GetUDPMotions() const;
-
- /// Retrieves the underlying udp touch handler.
- [[nodiscard]] UDPTouchFactory* GetUDPTouch();
-
- /// Retrieves the underlying udp touch handler.
- [[nodiscard]] const UDPTouchFactory* GetUDPTouch() const;
-
- /// Retrieves the underlying mouse button handler.
- [[nodiscard]] MouseButtonFactory* GetMouseButtons();
-
- /// Retrieves the underlying mouse button handler.
- [[nodiscard]] const MouseButtonFactory* GetMouseButtons() const;
-
- /// Retrieves the underlying mouse analog handler.
- [[nodiscard]] MouseAnalogFactory* GetMouseAnalogs();
-
- /// Retrieves the underlying mouse analog handler.
- [[nodiscard]] const MouseAnalogFactory* GetMouseAnalogs() const;
-
- /// Retrieves the underlying mouse motion handler.
- [[nodiscard]] MouseMotionFactory* GetMouseMotions();
-
- /// Retrieves the underlying mouse motion handler.
- [[nodiscard]] const MouseMotionFactory* GetMouseMotions() const;
-
- /// Retrieves the underlying mouse touch handler.
- [[nodiscard]] MouseTouchFactory* GetMouseTouch();
-
- /// Retrieves the underlying mouse touch handler.
- [[nodiscard]] const MouseTouchFactory* GetMouseTouch() const;
-
- /// Retrieves the underlying tas button handler.
- [[nodiscard]] TasButtonFactory* GetTasButtons();
-
- /// Retrieves the underlying tas button handler.
- [[nodiscard]] const TasButtonFactory* GetTasButtons() const;
-
- /// Retrieves the underlying tas analogs handler.
- [[nodiscard]] TasAnalogFactory* GetTasAnalogs();
-
- /// Retrieves the underlying tas analogs handler.
- [[nodiscard]] const TasAnalogFactory* GetTasAnalogs() const;
-
/// Reloads the input devices
void ReloadInputDevices();
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index fd0a130a3..8a0ea90f9 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -34,8 +34,6 @@
#include "core/frontend/framebuffer_layout.h"
#include "input_common/keyboard.h"
#include "input_common/main.h"
-#include "input_common/mouse/mouse_input.h"
-#include "input_common/tas/tas_input.h"
#include "video_core/renderer_base.h"
#include "video_core/video_core.h"
#include "yuzu/bootmanager.h"
@@ -394,34 +392,34 @@ void GRenderWindow::closeEvent(QCloseEvent* event) {
void GRenderWindow::keyPressEvent(QKeyEvent* event) {
if (!event->isAutoRepeat()) {
- input_subsystem->GetKeyboard()->PressKey(event->key());
+ // input_subsystem->GetKeyboard()->PressKey(event->key());
}
}
void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {
if (!event->isAutoRepeat()) {
- input_subsystem->GetKeyboard()->ReleaseKey(event->key());
- }
-}
-
-MouseInput::MouseButton GRenderWindow::QtButtonToMouseButton(Qt::MouseButton button) {
- switch (button) {
- case Qt::LeftButton:
- return MouseInput::MouseButton::Left;
- case Qt::RightButton:
- return MouseInput::MouseButton::Right;
- case Qt::MiddleButton:
- return MouseInput::MouseButton::Wheel;
- case Qt::BackButton:
- return MouseInput::MouseButton::Backward;
- case Qt::ForwardButton:
- return MouseInput::MouseButton::Forward;
- case Qt::TaskButton:
- return MouseInput::MouseButton::Task;
- default:
- return MouseInput::MouseButton::Extra;
- }
-}
+ // input_subsystem->GetKeyboard()->ReleaseKey(event->key());
+ }
+}
+
+//MouseInput::MouseButton GRenderWindow::QtButtonToMouseButton(Qt::MouseButton button) {
+// switch (button) {
+// case Qt::LeftButton:
+// return MouseInput::MouseButton::Left;
+// case Qt::RightButton:
+// return MouseInput::MouseButton::Right;
+// case Qt::MiddleButton:
+// return MouseInput::MouseButton::Wheel;
+// case Qt::BackButton:
+// return MouseInput::MouseButton::Backward;
+// case Qt::ForwardButton:
+// return MouseInput::MouseButton::Forward;
+// case Qt::TaskButton:
+// return MouseInput::MouseButton::Task;
+// default:
+// return MouseInput::MouseButton::Extra;
+// }
+//}
void GRenderWindow::mousePressEvent(QMouseEvent* event) {
// Touch input is handled in TouchBeginEvent
@@ -432,8 +430,8 @@ void GRenderWindow::mousePressEvent(QMouseEvent* event) {
// coordinates and map them to the current render area
const auto pos = mapFromGlobal(QCursor::pos());
const auto [x, y] = ScaleTouch(pos);
- const auto button = QtButtonToMouseButton(event->button());
- input_subsystem->GetMouse()->PressButton(x, y, button);
+ //const auto button = QtButtonToMouseButton(event->button());
+ //input_subsystem->GetMouse()->PressButton(x, y, button);
if (event->button() == Qt::LeftButton) {
this->TouchPressed(x, y, 0);
@@ -453,7 +451,7 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
const auto [x, y] = ScaleTouch(pos);
const int center_x = width() / 2;
const int center_y = height() / 2;
- input_subsystem->GetMouse()->MouseMove(x, y, center_x, center_y);
+ //input_subsystem->GetMouse()->MouseMove(x, y, center_x, center_y);
this->TouchMoved(x, y, 0);
if (Settings::values.mouse_panning) {
@@ -469,8 +467,8 @@ void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {
return;
}
- const auto button = QtButtonToMouseButton(event->button());
- input_subsystem->GetMouse()->ReleaseButton(button);
+ //const auto button = QtButtonToMouseButton(event->button());
+ //input_subsystem->GetMouse()->ReleaseButton(button);
if (event->button() == Qt::LeftButton) {
this->TouchReleased(0);
@@ -558,8 +556,8 @@ bool GRenderWindow::event(QEvent* event) {
void GRenderWindow::focusOutEvent(QFocusEvent* event) {
QWidget::focusOutEvent(event);
- input_subsystem->GetKeyboard()->ReleaseAllKeys();
- input_subsystem->GetMouse()->ReleaseAllButtons();
+ //input_subsystem->GetKeyboard()->ReleaseAllKeys();
+ //input_subsystem->GetMouse()->ReleaseAllButtons();
this->TouchReleased(0);
}
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h
index 061e3605f..f0784046b 100644
--- a/src/yuzu/bootmanager.h
+++ b/src/yuzu/bootmanager.h
@@ -165,7 +165,7 @@ public:
void keyReleaseEvent(QKeyEvent* event) override;
/// Converts a Qt mouse button into MouseInput mouse button
- static MouseInput::MouseButton QtButtonToMouseButton(Qt::MouseButton button);
+ // static MouseInput::MouseButton QtButtonToMouseButton(Qt::MouseButton button);
void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index 3aab5d5f8..09f0b219b 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -16,10 +16,7 @@
#include "core/hle/service/hid/controllers/npad.h"
#include "core/hle/service/hid/hid.h"
#include "core/hle/service/sm/sm.h"
-#include "input_common/gcadapter/gc_poller.h"
#include "input_common/main.h"
-#include "input_common/mouse/mouse_poller.h"
-#include "input_common/udp/udp.h"
#include "ui_configure_input_player.h"
#include "yuzu/bootmanager.h"
#include "yuzu/configuration/config.h"
@@ -564,55 +561,6 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
connect(poll_timer.get(), &QTimer::timeout, [this] {
Common::ParamPackage params;
- if (input_subsystem->GetGCButtons()->IsPolling()) {
- params = input_subsystem->GetGCButtons()->GetNextInput();
- if (params.Has("engine") && IsInputAcceptable(params)) {
- SetPollingResult(params, false);
- return;
- }
- }
- if (input_subsystem->GetGCAnalogs()->IsPolling()) {
- params = input_subsystem->GetGCAnalogs()->GetNextInput();
- if (params.Has("engine") && IsInputAcceptable(params)) {
- SetPollingResult(params, false);
- return;
- }
- }
- if (input_subsystem->GetUDPMotions()->IsPolling()) {
- params = input_subsystem->GetUDPMotions()->GetNextInput();
- if (params.Has("engine")) {
- SetPollingResult(params, false);
- return;
- }
- }
- if (input_subsystem->GetMouseButtons()->IsPolling()) {
- params = input_subsystem->GetMouseButtons()->GetNextInput();
- if (params.Has("engine") && IsInputAcceptable(params)) {
- SetPollingResult(params, false);
- return;
- }
- }
- if (input_subsystem->GetMouseAnalogs()->IsPolling()) {
- params = input_subsystem->GetMouseAnalogs()->GetNextInput();
- if (params.Has("engine") && IsInputAcceptable(params)) {
- SetPollingResult(params, false);
- return;
- }
- }
- if (input_subsystem->GetMouseMotions()->IsPolling()) {
- params = input_subsystem->GetMouseMotions()->GetNextInput();
- if (params.Has("engine") && IsInputAcceptable(params)) {
- SetPollingResult(params, false);
- return;
- }
- }
- if (input_subsystem->GetMouseTouch()->IsPolling()) {
- params = input_subsystem->GetMouseTouch()->GetNextInput();
- if (params.Has("engine") && IsInputAcceptable(params)) {
- SetPollingResult(params, false);
- return;
- }
- }
for (auto& poller : device_pollers) {
params = poller->GetNextInput();
if (params.Has("engine") && IsInputAcceptable(params)) {
@@ -1353,25 +1301,6 @@ void ConfigureInputPlayer::HandleClick(
QWidget::grabMouse();
QWidget::grabKeyboard();
- if (type == InputCommon::Polling::DeviceType::Button) {
- input_subsystem->GetGCButtons()->BeginConfiguration();
- } else {
- input_subsystem->GetGCAnalogs()->BeginConfiguration();
- }
-
- if (type == InputCommon::Polling::DeviceType::Motion) {
- input_subsystem->GetUDPMotions()->BeginConfiguration();
- }
-
- if (type == InputCommon::Polling::DeviceType::Button) {
- input_subsystem->GetMouseButtons()->BeginConfiguration();
- } else if (type == InputCommon::Polling::DeviceType::AnalogPreferred) {
- input_subsystem->GetMouseAnalogs()->BeginConfiguration();
- } else if (type == InputCommon::Polling::DeviceType::Motion) {
- input_subsystem->GetMouseMotions()->BeginConfiguration();
- } else {
- input_subsystem->GetMouseTouch()->BeginConfiguration();
- }
if (type == InputCommon::Polling::DeviceType::Button) {
ui->controllerFrame->BeginMappingButton(button_id);
@@ -1393,15 +1322,6 @@ void ConfigureInputPlayer::SetPollingResult(const Common::ParamPackage& params,
QWidget::releaseMouse();
QWidget::releaseKeyboard();
- input_subsystem->GetGCButtons()->EndConfiguration();
- input_subsystem->GetGCAnalogs()->EndConfiguration();
-
- input_subsystem->GetUDPMotions()->EndConfiguration();
-
- input_subsystem->GetMouseButtons()->EndConfiguration();
- input_subsystem->GetMouseAnalogs()->EndConfiguration();
- input_subsystem->GetMouseMotions()->EndConfiguration();
- input_subsystem->GetMouseTouch()->EndConfiguration();
if (!abort) {
(*input_setter)(params);
@@ -1435,8 +1355,7 @@ void ConfigureInputPlayer::mousePressEvent(QMouseEvent* event) {
return;
}
- const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
- input_subsystem->GetMouse()->PressButton(0, 0, button);
+ //const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
}
void ConfigureInputPlayer::keyPressEvent(QKeyEvent* event) {
diff --git a/src/yuzu/debugger/controller.cpp b/src/yuzu/debugger/controller.cpp
index 5a844409b..0e190a3d5 100644
--- a/src/yuzu/debugger/controller.cpp
+++ b/src/yuzu/debugger/controller.cpp
@@ -7,7 +7,6 @@
#include
#include "common/settings.h"
#include "input_common/main.h"
-#include "input_common/tas/tas_input.h"
#include "yuzu/configuration/configure_input_player_widget.h"
#include "yuzu/debugger/controller.h"
@@ -81,5 +80,5 @@ void ControllerDialog::InputController(ControllerInput input) {
buttons |= (btn ? 1U : 0U) << index;
index++;
}
- input_subsystem->GetTas()->RecordInput(buttons, input.axis_values);
+ //input_subsystem->GetTas()->RecordInput(buttons, input.axis_values);
}
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 88e84e8f7..663760a1e 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -2969,15 +2969,15 @@ void GMainWindow::UpdateWindowTitle(std::string_view title_name, std::string_vie
}
QString GMainWindow::GetTasStateDescription() const {
- auto [tas_status, current_tas_frame, total_tas_frames] = input_subsystem->GetTas()->GetStatus();
- switch (tas_status) {
- case TasInput::TasState::Running:
- return tr("TAS state: Running %1/%2").arg(current_tas_frame).arg(total_tas_frames);
- case TasInput::TasState::Recording:
- return tr("TAS state: Recording %1").arg(total_tas_frames);
- case TasInput::TasState::Stopped:
- return tr("TAS state: Idle %1/%2").arg(current_tas_frame).arg(total_tas_frames);
- default:
+ //auto [tas_status, current_tas_frame, total_tas_frames] = input_subsystem->GetTas()->GetStatus();
+ //switch (tas_status) {
+ //case TasInput::TasState::Running:
+ // return tr("TAS state: Running %1/%2").arg(current_tas_frame).arg(total_tas_frames);
+ //case TasInput::TasState::Recording:
+ // return tr("TAS state: Recording %1").arg(total_tas_frames);
+ //case TasInput::TasState::Stopped:
+ // return tr("TAS state: Idle %1/%2").arg(current_tas_frame).arg(total_tas_frames);
+ //default:
return tr("TAS State: Invalid");
}
}
--
cgit v1.2.3
From c405a19b73fa1e084918a2d39336363cd0f8b567 Mon Sep 17 00:00:00 2001
From: german77
Date: Mon, 20 Sep 2021 19:47:45 -0500
Subject: yuzu: Update frontend
---
src/yuzu/configuration/config.cpp | 1 -
src/yuzu/configuration/configure_input.cpp | 16 +-
src/yuzu/configuration/configure_input.h | 3 +-
src/yuzu/configuration/configure_input_player.cpp | 922 ++++++++-------------
src/yuzu/configuration/configure_input_player.h | 49 +-
src/yuzu/configuration/configure_input_player.ui | 10 -
.../configure_input_player_widget.cpp | 597 +++++++------
.../configuration/configure_input_player_widget.h | 133 +--
src/yuzu/configuration/configure_motion_touch.cpp | 4 +-
.../configuration/configure_mouse_advanced.cpp | 57 +-
src/yuzu/configuration/configure_mouse_advanced.h | 8 +-
.../configuration/configure_touch_from_button.cpp | 27 +-
.../configuration/configure_touch_from_button.h | 5 -
13 files changed, 822 insertions(+), 1010 deletions(-)
(limited to 'src/yuzu/configuration')
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp
index 2b670ddfd..56af07507 100644
--- a/src/yuzu/configuration/config.cpp
+++ b/src/yuzu/configuration/config.cpp
@@ -11,7 +11,6 @@
#include "core/hle/service/acc/profile_manager.h"
#include "core/hle/service/hid/controllers/npad.h"
#include "input_common/main.h"
-#include "input_common/udp/client.h"
#include "yuzu/configuration/config.h"
namespace FS = Common::FS;
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp
index 1599299db..61513865f 100644
--- a/src/yuzu/configuration/configure_input.cpp
+++ b/src/yuzu/configuration/configure_input.cpp
@@ -73,7 +73,7 @@ ConfigureInput::ConfigureInput(Core::System& system_, QWidget* parent)
ConfigureInput::~ConfigureInput() = default;
-void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem,
+void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem, Core::System& system,
std::size_t max_players) {
player_controllers = {
new ConfigureInputPlayer(this, 0, ui->consoleInputSettings, input_subsystem, profiles.get(),
@@ -184,22 +184,8 @@ QList ConfigureInput::GetSubTabs() const {
void ConfigureInput::ApplyConfiguration() {
for (auto* controller : player_controllers) {
controller->ApplyConfiguration();
- controller->TryDisconnectSelectedController();
}
- // This emulates a delay between disconnecting and reconnecting controllers as some games
- // do not respond to a change in controller type if it was instantaneous.
- using namespace std::chrono_literals;
- std::this_thread::sleep_for(150ms);
-
- for (auto* controller : player_controllers) {
- controller->TryConnectSelectedController();
- }
-
- // This emulates a delay between disconnecting and reconnecting controllers as some games
- // do not respond to a change in controller type if it was instantaneous.
- std::this_thread::sleep_for(150ms);
-
advanced->ApplyConfiguration();
const bool pre_docked_mode = Settings::values.use_docked_mode.GetValue();
diff --git a/src/yuzu/configuration/configure_input.h b/src/yuzu/configuration/configure_input.h
index 4cafa3dab..6e5edad58 100644
--- a/src/yuzu/configuration/configure_input.h
+++ b/src/yuzu/configuration/configure_input.h
@@ -42,7 +42,8 @@ public:
~ConfigureInput() override;
/// Initializes the input dialog with the given input subsystem.
- void Initialize(InputCommon::InputSubsystem* input_subsystem_, std::size_t max_players = 8);
+ void Initialize(InputCommon::InputSubsystem* input_subsystem_, Core::System& system,
+ std::size_t max_players = 8);
/// Save all button configurations to settings file.
void ApplyConfiguration();
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index 09f0b219b..adc9706f1 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -13,9 +13,11 @@
#include
#include "common/param_package.h"
#include "core/core.h"
-#include "core/hle/service/hid/controllers/npad.h"
-#include "core/hle/service/hid/hid.h"
-#include "core/hle/service/sm/sm.h"
+#include "core/hid/emulated_controller.h"
+#include "core/hid/hid_core.h"
+#include "core/hid/hid_types.h"
+#include "input_common/drivers/keyboard.h"
+#include "input_common/drivers/mouse.h"
#include "input_common/main.h"
#include "ui_configure_input_player.h"
#include "yuzu/bootmanager.h"
@@ -26,8 +28,6 @@
#include "yuzu/configuration/input_profiles.h"
#include "yuzu/util/limitable_input_dialog.h"
-using namespace Service::HID;
-
const std::array
ConfigureInputPlayer::analog_sub_buttons{{
"up",
@@ -40,31 +40,8 @@ namespace {
constexpr std::size_t HANDHELD_INDEX = 8;
-void UpdateController(Settings::ControllerType controller_type, std::size_t npad_index,
- bool connected, Core::System& system) {
- if (!system.IsPoweredOn()) {
- return;
- }
- Service::SM::ServiceManager& sm = system.ServiceManager();
-
- auto& npad = sm.GetService("hid")->GetAppletResource()->GetController(
- HidController::NPad);
-
- npad.UpdateControllerAt(npad.MapSettingsTypeToNPad(controller_type), npad_index, connected);
-}
-
QString GetKeyName(int key_code) {
switch (key_code) {
- case Qt::LeftButton:
- return QObject::tr("Click 0");
- case Qt::RightButton:
- return QObject::tr("Click 1");
- case Qt::MiddleButton:
- return QObject::tr("Click 2");
- case Qt::BackButton:
- return QObject::tr("Click 3");
- case Qt::ForwardButton:
- return QObject::tr("Click 4");
case Qt::Key_Shift:
return QObject::tr("Shift");
case Qt::Key_Control:
@@ -94,95 +71,26 @@ void SetAnalogParam(const Common::ParamPackage& input_param, Common::ParamPackag
}
analog_param.Set(button_name, input_param.Serialize());
}
+} // namespace
-QString ButtonToText(const Common::ParamPackage& param) {
+QString ConfigureInputPlayer::ButtonToText(const Common::ParamPackage& param) {
if (!param.Has("engine")) {
return QObject::tr("[not set]");
}
+ // Retrieve the names from Qt
if (param.Get("engine", "") == "keyboard") {
const QString button_str = GetKeyName(param.Get("code", 0));
const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : "");
return QObject::tr("%1%2").arg(toggle, button_str);
}
- if (param.Get("engine", "") == "gcpad") {
- if (param.Has("axis")) {
- const QString axis_str = QString::fromStdString(param.Get("axis", ""));
- const QString direction_str = QString::fromStdString(param.Get("direction", ""));
-
- return QObject::tr("GC Axis %1%2").arg(axis_str, direction_str);
- }
- if (param.Has("button")) {
- const QString button_str = QString::number(int(std::log2(param.Get("button", 0))));
- return QObject::tr("GC Button %1").arg(button_str);
- }
- return GetKeyName(param.Get("code", 0));
- }
-
- if (param.Get("engine", "") == "tas") {
- if (param.Has("axis")) {
- const QString axis_str = QString::fromStdString(param.Get("axis", ""));
-
- return QObject::tr("TAS Axis %1").arg(axis_str);
- }
- if (param.Has("button")) {
- const QString button_str = QString::number(int(std::log2(param.Get("button", 0))));
- return QObject::tr("TAS Btn %1").arg(button_str);
- }
- return GetKeyName(param.Get("code", 0));
- }
-
- if (param.Get("engine", "") == "cemuhookudp") {
- if (param.Has("pad_index")) {
- const QString motion_str = QString::fromStdString(param.Get("pad_index", ""));
- return QObject::tr("Motion %1").arg(motion_str);
- }
- return GetKeyName(param.Get("code", 0));
- }
-
- if (param.Get("engine", "") == "sdl") {
- if (param.Has("hat")) {
- const QString hat_str = QString::fromStdString(param.Get("hat", ""));
- const QString direction_str = QString::fromStdString(param.Get("direction", ""));
-
- return QObject::tr("Hat %1 %2").arg(hat_str, direction_str);
- }
-
- if (param.Has("axis")) {
- const QString axis_str = QString::fromStdString(param.Get("axis", ""));
- const QString direction_str = QString::fromStdString(param.Get("direction", ""));
-
- return QObject::tr("Axis %1%2").arg(axis_str, direction_str);
- }
-
- if (param.Has("button")) {
- const QString button_str = QString::fromStdString(param.Get("button", ""));
- const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : "");
-
- return QObject::tr("%1Button %2").arg(toggle, button_str);
- }
-
- if (param.Has("motion")) {
- return QObject::tr("SDL Motion");
- }
-
- return {};
- }
-
- if (param.Get("engine", "") == "mouse") {
- if (param.Has("button")) {
- const QString button_str = QString::number(int(param.Get("button", 0)));
- const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : "");
- return QObject::tr("%1Click %2").arg(toggle, button_str);
- }
- return GetKeyName(param.Get("code", 0));
- }
-
- return QObject::tr("[unknown]");
+ std::string button_name = input_subsystem->GetButtonName(param);
+ return QString::fromStdString(button_name);
}
-QString AnalogToText(const Common::ParamPackage& param, const std::string& dir) {
+QString ConfigureInputPlayer::AnalogToText(const Common::ParamPackage& param,
+ const std::string& dir) {
if (!param.Has("engine")) {
return QObject::tr("[not set]");
}
@@ -191,39 +99,39 @@ QString AnalogToText(const Common::ParamPackage& param, const std::string& dir)
return ButtonToText(Common::ParamPackage{param.Get(dir, "")});
}
+ if (!param.Has("axis_x") || !param.Has("axis_y")) {
+ return QObject::tr("[unknown]");
+ }
+
const auto engine_str = param.Get("engine", "");
const QString axis_x_str = QString::fromStdString(param.Get("axis_x", ""));
const QString axis_y_str = QString::fromStdString(param.Get("axis_y", ""));
const bool invert_x = param.Get("invert_x", "+") == "-";
const bool invert_y = param.Get("invert_y", "+") == "-";
- if (engine_str == "sdl" || engine_str == "gcpad" || engine_str == "mouse" ||
- engine_str == "tas") {
- if (dir == "modifier") {
- return QObject::tr("[unused]");
- }
- if (dir == "left") {
- const QString invert_x_str = QString::fromStdString(invert_x ? "+" : "-");
- return QObject::tr("Axis %1%2").arg(axis_x_str, invert_x_str);
- }
- if (dir == "right") {
- const QString invert_x_str = QString::fromStdString(invert_x ? "-" : "+");
- return QObject::tr("Axis %1%2").arg(axis_x_str, invert_x_str);
- }
- if (dir == "up") {
- const QString invert_y_str = QString::fromStdString(invert_y ? "-" : "+");
- return QObject::tr("Axis %1%2").arg(axis_y_str, invert_y_str);
- }
- if (dir == "down") {
- const QString invert_y_str = QString::fromStdString(invert_y ? "+" : "-");
- return QObject::tr("Axis %1%2").arg(axis_y_str, invert_y_str);
- }
+ if (dir == "modifier") {
+ return QObject::tr("[unused]");
+ }
- return {};
+ if (dir == "left") {
+ const QString invert_x_str = QString::fromStdString(invert_x ? "+" : "-");
+ return QObject::tr("Axis %1%2").arg(axis_x_str, invert_x_str);
+ }
+ if (dir == "right") {
+ const QString invert_x_str = QString::fromStdString(invert_x ? "-" : "+");
+ return QObject::tr("Axis %1%2").arg(axis_x_str, invert_x_str);
+ }
+ if (dir == "up") {
+ const QString invert_y_str = QString::fromStdString(invert_y ? "-" : "+");
+ return QObject::tr("Axis %1%2").arg(axis_y_str, invert_y_str);
}
+ if (dir == "down") {
+ const QString invert_y_str = QString::fromStdString(invert_y ? "+" : "-");
+ return QObject::tr("Axis %1%2").arg(axis_y_str, invert_y_str);
+ }
+
return QObject::tr("[unknown]");
}
-} // namespace
ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_index,
QWidget* bottom_row,
@@ -234,6 +142,9 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
debug(debug), input_subsystem{input_subsystem_}, profiles(profiles_),
timeout_timer(std::make_unique()), poll_timer(std::make_unique()),
bottom_row(bottom_row), system{system_} {
+
+ emulated_controller = system_.HIDCore().GetEmulatedControllerByIndex(player_index);
+ emulated_controller->EnableConfiguration();
ui->setupUi(this);
setFocusPolicy(Qt::ClickFocus);
@@ -275,31 +186,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
analog_map_range_groupbox = {ui->buttonLStickRangeGroup, ui->buttonRStickRangeGroup};
analog_map_range_spinbox = {ui->spinboxLStickRange, ui->spinboxRStickRange};
- const auto ConfigureButtonClick = [&](QPushButton* button, std::size_t button_id,
- Common::ParamPackage* param, int default_val,
- InputCommon::Polling::DeviceType type) {
- connect(button, &QPushButton::clicked, [=, this] {
- HandleClick(
- button, button_id,
- [=, this](Common::ParamPackage params) {
- // Workaround for ZL & ZR for analog triggers like on XBOX
- // controllers. Analog triggers (from controllers like the XBOX
- // controller) would not work due to a different range of their
- // signals (from 0 to 255 on analog triggers instead of -32768 to
- // 32768 on analog joysticks). The SDL driver misinterprets analog
- // triggers as analog joysticks.
- // TODO: reinterpret the signal range for analog triggers to map the
- // values correctly. This is required for the correct emulation of
- // the analog triggers of the GameCube controller.
- if (button == ui->buttonZL || button == ui->buttonZR) {
- params.Set("direction", "+");
- params.Set("threshold", "0.5");
- }
- *param = std::move(params);
- },
- type);
- });
- };
+ ui->controllerFrame->SetController(emulated_controller);
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) {
auto* const button = button_map[button_id];
@@ -308,34 +195,52 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
continue;
}
- ConfigureButtonClick(button_map[button_id], button_id, &buttons_param[button_id],
- Config::default_buttons[button_id],
- InputCommon::Polling::DeviceType::Button);
+ connect(button, &QPushButton::clicked, [=, this] {
+ HandleClick(
+ button, button_id,
+ [=, this](Common::ParamPackage params) {
+ emulated_controller->SetButtonParam(button_id, params);
+ },
+ InputCommon::Polling::InputType::Button);
+ });
button->setContextMenuPolicy(Qt::CustomContextMenu);
connect(button, &QPushButton::customContextMenuRequested,
[=, this](const QPoint& menu_location) {
QMenu context_menu;
+ Common::ParamPackage param = emulated_controller->GetButtonParam(button_id);
context_menu.addAction(tr("Clear"), [&] {
- buttons_param[button_id].Clear();
+ emulated_controller->SetButtonParam(button_id, {});
button_map[button_id]->setText(tr("[not set]"));
});
- if (buttons_param[button_id].Has("toggle")) {
+ if (param.Has("button") || param.Has("hat")) {
context_menu.addAction(tr("Toggle button"), [&] {
- const bool toggle_value =
- !buttons_param[button_id].Get("toggle", false);
- buttons_param[button_id].Set("toggle", toggle_value);
- button_map[button_id]->setText(ButtonToText(buttons_param[button_id]));
+ const bool toggle_value = !param.Get("toggle", false);
+ param.Set("toggle", toggle_value);
+ button_map[button_id]->setText(ButtonToText(param));
+ emulated_controller->SetButtonParam(button_id, param);
+ });
+ context_menu.addAction(tr("Invert button"), [&] {
+ const bool toggle_value = !param.Get("inverted", false);
+ param.Set("inverted", toggle_value);
+ button_map[button_id]->setText(ButtonToText(param));
+ emulated_controller->SetButtonParam(button_id, param);
});
}
- if (buttons_param[button_id].Has("threshold")) {
+ if (param.Has("axis")) {
+ context_menu.addAction(tr("Invert axis"), [&] {
+ const bool toggle_value = !(param.Get("invert", "+") == "-");
+ param.Set("invert", toggle_value ? "-" : "+");
+ button_map[button_id]->setText(ButtonToText(param));
+ emulated_controller->SetButtonParam(button_id, param);
+ });
context_menu.addAction(tr("Set threshold"), [&] {
- const int button_threshold = static_cast(
- buttons_param[button_id].Get("threshold", 0.5f) * 100.0f);
+ const int button_threshold =
+ static_cast(param.Get("threshold", 0.5f) * 100.0f);
const int new_threshold = QInputDialog::getInt(
this, tr("Set threshold"), tr("Choose a value between 0% and 100%"),
button_threshold, 0, 100);
- buttons_param[button_id].Set("threshold", new_threshold / 100.0f);
+ param.Set("threshold", new_threshold / 100.0f);
if (button_id == Settings::NativeButton::ZL) {
ui->sliderZLThreshold->setValue(new_threshold);
@@ -343,11 +248,10 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
if (button_id == Settings::NativeButton::ZR) {
ui->sliderZRThreshold->setValue(new_threshold);
}
+ emulated_controller->SetButtonParam(button_id, param);
});
}
-
context_menu.exec(button_map[button_id]->mapToGlobal(menu_location));
- ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
});
}
@@ -357,9 +261,14 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
continue;
}
- ConfigureButtonClick(motion_map[motion_id], motion_id, &motions_param[motion_id],
- Config::default_motions[motion_id],
- InputCommon::Polling::DeviceType::Motion);
+ connect(button, &QPushButton::clicked, [=, this] {
+ HandleClick(
+ button, motion_id,
+ [=, this](Common::ParamPackage params) {
+ emulated_controller->SetMotionParam(motion_id, params);
+ },
+ InputCommon::Polling::InputType::Motion);
+ });
button->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -367,7 +276,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
[=, this](const QPoint& menu_location) {
QMenu context_menu;
context_menu.addAction(tr("Clear"), [&] {
- motions_param[motion_id].Clear();
+ emulated_controller->SetMotionParam(motion_id, {});
motion_map[motion_id]->setText(tr("[not set]"));
});
context_menu.exec(motion_map[motion_id]->mapToGlobal(menu_location));
@@ -375,16 +284,22 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
}
connect(ui->sliderZLThreshold, &QSlider::valueChanged, [=, this] {
- if (buttons_param[Settings::NativeButton::ZL].Has("threshold")) {
+ Common::ParamPackage param =
+ emulated_controller->GetButtonParam(Settings::NativeButton::ZL);
+ if (param.Has("threshold")) {
const auto slider_value = ui->sliderZLThreshold->value();
- buttons_param[Settings::NativeButton::ZL].Set("threshold", slider_value / 100.0f);
+ param.Set("threshold", slider_value / 100.0f);
+ emulated_controller->SetButtonParam(Settings::NativeButton::ZL, param);
}
});
connect(ui->sliderZRThreshold, &QSlider::valueChanged, [=, this] {
- if (buttons_param[Settings::NativeButton::ZR].Has("threshold")) {
+ Common::ParamPackage param =
+ emulated_controller->GetButtonParam(Settings::NativeButton::ZR);
+ if (param.Has("threshold")) {
const auto slider_value = ui->sliderZRThreshold->value();
- buttons_param[Settings::NativeButton::ZR].Set("threshold", slider_value / 100.0f);
+ param.Set("threshold", slider_value / 100.0f);
+ emulated_controller->SetButtonParam(Settings::NativeButton::ZR, param);
}
});
@@ -412,45 +327,45 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
HandleClick(
analog_map_buttons[analog_id][sub_button_id], analog_id,
[=, this](const Common::ParamPackage& params) {
- SetAnalogParam(params, analogs_param[analog_id],
- analog_sub_buttons[sub_button_id]);
+ Common::ParamPackage param = emulated_controller->GetStickParam(analog_id);
+ SetAnalogParam(params, param, analog_sub_buttons[sub_button_id]);
+ emulated_controller->SetStickParam(analog_id, param);
},
- InputCommon::Polling::DeviceType::AnalogPreferred);
+ InputCommon::Polling::InputType::Stick);
});
analog_button->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(
- analog_button, &QPushButton::customContextMenuRequested,
- [=, this](const QPoint& menu_location) {
- QMenu context_menu;
- context_menu.addAction(tr("Clear"), [&] {
- analogs_param[analog_id].Clear();
- analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]"));
- });
- context_menu.addAction(tr("Invert axis"), [&] {
- if (sub_button_id == 2 || sub_button_id == 3) {
- const bool invert_value =
- analogs_param[analog_id].Get("invert_x", "+") == "-";
- const std::string invert_str = invert_value ? "+" : "-";
- analogs_param[analog_id].Set("invert_x", invert_str);
- }
- if (sub_button_id == 0 || sub_button_id == 1) {
- const bool invert_value =
- analogs_param[analog_id].Get("invert_y", "+") == "-";
- const std::string invert_str = invert_value ? "+" : "-";
- analogs_param[analog_id].Set("invert_y", invert_str);
- }
- for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM;
- ++sub_button_id) {
- analog_map_buttons[analog_id][sub_button_id]->setText(AnalogToText(
- analogs_param[analog_id], analog_sub_buttons[sub_button_id]));
- }
+ connect(analog_button, &QPushButton::customContextMenuRequested,
+ [=, this](const QPoint& menu_location) {
+ QMenu context_menu;
+ Common::ParamPackage param = emulated_controller->GetStickParam(analog_id);
+ context_menu.addAction(tr("Clear"), [&] {
+ emulated_controller->SetStickParam(analog_id, {});
+ analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]"));
+ });
+ context_menu.addAction(tr("Invert axis"), [&] {
+ if (sub_button_id == 2 || sub_button_id == 3) {
+ const bool invert_value = param.Get("invert_x", "+") == "-";
+ const std::string invert_str = invert_value ? "+" : "-";
+ param.Set("invert_x", invert_str);
+ emulated_controller->SetStickParam(analog_id, param);
+ }
+ if (sub_button_id == 0 || sub_button_id == 1) {
+ const bool invert_value = param.Get("invert_y", "+") == "-";
+ const std::string invert_str = invert_value ? "+" : "-";
+ param.Set("invert_y", invert_str);
+ emulated_controller->SetStickParam(analog_id, param);
+ }
+ for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM;
+ ++sub_button_id) {
+ analog_map_buttons[analog_id][sub_button_id]->setText(
+ AnalogToText(param, analog_sub_buttons[sub_button_id]));
+ }
+ });
+ context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(
+ menu_location));
});
- context_menu.exec(
- analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(menu_location));
- ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
- });
}
// Handle clicks for the modifier buttons as well.
@@ -458,9 +373,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
HandleClick(
analog_map_modifier_button[analog_id], analog_id,
[=, this](const Common::ParamPackage& params) {
- analogs_param[analog_id].Set("modifier", params.Serialize());
+ Common::ParamPackage param = emulated_controller->GetStickParam(analog_id);
+ param.Set("modifier", params.Serialize());
+ emulated_controller->SetStickParam(analog_id, param);
},
- InputCommon::Polling::DeviceType::Button);
+ InputCommon::Polling::InputType::Button);
});
analog_map_modifier_button[analog_id]->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -468,18 +385,21 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
connect(analog_map_modifier_button[analog_id], &QPushButton::customContextMenuRequested,
[=, this](const QPoint& menu_location) {
QMenu context_menu;
+ Common::ParamPackage param = emulated_controller->GetStickParam(analog_id);
context_menu.addAction(tr("Clear"), [&] {
- analogs_param[analog_id].Set("modifier", "");
+ param.Set("modifier", "");
analog_map_modifier_button[analog_id]->setText(tr("[not set]"));
+ emulated_controller->SetStickParam(analog_id, param);
});
context_menu.addAction(tr("Toggle button"), [&] {
Common::ParamPackage modifier_param =
- Common::ParamPackage{analogs_param[analog_id].Get("modifier", "")};
+ Common::ParamPackage{param.Get("modifier", "")};
const bool toggle_value = !modifier_param.Get("toggle", false);
modifier_param.Set("toggle", toggle_value);
- analogs_param[analog_id].Set("modifier", modifier_param.Serialize());
+ param.Set("modifier", modifier_param.Serialize());
analog_map_modifier_button[analog_id]->setText(
ButtonToText(modifier_param));
+ emulated_controller->SetStickParam(analog_id, param);
});
context_menu.exec(
analog_map_modifier_button[analog_id]->mapToGlobal(menu_location));
@@ -487,37 +407,39 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
connect(analog_map_range_spinbox[analog_id], qOverload(&QSpinBox::valueChanged),
[=, this] {
+ Common::ParamPackage param = emulated_controller->GetStickParam(analog_id);
const auto spinbox_value = analog_map_range_spinbox[analog_id]->value();
- analogs_param[analog_id].Set("range", spinbox_value / 100.0f);
- ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
+ param.Set("range", spinbox_value / 100.0f);
+ emulated_controller->SetStickParam(analog_id, param);
});
connect(analog_map_deadzone_slider[analog_id], &QSlider::valueChanged, [=, this] {
+ Common::ParamPackage param = emulated_controller->GetStickParam(analog_id);
const auto slider_value = analog_map_deadzone_slider[analog_id]->value();
analog_map_deadzone_label[analog_id]->setText(tr("Deadzone: %1%").arg(slider_value));
- analogs_param[analog_id].Set("deadzone", slider_value / 100.0f);
- ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
+ param.Set("deadzone", slider_value / 100.0f);
+ emulated_controller->SetStickParam(analog_id, param);
});
connect(analog_map_modifier_slider[analog_id], &QSlider::valueChanged, [=, this] {
+ Common::ParamPackage param = emulated_controller->GetStickParam(analog_id);
const auto slider_value = analog_map_modifier_slider[analog_id]->value();
analog_map_modifier_label[analog_id]->setText(
tr("Modifier Range: %1%").arg(slider_value));
- analogs_param[analog_id].Set("modifier_scale", slider_value / 100.0f);
+ param.Set("modifier_scale", slider_value / 100.0f);
+ emulated_controller->SetStickParam(analog_id, param);
});
}
// Player Connected checkbox
- connect(ui->groupConnectedController, &QGroupBox::toggled, [this](bool checked) {
- emit Connected(checked);
- ui->controllerFrame->SetConnectedStatus(checked);
- });
+ connect(ui->groupConnectedController, &QGroupBox::toggled,
+ [this](bool checked) { emit Connected(checked); });
if (player_index == 0) {
connect(ui->comboControllerType, qOverload(&QComboBox::currentIndexChanged),
[this](int index) {
emit HandheldStateChanged(GetControllerTypeFromIndex(index) ==
- Settings::ControllerType::Handheld);
+ Core::HID::NpadType::Handheld);
});
}
@@ -534,13 +456,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
SetConnectableControllers();
}
- UpdateControllerIcon();
UpdateControllerAvailableButtons();
UpdateControllerEnabledButtons();
UpdateControllerButtonNames();
UpdateMotionButtons();
connect(ui->comboControllerType, qOverload(&QComboBox::currentIndexChanged), [this](int) {
- UpdateControllerIcon();
UpdateControllerAvailableButtons();
UpdateControllerEnabledButtons();
UpdateControllerButtonNames();
@@ -560,13 +480,10 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); });
connect(poll_timer.get(), &QTimer::timeout, [this] {
- Common::ParamPackage params;
- for (auto& poller : device_pollers) {
- params = poller->GetNextInput();
- if (params.Has("engine") && IsInputAcceptable(params)) {
- SetPollingResult(params, false);
- return;
- }
+ const auto& params = input_subsystem->GetNextInput();
+ if (params.Has("engine") && IsInputAcceptable(params)) {
+ SetPollingResult(params, false);
+ return;
}
});
@@ -582,110 +499,14 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
&ConfigureInputPlayer::SaveProfile);
LoadConfiguration();
- ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
- ui->controllerFrame->SetConnectedStatus(ui->groupConnectedController->isChecked());
}
-ConfigureInputPlayer::~ConfigureInputPlayer() = default;
+ConfigureInputPlayer::~ConfigureInputPlayer() {
+ emulated_controller->DisableConfiguration();
+};
void ConfigureInputPlayer::ApplyConfiguration() {
- auto& player = Settings::values.players.GetValue()[player_index];
- auto& buttons = debug ? Settings::values.debug_pad_buttons : player.buttons;
- auto& analogs = debug ? Settings::values.debug_pad_analogs : player.analogs;
-
- std::transform(buttons_param.begin(), buttons_param.end(), buttons.begin(),
- [](const Common::ParamPackage& param) { return param.Serialize(); });
- std::transform(analogs_param.begin(), analogs_param.end(), analogs.begin(),
- [](const Common::ParamPackage& param) { return param.Serialize(); });
-
- if (debug) {
- return;
- }
-
- auto& motions = player.motions;
-
- std::transform(motions_param.begin(), motions_param.end(), motions.begin(),
- [](const Common::ParamPackage& param) { return param.Serialize(); });
-
- // Apply configuration for handheld
- if (player_index == 0) {
- auto& handheld = Settings::values.players.GetValue()[HANDHELD_INDEX];
- const auto handheld_connected = handheld.connected;
- handheld = player;
- handheld.connected = handheld_connected;
- }
-}
-
-void ConfigureInputPlayer::TryConnectSelectedController() {
- auto& player = Settings::values.players.GetValue()[player_index];
-
- const auto controller_type =
- GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
- const auto player_connected = ui->groupConnectedController->isChecked() &&
- controller_type != Settings::ControllerType::Handheld;
-
- // Connect Handheld depending on Player 1's controller configuration.
- if (player_index == 0) {
- auto& handheld = Settings::values.players.GetValue()[HANDHELD_INDEX];
- const auto handheld_connected = ui->groupConnectedController->isChecked() &&
- controller_type == Settings::ControllerType::Handheld;
- // Connect only if handheld is going from disconnected to connected
- if (!handheld.connected && handheld_connected) {
- UpdateController(controller_type, HANDHELD_INDEX, true, system);
- }
- handheld.connected = handheld_connected;
- }
-
- if (player.controller_type == controller_type && player.connected == player_connected) {
- // Set vibration devices in the event that the input device has changed.
- ConfigureVibration::SetVibrationDevices(player_index);
- return;
- }
-
- player.controller_type = controller_type;
- player.connected = player_connected;
-
- ConfigureVibration::SetVibrationDevices(player_index);
-
- if (!player.connected) {
- return;
- }
-
- UpdateController(controller_type, player_index, true, system);
-}
-
-void ConfigureInputPlayer::TryDisconnectSelectedController() {
- const auto& player = Settings::values.players.GetValue()[player_index];
-
- const auto controller_type =
- GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
- const auto player_connected = ui->groupConnectedController->isChecked() &&
- controller_type != Settings::ControllerType::Handheld;
-
- // Disconnect Handheld depending on Player 1's controller configuration.
- if (player_index == 0 && player.controller_type == Settings::ControllerType::Handheld) {
- const auto& handheld = Settings::values.players.GetValue()[HANDHELD_INDEX];
- const auto handheld_connected = ui->groupConnectedController->isChecked() &&
- controller_type == Settings::ControllerType::Handheld;
- // Disconnect only if handheld is going from connected to disconnected
- if (handheld.connected && !handheld_connected) {
- UpdateController(controller_type, HANDHELD_INDEX, false, system);
- }
- return;
- }
-
- // Do not do anything if the controller configuration has not changed.
- if (player.controller_type == controller_type && player.connected == player_connected) {
- return;
- }
-
- // Do not disconnect if the controller is already disconnected
- if (!player.connected) {
- return;
- }
-
- // Disconnect the controller first.
- UpdateController(controller_type, player_index, false, system);
+ emulated_controller->SaveCurrentConfig();
}
void ConfigureInputPlayer::showEvent(QShowEvent* event) {
@@ -710,34 +531,11 @@ void ConfigureInputPlayer::RetranslateUI() {
}
void ConfigureInputPlayer::LoadConfiguration() {
- auto& player = Settings::values.players.GetValue()[player_index];
- if (debug) {
- std::transform(Settings::values.debug_pad_buttons.begin(),
- Settings::values.debug_pad_buttons.end(), buttons_param.begin(),
- [](const std::string& str) { return Common::ParamPackage(str); });
- std::transform(Settings::values.debug_pad_analogs.begin(),
- Settings::values.debug_pad_analogs.end(), analogs_param.begin(),
- [](const std::string& str) { return Common::ParamPackage(str); });
- } else {
- std::transform(player.buttons.begin(), player.buttons.end(), buttons_param.begin(),
- [](const std::string& str) { return Common::ParamPackage(str); });
- std::transform(player.analogs.begin(), player.analogs.end(), analogs_param.begin(),
- [](const std::string& str) { return Common::ParamPackage(str); });
- std::transform(player.motions.begin(), player.motions.end(), motions_param.begin(),
- [](const std::string& str) { return Common::ParamPackage(str); });
- }
-
UpdateUI();
UpdateInputDeviceCombobox();
-
- if (debug) {
- return;
- }
-
- ui->comboControllerType->setCurrentIndex(GetIndexFromControllerType(player.controller_type));
- ui->groupConnectedController->setChecked(
- player.connected ||
- (player_index == 0 && Settings::values.players.GetValue()[HANDHELD_INDEX].connected));
+ const int comboBoxIndex = GetIndexFromControllerType(emulated_controller->GetNpadType());
+ ui->comboControllerType->setCurrentIndex(comboBoxIndex);
+ ui->groupConnectedController->setChecked(emulated_controller->IsConnected());
}
void ConfigureInputPlayer::ConnectPlayer(bool connected) {
@@ -751,48 +549,63 @@ void ConfigureInputPlayer::UpdateInputDeviceCombobox() {
return;
}
- // Find the first button that isn't empty.
- const auto button_param =
- std::find_if(buttons_param.begin(), buttons_param.end(),
- [](const Common::ParamPackage param) { return param.Has("engine"); });
- const bool buttons_empty = button_param == buttons_param.end();
+ const auto devices = emulated_controller->GetMappedDevices();
+ UpdateInputDevices();
+
+ if (devices.empty()) {
+ return;
+ }
+
+ if (devices.size() > 2) {
+ ui->comboDevices->setCurrentIndex(0);
+ return;
+ }
+
+ const auto first_engine = devices[0].Get("engine", "");
+ const auto first_guid = devices[0].Get("guid", "");
+ const auto first_port = devices[0].Get("port", "");
- const auto current_engine = button_param->Get("engine", "");
- const auto current_guid = button_param->Get("guid", "");
- const auto current_port = button_param->Get("port", "");
+ if (devices.size() == 1) {
+ const auto devices_it =
+ std::find_if(input_devices.begin(), input_devices.end(),
+ [first_engine, first_guid, first_port](const Common::ParamPackage param) {
+ return param.Get("engine", "") == first_engine &&
+ param.Get("guid", "") == first_guid &&
+ param.Get("port", "") == first_port;
+ });
+ const int device_index =
+ devices_it != input_devices.end()
+ ? static_cast(std::distance(input_devices.begin(), devices_it))
+ : 0;
+ ui->comboDevices->setCurrentIndex(device_index);
+ return;
+ }
- const bool is_keyboard_mouse = current_engine == "keyboard" || current_engine == "mouse";
+ const auto second_engine = devices[1].Get("engine", "");
+ const auto second_guid = devices[1].Get("guid", "");
+ const auto second_port = devices[1].Get("port", "");
- UpdateInputDevices();
+ const bool is_keyboard_mouse = (first_engine == "keyboard" || first_engine == "mouse") &&
+ (second_engine == "keyboard" || second_engine == "mouse");
- if (buttons_empty) {
+ if (is_keyboard_mouse) {
+ ui->comboDevices->setCurrentIndex(2);
return;
}
- const bool all_one_device =
- std::all_of(buttons_param.begin(), buttons_param.end(),
- [current_engine, current_guid, current_port,
- is_keyboard_mouse](const Common::ParamPackage param) {
- if (is_keyboard_mouse) {
- return !param.Has("engine") || param.Get("engine", "") == "keyboard" ||
- param.Get("engine", "") == "mouse";
- }
- return !param.Has("engine") || (param.Get("engine", "") == current_engine &&
- param.Get("guid", "") == current_guid &&
- param.Get("port", "") == current_port);
- });
+ const bool is_engine_equal = first_engine == second_engine;
+ const bool is_port_equal = first_port == second_port;
- if (all_one_device) {
- if (is_keyboard_mouse) {
- ui->comboDevices->setCurrentIndex(1);
- return;
- }
+ if (is_engine_equal && is_port_equal) {
const auto devices_it = std::find_if(
input_devices.begin(), input_devices.end(),
- [current_engine, current_guid, current_port](const Common::ParamPackage param) {
- return param.Get("class", "") == current_engine &&
- param.Get("guid", "") == current_guid &&
- param.Get("port", "") == current_port;
+ [first_engine, first_guid, second_guid, first_port](const Common::ParamPackage param) {
+ const bool is_guid_valid =
+ (param.Get("guid", "") == first_guid &&
+ param.Get("guid2", "") == second_guid) ||
+ (param.Get("guid", "") == second_guid && param.Get("guid2", "") == first_guid);
+ return param.Get("engine", "") == first_engine && is_guid_valid &&
+ param.Get("port", "") == first_port;
});
const int device_index =
devices_it != input_devices.end()
@@ -814,8 +627,7 @@ void ConfigureInputPlayer::ClearAll() {
if (button == nullptr) {
continue;
}
-
- buttons_param[button_id].Clear();
+ emulated_controller->SetButtonParam(button_id, {});
}
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
@@ -824,8 +636,7 @@ void ConfigureInputPlayer::ClearAll() {
if (analog_button == nullptr) {
continue;
}
-
- analogs_param[analog_id].Clear();
+ emulated_controller->SetStickParam(analog_id, {});
}
}
@@ -834,8 +645,7 @@ void ConfigureInputPlayer::ClearAll() {
if (motion_button == nullptr) {
continue;
}
-
- motions_param[motion_id].Clear();
+ emulated_controller->SetMotionParam(motion_id, {});
}
UpdateUI();
@@ -844,26 +654,31 @@ void ConfigureInputPlayer::ClearAll() {
void ConfigureInputPlayer::UpdateUI() {
for (int button = 0; button < Settings::NativeButton::NumButtons; ++button) {
- button_map[button]->setText(ButtonToText(buttons_param[button]));
+ const Common::ParamPackage param = emulated_controller->GetButtonParam(button);
+ button_map[button]->setText(ButtonToText(param));
}
- if (buttons_param[Settings::NativeButton::ZL].Has("threshold")) {
- const int button_threshold = static_cast(
- buttons_param[Settings::NativeButton::ZL].Get("threshold", 0.5f) * 100.0f);
+ const Common::ParamPackage ZL_param =
+ emulated_controller->GetButtonParam(Settings::NativeButton::ZL);
+ if (ZL_param.Has("threshold")) {
+ const int button_threshold = static_cast(ZL_param.Get("threshold", 0.5f) * 100.0f);
ui->sliderZLThreshold->setValue(button_threshold);
}
- if (buttons_param[Settings::NativeButton::ZR].Has("threshold")) {
- const int button_threshold = static_cast(
- buttons_param[Settings::NativeButton::ZR].Get("threshold", 0.5f) * 100.0f);
+ const Common::ParamPackage ZR_param =
+ emulated_controller->GetButtonParam(Settings::NativeButton::ZR);
+ if (ZR_param.Has("threshold")) {
+ const int button_threshold = static_cast(ZR_param.Get("threshold", 0.5f) * 100.0f);
ui->sliderZRThreshold->setValue(button_threshold);
}
for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
- motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id]));
+ const Common::ParamPackage param = emulated_controller->GetMotionParam(motion_id);
+ motion_map[motion_id]->setText(ButtonToText(param));
}
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
+ const Common::ParamPackage param = emulated_controller->GetStickParam(analog_id);
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
auto* const analog_button = analog_map_buttons[analog_id][sub_button_id];
@@ -871,12 +686,11 @@ void ConfigureInputPlayer::UpdateUI() {
continue;
}
- analog_button->setText(
- AnalogToText(analogs_param[analog_id], analog_sub_buttons[sub_button_id]));
+ analog_button->setText(AnalogToText(param, analog_sub_buttons[sub_button_id]));
}
analog_map_modifier_button[analog_id]->setText(
- ButtonToText(Common::ParamPackage{analogs_param[analog_id].Get("modifier", "")}));
+ ButtonToText(Common::ParamPackage{param.Get("modifier", "")}));
const auto deadzone_label = analog_map_deadzone_label[analog_id];
const auto deadzone_slider = analog_map_deadzone_slider[analog_id];
@@ -887,26 +701,14 @@ void ConfigureInputPlayer::UpdateUI() {
const auto range_spinbox = analog_map_range_spinbox[analog_id];
int slider_value;
- auto& param = analogs_param[analog_id];
- const bool is_controller =
- param.Get("engine", "") == "sdl" || param.Get("engine", "") == "gcpad" ||
- param.Get("engine", "") == "mouse" || param.Get("engine", "") == "tas";
+ const bool is_controller = input_subsystem->IsController(param);
if (is_controller) {
- if (!param.Has("deadzone")) {
- param.Set("deadzone", 0.1f);
- }
- slider_value = static_cast(param.Get("deadzone", 0.1f) * 100);
+ slider_value = static_cast(param.Get("deadzone", 0.15f) * 100);
deadzone_label->setText(tr("Deadzone: %1%").arg(slider_value));
deadzone_slider->setValue(slider_value);
- if (!param.Has("range")) {
- param.Set("range", 1.0f);
- }
range_spinbox->setValue(static_cast(param.Get("range", 1.0f) * 100));
} else {
- if (!param.Has("modifier_scale")) {
- param.Set("modifier_scale", 0.5f);
- }
slider_value = static_cast(param.Get("modifier_scale", 0.5f) * 100);
modifier_label->setText(tr("Modifier Range: %1%").arg(slider_value));
modifier_slider->setValue(slider_value);
@@ -918,49 +720,48 @@ void ConfigureInputPlayer::UpdateUI() {
modifier_label->setVisible(!is_controller);
modifier_slider->setVisible(!is_controller);
range_groupbox->setVisible(is_controller);
- ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
}
}
void ConfigureInputPlayer::SetConnectableControllers() {
const auto add_controllers = [this](bool enable_all,
- Controller_NPad::NpadStyleSet npad_style_set = {}) {
+ Core::HID::NpadStyleTag npad_style_set = {}) {
index_controller_type_pairs.clear();
ui->comboControllerType->clear();
if (enable_all || npad_style_set.fullkey == 1) {
index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
- Settings::ControllerType::ProController);
+ Core::HID::NpadType::ProController);
ui->comboControllerType->addItem(tr("Pro Controller"));
}
if (enable_all || npad_style_set.joycon_dual == 1) {
index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
- Settings::ControllerType::DualJoyconDetached);
+ Core::HID::NpadType::JoyconDual);
ui->comboControllerType->addItem(tr("Dual Joycons"));
}
if (enable_all || npad_style_set.joycon_left == 1) {
index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
- Settings::ControllerType::LeftJoycon);
+ Core::HID::NpadType::JoyconLeft);
ui->comboControllerType->addItem(tr("Left Joycon"));
}
if (enable_all || npad_style_set.joycon_right == 1) {
index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
- Settings::ControllerType::RightJoycon);
+ Core::HID::NpadType::JoyconRight);
ui->comboControllerType->addItem(tr("Right Joycon"));
}
if (player_index == 0 && (enable_all || npad_style_set.handheld == 1)) {
index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
- Settings::ControllerType::Handheld);
+ Core::HID::NpadType::Handheld);
ui->comboControllerType->addItem(tr("Handheld"));
}
if (enable_all || npad_style_set.gamecube == 1) {
index_controller_type_pairs.emplace_back(ui->comboControllerType->count(),
- Settings::ControllerType::GameCube);
+ Core::HID::NpadType::GameCube);
ui->comboControllerType->addItem(tr("GameCube Controller"));
}
};
@@ -970,27 +771,22 @@ void ConfigureInputPlayer::SetConnectableControllers() {
return;
}
- Service::SM::ServiceManager& sm = system.ServiceManager();
-
- auto& npad = sm.GetService("hid")->GetAppletResource()->GetController(
- HidController::NPad);
-
- add_controllers(false, npad.GetSupportedStyleSet());
+ add_controllers(false, system.HIDCore().GetSupportedStyleTag());
}
-Settings::ControllerType ConfigureInputPlayer::GetControllerTypeFromIndex(int index) const {
+Core::HID::NpadType ConfigureInputPlayer::GetControllerTypeFromIndex(int index) const {
const auto it =
std::find_if(index_controller_type_pairs.begin(), index_controller_type_pairs.end(),
[index](const auto& pair) { return pair.first == index; });
if (it == index_controller_type_pairs.end()) {
- return Settings::ControllerType::ProController;
+ return Core::HID::NpadType::ProController;
}
return it->second;
}
-int ConfigureInputPlayer::GetIndexFromControllerType(Settings::ControllerType type) const {
+int ConfigureInputPlayer::GetIndexFromControllerType(Core::HID::NpadType type) const {
const auto it =
std::find_if(index_controller_type_pairs.begin(), index_controller_type_pairs.end(),
[type](const auto& pair) { return pair.second == type; });
@@ -1005,52 +801,15 @@ int ConfigureInputPlayer::GetIndexFromControllerType(Settings::ControllerType ty
void ConfigureInputPlayer::UpdateInputDevices() {
input_devices = input_subsystem->GetInputDevices();
ui->comboDevices->clear();
- for (auto& device : input_devices) {
- const std::string display = device.Get("display", "Unknown");
- ui->comboDevices->addItem(QString::fromStdString(display), {});
- if (display == "TAS") {
- device.Set("pad", static_cast(player_index));
- }
+ for (auto device : input_devices) {
+ ui->comboDevices->addItem(QString::fromStdString(device.Get("display", "Unknown")), {});
}
}
-void ConfigureInputPlayer::UpdateControllerIcon() {
- // We aren't using Qt's built in theme support here since we aren't drawing an icon (and its
- // "nonstandard" to use an image through the icon support)
- const QString stylesheet = [this] {
- switch (GetControllerTypeFromIndex(ui->comboControllerType->currentIndex())) {
- case Settings::ControllerType::ProController:
- return QStringLiteral("image: url(:/controller/pro_controller%0)");
- case Settings::ControllerType::DualJoyconDetached:
- return QStringLiteral("image: url(:/controller/dual_joycon%0)");
- case Settings::ControllerType::LeftJoycon:
- return QStringLiteral("image: url(:/controller/single_joycon_left_vertical%0)");
- case Settings::ControllerType::RightJoycon:
- return QStringLiteral("image: url(:/controller/single_joycon_right_vertical%0)");
- case Settings::ControllerType::Handheld:
- return QStringLiteral("image: url(:/controller/handheld%0)");
- default:
- return QString{};
- }
- }();
-
- const QString theme = [] {
- if (QIcon::themeName().contains(QStringLiteral("dark"))) {
- return QStringLiteral("_dark");
- } else if (QIcon::themeName().contains(QStringLiteral("midnight"))) {
- return QStringLiteral("_midnight");
- } else {
- return QString{};
- }
- }();
- ui->controllerFrame->SetControllerType(
- GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()));
-}
-
void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
if (debug) {
- layout = Settings::ControllerType::ProController;
+ layout = Core::HID::NpadType::ProController;
}
// List of all the widgets that will be hidden by any of the following layouts that need
@@ -1075,15 +834,15 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
std::vector layout_hidden;
switch (layout) {
- case Settings::ControllerType::ProController:
- case Settings::ControllerType::DualJoyconDetached:
- case Settings::ControllerType::Handheld:
+ case Core::HID::NpadType::ProController:
+ case Core::HID::NpadType::JoyconDual:
+ case Core::HID::NpadType::Handheld:
layout_hidden = {
ui->buttonShoulderButtonsSLSR,
ui->horizontalSpacerShoulderButtonsWidget2,
};
break;
- case Settings::ControllerType::LeftJoycon:
+ case Core::HID::NpadType::JoyconLeft:
layout_hidden = {
ui->horizontalSpacerShoulderButtonsWidget2,
ui->buttonShoulderButtonsRight,
@@ -1091,7 +850,7 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
ui->bottomRight,
};
break;
- case Settings::ControllerType::RightJoycon:
+ case Core::HID::NpadType::JoyconRight:
layout_hidden = {
ui->horizontalSpacerShoulderButtonsWidget,
ui->buttonShoulderButtonsLeft,
@@ -1099,7 +858,7 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
ui->bottomLeft,
};
break;
- case Settings::ControllerType::GameCube:
+ case Core::HID::NpadType::GameCube:
layout_hidden = {
ui->buttonShoulderButtonsSLSR,
ui->horizontalSpacerShoulderButtonsWidget2,
@@ -1107,6 +866,8 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
ui->buttonMiscButtonsScreenshotGroup,
};
break;
+ default:
+ break;
}
for (auto* widget : layout_hidden) {
@@ -1117,13 +878,12 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
void ConfigureInputPlayer::UpdateControllerEnabledButtons() {
auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
if (debug) {
- layout = Settings::ControllerType::ProController;
+ layout = Core::HID::NpadType::ProController;
}
// List of all the widgets that will be disabled by any of the following layouts that need
// "enabled" after the controller type changes
- const std::array layout_enable = {
- ui->buttonHome,
+ const std::array layout_enable = {
ui->buttonLStickPressedGroup,
ui->groupRStickPressed,
ui->buttonShoulderButtonsButtonLGroup,
@@ -1135,17 +895,13 @@ void ConfigureInputPlayer::UpdateControllerEnabledButtons() {
std::vector layout_disable;
switch (layout) {
- case Settings::ControllerType::ProController:
- case Settings::ControllerType::DualJoyconDetached:
- case Settings::ControllerType::Handheld:
- case Settings::ControllerType::LeftJoycon:
- case Settings::ControllerType::RightJoycon:
- // TODO(wwylele): enable this when we actually emulate it
- layout_disable = {
- ui->buttonHome,
- };
+ case Core::HID::NpadType::ProController:
+ case Core::HID::NpadType::JoyconDual:
+ case Core::HID::NpadType::Handheld:
+ case Core::HID::NpadType::JoyconLeft:
+ case Core::HID::NpadType::JoyconRight:
break;
- case Settings::ControllerType::GameCube:
+ case Core::HID::NpadType::GameCube:
layout_disable = {
ui->buttonHome,
ui->buttonLStickPressedGroup,
@@ -1153,6 +909,8 @@ void ConfigureInputPlayer::UpdateControllerEnabledButtons() {
ui->buttonShoulderButtonsButtonLGroup,
};
break;
+ default:
+ break;
}
for (auto* widget : layout_disable) {
@@ -1170,24 +928,24 @@ void ConfigureInputPlayer::UpdateMotionButtons() {
// Show/hide the "Motion 1/2" groupboxes depending on the currently selected controller.
switch (GetControllerTypeFromIndex(ui->comboControllerType->currentIndex())) {
- case Settings::ControllerType::ProController:
- case Settings::ControllerType::LeftJoycon:
- case Settings::ControllerType::Handheld:
+ case Core::HID::NpadType::ProController:
+ case Core::HID::NpadType::JoyconLeft:
+ case Core::HID::NpadType::Handheld:
// Show "Motion 1" and hide "Motion 2".
ui->buttonMotionLeftGroup->show();
ui->buttonMotionRightGroup->hide();
break;
- case Settings::ControllerType::RightJoycon:
+ case Core::HID::NpadType::JoyconRight:
// Show "Motion 2" and hide "Motion 1".
ui->buttonMotionLeftGroup->hide();
ui->buttonMotionRightGroup->show();
break;
- case Settings::ControllerType::GameCube:
+ case Core::HID::NpadType::GameCube:
// Hide both "Motion 1/2".
ui->buttonMotionLeftGroup->hide();
ui->buttonMotionRightGroup->hide();
break;
- case Settings::ControllerType::DualJoyconDetached:
+ case Core::HID::NpadType::JoyconDual:
default:
// Show both "Motion 1/2".
ui->buttonMotionLeftGroup->show();
@@ -1199,15 +957,15 @@ void ConfigureInputPlayer::UpdateMotionButtons() {
void ConfigureInputPlayer::UpdateControllerButtonNames() {
auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
if (debug) {
- layout = Settings::ControllerType::ProController;
+ layout = Core::HID::NpadType::ProController;
}
switch (layout) {
- case Settings::ControllerType::ProController:
- case Settings::ControllerType::DualJoyconDetached:
- case Settings::ControllerType::Handheld:
- case Settings::ControllerType::LeftJoycon:
- case Settings::ControllerType::RightJoycon:
+ case Core::HID::NpadType::ProController:
+ case Core::HID::NpadType::JoyconDual:
+ case Core::HID::NpadType::Handheld:
+ case Core::HID::NpadType::JoyconLeft:
+ case Core::HID::NpadType::JoyconRight:
ui->buttonMiscButtonsPlusGroup->setTitle(tr("Plus"));
ui->buttonShoulderButtonsButtonZLGroup->setTitle(tr("ZL"));
ui->buttonShoulderButtonsZRGroup->setTitle(tr("ZR"));
@@ -1215,7 +973,7 @@ void ConfigureInputPlayer::UpdateControllerButtonNames() {
ui->LStick->setTitle(tr("Left Stick"));
ui->RStick->setTitle(tr("Right Stick"));
break;
- case Settings::ControllerType::GameCube:
+ case Core::HID::NpadType::GameCube:
ui->buttonMiscButtonsPlusGroup->setTitle(tr("Start / Pause"));
ui->buttonShoulderButtonsButtonZLGroup->setTitle(tr("L"));
ui->buttonShoulderButtonsZRGroup->setTitle(tr("R"));
@@ -1223,6 +981,8 @@ void ConfigureInputPlayer::UpdateControllerButtonNames() {
ui->LStick->setTitle(tr("Control Stick"));
ui->RStick->setTitle(tr("C-Stick"));
break;
+ default:
+ break;
}
}
@@ -1231,26 +991,93 @@ void ConfigureInputPlayer::UpdateMappingWithDefaults() {
return;
}
+ for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) {
+ const auto* const button = button_map[button_id];
+ if (button == nullptr) {
+ continue;
+ }
+ emulated_controller->SetButtonParam(button_id, {});
+ }
+
+ for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
+ for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
+ const auto* const analog_button = analog_map_buttons[analog_id][sub_button_id];
+ if (analog_button == nullptr) {
+ continue;
+ }
+ emulated_controller->SetStickParam(analog_id, {});
+ }
+ }
+
+ for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
+ const auto* const motion_button = motion_map[motion_id];
+ if (motion_button == nullptr) {
+ continue;
+ }
+ emulated_controller->SetMotionParam(motion_id, {});
+ }
+
+ // Reset keyboard bindings
if (ui->comboDevices->currentIndex() == 1) {
- // Reset keyboard bindings
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) {
- buttons_param[button_id] = Common::ParamPackage{
- InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])};
+ emulated_controller->SetButtonParam(
+ button_id, Common::ParamPackage{InputCommon::GenerateKeyboardParam(
+ Config::default_buttons[button_id])});
}
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
+ Common::ParamPackage analog_param{};
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
Common::ParamPackage params{InputCommon::GenerateKeyboardParam(
Config::default_analogs[analog_id][sub_button_id])};
- SetAnalogParam(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]);
+ SetAnalogParam(params, analog_param, analog_sub_buttons[sub_button_id]);
}
- analogs_param[analog_id].Set("modifier", InputCommon::GenerateKeyboardParam(
- Config::default_stick_mod[analog_id]));
+ analog_param.Set("modifier", InputCommon::GenerateKeyboardParam(
+ Config::default_stick_mod[analog_id]));
+ emulated_controller->SetStickParam(analog_id, analog_param);
+ }
+
+ for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
+ emulated_controller->SetMotionParam(
+ motion_id, Common::ParamPackage{InputCommon::GenerateKeyboardParam(
+ Config::default_motions[motion_id])});
+ }
+
+ UpdateUI();
+ return;
+ }
+
+ // Reset keyboard with mouse bindings
+ if (ui->comboDevices->currentIndex() == 2) {
+ for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) {
+ emulated_controller->SetButtonParam(
+ button_id, Common::ParamPackage{InputCommon::GenerateKeyboardParam(
+ Config::default_buttons[button_id])});
+ }
+
+ Common::ParamPackage left_analog_param{};
+ for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
+ Common::ParamPackage params{InputCommon::GenerateKeyboardParam(
+ Config::default_analogs[Settings::NativeAnalog::LStick][sub_button_id])};
+ SetAnalogParam(params, left_analog_param, analog_sub_buttons[sub_button_id]);
}
+ left_analog_param.Set("modifier",
+ InputCommon::GenerateKeyboardParam(
+ Config::default_stick_mod[Settings::NativeAnalog::LStick]));
+ emulated_controller->SetStickParam(Settings::NativeAnalog::LStick, left_analog_param);
+
+ Common::ParamPackage right_analog_param{};
+ right_analog_param.Set("engine", "mouse");
+ right_analog_param.Set("port", 0);
+ right_analog_param.Set("axis_x", 0);
+ right_analog_param.Set("axis_y", 1);
+ emulated_controller->SetStickParam(Settings::NativeAnalog::RStick,
+ std::move(right_analog_param));
for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
- motions_param[motion_id] = Common::ParamPackage{
- InputCommon::GenerateKeyboardParam(Config::default_motions[motion_id])};
+ emulated_controller->SetMotionParam(
+ motion_id, Common::ParamPackage{InputCommon::GenerateKeyboardParam(
+ Config::default_motions[motion_id])});
}
UpdateUI();
@@ -1262,14 +1089,17 @@ void ConfigureInputPlayer::UpdateMappingWithDefaults() {
auto button_mapping = input_subsystem->GetButtonMappingForDevice(device);
auto analog_mapping = input_subsystem->GetAnalogMappingForDevice(device);
auto motion_mapping = input_subsystem->GetMotionMappingForDevice(device);
- for (std::size_t i = 0; i < buttons_param.size(); ++i) {
- buttons_param[i] = button_mapping[static_cast(i)];
+ for (std::size_t i = 0; i < button_mapping.size(); ++i) {
+ emulated_controller->SetButtonParam(
+ i, button_mapping[static_cast(i)]);
}
- for (std::size_t i = 0; i < analogs_param.size(); ++i) {
- analogs_param[i] = analog_mapping[static_cast(i)];
+ for (std::size_t i = 0; i < analog_mapping.size(); ++i) {
+ emulated_controller->SetStickParam(
+ i, analog_mapping[static_cast(i)]);
}
- for (std::size_t i = 0; i < motions_param.size(); ++i) {
- motions_param[i] = motion_mapping[static_cast(i)];
+ for (std::size_t i = 0; i < motion_mapping.size(); ++i) {
+ emulated_controller->SetMotionParam(
+ i, motion_mapping[static_cast(i)]);
}
UpdateUI();
@@ -1278,7 +1108,7 @@ void ConfigureInputPlayer::UpdateMappingWithDefaults() {
void ConfigureInputPlayer::HandleClick(
QPushButton* button, std::size_t button_id,
std::function new_input_setter,
- InputCommon::Polling::DeviceType type) {
+ InputCommon::Polling::InputType type) {
if (button == ui->buttonMotionLeft || button == ui->buttonMotionRight) {
button->setText(tr("Shake!"));
} else {
@@ -1286,25 +1116,16 @@ void ConfigureInputPlayer::HandleClick(
}
button->setFocus();
- // The first two input devices are always Any and Keyboard/Mouse. If the user filtered to a
- // controller, then they don't want keyboard/mouse input
- want_keyboard_mouse = ui->comboDevices->currentIndex() < 2;
-
input_setter = new_input_setter;
- device_pollers = input_subsystem->GetPollers(type);
-
- for (auto& poller : device_pollers) {
- poller->Start();
- }
+ input_subsystem->BeginMapping(type);
QWidget::grabMouse();
QWidget::grabKeyboard();
-
- if (type == InputCommon::Polling::DeviceType::Button) {
+ if (type == InputCommon::Polling::InputType::Button) {
ui->controllerFrame->BeginMappingButton(button_id);
- } else if (type == InputCommon::Polling::DeviceType::AnalogPreferred) {
+ } else if (type == InputCommon::Polling::InputType::Stick) {
ui->controllerFrame->BeginMappingAnalog(button_id);
}
@@ -1315,14 +1136,11 @@ void ConfigureInputPlayer::HandleClick(
void ConfigureInputPlayer::SetPollingResult(const Common::ParamPackage& params, bool abort) {
timeout_timer->stop();
poll_timer->stop();
- for (auto& poller : device_pollers) {
- poller->Stop();
- }
+ input_subsystem->StopMapping();
QWidget::releaseMouse();
QWidget::releaseKeyboard();
-
if (!abort) {
(*input_setter)(params);
}
@@ -1340,13 +1158,14 @@ bool ConfigureInputPlayer::IsInputAcceptable(const Common::ParamPackage& params)
}
// Keyboard/Mouse
- if (ui->comboDevices->currentIndex() == 1) {
+ if (ui->comboDevices->currentIndex() == 2) {
return params.Get("engine", "") == "keyboard" || params.Get("engine", "") == "mouse";
}
const auto current_input_device = input_devices[ui->comboDevices->currentIndex()];
- return params.Get("engine", "") == current_input_device.Get("class", "") &&
- params.Get("guid", "") == current_input_device.Get("guid", "") &&
+ return params.Get("engine", "") == current_input_device.Get("engine", "") &&
+ (params.Get("guid", "") == current_input_device.Get("guid", "") ||
+ params.Get("guid", "") == current_input_device.Get("guid2", "")) &&
params.Get("port", "") == current_input_device.Get("port", "");
}
@@ -1355,25 +1174,18 @@ void ConfigureInputPlayer::mousePressEvent(QMouseEvent* event) {
return;
}
- //const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
+ const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
+ input_subsystem->GetMouse()->PressButton(0, 0, 0, 0, button);
}
void ConfigureInputPlayer::keyPressEvent(QKeyEvent* event) {
+ event->ignore();
if (!input_setter || !event) {
return;
}
-
if (event->key() != Qt::Key_Escape) {
- if (want_keyboard_mouse) {
- SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->key())},
- false);
- } else {
- // Escape key wasn't pressed and we don't want any keyboard keys, so don't stop polling
- return;
- }
+ input_subsystem->GetKeyboard()->PressKey(event->key());
}
-
- SetPollingResult({}, true);
}
void ConfigureInputPlayer::CreateProfile() {
diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h
index 39b44b8a5..02d6920f1 100644
--- a/src/yuzu/configuration/configure_input_player.h
+++ b/src/yuzu/configuration/configure_input_player.h
@@ -38,14 +38,22 @@ class InputSubsystem;
}
namespace InputCommon::Polling {
-class DevicePoller;
-enum class DeviceType;
+enum class InputType;
} // namespace InputCommon::Polling
namespace Ui {
class ConfigureInputPlayer;
}
+namespace Core {
+class System;
+}
+
+namespace Core::HID {
+class EmulatedController;
+enum class NpadType : u8;
+} // namespace Core::HID
+
class ConfigureInputPlayer : public QWidget {
Q_OBJECT
@@ -59,18 +67,6 @@ public:
/// Save all button configurations to settings file.
void ApplyConfiguration();
- /**
- * Attempts to connect the currently selected controller in the HID backend.
- * This function will not do anything if it is not connected in the frontend.
- */
- void TryConnectSelectedController();
-
- /**
- * Attempts to disconnect the currently selected controller in the HID backend.
- * This function will not do anything if the configuration has not changed.
- */
- void TryDisconnectSelectedController();
-
/// Set the connection state checkbox (used to sync state).
void ConnectPlayer(bool connected);
@@ -104,6 +100,10 @@ protected:
void showEvent(QShowEvent* event) override;
private:
+ QString ButtonToText(const Common::ParamPackage& param);
+
+ QString AnalogToText(const Common::ParamPackage& param, const std::string& dir);
+
void changeEvent(QEvent* event) override;
void RetranslateUI();
@@ -113,7 +113,7 @@ private:
/// Called when the button was pressed.
void HandleClick(QPushButton* button, std::size_t button_id,
std::function new_input_setter,
- InputCommon::Polling::DeviceType type);
+ InputCommon::Polling::InputType type);
/// Finish polling and configure input using the input_setter.
void SetPollingResult(const Common::ParamPackage& params, bool abort);
@@ -134,17 +134,14 @@ private:
void SetConnectableControllers();
/// Gets the Controller Type for a given controller combobox index.
- Settings::ControllerType GetControllerTypeFromIndex(int index) const;
+ Core::HID::NpadType GetControllerTypeFromIndex(int index) const;
/// Gets the controller combobox index for a given Controller Type.
- int GetIndexFromControllerType(Settings::ControllerType type) const;
+ int GetIndexFromControllerType(Core::HID::NpadType type) const;
/// Update the available input devices.
void UpdateInputDevices();
- /// Update the current controller icon.
- void UpdateControllerIcon();
-
/// Hides and disables controller settings based on the current controller type.
void UpdateControllerAvailableButtons();
@@ -185,7 +182,7 @@ private:
std::unique_ptr poll_timer;
/// Stores a pair of "Connected Controllers" combobox index and Controller Type enum.
- std::vector> index_controller_type_pairs;
+ std::vector> index_controller_type_pairs;
static constexpr int PLAYER_COUNT = 8;
std::array player_connected_checkbox;
@@ -193,9 +190,7 @@ private:
/// This will be the the setting function when an input is awaiting configuration.
std::optional> input_setter;
- std::array buttons_param;
- std::array analogs_param;
- std::array motions_param;
+ Core::HID::EmulatedController* emulated_controller;
static constexpr int ANALOG_SUB_BUTTONS_NUM = 4;
@@ -221,15 +216,9 @@ private:
static const std::array analog_sub_buttons;
- std::vector> device_pollers;
-
/// A flag to indicate that the "Map Analog Stick" pop-up has been shown and accepted once.
bool map_analog_stick_accepted{};
- /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false,
- /// keyboard events are ignored.
- bool want_keyboard_mouse{};
-
/// List of physical devices users can map with. If a SDL backed device is selected, then you
/// can use this device to get a default mapping.
std::vector input_devices;
diff --git a/src/yuzu/configuration/configure_input_player.ui b/src/yuzu/configuration/configure_input_player.ui
index e7433912b..14ca02fd8 100644
--- a/src/yuzu/configuration/configure_input_player.ui
+++ b/src/yuzu/configuration/configure_input_player.ui
@@ -148,16 +148,6 @@
21
- -
-
- Any
-
-
- -
-
- Keyboard/Mouse
-
-
-
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp
index f31f86339..03d29f194 100644
--- a/src/yuzu/configuration/configure_input_player_widget.cpp
+++ b/src/yuzu/configuration/configure_input_player_widget.cpp
@@ -6,10 +6,11 @@
#include
#include
#include
+#include "core/core.h"
#include "yuzu/configuration/configure_input_player_widget.h"
PlayerControlPreview::PlayerControlPreview(QWidget* parent) : QFrame(parent) {
- UpdateColors();
+ is_controller_set = false;
QTimer* timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, QOverload<>::of(&PlayerControlPreview::UpdateInput));
@@ -17,38 +18,11 @@ PlayerControlPreview::PlayerControlPreview(QWidget* parent) : QFrame(parent) {
timer->start(16);
}
-PlayerControlPreview::~PlayerControlPreview() = default;
-
-void PlayerControlPreview::SetPlayerInput(std::size_t index, const ButtonParam& buttons_param,
- const AnalogParam& analogs_param) {
- player_index = index;
- Settings::ButtonsRaw buttonss;
- Settings::AnalogsRaw analogs;
- std::transform(buttons_param.begin(), buttons_param.end(), buttonss.begin(),
- [](const Common::ParamPackage& param) { return param.Serialize(); });
- std::transform(analogs_param.begin(), analogs_param.end(), analogs.begin(),
- [](const Common::ParamPackage& param) { return param.Serialize(); });
-
- std::transform(buttonss.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
- buttonss.begin() + Settings::NativeButton::BUTTON_NS_END, buttons.begin(),
- Input::CreateDevice);
- std::transform(analogs.begin() + Settings::NativeAnalog::STICK_HID_BEGIN,
- analogs.begin() + Settings::NativeAnalog::STICK_HID_END, sticks.begin(),
- Input::CreateDevice);
- UpdateColors();
-}
-void PlayerControlPreview::SetPlayerInputRaw(std::size_t index,
- const Settings::ButtonsRaw& buttons_,
- Settings::AnalogsRaw analogs_) {
- player_index = index;
- std::transform(buttons_.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
- buttons_.begin() + Settings::NativeButton::BUTTON_NS_END, buttons.begin(),
- Input::CreateDevice);
- std::transform(analogs_.begin() + Settings::NativeAnalog::STICK_HID_BEGIN,
- analogs_.begin() + Settings::NativeAnalog::STICK_HID_END, sticks.begin(),
- Input::CreateDevice);
- UpdateColors();
-}
+PlayerControlPreview::~PlayerControlPreview() {
+ if (is_controller_set) {
+ controller->DeleteCallback(callback_key);
+ }
+};
PlayerControlPreview::LedPattern PlayerControlPreview::GetColorPattern(std::size_t index,
bool player_on) {
@@ -78,20 +52,16 @@ PlayerControlPreview::LedPattern PlayerControlPreview::GetColorPattern(std::size
}
}
-void PlayerControlPreview::SetConnectedStatus(bool checked) {
- LedPattern led_pattern = GetColorPattern(player_index, checked);
-
- led_color[0] = led_pattern.position1 ? colors.led_on : colors.led_off;
- led_color[1] = led_pattern.position2 ? colors.led_on : colors.led_off;
- led_color[2] = led_pattern.position3 ? colors.led_on : colors.led_off;
- led_color[3] = led_pattern.position4 ? colors.led_on : colors.led_off;
- is_enabled = checked;
- ResetInputs();
-}
-
-void PlayerControlPreview::SetControllerType(const Settings::ControllerType type) {
- controller_type = type;
- UpdateColors();
+void PlayerControlPreview::SetController(Core::HID::EmulatedController* controller_) {
+ if (is_controller_set) {
+ controller->DeleteCallback(callback_key);
+ }
+ is_controller_set = true;
+ controller = controller_;
+ Core::HID::ControllerUpdateCallback engine_callback{
+ [this](Core::HID::ControllerTriggerType type) { ControllerUpdate(type); }};
+ callback_key = controller->SetCallback(engine_callback);
+ ControllerUpdate(Core::HID::ControllerTriggerType::All);
}
void PlayerControlPreview::BeginMappingButton(std::size_t index) {
@@ -162,79 +132,99 @@ void PlayerControlPreview::UpdateColors() {
}
void PlayerControlPreview::ResetInputs() {
- for (std::size_t index = 0; index < button_values.size(); ++index) {
- button_values[index] = false;
- }
-
- for (std::size_t index = 0; index < axis_values.size(); ++index) {
- axis_values[index].properties = {0, 1, 0};
- axis_values[index].value = {0, 0};
- axis_values[index].raw_value = {0, 0};
- }
+ button_values.fill({
+ .value = false,
+ });
+ stick_values.fill({
+ .x = {.value = 0, .properties = {0, 1, 0}},
+ .y = {.value = 0, .properties = {0, 1, 0}},
+ });
+ trigger_values.fill({
+ .analog = {.value = 0, .properties = {0, 1, 0}},
+ .pressed = false,
+ });
update();
}
-void PlayerControlPreview::UpdateInput() {
- if (!is_enabled && !mapping_active && !Settings::values.tas_enable) {
+void PlayerControlPreview::ControllerUpdate(Core::HID::ControllerTriggerType type) {
+ if (type == Core::HID::ControllerTriggerType::All) {
+ ControllerUpdate(Core::HID::ControllerTriggerType::Color);
+ ControllerUpdate(Core::HID::ControllerTriggerType::Type);
+ ControllerUpdate(Core::HID::ControllerTriggerType::Connected);
+ ControllerUpdate(Core::HID::ControllerTriggerType::Button);
+ ControllerUpdate(Core::HID::ControllerTriggerType::Stick);
+ ControllerUpdate(Core::HID::ControllerTriggerType::Trigger);
+ ControllerUpdate(Core::HID::ControllerTriggerType::Battery);
return;
}
- bool input_changed = false;
- const auto& button_state = buttons;
- for (std::size_t index = 0; index < button_values.size(); ++index) {
- bool value = false;
- if (index < Settings::NativeButton::BUTTON_NS_END) {
- value = button_state[index]->GetStatus();
- }
- bool blink = mapping_active && index == button_mapping_index;
- if (analog_mapping_index == Settings::NativeAnalog::NUM_STICKS_HID) {
- blink &= blink_counter > 25;
- }
- if (button_values[index] != value || blink) {
- input_changed = true;
- }
- button_values[index] = value || blink;
+
+ switch (type) {
+ case Core::HID::ControllerTriggerType::Connected:
+ case Core::HID::ControllerTriggerType::Disconnected:
+ is_connected = controller->IsConnected();
+ needs_redraw = true;
+ break;
+ case Core::HID::ControllerTriggerType::Type:
+ controller_type = controller->GetNpadType();
+ needs_redraw = true;
+ break;
+ case Core::HID::ControllerTriggerType::Color:
+ UpdateColors();
+ needs_redraw = true;
+ break;
+ case Core::HID::ControllerTriggerType::Button:
+ button_values = controller->GetButtonsValues();
+ needs_redraw = true;
+ break;
+ case Core::HID::ControllerTriggerType::Stick:
+ using namespace Settings::NativeAnalog;
+ stick_values = controller->GetSticksValues();
+ // Y axis is inverted
+ stick_values[LStick].y.value = -stick_values[LStick].y.value;
+ stick_values[LStick].y.raw_value = -stick_values[LStick].y.raw_value;
+ stick_values[RStick].y.value = -stick_values[RStick].y.value;
+ stick_values[RStick].y.raw_value = -stick_values[RStick].y.raw_value;
+ needs_redraw = true;
+ break;
+ case Core::HID::ControllerTriggerType::Trigger:
+ trigger_values = controller->GetTriggersValues();
+ needs_redraw = true;
+ break;
+ case Core::HID::ControllerTriggerType::Battery:
+ battery_values = controller->GetBatteryValues();
+ needs_redraw = true;
+ break;
+ default:
+ break;
}
+}
- const auto& analog_state = sticks;
- for (std::size_t index = 0; index < axis_values.size(); ++index) {
- const auto [stick_x_f, stick_y_f] = analog_state[index]->GetStatus();
- const auto [stick_x_rf, stick_y_rf] = analog_state[index]->GetRawStatus();
+void PlayerControlPreview::UpdateInput() {
+ if (mapping_active) {
- if (static_cast(stick_x_rf * 45) !=
- static_cast(axis_values[index].raw_value.x() * 45) ||
- static_cast(-stick_y_rf * 45) !=
- static_cast(axis_values[index].raw_value.y() * 45)) {
- input_changed = true;
+ for (std::size_t index = 0; index < button_values.size(); ++index) {
+ bool blink = index == button_mapping_index;
+ if (analog_mapping_index == Settings::NativeAnalog::NumAnalogs) {
+ blink &= blink_counter > 25;
+ }
+ if (button_values[index].value != blink) {
+ needs_redraw = true;
+ }
+ button_values[index].value = blink;
}
- axis_values[index].properties = analog_state[index]->GetAnalogProperties();
- axis_values[index].value = QPointF(stick_x_f, -stick_y_f);
- axis_values[index].raw_value = QPointF(stick_x_rf, -stick_y_rf);
-
- const bool blink_analog = mapping_active && index == analog_mapping_index;
- if (blink_analog) {
- input_changed = true;
- axis_values[index].value =
- QPointF(blink_counter < 25 ? -blink_counter / 25.0f : 0,
- blink_counter > 25 ? -(blink_counter - 25) / 25.0f : 0);
+ for (std::size_t index = 0; index < stick_values.size(); ++index) {
+ const bool blink_analog = index == analog_mapping_index;
+ if (blink_analog) {
+ needs_redraw = true;
+ stick_values[index].x.value = blink_counter < 25 ? -blink_counter / 25.0f : 0;
+ stick_values[index].y.value =
+ blink_counter > 25 ? -(blink_counter - 25) / 25.0f : 0;
+ }
}
}
-
- if (input_changed) {
+ if (needs_redraw) {
update();
- if (controller_callback.input != nullptr) {
- ControllerInput input{
- .axis_values = {std::pair{
- axis_values[Settings::NativeAnalog::LStick].value.x(),
- axis_values[Settings::NativeAnalog::LStick].value.y()},
- std::pair{
- axis_values[Settings::NativeAnalog::RStick].value.x(),
- axis_values[Settings::NativeAnalog::RStick].value.y()}},
- .button_values = button_values,
- .changed = true,
- };
- controller_callback.input(std::move(input));
- }
}
if (mapping_active) {
@@ -242,10 +232,6 @@ void PlayerControlPreview::UpdateInput() {
}
}
-void PlayerControlPreview::SetCallBack(ControllerCallback callback_) {
- controller_callback = std::move(callback_);
-}
-
void PlayerControlPreview::paintEvent(QPaintEvent* event) {
QFrame::paintEvent(event);
QPainter p(this);
@@ -253,22 +239,22 @@ void PlayerControlPreview::paintEvent(QPaintEvent* event) {
const QPointF center = rect().center();
switch (controller_type) {
- case Settings::ControllerType::Handheld:
+ case Core::HID::NpadType::Handheld:
DrawHandheldController(p, center);
break;
- case Settings::ControllerType::DualJoyconDetached:
+ case Core::HID::NpadType::JoyconDual:
DrawDualController(p, center);
break;
- case Settings::ControllerType::LeftJoycon:
+ case Core::HID::NpadType::JoyconLeft:
DrawLeftController(p, center);
break;
- case Settings::ControllerType::RightJoycon:
+ case Core::HID::NpadType::JoyconRight:
DrawRightController(p, center);
break;
- case Settings::ControllerType::GameCube:
+ case Core::HID::NpadType::GameCube:
DrawGCController(p, center);
break;
- case Settings::ControllerType::ProController:
+ case Core::HID::NpadType::ProController:
default:
DrawProController(p, center);
break;
@@ -281,7 +267,7 @@ void PlayerControlPreview::DrawLeftController(QPainter& p, const QPointF center)
// Sideview left joystick
DrawJoystickSideview(p, center + QPoint(142, -69),
- -axis_values[Settings::NativeAnalog::LStick].value.y(), 1.15f,
+ -stick_values[Settings::NativeAnalog::LStick].y.value, 1.15f,
button_values[LStick]);
// Topview D-pad buttons
@@ -292,7 +278,7 @@ void PlayerControlPreview::DrawLeftController(QPainter& p, const QPointF center)
// Topview left joystick
DrawJoystickSideview(p, center + QPointF(-140.5f, -28),
- -axis_values[Settings::NativeAnalog::LStick].value.x() + 15.0f, 1.15f,
+ -stick_values[Settings::NativeAnalog::LStick].x.value + 15.0f, 1.15f,
button_values[LStick]);
// Topview minus button
@@ -334,8 +320,10 @@ void PlayerControlPreview::DrawLeftController(QPainter& p, const QPointF center)
{
// Draw joysticks
using namespace Settings::NativeAnalog;
- DrawJoystick(p, center + QPointF(9, -69) + (axis_values[LStick].value * 8), 1.8f,
- button_values[Settings::NativeButton::LStick]);
+ DrawJoystick(p,
+ center + QPointF(9, -69) +
+ (QPointF(stick_values[LStick].x.value, stick_values[LStick].y.value) * 8),
+ 1.8f, button_values[Settings::NativeButton::LStick]);
DrawRawJoystick(p, center + QPointF(-140, 90), QPointF(0, 0));
}
@@ -384,6 +372,9 @@ void PlayerControlPreview::DrawLeftController(QPainter& p, const QPointF center)
p.setPen(colors.font2);
p.setBrush(colors.font2);
DrawCircle(p, center + QPoint(26, 71), 5);
+
+ // Draw battery
+ DrawBattery(p, center + QPoint(-170, -140), battery_values[0]);
}
void PlayerControlPreview::DrawRightController(QPainter& p, const QPointF center) {
@@ -392,20 +383,22 @@ void PlayerControlPreview::DrawRightController(QPainter& p, const QPointF center
// Sideview right joystick
DrawJoystickSideview(p, center + QPoint(173 - 315, 11),
- axis_values[Settings::NativeAnalog::RStick].value.y() + 10.0f, 1.15f,
+ stick_values[Settings::NativeAnalog::RStick].y.value + 10.0f, 1.15f,
button_values[Settings::NativeButton::RStick]);
+ // Topview right joystick
+ DrawJoystickSideview(p, center + QPointF(140, -28),
+ -stick_values[Settings::NativeAnalog::RStick].x.value + 15.0f, 1.15f,
+ button_values[RStick]);
+
// Topview face buttons
p.setPen(colors.outline);
button_color = colors.button;
DrawRoundButton(p, center + QPoint(163, -21), button_values[A], 11, 5, Direction::Up);
+ DrawRoundButton(p, center + QPoint(140, -21), button_values[B], 11, 5, Direction::Up);
+ DrawRoundButton(p, center + QPoint(140, -21), button_values[X], 11, 5, Direction::Up);
DrawRoundButton(p, center + QPoint(117, -21), button_values[Y], 11, 5, Direction::Up);
- // Topview right joystick
- DrawJoystickSideview(p, center + QPointF(140, -28),
- -axis_values[Settings::NativeAnalog::RStick].value.x() + 15.0f, 1.15f,
- button_values[RStick]);
-
// Topview plus button
p.setPen(colors.outline);
button_color = colors.button;
@@ -448,8 +441,10 @@ void PlayerControlPreview::DrawRightController(QPainter& p, const QPointF center
{
// Draw joysticks
using namespace Settings::NativeAnalog;
- DrawJoystick(p, center + QPointF(-9, 11) + (axis_values[RStick].value * 8), 1.8f,
- button_values[Settings::NativeButton::RStick]);
+ DrawJoystick(p,
+ center + QPointF(-9, 11) +
+ (QPointF(stick_values[RStick].x.value, stick_values[RStick].y.value) * 8),
+ 1.8f, button_values[Settings::NativeButton::RStick]);
DrawRawJoystick(p, QPointF(0, 0), center + QPointF(140, 90));
}
@@ -503,6 +498,9 @@ void PlayerControlPreview::DrawRightController(QPainter& p, const QPointF center
p.setPen(colors.transparent);
p.setBrush(colors.font2);
DrawSymbol(p, center + QPoint(-26, 66), Symbol::House, 5);
+
+ // Draw battery
+ DrawBattery(p, center + QPoint(110, -140), battery_values[1]);
}
void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center) {
@@ -512,17 +510,19 @@ void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center)
// Left/Right trigger
DrawDualTriggers(p, center, button_values[L], button_values[R]);
+ // Topview right joystick
+ DrawJoystickSideview(p, center + QPointF(180, -78),
+ -stick_values[Settings::NativeAnalog::RStick].x.value + 15.0f, 1,
+ button_values[RStick]);
+
// Topview face buttons
p.setPen(colors.outline);
button_color = colors.button;
DrawRoundButton(p, center + QPoint(200, -71), button_values[A], 10, 5, Direction::Up);
+ DrawRoundButton(p, center + QPoint(180, -71), button_values[B], 10, 5, Direction::Up);
+ DrawRoundButton(p, center + QPoint(180, -71), button_values[X], 10, 5, Direction::Up);
DrawRoundButton(p, center + QPoint(160, -71), button_values[Y], 10, 5, Direction::Up);
- // Topview right joystick
- DrawJoystickSideview(p, center + QPointF(180, -78),
- -axis_values[Settings::NativeAnalog::RStick].value.x() + 15.0f, 1,
- button_values[RStick]);
-
// Topview plus button
p.setPen(colors.outline);
button_color = colors.button;
@@ -538,7 +538,7 @@ void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center)
// Topview left joystick
DrawJoystickSideview(p, center + QPointF(-180.5f, -78),
- -axis_values[Settings::NativeAnalog::LStick].value.x() + 15.0f, 1,
+ -stick_values[Settings::NativeAnalog::LStick].x.value + 15.0f, 1,
button_values[LStick]);
// Topview minus button
@@ -557,13 +557,13 @@ void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center)
{
// Draw joysticks
using namespace Settings::NativeAnalog;
- const auto& l_stick = axis_values[LStick];
+ const auto l_stick = QPointF(stick_values[LStick].x.value, stick_values[LStick].y.value);
const auto l_button = button_values[Settings::NativeButton::LStick];
- const auto& r_stick = axis_values[RStick];
+ const auto r_stick = QPointF(stick_values[RStick].x.value, stick_values[RStick].y.value);
const auto r_button = button_values[Settings::NativeButton::RStick];
- DrawJoystick(p, center + QPointF(-65, -65) + (l_stick.value * 7), 1.62f, l_button);
- DrawJoystick(p, center + QPointF(65, 12) + (r_stick.value * 7), 1.62f, r_button);
+ DrawJoystick(p, center + QPointF(-65, -65) + (l_stick * 7), 1.62f, l_button);
+ DrawJoystick(p, center + QPointF(65, 12) + (r_stick * 7), 1.62f, r_button);
DrawRawJoystick(p, center + QPointF(-180, 90), center + QPointF(180, 90));
}
@@ -634,6 +634,10 @@ void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center)
p.setPen(colors.transparent);
p.setBrush(colors.font2);
DrawSymbol(p, center + QPoint(50, 60), Symbol::House, 4.2f);
+
+ // Draw battery
+ DrawBattery(p, center + QPoint(-100, -160), battery_values[0]);
+ DrawBattery(p, center + QPoint(40, -160), battery_values[1]);
}
void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF center) {
@@ -643,13 +647,13 @@ void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF cen
{
// Draw joysticks
using namespace Settings::NativeAnalog;
- const auto& l_stick = axis_values[LStick];
+ const auto l_stick = QPointF(stick_values[LStick].x.value, stick_values[LStick].y.value);
const auto l_button = button_values[Settings::NativeButton::LStick];
- const auto& r_stick = axis_values[RStick];
+ const auto r_stick = QPointF(stick_values[RStick].x.value, stick_values[RStick].y.value);
const auto r_button = button_values[Settings::NativeButton::RStick];
- DrawJoystick(p, center + QPointF(-171, -41) + (l_stick.value * 4), 1.0f, l_button);
- DrawJoystick(p, center + QPointF(171, 8) + (r_stick.value * 4), 1.0f, r_button);
+ DrawJoystick(p, center + QPointF(-171, -41) + (l_stick * 4), 1.0f, l_button);
+ DrawJoystick(p, center + QPointF(171, 8) + (r_stick * 4), 1.0f, r_button);
DrawRawJoystick(p, center + QPointF(-50, 0), center + QPointF(50, 0));
}
@@ -732,6 +736,11 @@ void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF cen
p.setPen(colors.transparent);
p.setBrush(colors.font2);
DrawSymbol(p, center + QPoint(161, 37), Symbol::House, 2.75f);
+
+ // Draw battery
+ DrawBattery(p, center + QPoint(-200, 110), battery_values[0]);
+ DrawBattery(p, center + QPoint(-30, 110), battery_values[1]);
+ DrawBattery(p, center + QPoint(130, 110), battery_values[2]);
}
void PlayerControlPreview::DrawProController(QPainter& p, const QPointF center) {
@@ -741,9 +750,11 @@ void PlayerControlPreview::DrawProController(QPainter& p, const QPointF center)
{
// Draw joysticks
using namespace Settings::NativeAnalog;
- DrawProJoystick(p, center + QPointF(-111, -55), axis_values[LStick].value, 11,
+ const auto l_stick = QPointF(stick_values[LStick].x.value, stick_values[LStick].y.value);
+ const auto r_stick = QPointF(stick_values[RStick].x.value, stick_values[RStick].y.value);
+ DrawProJoystick(p, center + QPointF(-111, -55), l_stick, 11,
button_values[Settings::NativeButton::LStick]);
- DrawProJoystick(p, center + QPointF(51, 0), axis_values[RStick].value, 11,
+ DrawProJoystick(p, center + QPointF(51, 0), r_stick, 11,
button_values[Settings::NativeButton::RStick]);
DrawRawJoystick(p, center + QPointF(-50, 105), center + QPointF(50, 105));
}
@@ -817,24 +828,26 @@ void PlayerControlPreview::DrawProController(QPainter& p, const QPointF center)
p.setPen(colors.transparent);
p.setBrush(colors.font2);
DrawSymbol(p, center + QPoint(29, -56), Symbol::House, 3.9f);
+
+ // Draw battery
+ DrawBattery(p, center + QPoint(-30, -165), battery_values[0]);
}
void PlayerControlPreview::DrawGCController(QPainter& p, const QPointF center) {
- DrawGCTriggers(p, center, button_values[Settings::NativeButton::ZL],
- button_values[Settings::NativeButton::ZR]);
+ DrawGCTriggers(p, center, trigger_values[0], trigger_values[1]);
DrawGCButtonZ(p, center, button_values[Settings::NativeButton::R]);
DrawGCBody(p, center);
{
// Draw joysticks
using namespace Settings::NativeAnalog;
- DrawGCJoystick(p, center + QPointF(-111, -44) + (axis_values[LStick].value * 10), false);
+ const auto l_stick = QPointF(stick_values[LStick].x.value, stick_values[LStick].y.value);
+ const auto r_stick = QPointF(stick_values[RStick].x.value, stick_values[RStick].y.value);
+ DrawGCJoystick(p, center + QPointF(-111, -44) + (l_stick * 10), {});
button_color = colors.button2;
- DrawCircleButton(p, center + QPointF(61, 37) + (axis_values[RStick].value * 9.5f), false,
- 15);
+ DrawCircleButton(p, center + QPointF(61, 37) + (r_stick * 9.5f), {}, 15);
p.setPen(colors.transparent);
p.setBrush(colors.font);
- DrawSymbol(p, center + QPointF(61, 37) + (axis_values[RStick].value * 9.5f), Symbol::C,
- 1.0f);
+ DrawSymbol(p, center + QPointF(61, 37) + (r_stick * 9.5f), Symbol::C, 1.0f);
DrawRawJoystick(p, center + QPointF(-198, -125), center + QPointF(198, -125));
}
@@ -871,6 +884,9 @@ void PlayerControlPreview::DrawGCController(QPainter& p, const QPointF center) {
// Minus and Plus buttons
p.setPen(colors.outline);
DrawCircleButton(p, center + QPoint(0, -44), button_values[Plus], 8);
+
+ // Draw battery
+ DrawBattery(p, center + QPoint(-30, -165), battery_values[0]);
}
constexpr std::array symbol_a = {
@@ -1939,8 +1955,9 @@ void PlayerControlPreview::DrawRightBody(QPainter& p, const QPointF center) {
}
}
-void PlayerControlPreview::DrawProTriggers(QPainter& p, const QPointF center, bool left_pressed,
- bool right_pressed) {
+void PlayerControlPreview::DrawProTriggers(QPainter& p, const QPointF center,
+ const Input::ButtonStatus& left_pressed,
+ const Input::ButtonStatus& right_pressed) {
std::array qleft_trigger;
std::array qright_trigger;
std::array qbody_top;
@@ -1949,8 +1966,10 @@ void PlayerControlPreview::DrawProTriggers(QPainter& p, const QPointF center, bo
const float trigger_x = pro_left_trigger[point * 2 + 0];
const float trigger_y = pro_left_trigger[point * 2 + 1];
- qleft_trigger[point] = center + QPointF(trigger_x, trigger_y + (left_pressed ? 2 : 0));
- qright_trigger[point] = center + QPointF(-trigger_x, trigger_y + (right_pressed ? 2 : 0));
+ qleft_trigger[point] =
+ center + QPointF(trigger_x, trigger_y + (left_pressed.value ? 2 : 0));
+ qright_trigger[point] =
+ center + QPointF(-trigger_x, trigger_y + (right_pressed.value ? 2 : 0));
}
for (std::size_t point = 0; point < pro_body_top.size() / 2; ++point) {
@@ -1967,16 +1986,17 @@ void PlayerControlPreview::DrawProTriggers(QPainter& p, const QPointF center, bo
DrawPolygon(p, qbody_top);
// Left trigger
- p.setBrush(left_pressed ? colors.highlight : colors.button);
+ p.setBrush(left_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qleft_trigger);
// Right trigger
- p.setBrush(right_pressed ? colors.highlight : colors.button);
+ p.setBrush(right_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qright_trigger);
}
-void PlayerControlPreview::DrawGCTriggers(QPainter& p, const QPointF center, bool left_pressed,
- bool right_pressed) {
+void PlayerControlPreview::DrawGCTriggers(QPainter& p, const QPointF center,
+ Input::TriggerStatus left_trigger,
+ Input::TriggerStatus right_trigger) {
std::array qleft_trigger;
std::array qright_trigger;
@@ -1984,32 +2004,37 @@ void PlayerControlPreview::DrawGCTriggers(QPainter& p, const QPointF center, boo
const float trigger_x = left_gc_trigger[point * 2 + 0];
const float trigger_y = left_gc_trigger[point * 2 + 1];
- qleft_trigger[point] = center + QPointF(trigger_x, trigger_y + (left_pressed ? 10 : 0));
- qright_trigger[point] = center + QPointF(-trigger_x, trigger_y + (right_pressed ? 10 : 0));
+ qleft_trigger[point] =
+ center + QPointF(trigger_x, trigger_y + (left_trigger.analog.value * 10.0f));
+ qright_trigger[point] =
+ center + QPointF(-trigger_x, trigger_y + (right_trigger.analog.value * 10.0f));
}
// Left trigger
p.setPen(colors.outline);
- p.setBrush(left_pressed ? colors.highlight : colors.button);
+ p.setBrush(left_trigger.pressed ? colors.highlight : colors.button);
DrawPolygon(p, qleft_trigger);
// Right trigger
- p.setBrush(right_pressed ? colors.highlight : colors.button);
+ p.setBrush(right_trigger.pressed ? colors.highlight : colors.button);
DrawPolygon(p, qright_trigger);
// Draw L text
p.setPen(colors.transparent);
p.setBrush(colors.font);
- DrawSymbol(p, center + QPointF(-132, -119 + (left_pressed ? 10 : 0)), Symbol::L, 1.7f);
+ DrawSymbol(p, center + QPointF(-132, -119 + (left_trigger.analog.value * 10.0f)), Symbol::L,
+ 1.7f);
// Draw R text
p.setPen(colors.transparent);
p.setBrush(colors.font);
- DrawSymbol(p, center + QPointF(121.5f, -119 + (right_pressed ? 10 : 0)), Symbol::R, 1.7f);
+ DrawSymbol(p, center + QPointF(121.5f, -119 + (right_trigger.analog.value * 10.0f)), Symbol::R,
+ 1.7f);
}
void PlayerControlPreview::DrawHandheldTriggers(QPainter& p, const QPointF center,
- bool left_pressed, bool right_pressed) {
+ const Input::ButtonStatus& left_pressed,
+ const Input::ButtonStatus& right_pressed) {
std::array qleft_trigger;
std::array qright_trigger;
@@ -2018,23 +2043,24 @@ void PlayerControlPreview::DrawHandheldTriggers(QPainter& p, const QPointF cente
const float left_trigger_y = left_joycon_trigger[point * 2 + 1];
qleft_trigger[point] =
- center + QPointF(left_trigger_x, left_trigger_y + (left_pressed ? 0.5f : 0));
+ center + QPointF(left_trigger_x, left_trigger_y + (left_pressed.value ? 0.5f : 0));
qright_trigger[point] =
- center + QPointF(-left_trigger_x, left_trigger_y + (right_pressed ? 0.5f : 0));
+ center + QPointF(-left_trigger_x, left_trigger_y + (right_pressed.value ? 0.5f : 0));
}
// Left trigger
p.setPen(colors.outline);
- p.setBrush(left_pressed ? colors.highlight : colors.button);
+ p.setBrush(left_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qleft_trigger);
// Right trigger
- p.setBrush(right_pressed ? colors.highlight : colors.button);
+ p.setBrush(right_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qright_trigger);
}
-void PlayerControlPreview::DrawDualTriggers(QPainter& p, const QPointF center, bool left_pressed,
- bool right_pressed) {
+void PlayerControlPreview::DrawDualTriggers(QPainter& p, const QPointF center,
+ const Input::ButtonStatus& left_pressed,
+ const Input::ButtonStatus& right_pressed) {
std::array qleft_trigger;
std::array qright_trigger;
constexpr float size = 1.62f;
@@ -2043,25 +2069,27 @@ void PlayerControlPreview::DrawDualTriggers(QPainter& p, const QPointF center, b
const float left_trigger_x = left_joycon_trigger[point * 2 + 0];
const float left_trigger_y = left_joycon_trigger[point * 2 + 1];
- qleft_trigger[point] = center + QPointF(left_trigger_x * size + offset,
- left_trigger_y * size + (left_pressed ? 0.5f : 0));
+ qleft_trigger[point] =
+ center + QPointF(left_trigger_x * size + offset,
+ left_trigger_y * size + (left_pressed.value ? 0.5f : 0));
qright_trigger[point] =
center + QPointF(-left_trigger_x * size - offset,
- left_trigger_y * size + (right_pressed ? 0.5f : 0));
+ left_trigger_y * size + (right_pressed.value ? 0.5f : 0));
}
// Left trigger
p.setPen(colors.outline);
- p.setBrush(left_pressed ? colors.highlight : colors.button);
+ p.setBrush(left_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qleft_trigger);
// Right trigger
- p.setBrush(right_pressed ? colors.highlight : colors.button);
+ p.setBrush(right_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qright_trigger);
}
void PlayerControlPreview::DrawDualTriggersTopView(QPainter& p, const QPointF center,
- bool left_pressed, bool right_pressed) {
+ const Input::ButtonStatus& left_pressed,
+ const Input::ButtonStatus& right_pressed) {
std::array qleft_trigger;
std::array qright_trigger;
constexpr float size = 0.9f;
@@ -2080,9 +2108,9 @@ void PlayerControlPreview::DrawDualTriggersTopView(QPainter& p, const QPointF ce
}
p.setPen(colors.outline);
- p.setBrush(left_pressed ? colors.highlight : colors.button);
+ p.setBrush(left_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qleft_trigger);
- p.setBrush(right_pressed ? colors.highlight : colors.button);
+ p.setBrush(right_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qright_trigger);
// Draw L text
@@ -2097,7 +2125,8 @@ void PlayerControlPreview::DrawDualTriggersTopView(QPainter& p, const QPointF ce
}
void PlayerControlPreview::DrawDualZTriggersTopView(QPainter& p, const QPointF center,
- bool left_pressed, bool right_pressed) {
+ const Input::ButtonStatus& left_pressed,
+ const Input::ButtonStatus& right_pressed) {
std::array qleft_trigger;
std::array qright_trigger;
constexpr float size = 0.9f;
@@ -2114,9 +2143,9 @@ void PlayerControlPreview::DrawDualZTriggersTopView(QPainter& p, const QPointF c
}
p.setPen(colors.outline);
- p.setBrush(left_pressed ? colors.highlight : colors.button);
+ p.setBrush(left_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qleft_trigger);
- p.setBrush(right_pressed ? colors.highlight : colors.button);
+ p.setBrush(right_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qright_trigger);
// Draw ZL text
@@ -2130,7 +2159,8 @@ void PlayerControlPreview::DrawDualZTriggersTopView(QPainter& p, const QPointF c
DrawSymbol(p, center + QPointF(180, -113), Symbol::ZR, 1.0f);
}
-void PlayerControlPreview::DrawLeftTriggers(QPainter& p, const QPointF center, bool left_pressed) {
+void PlayerControlPreview::DrawLeftTriggers(QPainter& p, const QPointF center,
+ const Input::ButtonStatus& left_pressed) {
std::array qleft_trigger;
constexpr float size = 1.78f;
constexpr float offset = 311.5f;
@@ -2138,15 +2168,16 @@ void PlayerControlPreview::DrawLeftTriggers(QPainter& p, const QPointF center, b
for (std::size_t point = 0; point < left_joycon_trigger.size() / 2; ++point) {
qleft_trigger[point] = center + QPointF(left_joycon_trigger[point * 2] * size + offset,
left_joycon_trigger[point * 2 + 1] * size -
- (left_pressed ? 0.5f : 1.0f));
+ (left_pressed.value ? 0.5f : 1.0f));
}
p.setPen(colors.outline);
- p.setBrush(left_pressed ? colors.highlight : colors.button);
+ p.setBrush(left_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qleft_trigger);
}
-void PlayerControlPreview::DrawLeftZTriggers(QPainter& p, const QPointF center, bool left_pressed) {
+void PlayerControlPreview::DrawLeftZTriggers(QPainter& p, const QPointF center,
+ const Input::ButtonStatus& left_pressed) {
std::array qleft_trigger;
constexpr float size = 1.1115f;
constexpr float offset2 = 335;
@@ -2154,18 +2185,18 @@ void PlayerControlPreview::DrawLeftZTriggers(QPainter& p, const QPointF center,
for (std::size_t point = 0; point < left_joycon_sideview_zl.size() / 2; ++point) {
qleft_trigger[point] = center + QPointF(left_joycon_sideview_zl[point * 2] * size + offset2,
left_joycon_sideview_zl[point * 2 + 1] * size +
- (left_pressed ? 1.5f : 1.0f));
+ (left_pressed.value ? 1.5f : 1.0f));
}
p.setPen(colors.outline);
- p.setBrush(left_pressed ? colors.highlight : colors.button);
+ p.setBrush(left_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qleft_trigger);
- p.drawArc(center.x() + 158, center.y() + (left_pressed ? -203.5f : -204.0f), 77, 77, 225 * 16,
- 44 * 16);
+ p.drawArc(center.x() + 158, center.y() + (left_pressed.value ? -203.5f : -204.0f), 77, 77,
+ 225 * 16, 44 * 16);
}
void PlayerControlPreview::DrawLeftTriggersTopView(QPainter& p, const QPointF center,
- bool left_pressed) {
+ const Input::ButtonStatus& left_pressed) {
std::array qleft_trigger;
for (std::size_t point = 0; point < left_joystick_L_topview.size() / 2; ++point) {
@@ -2174,7 +2205,7 @@ void PlayerControlPreview::DrawLeftTriggersTopView(QPainter& p, const QPointF ce
}
p.setPen(colors.outline);
- p.setBrush(left_pressed ? colors.highlight : colors.button);
+ p.setBrush(left_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qleft_trigger);
// Draw L text
@@ -2184,7 +2215,7 @@ void PlayerControlPreview::DrawLeftTriggersTopView(QPainter& p, const QPointF ce
}
void PlayerControlPreview::DrawLeftZTriggersTopView(QPainter& p, const QPointF center,
- bool left_pressed) {
+ const Input::ButtonStatus& left_pressed) {
std::array qleft_trigger;
for (std::size_t point = 0; point < left_joystick_ZL_topview.size() / 2; ++point) {
@@ -2193,7 +2224,7 @@ void PlayerControlPreview::DrawLeftZTriggersTopView(QPainter& p, const QPointF c
}
p.setPen(colors.outline);
- p.setBrush(left_pressed ? colors.highlight : colors.button);
+ p.setBrush(left_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qleft_trigger);
// Draw ZL text
@@ -2203,7 +2234,7 @@ void PlayerControlPreview::DrawLeftZTriggersTopView(QPainter& p, const QPointF c
}
void PlayerControlPreview::DrawRightTriggers(QPainter& p, const QPointF center,
- bool right_pressed) {
+ const Input::ButtonStatus& right_pressed) {
std::array qright_trigger;
constexpr float size = 1.78f;
constexpr float offset = 311.5f;
@@ -2211,36 +2242,36 @@ void PlayerControlPreview::DrawRightTriggers(QPainter& p, const QPointF center,
for (std::size_t point = 0; point < left_joycon_trigger.size() / 2; ++point) {
qright_trigger[point] = center + QPointF(-left_joycon_trigger[point * 2] * size - offset,
left_joycon_trigger[point * 2 + 1] * size -
- (right_pressed ? 0.5f : 1.0f));
+ (right_pressed.value ? 0.5f : 1.0f));
}
p.setPen(colors.outline);
- p.setBrush(right_pressed ? colors.highlight : colors.button);
+ p.setBrush(right_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qright_trigger);
}
void PlayerControlPreview::DrawRightZTriggers(QPainter& p, const QPointF center,
- bool right_pressed) {
+ const Input::ButtonStatus& right_pressed) {
std::array qright_trigger;
constexpr float size = 1.1115f;
constexpr float offset2 = 335;
for (std::size_t point = 0; point < left_joycon_sideview_zl.size() / 2; ++point) {
qright_trigger[point] =
- center +
- QPointF(-left_joycon_sideview_zl[point * 2] * size - offset2,
- left_joycon_sideview_zl[point * 2 + 1] * size + (right_pressed ? 0.5f : 0) + 1);
+ center + QPointF(-left_joycon_sideview_zl[point * 2] * size - offset2,
+ left_joycon_sideview_zl[point * 2 + 1] * size +
+ (right_pressed.value ? 0.5f : 0) + 1);
}
p.setPen(colors.outline);
- p.setBrush(right_pressed ? colors.highlight : colors.button);
+ p.setBrush(right_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qright_trigger);
- p.drawArc(center.x() - 236, center.y() + (right_pressed ? -203.5f : -204.0f), 77, 77, 271 * 16,
- 44 * 16);
+ p.drawArc(center.x() - 236, center.y() + (right_pressed.value ? -203.5f : -204.0f), 77, 77,
+ 271 * 16, 44 * 16);
}
void PlayerControlPreview::DrawRightTriggersTopView(QPainter& p, const QPointF center,
- bool right_pressed) {
+ const Input::ButtonStatus& right_pressed) {
std::array qright_trigger;
for (std::size_t point = 0; point < left_joystick_L_topview.size() / 2; ++point) {
@@ -2249,7 +2280,7 @@ void PlayerControlPreview::DrawRightTriggersTopView(QPainter& p, const QPointF c
}
p.setPen(colors.outline);
- p.setBrush(right_pressed ? colors.highlight : colors.button);
+ p.setBrush(right_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qright_trigger);
// Draw R text
@@ -2259,7 +2290,7 @@ void PlayerControlPreview::DrawRightTriggersTopView(QPainter& p, const QPointF c
}
void PlayerControlPreview::DrawRightZTriggersTopView(QPainter& p, const QPointF center,
- bool right_pressed) {
+ const Input::ButtonStatus& right_pressed) {
std::array qright_trigger;
for (std::size_t point = 0; point < left_joystick_ZL_topview.size() / 2; ++point) {
@@ -2268,7 +2299,7 @@ void PlayerControlPreview::DrawRightZTriggersTopView(QPainter& p, const QPointF
}
p.setPen(colors.outline);
- p.setBrush(right_pressed ? colors.highlight : colors.button);
+ p.setBrush(right_pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qright_trigger);
// Draw ZR text
@@ -2278,13 +2309,13 @@ void PlayerControlPreview::DrawRightZTriggersTopView(QPainter& p, const QPointF
}
void PlayerControlPreview::DrawJoystick(QPainter& p, const QPointF center, float size,
- bool pressed) {
+ const Input::ButtonStatus& pressed) {
const float radius1 = 13.0f * size;
const float radius2 = 9.0f * size;
// Outer circle
p.setPen(colors.outline);
- p.setBrush(pressed ? colors.highlight : colors.button);
+ p.setBrush(pressed.value ? colors.highlight : colors.button);
DrawCircle(p, center, radius1);
// Cross
@@ -2292,17 +2323,17 @@ void PlayerControlPreview::DrawJoystick(QPainter& p, const QPointF center, float
p.drawLine(center - QPoint(0, radius1), center + QPoint(0, radius1));
// Inner circle
- p.setBrush(pressed ? colors.highlight2 : colors.button2);
+ p.setBrush(pressed.value ? colors.highlight2 : colors.button2);
DrawCircle(p, center, radius2);
}
void PlayerControlPreview::DrawJoystickSideview(QPainter& p, const QPointF center, float angle,
- float size, bool pressed) {
+ float size, const Input::ButtonStatus& pressed) {
QVector joystick;
joystick.reserve(static_cast(left_joystick_sideview.size() / 2));
for (std::size_t point = 0; point < left_joystick_sideview.size() / 2; ++point) {
- joystick.append(QPointF(left_joystick_sideview[point * 2] * size + (pressed ? 1 : 0),
+ joystick.append(QPointF(left_joystick_sideview[point * 2] * size + (pressed.value ? 1 : 0),
left_joystick_sideview[point * 2 + 1] * size - 1));
}
@@ -2314,14 +2345,15 @@ void PlayerControlPreview::DrawJoystickSideview(QPainter& p, const QPointF cente
// Draw joystick
p.setPen(colors.outline);
- p.setBrush(pressed ? colors.highlight : colors.button);
+ p.setBrush(pressed.value ? colors.highlight : colors.button);
p.drawPolygon(p2);
p.drawLine(p2.at(1), p2.at(30));
p.drawLine(p2.at(32), p2.at(71));
}
void PlayerControlPreview::DrawProJoystick(QPainter& p, const QPointF center, const QPointF offset,
- float offset_scalar, bool pressed) {
+ float offset_scalar,
+ const Input::ButtonStatus& pressed) {
const float radius1 = 24.0f;
const float radius2 = 17.0f;
@@ -2339,11 +2371,11 @@ void PlayerControlPreview::DrawProJoystick(QPainter& p, const QPointF center, co
// Outer circle
p.setPen(colors.outline);
- p.setBrush(pressed ? colors.highlight : colors.button);
+ p.setBrush(pressed.value ? colors.highlight : colors.button);
p.drawEllipse(QPointF(0, 0), radius1 * amplitude, radius1);
// Inner circle
- p.setBrush(pressed ? colors.highlight2 : colors.button2);
+ p.setBrush(pressed.value ? colors.highlight2 : colors.button2);
const float inner_offset =
(radius1 - radius2) * 0.4f * ((offset.x() == 0 && offset.y() < 0) ? -1.0f : 1.0f);
@@ -2355,14 +2387,15 @@ void PlayerControlPreview::DrawProJoystick(QPainter& p, const QPointF center, co
p.restore();
}
-void PlayerControlPreview::DrawGCJoystick(QPainter& p, const QPointF center, bool pressed) {
+void PlayerControlPreview::DrawGCJoystick(QPainter& p, const QPointF center,
+ const Input::ButtonStatus& pressed) {
// Outer circle
p.setPen(colors.outline);
- p.setBrush(pressed ? colors.highlight : colors.button);
+ p.setBrush(pressed.value ? colors.highlight : colors.button);
DrawCircle(p, center, 26.0f);
// Inner circle
- p.setBrush(pressed ? colors.highlight2 : colors.button2);
+ p.setBrush(pressed.value ? colors.highlight2 : colors.button2);
DrawCircle(p, center, 19.0f);
p.setBrush(colors.transparent);
DrawCircle(p, center, 13.5f);
@@ -2371,26 +2404,24 @@ void PlayerControlPreview::DrawGCJoystick(QPainter& p, const QPointF center, boo
void PlayerControlPreview::DrawRawJoystick(QPainter& p, QPointF center_left, QPointF center_right) {
using namespace Settings::NativeAnalog;
- if (controller_type != Settings::ControllerType::LeftJoycon) {
- DrawJoystickProperties(p, center_right, axis_values[RStick].properties);
+ if (controller_type != Core::HID::NpadType::JoyconLeft) {
+ DrawJoystickProperties(p, center_right, stick_values[RStick].x.properties);
p.setPen(colors.indicator);
p.setBrush(colors.indicator);
- DrawJoystickDot(p, center_right, axis_values[RStick].raw_value,
- axis_values[RStick].properties);
+ DrawJoystickDot(p, center_right, stick_values[RStick], true);
p.setPen(colors.indicator2);
p.setBrush(colors.indicator2);
- DrawJoystickDot(p, center_right, axis_values[RStick].value, axis_values[RStick].properties);
+ DrawJoystickDot(p, center_right, stick_values[RStick], false);
}
- if (controller_type != Settings::ControllerType::RightJoycon) {
- DrawJoystickProperties(p, center_left, axis_values[LStick].properties);
+ if (controller_type != Core::HID::NpadType::JoyconRight) {
+ DrawJoystickProperties(p, center_left, stick_values[LStick].x.properties);
p.setPen(colors.indicator);
p.setBrush(colors.indicator);
- DrawJoystickDot(p, center_left, axis_values[LStick].raw_value,
- axis_values[LStick].properties);
+ DrawJoystickDot(p, center_left, stick_values[LStick], true);
p.setPen(colors.indicator2);
p.setBrush(colors.indicator2);
- DrawJoystickDot(p, center_left, axis_values[LStick].value, axis_values[LStick].properties);
+ DrawJoystickDot(p, center_left, stick_values[LStick], false);
}
}
@@ -2414,19 +2445,26 @@ void PlayerControlPreview::DrawJoystickProperties(QPainter& p, const QPointF cen
DrawCircle(p, center, deadzone);
}
-void PlayerControlPreview::DrawJoystickDot(QPainter& p, const QPointF center, const QPointF value,
- const Input::AnalogProperties& properties) {
+void PlayerControlPreview::DrawJoystickDot(QPainter& p, const QPointF center,
+ const Input::StickStatus& stick, bool raw) {
constexpr float size = 45.0f;
- const float range = size * properties.range;
+ const float range = size * stick.x.properties.range;
+
+ if (raw) {
+ const QPointF value = QPointF(stick.x.raw_value, stick.y.raw_value) * size;
+ DrawCircle(p, center + value, 2);
+ return;
+ }
- // Dot pointer
- DrawCircle(p, center + (value * range), 2);
+ const QPointF value = QPointF(stick.x.value, stick.y.value) * range;
+ DrawCircle(p, center + value, 2);
}
-void PlayerControlPreview::DrawRoundButton(QPainter& p, QPointF center, bool pressed, float width,
+void PlayerControlPreview::DrawRoundButton(QPainter& p, QPointF center,
+ const Input::ButtonStatus& pressed, float width,
float height, Direction direction, float radius) {
p.setBrush(button_color);
- if (pressed) {
+ if (pressed.value) {
switch (direction) {
case Direction::Left:
center.setX(center.x() - 1);
@@ -2448,17 +2486,17 @@ void PlayerControlPreview::DrawRoundButton(QPainter& p, QPointF center, bool pre
QRectF rect = {center.x() - width, center.y() - height, width * 2.0f, height * 2.0f};
p.drawRoundedRect(rect, radius, radius);
}
-void PlayerControlPreview::DrawMinusButton(QPainter& p, const QPointF center, bool pressed,
- int button_size) {
+void PlayerControlPreview::DrawMinusButton(QPainter& p, const QPointF center,
+ const Input::ButtonStatus& pressed, int button_size) {
p.setPen(colors.outline);
- p.setBrush(pressed ? colors.highlight : colors.button);
+ p.setBrush(pressed.value ? colors.highlight : colors.button);
DrawRectangle(p, center, button_size, button_size / 3.0f);
}
-void PlayerControlPreview::DrawPlusButton(QPainter& p, const QPointF center, bool pressed,
- int button_size) {
+void PlayerControlPreview::DrawPlusButton(QPainter& p, const QPointF center,
+ const Input::ButtonStatus& pressed, int button_size) {
// Draw outer line
p.setPen(colors.outline);
- p.setBrush(pressed ? colors.highlight : colors.button);
+ p.setBrush(pressed.value ? colors.highlight : colors.button);
DrawRectangle(p, center, button_size, button_size / 3.0f);
DrawRectangle(p, center, button_size / 3.0f, button_size);
@@ -2471,7 +2509,8 @@ void PlayerControlPreview::DrawPlusButton(QPainter& p, const QPointF center, boo
DrawRectangle(p, center, button_size / 3.0f, button_size);
}
-void PlayerControlPreview::DrawGCButtonX(QPainter& p, const QPointF center, bool pressed) {
+void PlayerControlPreview::DrawGCButtonX(QPainter& p, const QPointF center,
+ const Input::ButtonStatus& pressed) {
std::array button_x;
for (std::size_t point = 0; point < gc_button_x.size() / 2; ++point) {
@@ -2479,11 +2518,12 @@ void PlayerControlPreview::DrawGCButtonX(QPainter& p, const QPointF center, bool
}
p.setPen(colors.outline);
- p.setBrush(pressed ? colors.highlight : colors.button);
+ p.setBrush(pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, button_x);
}
-void PlayerControlPreview::DrawGCButtonY(QPainter& p, const QPointF center, bool pressed) {
+void PlayerControlPreview::DrawGCButtonY(QPainter& p, const QPointF center,
+ const Input::ButtonStatus& pressed) {
std::array button_x;
for (std::size_t point = 0; point < gc_button_y.size() / 2; ++point) {
@@ -2491,27 +2531,28 @@ void PlayerControlPreview::DrawGCButtonY(QPainter& p, const QPointF center, bool
}
p.setPen(colors.outline);
- p.setBrush(pressed ? colors.highlight : colors.button);
+ p.setBrush(pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, button_x);
}
-void PlayerControlPreview::DrawGCButtonZ(QPainter& p, const QPointF center, bool pressed) {
+void PlayerControlPreview::DrawGCButtonZ(QPainter& p, const QPointF center,
+ const Input::ButtonStatus& pressed) {
std::array button_x;
for (std::size_t point = 0; point < gc_button_z.size() / 2; ++point) {
button_x[point] = center + QPointF(gc_button_z[point * 2],
- gc_button_z[point * 2 + 1] + (pressed ? 1 : 0));
+ gc_button_z[point * 2 + 1] + (pressed.value ? 1 : 0));
}
p.setPen(colors.outline);
- p.setBrush(pressed ? colors.highlight : colors.button2);
+ p.setBrush(pressed.value ? colors.highlight : colors.button2);
DrawPolygon(p, button_x);
}
-void PlayerControlPreview::DrawCircleButton(QPainter& p, const QPointF center, bool pressed,
- float button_size) {
+void PlayerControlPreview::DrawCircleButton(QPainter& p, const QPointF center,
+ const Input::ButtonStatus& pressed, float button_size) {
p.setBrush(button_color);
- if (pressed) {
+ if (pressed.value) {
p.setBrush(colors.highlight);
}
p.drawEllipse(center, button_size, button_size);
@@ -2540,7 +2581,8 @@ void PlayerControlPreview::DrawArrowButtonOutline(QPainter& p, const QPointF cen
}
void PlayerControlPreview::DrawArrowButton(QPainter& p, const QPointF center,
- const Direction direction, bool pressed, float size) {
+ const Direction direction,
+ const Input::ButtonStatus& pressed, float size) {
std::array arrow_button;
QPoint offset;
@@ -2567,8 +2609,8 @@ void PlayerControlPreview::DrawArrowButton(QPainter& p, const QPointF center,
}
// Draw arrow button
- p.setPen(pressed ? colors.highlight : colors.button);
- p.setBrush(pressed ? colors.highlight : colors.button);
+ p.setPen(pressed.value ? colors.highlight : colors.button);
+ p.setBrush(pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, arrow_button);
switch (direction) {
@@ -2596,7 +2638,8 @@ void PlayerControlPreview::DrawArrowButton(QPainter& p, const QPointF center,
}
void PlayerControlPreview::DrawTriggerButton(QPainter& p, const QPointF center,
- const Direction direction, bool pressed) {
+ const Direction direction,
+ const Input::ButtonStatus& pressed) {
std::array qtrigger_button;
for (std::size_t point = 0; point < trigger_button.size() / 2; ++point) {
@@ -2619,10 +2662,44 @@ void PlayerControlPreview::DrawTriggerButton(QPainter& p, const QPointF center,
// Draw arrow button
p.setPen(colors.outline);
- p.setBrush(pressed ? colors.highlight : colors.button);
+ p.setBrush(pressed.value ? colors.highlight : colors.button);
DrawPolygon(p, qtrigger_button);
}
+void PlayerControlPreview::DrawBattery(QPainter& p, QPointF center, Input::BatteryLevel battery) {
+ p.setPen(colors.outline);
+ p.setBrush(colors.transparent);
+ p.drawRect(center.x(), center.y(), 56, 20);
+ p.drawRect(center.x() + 56, center.y() + 6, 3, 8);
+ p.setBrush(colors.deadzone);
+ switch (battery) {
+ case Input::BatteryLevel::Charging:
+ p.setBrush(colors.indicator2);
+ p.drawText(center + QPoint(2, 14), tr("Charging"));
+ break;
+ case Input::BatteryLevel::Full:
+ p.drawRect(center.x() + 42, center.y(), 14, 20);
+ p.drawRect(center.x() + 28, center.y(), 14, 20);
+ p.drawRect(center.x() + 14, center.y(), 14, 20);
+ break;
+ case Input::BatteryLevel::Medium:
+ p.drawRect(center.x() + 28, center.y(), 14, 20);
+ p.drawRect(center.x() + 14, center.y(), 14, 20);
+ p.drawRect(center.x(), center.y(), 14, 20);
+ break;
+ case Input::BatteryLevel::Low:
+ p.drawRect(center.x() + 14, center.y(), 14, 20);
+ p.drawRect(center.x(), center.y(), 14, 20);
+ break;
+ case Input::BatteryLevel::Critical:
+ p.drawRect(center.x(), center.y(), 14, 20);
+ break;
+ case Input::BatteryLevel::Empty:
+ p.drawRect(center.x(), center.y(), 5, 20);
+ break;
+ }
+}
+
void PlayerControlPreview::DrawSymbol(QPainter& p, const QPointF center, Symbol symbol,
float icon_size) {
std::array house_icon;
diff --git a/src/yuzu/configuration/configure_input_player_widget.h b/src/yuzu/configuration/configure_input_player_widget.h
index f4bbfa528..b44a2e347 100644
--- a/src/yuzu/configuration/configure_input_player_widget.h
+++ b/src/yuzu/configuration/configure_input_player_widget.h
@@ -7,9 +7,10 @@
#include
#include
#include
+#include "common/input.h"
#include "common/settings.h"
-#include "core/frontend/input.h"
-#include "yuzu/debugger/controller.h"
+#include "core/hid/hid_core.h"
+#include "core/hid/hid_types.h"
class QLabel;
@@ -24,17 +25,12 @@ public:
explicit PlayerControlPreview(QWidget* parent);
~PlayerControlPreview() override;
- void SetPlayerInput(std::size_t index, const ButtonParam& buttons_param,
- const AnalogParam& analogs_param);
- void SetPlayerInputRaw(std::size_t index, const Settings::ButtonsRaw& buttons_,
- Settings::AnalogsRaw analogs_);
- void SetConnectedStatus(bool checked);
- void SetControllerType(Settings::ControllerType type);
+ void SetController(Core::HID::EmulatedController* controller);
void BeginMappingButton(std::size_t button_id);
void BeginMappingAnalog(std::size_t button_id);
void EndMapping();
+ void ControllerUpdate(Core::HID::ControllerTriggerType type);
void UpdateInput();
- void SetCallBack(ControllerCallback callback_);
protected:
void paintEvent(QPaintEvent* event) override;
@@ -63,15 +59,6 @@ private:
SR,
};
- struct AxisValue {
- QPointF value{};
- QPointF raw_value{};
- Input::AnalogProperties properties{};
- int size{};
- QPoint offset{};
- bool active{};
- };
-
struct LedPattern {
bool position1;
bool position2;
@@ -122,47 +109,66 @@ private:
void DrawGCBody(QPainter& p, QPointF center);
// Draw triggers functions
- void DrawProTriggers(QPainter& p, QPointF center, bool left_pressed, bool right_pressed);
- void DrawGCTriggers(QPainter& p, QPointF center, bool left_pressed, bool right_pressed);
- void DrawHandheldTriggers(QPainter& p, QPointF center, bool left_pressed, bool right_pressed);
- void DrawDualTriggers(QPainter& p, QPointF center, bool left_pressed, bool right_pressed);
- void DrawDualTriggersTopView(QPainter& p, QPointF center, bool left_pressed,
- bool right_pressed);
- void DrawDualZTriggersTopView(QPainter& p, QPointF center, bool left_pressed,
- bool right_pressed);
- void DrawLeftTriggers(QPainter& p, QPointF center, bool left_pressed);
- void DrawLeftZTriggers(QPainter& p, QPointF center, bool left_pressed);
- void DrawLeftTriggersTopView(QPainter& p, QPointF center, bool left_pressed);
- void DrawLeftZTriggersTopView(QPainter& p, QPointF center, bool left_pressed);
- void DrawRightTriggers(QPainter& p, QPointF center, bool right_pressed);
- void DrawRightZTriggers(QPainter& p, QPointF center, bool right_pressed);
- void DrawRightTriggersTopView(QPainter& p, QPointF center, bool right_pressed);
- void DrawRightZTriggersTopView(QPainter& p, QPointF center, bool right_pressed);
+ void DrawProTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed,
+ const Input::ButtonStatus& right_pressed);
+ void DrawGCTriggers(QPainter& p, QPointF center, Input::TriggerStatus left_trigger,
+ Input::TriggerStatus right_trigger);
+ void DrawHandheldTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed,
+ const Input::ButtonStatus& right_pressed);
+ void DrawDualTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed,
+ const Input::ButtonStatus& right_pressed);
+ void DrawDualTriggersTopView(QPainter& p, QPointF center,
+ const Input::ButtonStatus& left_pressed,
+ const Input::ButtonStatus& right_pressed);
+ void DrawDualZTriggersTopView(QPainter& p, QPointF center,
+ const Input::ButtonStatus& left_pressed,
+ const Input::ButtonStatus& right_pressed);
+ void DrawLeftTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed);
+ void DrawLeftZTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed);
+ void DrawLeftTriggersTopView(QPainter& p, QPointF center,
+ const Input::ButtonStatus& left_pressed);
+ void DrawLeftZTriggersTopView(QPainter& p, QPointF center,
+ const Input::ButtonStatus& left_pressed);
+ void DrawRightTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& right_pressed);
+ void DrawRightZTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& right_pressed);
+ void DrawRightTriggersTopView(QPainter& p, QPointF center,
+ const Input::ButtonStatus& right_pressed);
+ void DrawRightZTriggersTopView(QPainter& p, QPointF center,
+ const Input::ButtonStatus& right_pressed);
// Draw joystick functions
- void DrawJoystick(QPainter& p, QPointF center, float size, bool pressed);
- void DrawJoystickSideview(QPainter& p, QPointF center, float angle, float size, bool pressed);
+ void DrawJoystick(QPainter& p, QPointF center, float size, const Input::ButtonStatus& pressed);
+ void DrawJoystickSideview(QPainter& p, QPointF center, float angle, float size,
+ const Input::ButtonStatus& pressed);
void DrawRawJoystick(QPainter& p, QPointF center_left, QPointF center_right);
void DrawJoystickProperties(QPainter& p, QPointF center,
const Input::AnalogProperties& properties);
- void DrawJoystickDot(QPainter& p, QPointF center, QPointF value,
- const Input::AnalogProperties& properties);
- void DrawProJoystick(QPainter& p, QPointF center, QPointF offset, float scalar, bool pressed);
- void DrawGCJoystick(QPainter& p, QPointF center, bool pressed);
+ void DrawJoystickDot(QPainter& p, QPointF center, const Input::StickStatus& stick, bool raw);
+ void DrawProJoystick(QPainter& p, QPointF center, QPointF offset, float scalar,
+ const Input::ButtonStatus& pressed);
+ void DrawGCJoystick(QPainter& p, QPointF center, const Input::ButtonStatus& pressed);
// Draw button functions
- void DrawCircleButton(QPainter& p, QPointF center, bool pressed, float button_size);
- void DrawRoundButton(QPainter& p, QPointF center, bool pressed, float width, float height,
- Direction direction = Direction::None, float radius = 2);
- void DrawMinusButton(QPainter& p, QPointF center, bool pressed, int button_size);
- void DrawPlusButton(QPainter& p, QPointF center, bool pressed, int button_size);
- void DrawGCButtonX(QPainter& p, QPointF center, bool pressed);
- void DrawGCButtonY(QPainter& p, QPointF center, bool pressed);
- void DrawGCButtonZ(QPainter& p, QPointF center, bool pressed);
+ void DrawCircleButton(QPainter& p, QPointF center, const Input::ButtonStatus& pressed,
+ float button_size);
+ void DrawRoundButton(QPainter& p, QPointF center, const Input::ButtonStatus& pressed,
+ float width, float height, Direction direction = Direction::None,
+ float radius = 2);
+ void DrawMinusButton(QPainter& p, QPointF center, const Input::ButtonStatus& pressed,
+ int button_size);
+ void DrawPlusButton(QPainter& p, QPointF center, const Input::ButtonStatus& pressed,
+ int button_size);
+ void DrawGCButtonX(QPainter& p, QPointF center, const Input::ButtonStatus& pressed);
+ void DrawGCButtonY(QPainter& p, QPointF center, const Input::ButtonStatus& pressed);
+ void DrawGCButtonZ(QPainter& p, QPointF center, const Input::ButtonStatus& pressed);
void DrawArrowButtonOutline(QPainter& p, const QPointF center, float size = 1.0f);
- void DrawArrowButton(QPainter& p, QPointF center, Direction direction, bool pressed,
- float size = 1.0f);
- void DrawTriggerButton(QPainter& p, QPointF center, Direction direction, bool pressed);
+ void DrawArrowButton(QPainter& p, QPointF center, Direction direction,
+ const Input::ButtonStatus& pressed, float size = 1.0f);
+ void DrawTriggerButton(QPainter& p, QPointF center, Direction direction,
+ const Input::ButtonStatus& pressed);
+
+ // Draw battery functions
+ void DrawBattery(QPainter& p, QPointF center, Input::BatteryLevel battery);
// Draw icon functions
void DrawSymbol(QPainter& p, QPointF center, Symbol symbol, float icon_size);
@@ -178,24 +184,23 @@ private:
void SetTextFont(QPainter& p, float text_size,
const QString& font_family = QStringLiteral("sans-serif"));
- using ButtonArray =
- std::array, Settings::NativeButton::BUTTON_NS_END>;
- using StickArray =
- std::array, Settings::NativeAnalog::NUM_STICKS_HID>;
+ bool is_controller_set{};
+ bool is_connected{};
+ bool needs_redraw{};
+ Core::HID::NpadType controller_type;
- ControllerCallback controller_callback;
- bool is_enabled{};
bool mapping_active{};
int blink_counter{};
+ int callback_key;
QColor button_color{};
ColorMapping colors{};
std::array led_color{};
- ButtonArray buttons{};
- StickArray sticks{};
std::size_t player_index{};
- std::size_t button_mapping_index{Settings::NativeButton::BUTTON_NS_END};
- std::size_t analog_mapping_index{Settings::NativeAnalog::NUM_STICKS_HID};
- std::array axis_values{};
- std::array button_values{};
- Settings::ControllerType controller_type{Settings::ControllerType::ProController};
+ Core::HID::EmulatedController* controller;
+ std::size_t button_mapping_index{Settings::NativeButton::NumButtons};
+ std::size_t analog_mapping_index{Settings::NativeAnalog::NumAnalogs};
+ Core::HID::ButtonValues button_values{};
+ Core::HID::SticksValues stick_values{};
+ Core::HID::TriggerValues trigger_values{};
+ Core::HID::BatteryValues battery_values{};
};
diff --git a/src/yuzu/configuration/configure_motion_touch.cpp b/src/yuzu/configuration/configure_motion_touch.cpp
index f8e08c422..9fd1a919f 100644
--- a/src/yuzu/configuration/configure_motion_touch.cpp
+++ b/src/yuzu/configuration/configure_motion_touch.cpp
@@ -15,9 +15,9 @@
#include "common/logging/log.h"
#include "common/settings.h"
+#include "input_common/drivers/udp_client.h"
+#include "input_common/helpers/udp_protocol.h"
#include "input_common/main.h"
-#include "input_common/udp/client.h"
-#include "input_common/udp/udp.h"
#include "ui_configure_motion_touch.h"
#include "yuzu/configuration/configure_motion_touch.h"
#include "yuzu/configuration/configure_touch_from_button.h"
diff --git a/src/yuzu/configuration/configure_mouse_advanced.cpp b/src/yuzu/configuration/configure_mouse_advanced.cpp
index 2af3afda8..1e7a3751d 100644
--- a/src/yuzu/configuration/configure_mouse_advanced.cpp
+++ b/src/yuzu/configuration/configure_mouse_advanced.cpp
@@ -11,8 +11,11 @@
#include "common/assert.h"
#include "common/param_package.h"
+#include "input_common/drivers/keyboard.h"
+#include "input_common/drivers/mouse.h"
#include "input_common/main.h"
#include "ui_configure_mouse_advanced.h"
+#include "yuzu/bootmanager.h"
#include "yuzu/configuration/config.h"
#include "yuzu/configuration/configure_mouse_advanced.h"
@@ -101,7 +104,7 @@ ConfigureMouseAdvanced::ConfigureMouseAdvanced(QWidget* parent,
[=, this](const Common::ParamPackage& params) {
buttons_param[button_id] = params;
},
- InputCommon::Polling::DeviceType::Button);
+ InputCommon::Polling::InputType::Button);
});
connect(button, &QPushButton::customContextMenuRequested,
[=, this](const QPoint& menu_location) {
@@ -127,13 +130,10 @@ ConfigureMouseAdvanced::ConfigureMouseAdvanced(QWidget* parent,
connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); });
connect(poll_timer.get(), &QTimer::timeout, [this] {
- Common::ParamPackage params;
- for (auto& poller : device_pollers) {
- params = poller->GetNextInput();
- if (params.Has("engine")) {
- SetPollingResult(params, false);
- return;
- }
+ const auto& params = input_subsystem->GetNextInput();
+ if (params.Has("engine")) {
+ SetPollingResult(params, false);
+ return;
}
});
@@ -196,26 +196,13 @@ void ConfigureMouseAdvanced::UpdateButtonLabels() {
void ConfigureMouseAdvanced::HandleClick(
QPushButton* button, std::function new_input_setter,
- InputCommon::Polling::DeviceType type) {
+ InputCommon::Polling::InputType type) {
button->setText(tr("[press key]"));
button->setFocus();
- // Keyboard keys or mouse buttons can only be used as button devices
- want_keyboard_mouse = type == InputCommon::Polling::DeviceType::Button;
- if (want_keyboard_mouse) {
- const auto iter = std::find(button_map.begin(), button_map.end(), button);
- ASSERT(iter != button_map.end());
- const auto index = std::distance(button_map.begin(), iter);
- ASSERT(index < Settings::NativeButton::NumButtons && index >= 0);
- }
-
input_setter = new_input_setter;
- device_pollers = input_subsystem->GetPollers(type);
-
- for (auto& poller : device_pollers) {
- poller->Start();
- }
+ input_subsystem->BeginMapping(type);
QWidget::grabMouse();
QWidget::grabKeyboard();
@@ -227,9 +214,7 @@ void ConfigureMouseAdvanced::HandleClick(
void ConfigureMouseAdvanced::SetPollingResult(const Common::ParamPackage& params, bool abort) {
timeout_timer->stop();
poll_timer->stop();
- for (auto& poller : device_pollers) {
- poller->Stop();
- }
+ input_subsystem->StopMapping();
QWidget::releaseMouse();
QWidget::releaseKeyboard();
@@ -247,15 +232,8 @@ void ConfigureMouseAdvanced::mousePressEvent(QMouseEvent* event) {
return;
}
- if (want_keyboard_mouse) {
- SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->button())},
- false);
- } else {
- // We don't want any mouse buttons, so don't stop polling
- return;
- }
-
- SetPollingResult({}, true);
+ const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
+ input_subsystem->GetMouse()->PressButton(0, 0, 0, 0, button);
}
void ConfigureMouseAdvanced::keyPressEvent(QKeyEvent* event) {
@@ -264,13 +242,6 @@ void ConfigureMouseAdvanced::keyPressEvent(QKeyEvent* event) {
}
if (event->key() != Qt::Key_Escape) {
- if (want_keyboard_mouse) {
- SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->key())},
- false);
- } else {
- // Escape key wasn't pressed and we don't want any keyboard keys, so don't stop polling
- return;
- }
+ input_subsystem->GetKeyboard()->PressKey(event->key());
}
- SetPollingResult({}, true);
}
diff --git a/src/yuzu/configuration/configure_mouse_advanced.h b/src/yuzu/configuration/configure_mouse_advanced.h
index 65b6fca9a..5fa534eaf 100644
--- a/src/yuzu/configuration/configure_mouse_advanced.h
+++ b/src/yuzu/configuration/configure_mouse_advanced.h
@@ -46,7 +46,7 @@ private:
/// Called when the button was pressed.
void HandleClick(QPushButton* button,
std::function new_input_setter,
- InputCommon::Polling::DeviceType type);
+ InputCommon::Polling::InputType type);
/// Finish polling and configure input using the input_setter
void SetPollingResult(const Common::ParamPackage& params, bool abort);
@@ -67,12 +67,6 @@ private:
std::array button_map;
std::array buttons_param;
- std::vector> device_pollers;
-
std::unique_ptr timeout_timer;
std::unique_ptr poll_timer;
-
- /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false,
- /// keyboard events are ignored.
- bool want_keyboard_mouse = false;
};
diff --git a/src/yuzu/configuration/configure_touch_from_button.cpp b/src/yuzu/configuration/configure_touch_from_button.cpp
index 40129f228..bde0a08c4 100644
--- a/src/yuzu/configuration/configure_touch_from_button.cpp
+++ b/src/yuzu/configuration/configure_touch_from_button.cpp
@@ -163,13 +163,10 @@ void ConfigureTouchFromButton::ConnectEvents() {
connect(timeout_timer.get(), &QTimer::timeout, [this]() { SetPollingResult({}, true); });
connect(poll_timer.get(), &QTimer::timeout, [this]() {
- Common::ParamPackage params;
- for (auto& poller : device_pollers) {
- params = poller->GetNextInput();
- if (params.Has("engine")) {
- SetPollingResult(params, false);
- return;
- }
+ const auto& params = input_subsystem->GetNextInput();
+ if (params.Has("engine")) {
+ SetPollingResult(params, false);
+ return;
}
});
}
@@ -248,11 +245,7 @@ void ConfigureTouchFromButton::GetButtonInput(const int row_index, const bool is
}
};
- device_pollers = input_subsystem->GetPollers(InputCommon::Polling::DeviceType::Button);
-
- for (auto& poller : device_pollers) {
- poller->Start();
- }
+ input_subsystem->BeginMapping(InputCommon::Polling::InputType::Button);
grabKeyboard();
grabMouse();
@@ -365,14 +358,14 @@ void ConfigureTouchFromButton::SetCoordinates(const int dot_id, const QPoint& po
void ConfigureTouchFromButton::SetPollingResult(const Common::ParamPackage& params,
const bool cancel) {
+ timeout_timer->stop();
+ poll_timer->stop();
+ input_subsystem->StopMapping();
+
releaseKeyboard();
releaseMouse();
qApp->restoreOverrideCursor();
- timeout_timer->stop();
- poll_timer->stop();
- for (auto& poller : device_pollers) {
- poller->Stop();
- }
+
if (input_setter) {
(*input_setter)(params, cancel);
input_setter.reset();
diff --git a/src/yuzu/configuration/configure_touch_from_button.h b/src/yuzu/configuration/configure_touch_from_button.h
index d9513e3bc..e1400481a 100644
--- a/src/yuzu/configuration/configure_touch_from_button.h
+++ b/src/yuzu/configuration/configure_touch_from_button.h
@@ -24,10 +24,6 @@ namespace InputCommon {
class InputSubsystem;
}
-namespace InputCommon::Polling {
-class DevicePoller;
-}
-
namespace Settings {
struct TouchFromButtonMap;
}
@@ -85,7 +81,6 @@ private:
std::unique_ptr timeout_timer;
std::unique_ptr poll_timer;
- std::vector> device_pollers;
std::optional> input_setter;
static constexpr int DataRoleDot = Qt::ItemDataRole::UserRole + 2;
--
cgit v1.2.3
From 06a5ef5874144a70e30e577a83ba68d1dad79e78 Mon Sep 17 00:00:00 2001
From: german77
Date: Mon, 11 Oct 2021 00:43:11 -0500
Subject: core/hid: Add output devices
---
src/common/input.h | 39 +++++++
src/core/hid/emulated_controller.cpp | 119 ++++++++++++++++-----
src/core/hid/emulated_controller.h | 13 ++-
src/core/hid/hid_types.h | 18 ++++
src/core/hle/service/hid/controllers/npad.cpp | 27 +----
src/core/hle/service/hid/controllers/npad.h | 18 +---
src/input_common/drivers/gc_adapter.cpp | 8 +-
src/input_common/drivers/gc_adapter.h | 2 +-
src/input_common/drivers/sdl_driver.cpp | 8 +-
src/input_common/drivers/sdl_driver.h | 2 +-
src/input_common/helpers/stick_from_buttons.cpp | 3 +-
src/input_common/helpers/stick_from_buttons.h | 3 +-
src/input_common/helpers/touch_from_buttons.cpp | 4 +-
src/input_common/input_engine.h | 18 ++--
src/input_common/input_poller.cpp | 40 ++++++-
src/input_common/input_poller.h | 28 ++++-
src/input_common/main.cpp | 30 ++++--
src/yuzu/configuration/configure_input_player.cpp | 7 ++
.../configure_input_player_widget.cpp | 59 ++++------
.../configuration/configure_input_player_widget.h | 10 +-
20 files changed, 312 insertions(+), 144 deletions(-)
(limited to 'src/yuzu/configuration')
diff --git a/src/common/input.h b/src/common/input.h
index 6eefc55f9..3a28b77a7 100644
--- a/src/common/input.h
+++ b/src/common/input.h
@@ -38,6 +38,27 @@ enum class BatteryLevel {
Charging,
};
+enum class PollingMode {
+ Active,
+ Pasive,
+ Camera,
+ NCF,
+ IR,
+};
+
+enum class VibrationError {
+ None,
+ NotSupported,
+ Disabled,
+ Unknown,
+};
+
+enum class PollingError {
+ None,
+ NotSupported,
+ Unknown,
+};
+
struct AnalogProperties {
float deadzone{};
float range{1.0f};
@@ -149,6 +170,24 @@ private:
InputCallback callback;
};
+/// An abstract class template for an output device (rumble, LED pattern, polling mode).
+class OutputDevice {
+public:
+ virtual ~OutputDevice() = default;
+
+ virtual void SetLED([[maybe_unused]] LedStatus led_status) {
+ return;
+ }
+
+ virtual VibrationError SetVibration([[maybe_unused]] VibrationStatus vibration_status) {
+ return VibrationError::NotSupported;
+ }
+
+ virtual PollingError SetPollingMode([[maybe_unused]] PollingMode polling_mode) {
+ return PollingError::NotSupported;
+ }
+};
+
/// An abstract class template for a factory that can create input devices.
template
class Factory {
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 4eb5d99bc..b9d16657a 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -66,12 +66,32 @@ void EmulatedController::ReloadFromSettings() {
for (std::size_t index = 0; index < player.motions.size(); ++index) {
motion_params[index] = Common::ParamPackage(player.motions[index]);
}
+
+ controller.colors_state.left = {
+ .body = player.body_color_left,
+ .button = player.button_color_left,
+ };
+
+ controller.colors_state.right = {
+ .body = player.body_color_right,
+ .button = player.button_color_right,
+ };
+
+ controller.colors_state.fullkey = controller.colors_state.left;
+
+ SetNpadType(MapSettingsTypeToNPad(player.controller_type));
+
+ if (player.connected) {
+ Connect();
+ } else {
+ Disconnect();
+ }
+
ReloadInput();
}
void EmulatedController::ReloadInput() {
const auto player_index = NpadIdTypeToIndex(npad_id_type);
- const auto& player = Settings::values.players.GetValue()[player_index];
const auto left_side = button_params[Settings::NativeButton::ZL];
const auto right_side = button_params[Settings::NativeButton::ZR];
@@ -90,21 +110,13 @@ void EmulatedController::ReloadInput() {
trigger_devices[1] =
Input::CreateDevice(button_params[Settings::NativeButton::ZR]);
- controller.colors_state.left = {
- .body = player.body_color_left,
- .button = player.button_color_left,
- };
-
- controller.colors_state.right = {
- .body = player.body_color_right,
- .button = player.button_color_right,
- };
-
- controller.colors_state.fullkey = controller.colors_state.left;
-
battery_devices[0] = Input::CreateDevice(left_side);
battery_devices[1] = Input::CreateDevice(right_side);
+ button_params[Settings::NativeButton::ZL].Set("output",true);
+ output_devices[0] =
+ Input::CreateDevice(button_params[Settings::NativeButton::ZL]);
+
for (std::size_t index = 0; index < button_devices.size(); ++index) {
if (!button_devices[index]) {
continue;
@@ -149,14 +161,6 @@ void EmulatedController::ReloadInput() {
[this, index](Input::CallbackStatus callback) { SetMotion(callback, index); }};
motion_devices[index]->SetCallback(motion_callback);
}
-
- SetNpadType(MapSettingsTypeToNPad(player.controller_type));
-
- if (player.connected) {
- Connect();
- } else {
- Disconnect();
- }
}
void EmulatedController::UnloadInput() {
@@ -197,7 +201,8 @@ void EmulatedController::SaveCurrentConfig() {
const auto player_index = NpadIdTypeToIndex(npad_id_type);
auto& player = Settings::values.players.GetValue()[player_index];
-
+ player.connected = is_connected;
+ player.controller_type = MapNPadToSettingsType(npad_type);
for (std::size_t index = 0; index < player.buttons.size(); ++index) {
player.buttons[index] = button_params[index].Serialize();
}
@@ -601,13 +606,50 @@ void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t
TriggerOnChange(ControllerTriggerType::Battery);
}
-bool EmulatedController::SetVibration([[maybe_unused]] std::size_t device_index,
- [[maybe_unused]] VibrationValue vibration) {
- return false;
+bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue vibration) {
+ if (!output_devices[device_index]) {
+ return false;
+ }
+
+ const Input::VibrationStatus status = {
+ .low_amplitude = vibration.high_amplitude,
+ .low_frequency = vibration.high_amplitude,
+ .high_amplitude = vibration.high_amplitude,
+ .high_frequency = vibration.high_amplitude,
+ };
+ return output_devices[device_index]->SetVibration(status) == Input::VibrationError::None;
+}
+
+bool EmulatedController::TestVibration(std::size_t device_index) {
+ if (!output_devices[device_index]) {
+ return false;
+ }
+
+ // Send a slight vibration to test for rumble support
+ constexpr Input::VibrationStatus status = {
+ .low_amplitude = 0.001f,
+ .low_frequency = 160.0f,
+ .high_amplitude = 0.001f,
+ .high_frequency = 320.0f,
+ };
+ return output_devices[device_index]->SetVibration(status) == Input::VibrationError::None;
}
-int EmulatedController::TestVibration(std::size_t device_index) {
- return 1;
+void EmulatedController::SetLedPattern() {
+ for (auto& device : output_devices) {
+ if (!device) {
+ continue;
+ }
+
+ const LedPattern pattern = GetLedPattern();
+ const Input::LedStatus status = {
+ .led_1 = pattern.position1 != 0,
+ .led_2 = pattern.position2 != 0,
+ .led_3 = pattern.position3 != 0,
+ .led_4 = pattern.position4 != 0,
+ };
+ device->SetLED(status);
+ }
}
void EmulatedController::Connect() {
@@ -655,6 +697,29 @@ void EmulatedController::SetNpadType(NpadType npad_type_) {
TriggerOnChange(ControllerTriggerType::Type);
}
+LedPattern EmulatedController::GetLedPattern() const {
+ switch (npad_id_type) {
+ case NpadIdType::Player1:
+ return LedPattern{1, 0, 0, 0};
+ case NpadIdType::Player2:
+ return LedPattern{1, 1, 0, 0};
+ case NpadIdType::Player3:
+ return LedPattern{1, 1, 1, 0};
+ case NpadIdType::Player4:
+ return LedPattern{1, 1, 1, 1};
+ case NpadIdType::Player5:
+ return LedPattern{1, 0, 0, 1};
+ case NpadIdType::Player6:
+ return LedPattern{1, 0, 1, 0};
+ case NpadIdType::Player7:
+ return LedPattern{1, 0, 1, 1};
+ case NpadIdType::Player8:
+ return LedPattern{0, 1, 1, 0};
+ default:
+ return LedPattern{0, 0, 0, 0};
+ }
+}
+
ButtonValues EmulatedController::GetButtonsValues() const {
return controller.button_values;
}
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index 94db9b00b..322d2cab0 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -33,12 +33,14 @@ using ControllerMotionDevices =
using TriggerDevices =
std::array, Settings::NativeTrigger::NumTriggers>;
using BatteryDevices = std::array, 2>;
+using OutputDevices = std::array, 2>;
using ButtonParams = std::array;
using StickParams = std::array;
using ControllerMotionParams = std::array;
using TriggerParams = std::array;
using BatteryParams = std::array;
+using OutputParams = std::array;
using ButtonValues = std::array;
using SticksValues = std::array;
@@ -94,6 +96,7 @@ struct ControllerStatus {
ControllerColors colors_state{};
BatteryLevelState battery_state{};
};
+
enum class ControllerTriggerType {
Button,
Stick,
@@ -137,6 +140,9 @@ public:
/// Gets the NpadType for this controller.
NpadType GetNpadType() const;
+ /// Gets the NpadType for this controller.
+ LedPattern GetLedPattern() const;
+
void Connect();
void Disconnect();
@@ -179,7 +185,9 @@ public:
BatteryLevelState GetBattery() const;
bool SetVibration(std::size_t device_index, VibrationValue vibration);
- int TestVibration(std::size_t device_index);
+ bool TestVibration(std::size_t device_index);
+
+ void SetLedPattern();
int SetCallback(ControllerUpdateCallback update_callback);
void DeleteCallback(int key);
@@ -215,13 +223,14 @@ private:
ControllerMotionParams motion_params;
TriggerParams trigger_params;
BatteryParams battery_params;
+ OutputParams output_params;
ButtonDevices button_devices;
StickDevices stick_devices;
ControllerMotionDevices motion_devices;
TriggerDevices trigger_devices;
BatteryDevices battery_devices;
- // VibrationDevices vibration_devices;
+ OutputDevices output_devices;
mutable std::mutex mutex;
std::unordered_map callback_list;
diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h
index d3f7930c9..f12a14cb8 100644
--- a/src/core/hid/hid_types.h
+++ b/src/core/hid/hid_types.h
@@ -112,6 +112,8 @@ struct NpadStyleTag {
BitField<7, 1, u32> lark;
BitField<8, 1, u32> handheld_lark;
BitField<9, 1, u32> lucia;
+ BitField<10, 1, u32> lagoon;
+ BitField<11, 1, u32> lager;
BitField<29, 1, u32> system_ext;
BitField<30, 1, u32> system;
};
@@ -175,6 +177,22 @@ struct NpadPowerInfo {
};
static_assert(sizeof(NpadPowerInfo) == 0xC, "NpadPowerInfo is an invalid size");
+struct LedPattern {
+ explicit LedPattern(u64 light1, u64 light2, u64 light3, u64 light4) {
+ position1.Assign(light1);
+ position2.Assign(light2);
+ position3.Assign(light3);
+ position4.Assign(light4);
+ }
+ union {
+ u64 raw{};
+ BitField<0, 1, u64> position1;
+ BitField<1, 1, u64> position2;
+ BitField<2, 1, u64> position3;
+ BitField<3, 1, u64> position4;
+ };
+};
+
// This is nn::hid::NpadButton
enum class NpadButton : u64 {
None = 0,
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 03cbd42f4..a2e9ddf4d 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -796,7 +796,7 @@ void Controller_NPad::InitializeVibrationDeviceAtIndex(std::size_t npad_index,
}
controller.vibration[device_index].device_mounted =
- controller.device->TestVibration(device_index) == 1;
+ controller.device->TestVibration(device_index);
}
void Controller_NPad::SetPermitVibrationSession(bool permit_vibration_session) {
@@ -954,31 +954,12 @@ bool Controller_NPad::SwapNpadAssignment(u32 npad_id_1, u32 npad_id_2) {
return true;
}
-Controller_NPad::LedPattern Controller_NPad::GetLedPattern(u32 npad_id) {
+Core::HID::LedPattern Controller_NPad::GetLedPattern(u32 npad_id) {
if (npad_id == npad_id_list.back() || npad_id == npad_id_list[npad_id_list.size() - 2]) {
// These are controllers without led patterns
- return LedPattern{0, 0, 0, 0};
- }
- switch (npad_id) {
- case 0:
- return LedPattern{1, 0, 0, 0};
- case 1:
- return LedPattern{1, 1, 0, 0};
- case 2:
- return LedPattern{1, 1, 1, 0};
- case 3:
- return LedPattern{1, 1, 1, 1};
- case 4:
- return LedPattern{1, 0, 0, 1};
- case 5:
- return LedPattern{1, 0, 1, 0};
- case 6:
- return LedPattern{1, 0, 1, 1};
- case 7:
- return LedPattern{0, 1, 1, 0};
- default:
- return LedPattern{0, 0, 0, 0};
+ return Core::HID::LedPattern{0, 0, 0, 0};
}
+ return controller_data[npad_id].device->GetLedPattern();
}
bool Controller_NPad::IsUnintendedHomeButtonInputProtectionEnabled(u32 npad_id) const {
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h
index 483cae5b6..b0e2f8430 100644
--- a/src/core/hle/service/hid/controllers/npad.h
+++ b/src/core/hle/service/hid/controllers/npad.h
@@ -115,22 +115,6 @@ public:
.freq_high = 320.0f,
};
- struct LedPattern {
- explicit LedPattern(u64 light1, u64 light2, u64 light3, u64 light4) {
- position1.Assign(light1);
- position2.Assign(light2);
- position3.Assign(light3);
- position4.Assign(light4);
- }
- union {
- u64 raw{};
- BitField<0, 1, u64> position1;
- BitField<1, 1, u64> position2;
- BitField<2, 1, u64> position3;
- BitField<3, 1, u64> position4;
- };
- };
-
void SetSupportedStyleSet(Core::HID::NpadStyleTag style_set);
Core::HID::NpadStyleTag GetSupportedStyleSet() const;
@@ -186,7 +170,7 @@ public:
void SetSixAxisFusionParameters(f32 parameter1, f32 parameter2);
std::pair GetSixAxisFusionParameters();
void ResetSixAxisFusionParameters();
- LedPattern GetLedPattern(u32 npad_id);
+ Core::HID::LedPattern GetLedPattern(u32 npad_id);
bool IsUnintendedHomeButtonInputProtectionEnabled(u32 npad_id) const;
void SetUnintendedHomeButtonInputProtectionEnabled(bool is_protection_enabled, u32 npad_id);
void SetAnalogStickUseCenterClamp(bool use_center_clamp);
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp
index 6721ba4f7..2aa5a16a6 100644
--- a/src/input_common/drivers/gc_adapter.cpp
+++ b/src/input_common/drivers/gc_adapter.cpp
@@ -322,13 +322,17 @@ bool GCAdapter::GetGCEndpoint(libusb_device* device) {
return true;
}
-bool GCAdapter::SetRumble(const PadIdentifier& identifier, const Input::VibrationStatus vibration) {
+Input::VibrationError GCAdapter::SetRumble(const PadIdentifier& identifier, const Input::VibrationStatus vibration) {
const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f;
const auto processed_amplitude =
static_cast((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8);
pads[identifier.port].rumble_amplitude = processed_amplitude;
- return rumble_enabled;
+
+ if (!rumble_enabled) {
+ return Input::VibrationError::Disabled;
+ }
+ return Input::VibrationError::None;
}
void GCAdapter::UpdateVibrations() {
diff --git a/src/input_common/drivers/gc_adapter.h b/src/input_common/drivers/gc_adapter.h
index c0bf1ed7a..dd23dd9f3 100644
--- a/src/input_common/drivers/gc_adapter.h
+++ b/src/input_common/drivers/gc_adapter.h
@@ -24,7 +24,7 @@ public:
explicit GCAdapter(const std::string input_engine_);
~GCAdapter();
- bool SetRumble(const PadIdentifier& identifier,
+ Input::VibrationError SetRumble(const PadIdentifier& identifier,
const Input::VibrationStatus vibration) override;
/// Used for automapping features
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index efb4a2106..f7f03c5f2 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -506,7 +506,8 @@ std::vector SDLDriver::GetInputDevices() const {
}
return devices;
}
-bool SDLDriver::SetRumble(const PadIdentifier& identifier, const Input::VibrationStatus vibration) {
+Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier,
+ const Input::VibrationStatus vibration) {
const auto joystick =
GetSDLJoystickByGUID(identifier.guid.Format(), static_cast(identifier.port));
const auto process_amplitude = [](f32 amplitude) {
@@ -519,7 +520,10 @@ bool SDLDriver::SetRumble(const PadIdentifier& identifier, const Input::Vibratio
.high_frequency = vibration.high_frequency,
};
- return joystick->RumblePlay(new_vibration);
+ if (!joystick->RumblePlay(new_vibration)) {
+ return Input::VibrationError::Unknown;
+ }
+ return Input::VibrationError::None;
}
Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid,
s32 axis, float value) const {
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h
index d8d350184..f66b33c77 100644
--- a/src/input_common/drivers/sdl_driver.h
+++ b/src/input_common/drivers/sdl_driver.h
@@ -58,7 +58,7 @@ public:
std::string GetHatButtonName(u8 direction_value) const override;
u8 GetHatButtonId(const std::string direction_name) const override;
- bool SetRumble(const PadIdentifier& identifier,
+ Input::VibrationError SetRumble(const PadIdentifier& identifier,
const Input::VibrationStatus vibration) override;
private:
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp
index 38f150746..89ba4aeb1 100644
--- a/src/input_common/helpers/stick_from_buttons.cpp
+++ b/src/input_common/helpers/stick_from_buttons.cpp
@@ -251,7 +251,8 @@ private:
std::chrono::time_point last_update;
};
-std::unique_ptr StickFromButton::Create(const Common::ParamPackage& params) {
+std::unique_ptr StickFromButton::Create(
+ const Common::ParamPackage& params) {
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
auto up = Input::CreateDeviceFromString(params.Get("up", null_engine));
auto down = Input::CreateDeviceFromString(params.Get("down", null_engine));
diff --git a/src/input_common/helpers/stick_from_buttons.h b/src/input_common/helpers/stick_from_buttons.h
index 1d6e24c98..87165e022 100644
--- a/src/input_common/helpers/stick_from_buttons.h
+++ b/src/input_common/helpers/stick_from_buttons.h
@@ -25,7 +25,8 @@ public:
* - "modifier": a serialized ParamPackage for creating a button device as the modifier
* - "modifier_scale": a float for the multiplier the modifier gives to the position
*/
- std::unique_ptr Create(const Common::ParamPackage& params) override;
+ std::unique_ptr Create(
+ const Common::ParamPackage& params) override;
};
} // namespace InputCommon
diff --git a/src/input_common/helpers/touch_from_buttons.cpp b/src/input_common/helpers/touch_from_buttons.cpp
index 2abfaf841..6c9046ffb 100644
--- a/src/input_common/helpers/touch_from_buttons.cpp
+++ b/src/input_common/helpers/touch_from_buttons.cpp
@@ -57,7 +57,9 @@ private:
const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false};
};
-std::unique_ptr TouchFromButton::Create(const Common::ParamPackage& params) {
+
+std::unique_ptr TouchFromButton::Create(
+ const Common::ParamPackage& params) {
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
auto button =
Input::CreateDeviceFromString(params.Get("button", null_engine));
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h
index 86a8e00d8..8a953c382 100644
--- a/src/input_common/input_engine.h
+++ b/src/input_common/input_engine.h
@@ -114,18 +114,24 @@ public:
// Disable configuring mode for mapping
void EndConfiguration();
- // Sets rumble to a controller
- virtual bool SetRumble([[maybe_unused]] const PadIdentifier& identifier,
- [[maybe_unused]] const Input::VibrationStatus vibration) {
- return false;
- }
-
// Sets a led pattern for a controller
virtual void SetLeds([[maybe_unused]] const PadIdentifier& identifier,
[[maybe_unused]] const Input::LedStatus led_status) {
return;
}
+ // Sets rumble to a controller
+ virtual Input::VibrationError SetRumble([[maybe_unused]] const PadIdentifier& identifier,
+ [[maybe_unused]] const Input::VibrationStatus vibration) {
+ return Input::VibrationError::NotSupported;
+ }
+
+ // Sets polling mode to a controller
+ virtual Input::PollingError SetPollingMode([[maybe_unused]] const PadIdentifier& identifier,
+ [[maybe_unused]] const Input::PollingMode vibration) {
+ return Input::PollingError::NotSupported;
+ }
+
// Returns the engine name
[[nodiscard]] const std::string& GetEngineName() const;
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp
index 46a7dd276..781012886 100644
--- a/src/input_common/input_poller.cpp
+++ b/src/input_common/input_poller.cpp
@@ -592,6 +592,28 @@ private:
InputEngine* input_engine;
};
+class OutputFromIdentifier final : public Input::OutputDevice {
+public:
+ explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_)
+ : identifier(identifier_), input_engine(input_engine_) {}
+
+ virtual void SetLED( Input::LedStatus led_status) {
+ input_engine->SetLeds(identifier, led_status);
+ }
+
+ virtual Input::VibrationError SetVibration(Input::VibrationStatus vibration_status) {
+ return input_engine->SetRumble(identifier, vibration_status);
+ }
+
+ virtual Input::PollingError SetPollingMode(Input::PollingMode polling_mode) {
+ return input_engine->SetPollingMode(identifier, polling_mode);
+ }
+
+private:
+ const PadIdentifier identifier;
+ InputEngine* input_engine;
+};
+
std::unique_ptr InputFactory::CreateButtonDevice(
const Common::ParamPackage& params) {
const PadIdentifier identifier = {
@@ -825,7 +847,8 @@ std::unique_ptr InputFactory::CreateMotionDevice(Common::Par
InputFactory::InputFactory(std::shared_ptr input_engine_)
: input_engine(std::move(input_engine_)) {}
-std::unique_ptr InputFactory::Create(const Common::ParamPackage& params) {
+std::unique_ptr InputFactory::Create(
+ const Common::ParamPackage& params) {
if (params.Has("button") && params.Has("axis")) {
return CreateTriggerDevice(params);
}
@@ -857,4 +880,19 @@ std::unique_ptr InputFactory::Create(const Common::ParamPack
return std::make_unique();
}
+OutputFactory::OutputFactory(std::shared_ptr input_engine_)
+ : input_engine(std::move(input_engine_)) {}
+
+std::unique_ptr OutputFactory::Create(
+ const Common::ParamPackage& params) {
+ const PadIdentifier identifier = {
+ .guid = Common::UUID{params.Get("guid", "")},
+ .port = static_cast(params.Get("port", 0)),
+ .pad = static_cast(params.Get("pad", 0)),
+ };
+
+ input_engine->PreSetController(identifier);
+ return std::make_unique(identifier, input_engine.get());
+}
+
} // namespace InputCommon
diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h
index 3c1e5b541..16cade5fa 100644
--- a/src/input_common/input_poller.h
+++ b/src/input_common/input_poller.h
@@ -16,12 +16,32 @@ class InputEngine;
/**
* An Input factory. It receives input events and forward them to all input devices it created.
*/
+
+class OutputFactory final : public Input::Factory {
+public:
+ explicit OutputFactory(std::shared_ptr input_engine_);
+
+ /**
+ * Creates an output device from the parameters given.
+ * @param params contains parameters for creating the device:
+ * @param - "guid": text string for identifing controllers
+ * @param - "port": port of the connected device
+ * @param - "pad": slot of the connected controller
+ * @return an unique ouput device with the parameters specified
+ */
+ std::unique_ptr Create(
+ const Common::ParamPackage& params) override;
+
+private:
+ std::shared_ptr input_engine;
+};
+
class InputFactory final : public Input::Factory {
public:
explicit InputFactory(std::shared_ptr input_engine_);
/**
- * Creates a input device from the parameters given. Identifies the type of input to be returned
+ * Creates an input device from the parameters given. Identifies the type of input to be returned
* if it contains the following parameters:
* - button: Contains "button" or "code"
* - hat_button: Contains "hat"
@@ -32,6 +52,7 @@ public:
* - motion: Contains "motion"
* - touch: Contains "button", "axis_x" and "axis_y"
* - battery: Contains "battery"
+ * - output: Contains "output"
* @param params contains parameters for creating the device:
* @param - "code": the code of the keyboard key to bind with the input
* @param - "button": same as "code" but for controller buttons
@@ -41,10 +62,11 @@ public:
* @param - "axis_x": same as axis but specifing horizontal direction
* @param - "axis_y": same as axis but specifing vertical direction
* @param - "axis_z": same as axis but specifing forward direction
- * @param - "battery": Only used as a placeholder to set the input type
+ * @param - "battery": Only used as a placeholder to set the input type
* @return an unique input device with the parameters specified
*/
- std::unique_ptr Create(const Common::ParamPackage& params) override;
+ std::unique_ptr Create(
+ const Common::ParamPackage& params) override;
private:
/**
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index 46ca6b76c..b7fe9cb37 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -46,8 +46,10 @@ struct InputSubsystem::Impl {
gcadapter = std::make_shared("gcpad");
gcadapter->SetMappingCallback(mapping_callback);
- gcadapter_factory = std::make_shared(gcadapter);
- Input::RegisterFactory(gcadapter->GetEngineName(), gcadapter_factory);
+ gcadapter_input_factory = std::make_shared(gcadapter);
+ gcadapter_output_factory = std::make_shared(gcadapter);
+ Input::RegisterFactory(gcadapter->GetEngineName(), gcadapter_input_factory);
+ Input::RegisterFactory(gcadapter->GetEngineName(), gcadapter_output_factory);
udp_client = std::make_shared("cemuhookudp");
udp_client->SetMappingCallback(mapping_callback);
@@ -62,8 +64,10 @@ struct InputSubsystem::Impl {
#ifdef HAVE_SDL2
sdl = std::make_shared("sdl");
sdl->SetMappingCallback(mapping_callback);
- sdl_factory = std::make_shared(sdl);
- Input::RegisterFactory(sdl->GetEngineName(), sdl_factory);
+ sdl_input_factory = std::make_shared(sdl);
+ sdl_output_factory = std::make_shared(sdl);
+ Input::RegisterFactory(sdl->GetEngineName(), sdl_input_factory);
+ Input::RegisterFactory(sdl->GetEngineName(), sdl_output_factory);
#endif
Input::RegisterFactory("touch_from_button",
@@ -247,21 +251,27 @@ struct InputSubsystem::Impl {
}
std::shared_ptr mapping_factory;
+
std::shared_ptr keyboard;
- std::shared_ptr keyboard_factory;
std::shared_ptr mouse;
- std::shared_ptr mouse_factory;
std::shared_ptr gcadapter;
- std::shared_ptr gcadapter_factory;
std::shared_ptr touch_screen;
- std::shared_ptr touch_screen_factory;
+ std::shared_ptr tas_input;
std::shared_ptr udp_client;
+
+ std::shared_ptr keyboard_factory;
+ std::shared_ptr mouse_factory;
+ std::shared_ptr gcadapter_input_factory;
+ std::shared_ptr touch_screen_factory;
std::shared_ptr udp_client_factory;
- std::shared_ptr tas_input;
std::shared_ptr tas_input_factory;
+
+ std::shared_ptr gcadapter_output_factory;
+
#ifdef HAVE_SDL2
std::shared_ptr sdl;
- std::shared_ptr sdl_factory;
+ std::shared_ptr sdl_input_factory;
+ std::shared_ptr sdl_output_factory;
#endif
};
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index adc9706f1..ed9c3facf 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -465,6 +465,8 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
UpdateControllerEnabledButtons();
UpdateControllerButtonNames();
UpdateMotionButtons();
+ emulated_controller->SetNpadType(
+ GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()));
});
connect(ui->comboDevices, qOverload(&QComboBox::activated), this,
@@ -540,6 +542,11 @@ void ConfigureInputPlayer::LoadConfiguration() {
void ConfigureInputPlayer::ConnectPlayer(bool connected) {
ui->groupConnectedController->setChecked(connected);
+ if (connected) {
+ emulated_controller->Connect();
+ } else {
+ emulated_controller->Disconnect();
+ }
}
void ConfigureInputPlayer::UpdateInputDeviceCombobox() {
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp
index 03d29f194..2ba9d7290 100644
--- a/src/yuzu/configuration/configure_input_player_widget.cpp
+++ b/src/yuzu/configuration/configure_input_player_widget.cpp
@@ -24,34 +24,6 @@ PlayerControlPreview::~PlayerControlPreview() {
}
};
-PlayerControlPreview::LedPattern PlayerControlPreview::GetColorPattern(std::size_t index,
- bool player_on) {
- if (!player_on) {
- return {0, 0, 0, 0};
- }
-
- switch (index) {
- case 0:
- return {1, 0, 0, 0};
- case 1:
- return {1, 1, 0, 0};
- case 2:
- return {1, 1, 1, 0};
- case 3:
- return {1, 1, 1, 1};
- case 4:
- return {1, 0, 0, 1};
- case 5:
- return {1, 0, 1, 0};
- case 6:
- return {1, 0, 1, 1};
- case 7:
- return {0, 1, 1, 0};
- default:
- return {0, 0, 0, 0};
- }
-}
-
void PlayerControlPreview::SetController(Core::HID::EmulatedController* controller_) {
if (is_controller_set) {
controller->DeleteCallback(callback_key);
@@ -160,8 +132,13 @@ void PlayerControlPreview::ControllerUpdate(Core::HID::ControllerTriggerType typ
switch (type) {
case Core::HID::ControllerTriggerType::Connected:
+ is_connected = true;
+ led_pattern = controller->GetLedPattern();
+ needs_redraw = true;
+ break;
case Core::HID::ControllerTriggerType::Disconnected:
- is_connected = controller->IsConnected();
+ is_connected = false;
+ led_pattern.raw = 0;
needs_redraw = true;
break;
case Core::HID::ControllerTriggerType::Type:
@@ -1853,10 +1830,14 @@ void PlayerControlPreview::DrawLeftBody(QPainter& p, const QPointF center) {
const float led_size = 5.0f;
const QPointF led_position = sideview_center + QPointF(0, -36);
int led_count = 0;
- for (const auto& color : led_color) {
- p.setBrush(color);
- DrawRectangle(p, led_position + QPointF(0, 12 * led_count++), led_size, led_size);
- }
+ p.setBrush(led_pattern.position1 ? colors.led_on : colors.led_off);
+ DrawRectangle(p, led_position + QPointF(0, 12 * led_count++), led_size, led_size);
+ p.setBrush(led_pattern.position2 ? colors.led_on : colors.led_off);
+ DrawRectangle(p, led_position + QPointF(0, 12 * led_count++), led_size, led_size);
+ p.setBrush(led_pattern.position3 ? colors.led_on : colors.led_off);
+ DrawRectangle(p, led_position + QPointF(0, 12 * led_count++), led_size, led_size);
+ p.setBrush(led_pattern.position4 ? colors.led_on : colors.led_off);
+ DrawRectangle(p, led_position + QPointF(0, 12 * led_count++), led_size, led_size);
}
void PlayerControlPreview::DrawRightBody(QPainter& p, const QPointF center) {
@@ -1949,10 +1930,14 @@ void PlayerControlPreview::DrawRightBody(QPainter& p, const QPointF center) {
const float led_size = 5.0f;
const QPointF led_position = sideview_center + QPointF(0, -36);
int led_count = 0;
- for (const auto& color : led_color) {
- p.setBrush(color);
- DrawRectangle(p, led_position + QPointF(0, 12 * led_count++), led_size, led_size);
- }
+ p.setBrush(led_pattern.position1 ? colors.led_on : colors.led_off);
+ DrawRectangle(p, led_position + QPointF(0, 12 * led_count++), led_size, led_size);
+ p.setBrush(led_pattern.position2 ? colors.led_on : colors.led_off);
+ DrawRectangle(p, led_position + QPointF(0, 12 * led_count++), led_size, led_size);
+ p.setBrush(led_pattern.position3 ? colors.led_on : colors.led_off);
+ DrawRectangle(p, led_position + QPointF(0, 12 * led_count++), led_size, led_size);
+ p.setBrush(led_pattern.position4 ? colors.led_on : colors.led_off);
+ DrawRectangle(p, led_position + QPointF(0, 12 * led_count++), led_size, led_size);
}
void PlayerControlPreview::DrawProTriggers(QPainter& p, const QPointF center,
diff --git a/src/yuzu/configuration/configure_input_player_widget.h b/src/yuzu/configuration/configure_input_player_widget.h
index b44a2e347..16f9748f5 100644
--- a/src/yuzu/configuration/configure_input_player_widget.h
+++ b/src/yuzu/configuration/configure_input_player_widget.h
@@ -59,13 +59,6 @@ private:
SR,
};
- struct LedPattern {
- bool position1;
- bool position2;
- bool position3;
- bool position4;
- };
-
struct ColorMapping {
QColor outline{};
QColor primary{};
@@ -88,7 +81,6 @@ private:
QColor deadzone{};
};
- static LedPattern GetColorPattern(std::size_t index, bool player_on);
void UpdateColors();
void ResetInputs();
@@ -194,7 +186,7 @@ private:
int callback_key;
QColor button_color{};
ColorMapping colors{};
- std::array led_color{};
+ Core::HID::LedPattern led_pattern{0, 0, 0, 0};
std::size_t player_index{};
Core::HID::EmulatedController* controller;
std::size_t button_mapping_index{Settings::NativeButton::NumButtons};
--
cgit v1.2.3
From e0da5c1bbcdf85676f968b63c8ae2587f0464193 Mon Sep 17 00:00:00 2001
From: german77
Date: Fri, 15 Oct 2021 19:07:47 -0500
Subject: kraken: Fix errors from rebase and format files
---
src/core/hid/emulated_controller.cpp | 6 +++++-
src/core/hle/service/hid/hid.cpp | 1 -
src/input_common/drivers/gc_adapter.cpp | 3 ++-
src/input_common/drivers/gc_adapter.h | 2 +-
src/input_common/drivers/sdl_driver.h | 2 +-
src/input_common/helpers/stick_from_buttons.cpp | 3 +--
src/input_common/helpers/stick_from_buttons.h | 3 +--
src/input_common/helpers/touch_from_buttons.cpp | 4 +---
src/input_common/input_engine.h | 10 +++++----
src/input_common/input_poller.cpp | 8 +++----
src/input_common/input_poller.h | 10 ++++-----
src/input_common/main.cpp | 6 ++++--
src/yuzu/applets/qt_controller.h | 1 -
src/yuzu/configuration/configure_dialog.cpp | 2 +-
src/yuzu/configuration/configure_input.cpp | 9 ++++----
.../configure_input_player_widget.cpp | 25 ++++++++++++----------
.../configuration/configure_input_player_widget.h | 16 +++++++++++++-
src/yuzu/debugger/controller.cpp | 9 ++++++--
src/yuzu/debugger/controller.h | 9 +++++++-
src/yuzu/main.cpp | 7 +++---
20 files changed, 83 insertions(+), 53 deletions(-)
(limited to 'src/yuzu/configuration')
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index b9d16657a..b04ab4cd8 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -91,6 +91,7 @@ void EmulatedController::ReloadFromSettings() {
}
void EmulatedController::ReloadInput() {
+ // If you load any device here add the equivalent to the UnloadInput() function
const auto player_index = NpadIdTypeToIndex(npad_id_type);
const auto left_side = button_params[Settings::NativeButton::ZL];
const auto right_side = button_params[Settings::NativeButton::ZR];
@@ -113,7 +114,7 @@ void EmulatedController::ReloadInput() {
battery_devices[0] = Input::CreateDevice(left_side);
battery_devices[1] = Input::CreateDevice(right_side);
- button_params[Settings::NativeButton::ZL].Set("output",true);
+ button_params[Settings::NativeButton::ZL].Set("output", true);
output_devices[0] =
Input::CreateDevice(button_params[Settings::NativeButton::ZL]);
@@ -179,6 +180,9 @@ void EmulatedController::UnloadInput() {
for (auto& battery : battery_devices) {
battery.reset();
}
+ for (auto& output : output_devices) {
+ output.reset();
+ }
}
void EmulatedController::EnableConfiguration() {
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 18f29bb78..5391334f4 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -8,7 +8,6 @@
#include "common/settings.h"
#include "core/core.h"
#include "core/core_timing.h"
-#include "core/frontend/input.h"
#include "core/hardware_properties.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/k_readable_event.h"
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp
index 2aa5a16a6..4a56abb99 100644
--- a/src/input_common/drivers/gc_adapter.cpp
+++ b/src/input_common/drivers/gc_adapter.cpp
@@ -322,7 +322,8 @@ bool GCAdapter::GetGCEndpoint(libusb_device* device) {
return true;
}
-Input::VibrationError GCAdapter::SetRumble(const PadIdentifier& identifier, const Input::VibrationStatus vibration) {
+Input::VibrationError GCAdapter::SetRumble(const PadIdentifier& identifier,
+ const Input::VibrationStatus vibration) {
const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f;
const auto processed_amplitude =
static_cast((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8);
diff --git a/src/input_common/drivers/gc_adapter.h b/src/input_common/drivers/gc_adapter.h
index dd23dd9f3..dd0e4aa1d 100644
--- a/src/input_common/drivers/gc_adapter.h
+++ b/src/input_common/drivers/gc_adapter.h
@@ -25,7 +25,7 @@ public:
~GCAdapter();
Input::VibrationError SetRumble(const PadIdentifier& identifier,
- const Input::VibrationStatus vibration) override;
+ const Input::VibrationStatus vibration) override;
/// Used for automapping features
std::vector GetInputDevices() const override;
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h
index f66b33c77..1ff85f48d 100644
--- a/src/input_common/drivers/sdl_driver.h
+++ b/src/input_common/drivers/sdl_driver.h
@@ -59,7 +59,7 @@ public:
u8 GetHatButtonId(const std::string direction_name) const override;
Input::VibrationError SetRumble(const PadIdentifier& identifier,
- const Input::VibrationStatus vibration) override;
+ const Input::VibrationStatus vibration) override;
private:
void InitJoystick(int joystick_index);
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp
index 89ba4aeb1..38f150746 100644
--- a/src/input_common/helpers/stick_from_buttons.cpp
+++ b/src/input_common/helpers/stick_from_buttons.cpp
@@ -251,8 +251,7 @@ private:
std::chrono::time_point last_update;
};
-std::unique_ptr StickFromButton::Create(
- const Common::ParamPackage& params) {
+std::unique_ptr StickFromButton::Create(const Common::ParamPackage& params) {
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
auto up = Input::CreateDeviceFromString(params.Get("up", null_engine));
auto down = Input::CreateDeviceFromString(params.Get("down", null_engine));
diff --git a/src/input_common/helpers/stick_from_buttons.h b/src/input_common/helpers/stick_from_buttons.h
index 87165e022..1d6e24c98 100644
--- a/src/input_common/helpers/stick_from_buttons.h
+++ b/src/input_common/helpers/stick_from_buttons.h
@@ -25,8 +25,7 @@ public:
* - "modifier": a serialized ParamPackage for creating a button device as the modifier
* - "modifier_scale": a float for the multiplier the modifier gives to the position
*/
- std::unique_ptr Create(
- const Common::ParamPackage& params) override;
+ std::unique_ptr Create(const Common::ParamPackage& params) override;
};
} // namespace InputCommon
diff --git a/src/input_common/helpers/touch_from_buttons.cpp b/src/input_common/helpers/touch_from_buttons.cpp
index 6c9046ffb..2abfaf841 100644
--- a/src/input_common/helpers/touch_from_buttons.cpp
+++ b/src/input_common/helpers/touch_from_buttons.cpp
@@ -57,9 +57,7 @@ private:
const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false};
};
-
-std::unique_ptr TouchFromButton::Create(
- const Common::ParamPackage& params) {
+std::unique_ptr TouchFromButton::Create(const Common::ParamPackage& params) {
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
auto button =
Input::CreateDeviceFromString(params.Get("button", null_engine));
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h
index 8a953c382..31ce900d7 100644
--- a/src/input_common/input_engine.h
+++ b/src/input_common/input_engine.h
@@ -121,14 +121,16 @@ public:
}
// Sets rumble to a controller
- virtual Input::VibrationError SetRumble([[maybe_unused]] const PadIdentifier& identifier,
- [[maybe_unused]] const Input::VibrationStatus vibration) {
+ virtual Input::VibrationError SetRumble(
+ [[maybe_unused]] const PadIdentifier& identifier,
+ [[maybe_unused]] const Input::VibrationStatus vibration) {
return Input::VibrationError::NotSupported;
}
// Sets polling mode to a controller
- virtual Input::PollingError SetPollingMode([[maybe_unused]] const PadIdentifier& identifier,
- [[maybe_unused]] const Input::PollingMode vibration) {
+ virtual Input::PollingError SetPollingMode(
+ [[maybe_unused]] const PadIdentifier& identifier,
+ [[maybe_unused]] const Input::PollingMode vibration) {
return Input::PollingError::NotSupported;
}
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp
index 781012886..62ade951c 100644
--- a/src/input_common/input_poller.cpp
+++ b/src/input_common/input_poller.cpp
@@ -597,7 +597,7 @@ public:
explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_)
: identifier(identifier_), input_engine(input_engine_) {}
- virtual void SetLED( Input::LedStatus led_status) {
+ virtual void SetLED(Input::LedStatus led_status) {
input_engine->SetLeds(identifier, led_status);
}
@@ -847,8 +847,7 @@ std::unique_ptr InputFactory::CreateMotionDevice(Common::Par
InputFactory::InputFactory(std::shared_ptr input_engine_)
: input_engine(std::move(input_engine_)) {}
-std::unique_ptr InputFactory::Create(
- const Common::ParamPackage& params) {
+std::unique_ptr InputFactory::Create(const Common::ParamPackage& params) {
if (params.Has("button") && params.Has("axis")) {
return CreateTriggerDevice(params);
}
@@ -883,8 +882,7 @@ std::unique_ptr InputFactory::Create(
OutputFactory::OutputFactory(std::shared_ptr input_engine_)
: input_engine(std::move(input_engine_)) {}
-std::unique_ptr OutputFactory::Create(
- const Common::ParamPackage& params) {
+std::unique_ptr OutputFactory::Create(const Common::ParamPackage& params) {
const PadIdentifier identifier = {
.guid = Common::UUID{params.Get("guid", "")},
.port = static_cast(params.Get("port", 0)),
diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h
index 16cade5fa..1357e104b 100644
--- a/src/input_common/input_poller.h
+++ b/src/input_common/input_poller.h
@@ -29,8 +29,7 @@ public:
* @param - "pad": slot of the connected controller
* @return an unique ouput device with the parameters specified
*/
- std::unique_ptr Create(
- const Common::ParamPackage& params) override;
+ std::unique_ptr Create(const Common::ParamPackage& params) override;
private:
std::shared_ptr input_engine;
@@ -41,8 +40,8 @@ public:
explicit InputFactory(std::shared_ptr input_engine_);
/**
- * Creates an input device from the parameters given. Identifies the type of input to be returned
- * if it contains the following parameters:
+ * Creates an input device from the parameters given. Identifies the type of input to be
+ * returned if it contains the following parameters:
* - button: Contains "button" or "code"
* - hat_button: Contains "hat"
* - analog: Contains "axis"
@@ -65,8 +64,7 @@ public:
* @param - "battery": Only used as a placeholder to set the input type
* @return an unique input device with the parameters specified
*/
- std::unique_ptr Create(
- const Common::ParamPackage& params) override;
+ std::unique_ptr Create(const Common::ParamPackage& params) override;
private:
/**
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index b7fe9cb37..7807dd38f 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -48,8 +48,10 @@ struct InputSubsystem::Impl {
gcadapter->SetMappingCallback(mapping_callback);
gcadapter_input_factory = std::make_shared(gcadapter);
gcadapter_output_factory = std::make_shared(gcadapter);
- Input::RegisterFactory(gcadapter->GetEngineName(), gcadapter_input_factory);
- Input::RegisterFactory(gcadapter->GetEngineName(), gcadapter_output_factory);
+ Input::RegisterFactory(gcadapter->GetEngineName(),
+ gcadapter_input_factory);
+ Input::RegisterFactory(gcadapter->GetEngineName(),
+ gcadapter_output_factory);
udp_client = std::make_shared("cemuhookudp");
udp_client->SetMappingCallback(mapping_callback);
diff --git a/src/yuzu/applets/qt_controller.h b/src/yuzu/applets/qt_controller.h
index 98060e6f8..ca09fde04 100644
--- a/src/yuzu/applets/qt_controller.h
+++ b/src/yuzu/applets/qt_controller.h
@@ -106,7 +106,6 @@ private:
Core::Frontend::ControllerParameters parameters;
InputCommon::InputSubsystem* input_subsystem;
- Core::System& system;
std::unique_ptr input_profiles;
diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp
index 642a5f966..1eb9d70e5 100644
--- a/src/yuzu/configuration/configure_dialog.cpp
+++ b/src/yuzu/configuration/configure_dialog.cpp
@@ -74,7 +74,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry,
hotkeys_tab->Populate(registry);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
- input_tab->Initialize(input_subsystem);
+ input_tab->Initialize(input_subsystem, system_);
general_tab->SetResetCallback([&] { this->close(); });
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp
index 61513865f..a8611f77f 100644
--- a/src/yuzu/configuration/configure_input.cpp
+++ b/src/yuzu/configuration/configure_input.cpp
@@ -146,10 +146,11 @@ void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem, Co
advanced = new ConfigureInputAdvanced(this);
ui->tabAdvanced->setLayout(new QHBoxLayout(ui->tabAdvanced));
ui->tabAdvanced->layout()->addWidget(advanced);
- connect(advanced, &ConfigureInputAdvanced::CallDebugControllerDialog, [this, input_subsystem] {
- CallConfigureDialog(*this, input_subsystem, profiles.get(),
- system);
- });
+ connect(advanced, &ConfigureInputAdvanced::CallDebugControllerDialog,
+ [this, input_subsystem, &system] {
+ CallConfigureDialog(*this, input_subsystem,
+ profiles.get(), system);
+ });
connect(advanced, &ConfigureInputAdvanced::CallMouseConfigDialog, [this, input_subsystem] {
CallConfigureDialog(*this, input_subsystem);
});
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp
index 2ba9d7290..446b72e55 100644
--- a/src/yuzu/configuration/configure_input_player_widget.cpp
+++ b/src/yuzu/configuration/configure_input_player_widget.cpp
@@ -19,15 +19,11 @@ PlayerControlPreview::PlayerControlPreview(QWidget* parent) : QFrame(parent) {
}
PlayerControlPreview::~PlayerControlPreview() {
- if (is_controller_set) {
- controller->DeleteCallback(callback_key);
- }
+ UnloadController();
};
void PlayerControlPreview::SetController(Core::HID::EmulatedController* controller_) {
- if (is_controller_set) {
- controller->DeleteCallback(callback_key);
- }
+ UnloadController();
is_controller_set = true;
controller = controller_;
Core::HID::ControllerUpdateCallback engine_callback{
@@ -36,14 +32,21 @@ void PlayerControlPreview::SetController(Core::HID::EmulatedController* controll
ControllerUpdate(Core::HID::ControllerTriggerType::All);
}
-void PlayerControlPreview::BeginMappingButton(std::size_t index) {
- button_mapping_index = index;
+void PlayerControlPreview::UnloadController() {
+ if (is_controller_set) {
+ controller->DeleteCallback(callback_key);
+ is_controller_set = false;
+ }
+}
+
+void PlayerControlPreview::BeginMappingButton(std::size_t button_id) {
+ button_mapping_index = button_id;
mapping_active = true;
}
-void PlayerControlPreview::BeginMappingAnalog(std::size_t index) {
- button_mapping_index = Settings::NativeButton::LStick + index;
- analog_mapping_index = index;
+void PlayerControlPreview::BeginMappingAnalog(std::size_t stick_id) {
+ button_mapping_index = Settings::NativeButton::LStick + stick_id;
+ analog_mapping_index = stick_id;
mapping_active = true;
}
diff --git a/src/yuzu/configuration/configure_input_player_widget.h b/src/yuzu/configuration/configure_input_player_widget.h
index 16f9748f5..333c3fc56 100644
--- a/src/yuzu/configuration/configure_input_player_widget.h
+++ b/src/yuzu/configuration/configure_input_player_widget.h
@@ -25,11 +25,25 @@ public:
explicit PlayerControlPreview(QWidget* parent);
~PlayerControlPreview() override;
+ // Sets the emulated controller to be displayed
void SetController(Core::HID::EmulatedController* controller);
+
+ // Disables events from the emulated controller
+ void UnloadController();
+
+ // Starts blinking animation at the button specified
void BeginMappingButton(std::size_t button_id);
- void BeginMappingAnalog(std::size_t button_id);
+
+ // Starts moving animation at the stick specified
+ void BeginMappingAnalog(std::size_t stick_id);
+
+ // Stops any ongoing animation
void EndMapping();
+
+ // Handles emulated controller events
void ControllerUpdate(Core::HID::ControllerTriggerType type);
+
+ // Updates input on sheduled interval
void UpdateInput();
protected:
diff --git a/src/yuzu/debugger/controller.cpp b/src/yuzu/debugger/controller.cpp
index d8e41f8b6..3619aed26 100644
--- a/src/yuzu/debugger/controller.cpp
+++ b/src/yuzu/debugger/controller.cpp
@@ -10,7 +10,8 @@
#include "yuzu/configuration/configure_input_player_widget.h"
#include "yuzu/debugger/controller.h"
-ControllerDialog::ControllerDialog(QWidget* parent) : QWidget(parent, Qt::Dialog) {
+ControllerDialog::ControllerDialog(Core::System& system, QWidget* parent)
+ : QWidget(parent, Qt::Dialog) {
setObjectName(QStringLiteral("Controller"));
setWindowTitle(tr("Controller P1"));
resize(500, 350);
@@ -20,7 +21,7 @@ ControllerDialog::ControllerDialog(QWidget* parent) : QWidget(parent, Qt::Dialog
Qt::WindowMaximizeButtonHint);
widget = new PlayerControlPreview(this);
- widget->SetController(Core::System::GetInstance().HIDCore().GetEmulatedController(
+ widget->SetController(system.HIDCore().GetEmulatedController(
Core::HID::NpadIdType::Player1));
QLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
@@ -45,6 +46,10 @@ QAction* ControllerDialog::toggleViewAction() {
return toggle_view_action;
}
+void ControllerDialog::UnloadController() {
+ widget->UnloadController();
+}
+
void ControllerDialog::showEvent(QShowEvent* ev) {
if (toggle_view_action) {
toggle_view_action->setChecked(isVisible());
diff --git a/src/yuzu/debugger/controller.h b/src/yuzu/debugger/controller.h
index 697489cbb..33f617b9b 100644
--- a/src/yuzu/debugger/controller.h
+++ b/src/yuzu/debugger/controller.h
@@ -11,6 +11,10 @@ class QHideEvent;
class QShowEvent;
class PlayerControlPreview;
+namespace Core {
+class System;
+}
+
namespace InputCommon {
class InputSubsystem;
}
@@ -19,11 +23,14 @@ class ControllerDialog : public QWidget {
Q_OBJECT
public:
- explicit ControllerDialog(QWidget* parent = nullptr);
+ explicit ControllerDialog(Core::System& system, QWidget* parent = nullptr);
/// Returns a QAction that can be used to toggle visibility of this dialog.
QAction* toggleViewAction();
+ // Disables events from the emulated controller
+ void UnloadController();
+
protected:
void showEvent(QShowEvent* ev) override;
void hideEvent(QHideEvent* ev) override;
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 19cb5313f..ae997ccfa 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -228,7 +228,7 @@ GMainWindow::GMainWindow()
ConnectMenuEvents();
ConnectWidgetEvents();
- Core::System::GetInstance().HIDCore().ReloadInputDevices();
+ system->HIDCore().ReloadInputDevices();
const auto branch_name = std::string(Common::g_scm_branch);
const auto description = std::string(Common::g_scm_desc);
@@ -924,7 +924,7 @@ void GMainWindow::InitializeDebugWidgets() {
waitTreeWidget->hide();
debug_menu->addAction(waitTreeWidget->toggleViewAction());
- controller_dialog = new ControllerDialog(this);
+ controller_dialog = new ControllerDialog(*system, this);
controller_dialog->hide();
debug_menu->addAction(controller_dialog->toggleViewAction());
@@ -3372,7 +3372,8 @@ void GMainWindow::closeEvent(QCloseEvent* event) {
UpdateUISettings();
game_list->SaveInterfaceLayout();
hotkey_registry.SaveHotkeys();
- Core::System::GetInstance().HIDCore().UnloadInputDevices();
+ controller_dialog->UnloadController();
+ system->HIDCore().UnloadInputDevices();
// Shutdown session if the emu thread is active...
if (emu_thread != nullptr) {
--
cgit v1.2.3
From 4d308fd0b4fc8f14754c47811e751bf068b330b8 Mon Sep 17 00:00:00 2001
From: german77
Date: Mon, 18 Oct 2021 23:15:46 -0500
Subject: hid: Fix controller connection/disconnection
---
src/core/hid/emulated_console.cpp | 1 -
src/core/hid/emulated_controller.cpp | 98 +++++++++++++++++-----
src/core/hid/emulated_controller.h | 18 +++-
src/core/hid/hid_types.h | 8 +-
.../service/hid/controllers/controller_base.cpp | 2 +-
src/core/hle/service/hid/controllers/npad.cpp | 77 +++++++++++------
src/core/hle/service/hid/controllers/npad.h | 3 +
src/yuzu/configuration/configure_input.cpp | 1 +
src/yuzu/configuration/configure_input_player.cpp | 81 ++++++++++++++++--
.../configure_input_player_widget.cpp | 2 +-
10 files changed, 226 insertions(+), 65 deletions(-)
(limited to 'src/yuzu/configuration')
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp
index c65d05041..7f7c8fd59 100644
--- a/src/core/hid/emulated_console.cpp
+++ b/src/core/hid/emulated_console.cpp
@@ -53,7 +53,6 @@ void EmulatedConsole::ReloadInput() {
touch_button_params.Set("x", x);
touch_button_params.Set("y", y);
touch_button_params.Set("touch_id", static_cast(index));
- LOG_ERROR(Common, "{} ", touch_button_params.Serialize());
touch_devices[index] =
Input::CreateDeviceFromString(touch_button_params.Serialize());
if (!touch_devices[index]) {
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index b04ab4cd8..7ef6ef118 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -54,6 +54,7 @@ Settings::ControllerType EmulatedController::MapNPadToSettingsType(NpadType type
}
void EmulatedController::ReloadFromSettings() {
+ //LOG_ERROR(Service_HID, "reload config from settings {}", NpadIdTypeToIndex(npad_id_type));
const auto player_index = NpadIdTypeToIndex(npad_id_type);
const auto& player = Settings::values.players.GetValue()[player_index];
@@ -91,6 +92,7 @@ void EmulatedController::ReloadFromSettings() {
}
void EmulatedController::ReloadInput() {
+ //LOG_ERROR(Service_HID, "reload config {}", NpadIdTypeToIndex(npad_id_type));
// If you load any device here add the equivalent to the UnloadInput() function
const auto player_index = NpadIdTypeToIndex(npad_id_type);
const auto left_side = button_params[Settings::NativeButton::ZL];
@@ -187,11 +189,29 @@ void EmulatedController::UnloadInput() {
void EmulatedController::EnableConfiguration() {
is_configuring = true;
- SaveCurrentConfig();
+ temporary_is_connected = is_connected;
+ temporary_npad_type = npad_type;
}
void EmulatedController::DisableConfiguration() {
is_configuring = false;
+
+ // Apply temporary npad type to the real controller
+ if (temporary_npad_type != npad_type) {
+ if (is_connected) {
+ Disconnect();
+ }
+ SetNpadType(temporary_npad_type);
+ }
+
+ // Apply temporary connected status to the real controller
+ if (temporary_is_connected != is_connected) {
+ if (temporary_is_connected) {
+ Connect();
+ return;
+ }
+ Disconnect();
+ }
}
bool EmulatedController::IsConfiguring() const {
@@ -199,10 +219,6 @@ bool EmulatedController::IsConfiguring() const {
}
void EmulatedController::SaveCurrentConfig() {
- if (!is_configuring) {
- return;
- }
-
const auto player_index = NpadIdTypeToIndex(npad_id_type);
auto& player = Settings::values.players.GetValue()[player_index];
player.connected = is_connected;
@@ -657,26 +673,47 @@ void EmulatedController::SetLedPattern() {
}
void EmulatedController::Connect() {
- std::lock_guard lock{mutex};
- if (is_connected) {
- LOG_WARNING(Service_HID, "Tried to turn on a connected controller {}", npad_id_type);
- return;
+ {
+ std::lock_guard lock{mutex};
+ if (is_configuring) {
+ temporary_is_connected = true;
+ TriggerOnChange(ControllerTriggerType::Connected);
+ return;
+ }
+
+ if (is_connected) {
+ return;
+ }
+ is_connected = true;
}
- is_connected = true;
+ LOG_ERROR(Service_HID, "Connected controller {}", NpadIdTypeToIndex(npad_id_type));
TriggerOnChange(ControllerTriggerType::Connected);
}
void EmulatedController::Disconnect() {
- std::lock_guard lock{mutex};
- if (!is_connected) {
- LOG_WARNING(Service_HID, "Tried to turn off a disconnected controller {}", npad_id_type);
- return;
+ {
+ std::lock_guard lock{mutex};
+ if (is_configuring) {
+ temporary_is_connected = false;
+ LOG_ERROR(Service_HID, "Disconnected temporal controller {}",
+ NpadIdTypeToIndex(npad_id_type));
+ TriggerOnChange(ControllerTriggerType::Disconnected);
+ return;
+ }
+
+ if (!is_connected) {
+ return;
+ }
+ is_connected = false;
}
- is_connected = false;
+ LOG_ERROR(Service_HID, "Disconnected controller {}", NpadIdTypeToIndex(npad_id_type));
TriggerOnChange(ControllerTriggerType::Disconnected);
}
-bool EmulatedController::IsConnected() const {
+bool EmulatedController::IsConnected(bool temporary) const {
+ if (temporary) {
+ return temporary_is_connected;
+ }
return is_connected;
}
@@ -688,16 +725,35 @@ NpadIdType EmulatedController::GetNpadIdType() const {
return npad_id_type;
}
-NpadType EmulatedController::GetNpadType() const {
+NpadType EmulatedController::GetNpadType(bool temporary) const {
+ if (temporary) {
+ return temporary_npad_type;
+ }
return npad_type;
}
void EmulatedController::SetNpadType(NpadType npad_type_) {
- std::lock_guard lock{mutex};
- if (npad_type == npad_type_) {
- return;
+ {
+ std::lock_guard lock{mutex};
+
+ if (is_configuring) {
+ if (temporary_npad_type == npad_type_) {
+ return;
+ }
+ temporary_npad_type = npad_type_;
+ TriggerOnChange(ControllerTriggerType::Type);
+ return;
+ }
+
+ if (npad_type == npad_type_) {
+ return;
+ }
+ if (is_connected) {
+ LOG_WARNING(Service_HID, "Controller {} type changed while it's connected",
+ NpadIdTypeToIndex(npad_id_type));
+ }
+ npad_type = npad_type_;
}
- npad_type = npad_type_;
TriggerOnChange(ControllerTriggerType::Type);
}
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index 096fe1705..6a6dc1892 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -139,8 +139,12 @@ public:
/// Sets the NpadType for this controller
void SetNpadType(NpadType npad_type_);
- /// Gets the NpadType for this controller
- NpadType GetNpadType() const;
+ /**
+ * Gets the NpadType for this controller
+ * @param Returns the temporary value if true
+ * @return NpadType set on the controller
+ */
+ NpadType GetNpadType(bool temporary = false) const;
/// Sets the connected status to true
void Connect();
@@ -148,8 +152,12 @@ public:
/// Sets the connected status to false
void Disconnect();
- /// Returns true if the controller has the connected status
- bool IsConnected() const;
+ /**
+ * Is the emulated connected
+ * @param Returns the temporary value if true
+ * @return true if the controller has the connected status
+ */
+ bool IsConnected(bool temporary = false) const;
/// Returns true if vibration is enabled
bool IsVibrationEnabled() const;
@@ -323,7 +331,9 @@ private:
NpadIdType npad_id_type;
NpadType npad_type{NpadType::None};
+ NpadType temporary_npad_type{NpadType::None};
bool is_connected{false};
+ bool temporary_is_connected{false};
bool is_configuring{false};
bool is_vibration_enabled{true};
f32 motion_sensitivity{0.01f};
diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h
index f12a14cb8..539436283 100644
--- a/src/core/hid/hid_types.h
+++ b/src/core/hid/hid_types.h
@@ -47,9 +47,9 @@ constexpr size_t NpadIdTypeToIndex(NpadIdType npad_id_type) {
return 6;
case NpadIdType::Player8:
return 7;
- case NpadIdType::Other:
- return 8;
case NpadIdType::Handheld:
+ return 8;
+ case NpadIdType::Other:
return 9;
default:
return 0;
@@ -76,9 +76,9 @@ constexpr NpadIdType IndexToNpadIdType(size_t index) {
case 7:
return NpadIdType::Player8;
case 8:
- return NpadIdType::Other;
- case 9:
return NpadIdType::Handheld;
+ case 9:
+ return NpadIdType::Other;
default:
return NpadIdType::Invalid;
}
diff --git a/src/core/hle/service/hid/controllers/controller_base.cpp b/src/core/hle/service/hid/controllers/controller_base.cpp
index 9d1e6db6a..74a394784 100644
--- a/src/core/hle/service/hid/controllers/controller_base.cpp
+++ b/src/core/hle/service/hid/controllers/controller_base.cpp
@@ -11,7 +11,7 @@ ControllerBase::~ControllerBase() = default;
void ControllerBase::ActivateController() {
if (is_activated) {
- OnRelease();
+ return;
}
is_activated = true;
OnInit();
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index a2e9ddf4d..144abab65 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -125,18 +125,22 @@ void Controller_NPad::ControllerUpdate(Core::HID::ControllerTriggerType type,
return;
}
+ auto& controller = controller_data[controller_idx];
+ const auto is_connected = controller.device->IsConnected();
+ const auto npad_type = controller.device->GetNpadType();
switch (type) {
case Core::HID::ControllerTriggerType::Connected:
- InitNewlyAddedController(controller_idx);
- break;
case Core::HID::ControllerTriggerType::Disconnected:
- DisconnectNpadAtIndex(controller_idx);
+ if (is_connected == controller.is_connected) {
+ return;
+ }
+ UpdateControllerAt(npad_type, controller_idx, is_connected);
break;
case Core::HID::ControllerTriggerType::Type: {
- auto& controller = controller_data[controller_idx];
- if (controller.device->IsConnected()) {
- LOG_ERROR(Service_HID, "Controller type changed without turning off the controller");
+ if (npad_type == controller.npad_type) {
+ return;
}
+ // UpdateControllerAt(npad_type, controller_idx, is_connected);
break;
}
default:
@@ -146,6 +150,7 @@ void Controller_NPad::ControllerUpdate(Core::HID::ControllerTriggerType type,
void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) {
auto& controller = controller_data[controller_idx];
+ LOG_ERROR(Service_HID, "Connect {} {}", controller_idx, controller.is_connected);
const auto controller_type = controller.device->GetNpadType();
auto& shared_memory = controller.shared_memory_entry;
if (controller_type == Core::HID::NpadType::None) {
@@ -235,20 +240,23 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) {
shared_memory.battery_level_left = battery_level.left.battery_level;
shared_memory.battery_level_right = battery_level.right.battery_level;
+ controller.is_connected = true;
+ controller.device->Connect();
SignalStyleSetChangedEvent(IndexToNPad(controller_idx));
+ WriteEmptyEntry(controller.shared_memory_entry);
}
void Controller_NPad::OnInit() {
+ if (!IsControllerActivated()) {
+ return;
+ }
+
for (std::size_t i = 0; i < controller_data.size(); ++i) {
auto& controller = controller_data[i];
controller.styleset_changed_event =
service_context.CreateEvent(fmt::format("npad:NpadStyleSetChanged_{}", i));
}
- if (!IsControllerActivated()) {
- return;
- }
-
if (system.HIDCore().GetSupportedStyleTag().raw == 0) {
// We want to support all controllers
Core::HID::NpadStyleTag style{};
@@ -277,20 +285,33 @@ void Controller_NPad::OnInit() {
for (auto& controller : controller_data) {
NPadGenericState dummy_pad_state{};
auto& npad = controller.shared_memory_entry;
- for (std::size_t i = 0; i < 17; ++i) {
- dummy_pad_state.sampling_number =
- npad.fullkey_lifo.ReadCurrentEntry().sampling_number + 1;
- npad.fullkey_lifo.WriteNextEntry(dummy_pad_state);
- npad.handheld_lifo.WriteNextEntry(dummy_pad_state);
- npad.joy_dual_lifo.WriteNextEntry(dummy_pad_state);
- npad.joy_left_lifo.WriteNextEntry(dummy_pad_state);
- npad.joy_right_lifo.WriteNextEntry(dummy_pad_state);
- npad.joy_right_lifo.WriteNextEntry(dummy_pad_state);
- npad.palma_lifo.WriteNextEntry(dummy_pad_state);
+ for (std::size_t i = 0; i < 19; ++i) {
+ WriteEmptyEntry(npad);
}
}
}
+void Controller_NPad::WriteEmptyEntry(NpadInternalState& npad) {
+ NPadGenericState dummy_pad_state{};
+ NpadGcTriggerState dummy_gc_state{};
+ dummy_pad_state.sampling_number = npad.fullkey_lifo.ReadCurrentEntry().sampling_number + 1;
+ npad.fullkey_lifo.WriteNextEntry(dummy_pad_state);
+ dummy_pad_state.sampling_number = npad.handheld_lifo.ReadCurrentEntry().sampling_number + 1;
+ npad.handheld_lifo.WriteNextEntry(dummy_pad_state);
+ dummy_pad_state.sampling_number = npad.joy_dual_lifo.ReadCurrentEntry().sampling_number + 1;
+ npad.joy_dual_lifo.WriteNextEntry(dummy_pad_state);
+ dummy_pad_state.sampling_number = npad.joy_left_lifo.ReadCurrentEntry().sampling_number + 1;
+ npad.joy_left_lifo.WriteNextEntry(dummy_pad_state);
+ dummy_pad_state.sampling_number = npad.joy_right_lifo.ReadCurrentEntry().sampling_number + 1;
+ npad.joy_right_lifo.WriteNextEntry(dummy_pad_state);
+ dummy_pad_state.sampling_number = npad.palma_lifo.ReadCurrentEntry().sampling_number + 1;
+ npad.palma_lifo.WriteNextEntry(dummy_pad_state);
+ dummy_pad_state.sampling_number = npad.system_ext_lifo.ReadCurrentEntry().sampling_number + 1;
+ npad.system_ext_lifo.WriteNextEntry(dummy_pad_state);
+ dummy_gc_state.sampling_number = npad.gc_trigger_lifo.ReadCurrentEntry().sampling_number + 1;
+ npad.gc_trigger_lifo.WriteNextEntry(dummy_gc_state);
+}
+
void Controller_NPad::OnRelease() {
for (std::size_t i = 0; i < controller_data.size(); ++i) {
auto& controller = controller_data[i];
@@ -359,6 +380,7 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
if (!IsControllerActivated()) {
return;
}
+
for (std::size_t i = 0; i < controller_data.size(); ++i) {
auto& controller = controller_data[i];
auto& npad = controller.shared_memory_entry;
@@ -366,6 +388,9 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
const auto& controller_type = controller.device->GetNpadType();
if (controller_type == Core::HID::NpadType::None || !controller.device->IsConnected()) {
+ // Refresh shared memory
+ std::memcpy(data + NPAD_OFFSET + (i * sizeof(NpadInternalState)),
+ &controller.shared_memory_entry, sizeof(NpadInternalState));
continue;
}
const u32 npad_index = static_cast(i);
@@ -830,14 +855,14 @@ void Controller_NPad::AddNewControllerAt(Core::HID::NpadType controller, std::si
void Controller_NPad::UpdateControllerAt(Core::HID::NpadType type, std::size_t npad_index,
bool connected) {
- auto& controller = controller_data[npad_index].device;
+ auto& controller = controller_data[npad_index];
if (!connected) {
DisconnectNpadAtIndex(npad_index);
return;
}
- controller->SetNpadType(type);
- controller->Connect();
+ controller.device->SetNpadType(type);
+ controller.device->Connect();
InitNewlyAddedController(npad_index);
}
@@ -847,14 +872,13 @@ void Controller_NPad::DisconnectNpad(u32 npad_id) {
void Controller_NPad::DisconnectNpadAtIndex(std::size_t npad_index) {
auto& controller = controller_data[npad_index];
+ LOG_ERROR(Service_HID, "Disconnect {} {}", npad_index, controller.is_connected);
for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) {
// Send an empty vibration to stop any vibrations.
VibrateControllerAtIndex(npad_index, device_idx, {});
controller.vibration[device_idx].device_mounted = false;
}
- controller.device->Disconnect();
-
auto& shared_memory_entry = controller.shared_memory_entry;
shared_memory_entry.style_set.raw = 0; // Zero out
shared_memory_entry.device_type.raw = 0;
@@ -868,7 +892,10 @@ void Controller_NPad::DisconnectNpadAtIndex(std::size_t npad_index) {
shared_memory_entry.assignment_mode = NpadJoyAssignmentMode::Dual;
shared_memory_entry.footer_type = AppletFooterUiType::None;
+ controller.is_connected = false;
+ controller.device->Disconnect();
SignalStyleSetChangedEvent(IndexToNPad(npad_index));
+ WriteEmptyEntry(controller.shared_memory_entry);
}
void Controller_NPad::SetGyroscopeZeroDriftMode(GyroscopeZeroDriftMode drift_mode) {
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h
index b0e2f8430..d805ccb97 100644
--- a/src/core/hle/service/hid/controllers/npad.h
+++ b/src/core/hle/service/hid/controllers/npad.h
@@ -417,6 +417,8 @@ private:
std::array vibration{};
bool unintended_home_button_input_protection{};
+ bool is_connected{};
+ Core::HID::NpadType npad_type{Core::HID::NpadType::None};
// Current pad state
NPadGenericState npad_pad_state{};
@@ -435,6 +437,7 @@ private:
void InitNewlyAddedController(std::size_t controller_idx);
bool IsControllerSupported(Core::HID::NpadType controller) const;
void RequestPadStateUpdate(u32 npad_id);
+ void WriteEmptyEntry(NpadInternalState& npad);
std::atomic press_state{};
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp
index a8611f77f..67faa8be8 100644
--- a/src/yuzu/configuration/configure_input.cpp
+++ b/src/yuzu/configuration/configure_input.cpp
@@ -114,6 +114,7 @@ void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem, Co
player_tabs[i]->setLayout(new QHBoxLayout(player_tabs[i]));
player_tabs[i]->layout()->addWidget(player_controllers[i]);
connect(player_controllers[i], &ConfigureInputPlayer::Connected, [&, i](bool is_connected) {
+ // Ensures that the controllers are always connected in sequential order
if (is_connected) {
for (std::size_t index = 0; index <= i; ++index) {
player_connected[index]->setChecked(is_connected);
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index ed9c3facf..81310a5b3 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -143,8 +143,26 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
timeout_timer(std::make_unique()), poll_timer(std::make_unique()),
bottom_row(bottom_row), system{system_} {
- emulated_controller = system_.HIDCore().GetEmulatedControllerByIndex(player_index);
- emulated_controller->EnableConfiguration();
+ if (player_index == 0) {
+ auto* emulated_controller_p1 =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
+ auto* emulated_controller_hanheld =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
+ emulated_controller_p1->SaveCurrentConfig();
+ emulated_controller_p1->EnableConfiguration();
+ emulated_controller_hanheld->SaveCurrentConfig();
+ emulated_controller_hanheld->EnableConfiguration();
+ if (emulated_controller_hanheld->IsConnected(true)) {
+ emulated_controller_p1->Disconnect();
+ emulated_controller = emulated_controller_hanheld;
+ } else {
+ emulated_controller = emulated_controller_p1;
+ }
+ } else {
+ emulated_controller = system_.HIDCore().GetEmulatedControllerByIndex(player_index);
+ emulated_controller->SaveCurrentConfig();
+ emulated_controller->EnableConfiguration();
+ }
ui->setupUi(this);
setFocusPolicy(Qt::ClickFocus);
@@ -460,13 +478,36 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
UpdateControllerEnabledButtons();
UpdateControllerButtonNames();
UpdateMotionButtons();
- connect(ui->comboControllerType, qOverload(&QComboBox::currentIndexChanged), [this](int) {
+ connect(ui->comboControllerType, qOverload(&QComboBox::currentIndexChanged), [this, player_index](int) {
UpdateControllerAvailableButtons();
UpdateControllerEnabledButtons();
UpdateControllerButtonNames();
UpdateMotionButtons();
- emulated_controller->SetNpadType(
- GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()));
+ const Core::HID::NpadType type = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex());
+
+ if (player_index == 0) {
+ auto* emulated_controller_p1 =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
+ auto* emulated_controller_hanheld =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
+ bool is_connected = emulated_controller->IsConnected(true);
+
+ emulated_controller_p1->SetNpadType(type);
+ emulated_controller_hanheld->SetNpadType(type);
+ if (is_connected) {
+ if (type == Core::HID::NpadType::Handheld) {
+ emulated_controller_p1->Disconnect();
+ emulated_controller_hanheld->Connect();
+ emulated_controller = emulated_controller_hanheld;
+ } else {
+ emulated_controller_hanheld->Disconnect();
+ emulated_controller_p1->Connect();
+ emulated_controller = emulated_controller_p1;
+ }
+ }
+ ui->controllerFrame->SetController(emulated_controller);
+ }
+ emulated_controller->SetNpadType(type);
});
connect(ui->comboDevices, qOverload(&QComboBox::activated), this,
@@ -504,11 +545,35 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
}
ConfigureInputPlayer::~ConfigureInputPlayer() {
- emulated_controller->DisableConfiguration();
+ if (player_index == 0) {
+ auto* emulated_controller_p1 =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
+ auto* emulated_controller_hanheld =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
+ emulated_controller_p1->DisableConfiguration();
+ emulated_controller_hanheld->DisableConfiguration();
+ } else {
+ emulated_controller->DisableConfiguration();
+ }
};
void ConfigureInputPlayer::ApplyConfiguration() {
+ if (player_index == 0) {
+ auto* emulated_controller_p1 =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
+ auto* emulated_controller_hanheld =
+ system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
+ emulated_controller_p1->DisableConfiguration();
+ emulated_controller_p1->SaveCurrentConfig();
+ emulated_controller_p1->EnableConfiguration();
+ emulated_controller_hanheld->DisableConfiguration();
+ emulated_controller_hanheld->SaveCurrentConfig();
+ emulated_controller_hanheld->EnableConfiguration();
+ return;
+ }
+ emulated_controller->DisableConfiguration();
emulated_controller->SaveCurrentConfig();
+ emulated_controller->EnableConfiguration();
}
void ConfigureInputPlayer::showEvent(QShowEvent* event) {
@@ -535,9 +600,9 @@ void ConfigureInputPlayer::RetranslateUI() {
void ConfigureInputPlayer::LoadConfiguration() {
UpdateUI();
UpdateInputDeviceCombobox();
- const int comboBoxIndex = GetIndexFromControllerType(emulated_controller->GetNpadType());
+ const int comboBoxIndex = GetIndexFromControllerType(emulated_controller->GetNpadType(true));
ui->comboControllerType->setCurrentIndex(comboBoxIndex);
- ui->groupConnectedController->setChecked(emulated_controller->IsConnected());
+ ui->groupConnectedController->setChecked(emulated_controller->IsConnected(true));
}
void ConfigureInputPlayer::ConnectPlayer(bool connected) {
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp
index 446b72e55..3b79b6076 100644
--- a/src/yuzu/configuration/configure_input_player_widget.cpp
+++ b/src/yuzu/configuration/configure_input_player_widget.cpp
@@ -145,7 +145,7 @@ void PlayerControlPreview::ControllerUpdate(Core::HID::ControllerTriggerType typ
needs_redraw = true;
break;
case Core::HID::ControllerTriggerType::Type:
- controller_type = controller->GetNpadType();
+ controller_type = controller->GetNpadType(true);
needs_redraw = true;
break;
case Core::HID::ControllerTriggerType::Color:
--
cgit v1.2.3
From 601ac43495904f3f7666d79a800a8b4eda5a8461 Mon Sep 17 00:00:00 2001
From: german77
Date: Tue, 19 Oct 2021 00:12:24 -0500
Subject: core/hid: Only signal when needed
---
src/common/input.h | 1 +
src/core/hid/emulated_controller.cpp | 259 +++++++++++----------
src/core/hid/emulated_controller.h | 6 +-
src/core/hid/input_converter.cpp | 2 +-
src/core/hle/service/hid/controllers/npad.cpp | 6 +-
src/input_common/drivers/gc_adapter.cpp | 75 +++++-
src/input_common/drivers/gc_adapter.h | 6 +-
src/input_common/drivers/keyboard.cpp | 2 +-
src/input_common/drivers/sdl_driver.cpp | 22 +-
src/input_common/drivers/tas_input.cpp | 2 +-
.../configure_input_player_widget.cpp | 12 +-
11 files changed, 240 insertions(+), 153 deletions(-)
(limited to 'src/yuzu/configuration')
diff --git a/src/common/input.h b/src/common/input.h
index 3a28b77a7..8871a9d07 100644
--- a/src/common/input.h
+++ b/src/common/input.h
@@ -30,6 +30,7 @@ enum class InputType {
};
enum class BatteryLevel {
+ None,
Empty,
Critical,
Low,
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 7ef6ef118..e102c9437 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -94,7 +94,6 @@ void EmulatedController::ReloadFromSettings() {
void EmulatedController::ReloadInput() {
//LOG_ERROR(Service_HID, "reload config {}", NpadIdTypeToIndex(npad_id_type));
// If you load any device here add the equivalent to the UnloadInput() function
- const auto player_index = NpadIdTypeToIndex(npad_id_type);
const auto left_side = button_params[Settings::NativeButton::ZL];
const auto right_side = button_params[Settings::NativeButton::ZR];
@@ -337,120 +336,130 @@ void EmulatedController::SetButton(Input::CallbackStatus callback, std::size_t i
if (index >= controller.button_values.size()) {
return;
}
- std::lock_guard lock{mutex};
- bool value_changed = false;
- const auto new_status = TransformToButton(callback);
- auto& current_status = controller.button_values[index];
- current_status.toggle = new_status.toggle;
-
- // Update button status with current
- if (!current_status.toggle) {
- current_status.locked = false;
- if (current_status.value != new_status.value) {
- current_status.value = new_status.value;
- value_changed = true;
- }
- } else {
- // Toggle button and lock status
- if (new_status.value && !current_status.locked) {
- current_status.locked = true;
- current_status.value = !current_status.value;
- value_changed = true;
- }
+ {
+ std::lock_guard lock{mutex};
+ bool value_changed = false;
+ const auto new_status = TransformToButton(callback);
+ auto& current_status = controller.button_values[index];
+ current_status.toggle = new_status.toggle;
- // Unlock button ready for next press
- if (!new_status.value && current_status.locked) {
+ // Update button status with current
+ if (!current_status.toggle) {
current_status.locked = false;
+ if (current_status.value != new_status.value) {
+ current_status.value = new_status.value;
+ value_changed = true;
+ }
+ } else {
+ // Toggle button and lock status
+ if (new_status.value && !current_status.locked) {
+ current_status.locked = true;
+ current_status.value = !current_status.value;
+ value_changed = true;
+ }
+
+ // Unlock button ready for next press
+ if (!new_status.value && current_status.locked) {
+ current_status.locked = false;
+ }
}
- }
- if (!value_changed) {
- return;
- }
+ if (!value_changed) {
+ return;
+ }
- if (is_configuring) {
- controller.npad_button_state.raw = NpadButton::None;
- controller.debug_pad_button_state.raw = 0;
- TriggerOnChange(ControllerTriggerType::Button);
- return;
- }
+ if (is_configuring) {
+ controller.npad_button_state.raw = NpadButton::None;
+ controller.debug_pad_button_state.raw = 0;
+ TriggerOnChange(ControllerTriggerType::Button, false);
+ return;
+ }
- switch (index) {
- case Settings::NativeButton::A:
- controller.npad_button_state.a.Assign(current_status.value);
- controller.debug_pad_button_state.a.Assign(current_status.value);
- break;
- case Settings::NativeButton::B:
- controller.npad_button_state.b.Assign(current_status.value);
- controller.debug_pad_button_state.b.Assign(current_status.value);
- break;
- case Settings::NativeButton::X:
- controller.npad_button_state.x.Assign(current_status.value);
- controller.debug_pad_button_state.x.Assign(current_status.value);
- break;
- case Settings::NativeButton::Y:
- controller.npad_button_state.y.Assign(current_status.value);
- controller.debug_pad_button_state.y.Assign(current_status.value);
- break;
- case Settings::NativeButton::LStick:
- controller.npad_button_state.stick_l.Assign(current_status.value);
- break;
- case Settings::NativeButton::RStick:
- controller.npad_button_state.stick_r.Assign(current_status.value);
- break;
- case Settings::NativeButton::L:
- controller.npad_button_state.l.Assign(current_status.value);
- controller.debug_pad_button_state.l.Assign(current_status.value);
- break;
- case Settings::NativeButton::R:
- controller.npad_button_state.r.Assign(current_status.value);
- controller.debug_pad_button_state.r.Assign(current_status.value);
- break;
- case Settings::NativeButton::ZL:
- controller.npad_button_state.zl.Assign(current_status.value);
- controller.debug_pad_button_state.zl.Assign(current_status.value);
- break;
- case Settings::NativeButton::ZR:
- controller.npad_button_state.zr.Assign(current_status.value);
- controller.debug_pad_button_state.zr.Assign(current_status.value);
- break;
- case Settings::NativeButton::Plus:
- controller.npad_button_state.plus.Assign(current_status.value);
- controller.debug_pad_button_state.plus.Assign(current_status.value);
- break;
- case Settings::NativeButton::Minus:
- controller.npad_button_state.minus.Assign(current_status.value);
- controller.debug_pad_button_state.minus.Assign(current_status.value);
- break;
- case Settings::NativeButton::DLeft:
- controller.npad_button_state.left.Assign(current_status.value);
- controller.debug_pad_button_state.d_left.Assign(current_status.value);
- break;
- case Settings::NativeButton::DUp:
- controller.npad_button_state.up.Assign(current_status.value);
- controller.debug_pad_button_state.d_up.Assign(current_status.value);
- break;
- case Settings::NativeButton::DRight:
- controller.npad_button_state.right.Assign(current_status.value);
- controller.debug_pad_button_state.d_right.Assign(current_status.value);
- break;
- case Settings::NativeButton::DDown:
- controller.npad_button_state.down.Assign(current_status.value);
- controller.debug_pad_button_state.d_down.Assign(current_status.value);
- break;
- case Settings::NativeButton::SL:
- controller.npad_button_state.left_sl.Assign(current_status.value);
- controller.npad_button_state.right_sl.Assign(current_status.value);
- break;
- case Settings::NativeButton::SR:
- controller.npad_button_state.left_sr.Assign(current_status.value);
- controller.npad_button_state.right_sr.Assign(current_status.value);
- break;
- case Settings::NativeButton::Home:
- case Settings::NativeButton::Screenshot:
- break;
+ switch (index) {
+ case Settings::NativeButton::A:
+ controller.npad_button_state.a.Assign(current_status.value);
+ controller.debug_pad_button_state.a.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::B:
+ controller.npad_button_state.b.Assign(current_status.value);
+ controller.debug_pad_button_state.b.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::X:
+ controller.npad_button_state.x.Assign(current_status.value);
+ controller.debug_pad_button_state.x.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::Y:
+ controller.npad_button_state.y.Assign(current_status.value);
+ controller.debug_pad_button_state.y.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::LStick:
+ controller.npad_button_state.stick_l.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::RStick:
+ controller.npad_button_state.stick_r.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::L:
+ controller.npad_button_state.l.Assign(current_status.value);
+ controller.debug_pad_button_state.l.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::R:
+ controller.npad_button_state.r.Assign(current_status.value);
+ controller.debug_pad_button_state.r.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::ZL:
+ controller.npad_button_state.zl.Assign(current_status.value);
+ controller.debug_pad_button_state.zl.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::ZR:
+ controller.npad_button_state.zr.Assign(current_status.value);
+ controller.debug_pad_button_state.zr.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::Plus:
+ controller.npad_button_state.plus.Assign(current_status.value);
+ controller.debug_pad_button_state.plus.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::Minus:
+ controller.npad_button_state.minus.Assign(current_status.value);
+ controller.debug_pad_button_state.minus.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::DLeft:
+ controller.npad_button_state.left.Assign(current_status.value);
+ controller.debug_pad_button_state.d_left.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::DUp:
+ controller.npad_button_state.up.Assign(current_status.value);
+ controller.debug_pad_button_state.d_up.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::DRight:
+ controller.npad_button_state.right.Assign(current_status.value);
+ controller.debug_pad_button_state.d_right.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::DDown:
+ controller.npad_button_state.down.Assign(current_status.value);
+ controller.debug_pad_button_state.d_down.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::SL:
+ controller.npad_button_state.left_sl.Assign(current_status.value);
+ controller.npad_button_state.right_sl.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::SR:
+ controller.npad_button_state.left_sr.Assign(current_status.value);
+ controller.npad_button_state.right_sr.Assign(current_status.value);
+ break;
+ case Settings::NativeButton::Home:
+ case Settings::NativeButton::Screenshot:
+ break;
+ }
+ }
+ if (!is_connected) {
+ if (npad_id_type == NpadIdType::Player1 && npad_type != NpadType::Handheld) {
+ Connect();
+ }
+ if (npad_id_type == NpadIdType::Handheld && npad_type == NpadType::Handheld) {
+ Connect();
+ }
}
- TriggerOnChange(ControllerTriggerType::Button);
+ TriggerOnChange(ControllerTriggerType::Button, true);
}
void EmulatedController::SetStick(Input::CallbackStatus callback, std::size_t index) {
@@ -463,7 +472,7 @@ void EmulatedController::SetStick(Input::CallbackStatus callback, std::size_t in
if (is_configuring) {
controller.analog_stick_state.left = {};
controller.analog_stick_state.right = {};
- TriggerOnChange(ControllerTriggerType::Stick);
+ TriggerOnChange(ControllerTriggerType::Stick, false);
return;
}
@@ -489,7 +498,7 @@ void EmulatedController::SetStick(Input::CallbackStatus callback, std::size_t in
break;
}
- TriggerOnChange(ControllerTriggerType::Stick);
+ TriggerOnChange(ControllerTriggerType::Stick, true);
}
void EmulatedController::SetTrigger(Input::CallbackStatus callback, std::size_t index) {
@@ -502,7 +511,7 @@ void EmulatedController::SetTrigger(Input::CallbackStatus callback, std::size_t
if (is_configuring) {
controller.gc_trigger_state.left = 0;
controller.gc_trigger_state.right = 0;
- TriggerOnChange(ControllerTriggerType::Trigger);
+ TriggerOnChange(ControllerTriggerType::Trigger, false);
return;
}
@@ -520,7 +529,7 @@ void EmulatedController::SetTrigger(Input::CallbackStatus callback, std::size_t
break;
}
- TriggerOnChange(ControllerTriggerType::Trigger);
+ TriggerOnChange(ControllerTriggerType::Trigger, true);
}
void EmulatedController::SetMotion(Input::CallbackStatus callback, std::size_t index) {
@@ -546,7 +555,7 @@ void EmulatedController::SetMotion(Input::CallbackStatus callback, std::size_t i
emulated.UpdateOrientation(raw_status.delta_timestamp);
if (is_configuring) {
- TriggerOnChange(ControllerTriggerType::Motion);
+ TriggerOnChange(ControllerTriggerType::Motion, false);
return;
}
@@ -557,7 +566,7 @@ void EmulatedController::SetMotion(Input::CallbackStatus callback, std::size_t i
motion.orientation = emulated.GetOrientation();
motion.is_at_rest = emulated.IsMoving(motion_sensitivity);
- TriggerOnChange(ControllerTriggerType::Motion);
+ TriggerOnChange(ControllerTriggerType::Motion, true);
}
void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t index) {
@@ -568,7 +577,7 @@ void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t
controller.battery_values[index] = TransformToBattery(callback);
if (is_configuring) {
- TriggerOnChange(ControllerTriggerType::Battery);
+ TriggerOnChange(ControllerTriggerType::Battery, false);
return;
}
@@ -593,6 +602,7 @@ void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t
case Input::BatteryLevel::Empty:
battery_level = 0;
break;
+ case Input::BatteryLevel::None:
case Input::BatteryLevel::Full:
default:
is_powered = true;
@@ -623,7 +633,7 @@ void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t
};
break;
}
- TriggerOnChange(ControllerTriggerType::Battery);
+ TriggerOnChange(ControllerTriggerType::Battery, true);
}
bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue vibration) {
@@ -677,7 +687,7 @@ void EmulatedController::Connect() {
std::lock_guard lock{mutex};
if (is_configuring) {
temporary_is_connected = true;
- TriggerOnChange(ControllerTriggerType::Connected);
+ TriggerOnChange(ControllerTriggerType::Connected,false);
return;
}
@@ -687,7 +697,7 @@ void EmulatedController::Connect() {
is_connected = true;
}
LOG_ERROR(Service_HID, "Connected controller {}", NpadIdTypeToIndex(npad_id_type));
- TriggerOnChange(ControllerTriggerType::Connected);
+ TriggerOnChange(ControllerTriggerType::Connected,true);
}
void EmulatedController::Disconnect() {
@@ -697,7 +707,7 @@ void EmulatedController::Disconnect() {
temporary_is_connected = false;
LOG_ERROR(Service_HID, "Disconnected temporal controller {}",
NpadIdTypeToIndex(npad_id_type));
- TriggerOnChange(ControllerTriggerType::Disconnected);
+ TriggerOnChange(ControllerTriggerType::Disconnected,false);
return;
}
@@ -707,7 +717,7 @@ void EmulatedController::Disconnect() {
is_connected = false;
}
LOG_ERROR(Service_HID, "Disconnected controller {}", NpadIdTypeToIndex(npad_id_type));
- TriggerOnChange(ControllerTriggerType::Disconnected);
+ TriggerOnChange(ControllerTriggerType::Disconnected,true);
}
bool EmulatedController::IsConnected(bool temporary) const {
@@ -741,7 +751,7 @@ void EmulatedController::SetNpadType(NpadType npad_type_) {
return;
}
temporary_npad_type = npad_type_;
- TriggerOnChange(ControllerTriggerType::Type);
+ TriggerOnChange(ControllerTriggerType::Type,false);
return;
}
@@ -754,7 +764,7 @@ void EmulatedController::SetNpadType(NpadType npad_type_) {
}
npad_type = npad_type_;
}
- TriggerOnChange(ControllerTriggerType::Type);
+ TriggerOnChange(ControllerTriggerType::Type,true);
}
LedPattern EmulatedController::GetLedPattern() const {
@@ -844,9 +854,12 @@ BatteryLevelState EmulatedController::GetBattery() const {
return controller.battery_state;
}
-void EmulatedController::TriggerOnChange(ControllerTriggerType type) {
+void EmulatedController::TriggerOnChange(ControllerTriggerType type, bool is_service_update) {
for (const std::pair poller_pair : callback_list) {
const ControllerUpdateCallback& poller = poller_pair.second;
+ if (!is_service_update && poller.is_service) {
+ continue;
+ }
if (poller.on_change) {
poller.on_change(type);
}
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index 6a6dc1892..3a0b20cf8 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -113,6 +113,7 @@ enum class ControllerTriggerType {
struct ControllerUpdateCallback {
std::function on_change;
+ bool is_service;
};
class EmulatedController {
@@ -325,9 +326,10 @@ private:
/**
* Triggers a callback that something has changed on the controller status
- * @param Input type of the event to trigger
+ * @param type: Input type of the event to trigger
+ * @param is_service_update: indicates if this event should be sended to only services
*/
- void TriggerOnChange(ControllerTriggerType type);
+ void TriggerOnChange(ControllerTriggerType type, bool is_service_update);
NpadIdType npad_id_type;
NpadType npad_type{NpadType::None};
diff --git a/src/core/hid/input_converter.cpp b/src/core/hid/input_converter.cpp
index 5834622e9..128a48ec9 100644
--- a/src/core/hid/input_converter.cpp
+++ b/src/core/hid/input_converter.cpp
@@ -10,7 +10,7 @@
namespace Core::HID {
Input::BatteryStatus TransformToBattery(const Input::CallbackStatus& callback) {
- Input::BatteryStatus battery{};
+ Input::BatteryStatus battery{Input::BatteryStatus::None};
switch (callback.type) {
case Input::InputType::Analog:
case Input::InputType::Trigger: {
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 144abab65..6b9d6d11c 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -104,7 +104,10 @@ Controller_NPad::Controller_NPad(Core::System& system_,
controller.vibration[0].latest_vibration_value = DEFAULT_VIBRATION_VALUE;
controller.vibration[1].latest_vibration_value = DEFAULT_VIBRATION_VALUE;
Core::HID::ControllerUpdateCallback engine_callback{
- [this, i](Core::HID::ControllerTriggerType type) { ControllerUpdate(type, i); }};
+ .on_change = [this,
+ i](Core::HID::ControllerTriggerType type) { ControllerUpdate(type, i); },
+ .is_service = true,
+ };
controller.callback_key = controller.device->SetCallback(engine_callback);
}
}
@@ -283,7 +286,6 @@ void Controller_NPad::OnInit() {
// Prefill controller buffers
for (auto& controller : controller_data) {
- NPadGenericState dummy_pad_state{};
auto& npad = controller.shared_memory_entry;
for (std::size_t i = 0; i < 19; ++i) {
WriteEmptyEntry(npad);
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp
index 4a56abb99..4fb6ab5af 100644
--- a/src/input_common/drivers/gc_adapter.cpp
+++ b/src/input_common/drivers/gc_adapter.cpp
@@ -150,7 +150,10 @@ void GCAdapter::UpdatePadType(std::size_t port, ControllerTypes pad_type) {
return;
}
// Device changed reset device and set new type
- pads[port] = {};
+ pads[port].axis_origin = {};
+ pads[port].reset_origin_counter = {};
+ pads[port].enable_vibration = {};
+ pads[port].rumble_amplitude = {};
pads[port].type = pad_type;
}
@@ -396,12 +399,11 @@ std::vector GCAdapter::GetInputDevices() const {
if (!DeviceConnected(port)) {
continue;
}
- const std::string name = fmt::format("Gamecube Controller {}", port + 1);
- devices.emplace_back(Common::ParamPackage{
- {"engine", "gcpad"},
- {"display", std::move(name)},
- {"port", std::to_string(port)},
- });
+ Common::ParamPackage identifier{};
+ identifier.Set("engine", GetEngineName());
+ identifier.Set("display", fmt::format("Gamecube Controller {}", port + 1));
+ identifier.Set("port", static_cast(port));
+ devices.emplace_back(identifier);
}
return devices;
}
@@ -431,7 +433,8 @@ ButtonMapping GCAdapter::GetButtonMappingForDevice(const Common::ParamPackage& p
ButtonMapping mapping{};
for (const auto& [switch_button, gcadapter_button] : switch_to_gcadapter_button) {
- Common::ParamPackage button_params({{"engine", "gcpad"}});
+ Common::ParamPackage button_params{};
+ button_params.Set("engine", GetEngineName());
button_params.Set("port", params.Get("port", 0));
button_params.Set("button", static_cast(gcadapter_button));
mapping.insert_or_assign(switch_button, std::move(button_params));
@@ -444,7 +447,8 @@ ButtonMapping GCAdapter::GetButtonMappingForDevice(const Common::ParamPackage& p
{Settings::NativeButton::ZR, PadButton::TriggerR, PadAxes::TriggerRight},
};
for (const auto& [switch_button, gcadapter_buton, gcadapter_axis] : switch_to_gcadapter_axis) {
- Common::ParamPackage button_params({{"engine", "gcpad"}});
+ Common::ParamPackage button_params{};
+ button_params.Set("engine", GetEngineName());
button_params.Set("port", params.Get("port", 0));
button_params.Set("button", static_cast(gcadapter_buton));
button_params.Set("axis", static_cast(gcadapter_axis));
@@ -463,13 +467,13 @@ AnalogMapping GCAdapter::GetAnalogMappingForDevice(const Common::ParamPackage& p
AnalogMapping mapping = {};
Common::ParamPackage left_analog_params;
- left_analog_params.Set("engine", "gcpad");
+ left_analog_params.Set("engine", GetEngineName());
left_analog_params.Set("port", params.Get("port", 0));
left_analog_params.Set("axis_x", static_cast(PadAxes::StickX));
left_analog_params.Set("axis_y", static_cast(PadAxes::StickY));
mapping.insert_or_assign(Settings::NativeAnalog::LStick, std::move(left_analog_params));
Common::ParamPackage right_analog_params;
- right_analog_params.Set("engine", "gcpad");
+ right_analog_params.Set("engine", GetEngineName());
right_analog_params.Set("port", params.Get("port", 0));
right_analog_params.Set("axis_x", static_cast(PadAxes::SubstickX));
right_analog_params.Set("axis_y", static_cast(PadAxes::SubstickY));
@@ -477,9 +481,56 @@ AnalogMapping GCAdapter::GetAnalogMappingForDevice(const Common::ParamPackage& p
return mapping;
}
+std::string GCAdapter::GetUIButtonName(const Common::ParamPackage& params) const {
+ PadButton button = static_cast(params.Get("button", 0));
+ switch (button) {
+ case PadButton::ButtonLeft:
+ return "left";
+ break;
+ case PadButton::ButtonRight:
+ return "right";
+ break;
+ case PadButton::ButtonDown:
+ return "down";
+ break;
+ case PadButton::ButtonUp:
+ return "up";
+ break;
+ case PadButton::TriggerZ:
+ return "Z";
+ break;
+ case PadButton::TriggerR:
+ return "R";
+ break;
+ case PadButton::TriggerL:
+ return "L";
+ break;
+ case PadButton::ButtonA:
+ return "A";
+ break;
+ case PadButton::ButtonB:
+ return "B";
+ break;
+ case PadButton::ButtonX:
+ return "X";
+ break;
+ case PadButton::ButtonY:
+ return "Y";
+ break;
+ case PadButton::ButtonStart:
+ return "start";
+ break;
+ default:
+ return "Unkown GC";
+ }
+}
+
std::string GCAdapter::GetUIName(const Common::ParamPackage& params) const {
if (params.Has("button")) {
- return fmt::format("Button {}", params.Get("button", 0));
+ return fmt::format("Button {}", GetUIButtonName(params));
+ }
+ if (params.Has("axis")) {
+ return fmt::format("Axis {}", params.Get("axis",0));
}
return "Bad GC Adapter";
diff --git a/src/input_common/drivers/gc_adapter.h b/src/input_common/drivers/gc_adapter.h
index dd0e4aa1d..b82e4803d 100644
--- a/src/input_common/drivers/gc_adapter.h
+++ b/src/input_common/drivers/gc_adapter.h
@@ -105,8 +105,12 @@ private:
void Reset();
void UpdateVibrations();
- // Updates vibration state of all controllers
+
+ /// Updates vibration state of all controllers
void SendVibrations();
+
+ std::string GetUIButtonName(const Common::ParamPackage& params) const;
+
std::unique_ptr usb_adapter_handle;
std::array pads;
diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp
index b00a4b8d9..85a781a30 100644
--- a/src/input_common/drivers/keyboard.cpp
+++ b/src/input_common/drivers/keyboard.cpp
@@ -26,7 +26,7 @@ void Keyboard::ReleaseAllKeys() {
std::vector Keyboard::GetInputDevices() const {
std::vector devices;
devices.emplace_back(Common::ParamPackage{
- {"engine", "keyboard"},
+ {"engine", GetEngineName()},
{"display", "Keyboard Only"},
});
return devices;
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index f7f03c5f2..cee2d965f 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -305,6 +305,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
if (joystick_map.find(guid) == joystick_map.end()) {
auto joystick = std::make_shared(guid, 0, sdl_joystick, sdl_gamecontroller);
PreSetController(joystick->GetPadIdentifier());
+ SetBattery(joystick->GetPadIdentifier(), joystick->GetBatteryLevel());
joystick_map[guid].emplace_back(std::move(joystick));
return;
}
@@ -322,6 +323,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
const int port = static_cast(joystick_guid_list.size());
auto joystick = std::make_shared(guid, port, sdl_joystick, sdl_gamecontroller);
PreSetController(joystick->GetPadIdentifier());
+ SetBattery(joystick->GetPadIdentifier(), joystick->GetBatteryLevel());
joystick_guid_list.emplace_back(std::move(joystick));
}
@@ -472,7 +474,7 @@ std::vector SDLDriver::GetInputDevices() const {
const std::string name =
fmt::format("{} {}", joystick->GetControllerName(), joystick->GetPort());
devices.emplace_back(Common::ParamPackage{
- {"engine", "sdl"},
+ {"engine", GetEngineName()},
{"display", std::move(name)},
{"guid", joystick->GetGUID()},
{"port", std::to_string(joystick->GetPort())},
@@ -495,7 +497,7 @@ std::vector SDLDriver::GetInputDevices() const {
const std::string name =
fmt::format("{} {}", "Nintendo Dual Joy-Con", joystick->GetPort());
devices.emplace_back(Common::ParamPackage{
- {"engine", "sdl"},
+ {"engine", GetEngineName()},
{"display", std::move(name)},
{"guid", joystick->GetGUID()},
{"guid2", joystick2->GetGUID()},
@@ -527,7 +529,8 @@ Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier,
}
Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid,
s32 axis, float value) const {
- Common::ParamPackage params({{"engine", "sdl"}});
+ Common::ParamPackage params{};
+ params.Set("engine", GetEngineName());
params.Set("port", port);
params.Set("guid", std::move(guid));
params.Set("axis", axis);
@@ -538,7 +541,8 @@ Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::
Common::ParamPackage SDLDriver::BuildButtonParamPackageForButton(int port, std::string guid,
s32 button) const {
- Common::ParamPackage params({{"engine", "sdl"}});
+ Common::ParamPackage params{};
+ params.Set("engine", GetEngineName());
params.Set("port", port);
params.Set("guid", std::move(guid));
params.Set("button", button);
@@ -547,8 +551,8 @@ Common::ParamPackage SDLDriver::BuildButtonParamPackageForButton(int port, std::
Common::ParamPackage SDLDriver::BuildHatParamPackageForButton(int port, std::string guid, s32 hat,
u8 value) const {
- Common::ParamPackage params({{"engine", "sdl"}});
-
+ Common::ParamPackage params{};
+ params.Set("engine", GetEngineName());
params.Set("port", port);
params.Set("guid", std::move(guid));
params.Set("hat", hat);
@@ -557,7 +561,9 @@ Common::ParamPackage SDLDriver::BuildHatParamPackageForButton(int port, std::str
}
Common::ParamPackage SDLDriver::BuildMotionParam(int port, std::string guid) const {
- Common::ParamPackage params({{"engine", "sdl"}, {"motion", "0"}});
+ Common::ParamPackage params{};
+ params.Set("engine", GetEngineName());
+ params.Set("motion", 0);
params.Set("port", port);
params.Set("guid", std::move(guid));
return params;
@@ -583,7 +589,7 @@ Common::ParamPackage SDLDriver::BuildParamPackageForAnalog(PadIdentifier identif
int axis_y, float offset_x,
float offset_y) const {
Common::ParamPackage params;
- params.Set("engine", "sdl");
+ params.Set("engine", GetEngineName());
params.Set("port", static_cast(identifier.port));
params.Set("guid", identifier.guid.Format());
params.Set("axis_x", axis_x);
diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cpp
index 5e2101b27..7e7a1d58f 100644
--- a/src/input_common/drivers/tas_input.cpp
+++ b/src/input_common/drivers/tas_input.cpp
@@ -127,7 +127,7 @@ void Tas::WriteTasFile(std::u8string file_name) {
std::string output_text;
for (size_t frame = 0; frame < record_commands.size(); frame++) {
const TASCommand& line = record_commands[frame];
- output_text += fmt::format("{} {} {} {} {}\n", frame, WriteCommandButtons(line.buttons),
+ output_text += fmt::format("{} {} {} {}\n", frame, WriteCommandButtons(line.buttons),
WriteCommandAxis(line.l_axis), WriteCommandAxis(line.r_axis));
}
const auto bytes_written = Common::FS::WriteStringToFile(
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp
index 3b79b6076..93f7eddc9 100644
--- a/src/yuzu/configuration/configure_input_player_widget.cpp
+++ b/src/yuzu/configuration/configure_input_player_widget.cpp
@@ -27,7 +27,9 @@ void PlayerControlPreview::SetController(Core::HID::EmulatedController* controll
is_controller_set = true;
controller = controller_;
Core::HID::ControllerUpdateCallback engine_callback{
- [this](Core::HID::ControllerTriggerType type) { ControllerUpdate(type); }};
+ .on_change = [this](Core::HID::ControllerTriggerType type) { ControllerUpdate(type); },
+ .is_service = false,
+ };
callback_key = controller->SetCallback(engine_callback);
ControllerUpdate(Core::HID::ControllerTriggerType::All);
}
@@ -810,7 +812,7 @@ void PlayerControlPreview::DrawProController(QPainter& p, const QPointF center)
DrawSymbol(p, center + QPoint(29, -56), Symbol::House, 3.9f);
// Draw battery
- DrawBattery(p, center + QPoint(-30, -165), battery_values[0]);
+ DrawBattery(p, center + QPoint(-30, -160), battery_values[0]);
}
void PlayerControlPreview::DrawGCController(QPainter& p, const QPointF center) {
@@ -2655,6 +2657,9 @@ void PlayerControlPreview::DrawTriggerButton(QPainter& p, const QPointF center,
}
void PlayerControlPreview::DrawBattery(QPainter& p, QPointF center, Input::BatteryLevel battery) {
+ if (battery == Input::BatteryLevel::None) {
+ return;
+ }
p.setPen(colors.outline);
p.setBrush(colors.transparent);
p.drawRect(center.x(), center.y(), 56, 20);
@@ -2669,6 +2674,7 @@ void PlayerControlPreview::DrawBattery(QPainter& p, QPointF center, Input::Batte
p.drawRect(center.x() + 42, center.y(), 14, 20);
p.drawRect(center.x() + 28, center.y(), 14, 20);
p.drawRect(center.x() + 14, center.y(), 14, 20);
+ p.drawRect(center.x(), center.y(), 14, 20);
break;
case Input::BatteryLevel::Medium:
p.drawRect(center.x() + 28, center.y(), 14, 20);
@@ -2685,6 +2691,8 @@ void PlayerControlPreview::DrawBattery(QPainter& p, QPointF center, Input::Batte
case Input::BatteryLevel::Empty:
p.drawRect(center.x(), center.y(), 5, 20);
break;
+ default:
+ break;
}
}
--
cgit v1.2.3
From af55dd193533be577d0a3d01f93a4a3a2c27cd5d Mon Sep 17 00:00:00 2001
From: german77
Date: Wed, 20 Oct 2021 17:53:14 -0500
Subject: configuration: Migrate controller settings to emulated controller
---
src/core/hid/emulated_controller.cpp | 1 -
src/core/hid/emulated_controller.h | 2 +-
src/core/hid/hid_core.cpp | 21 +++
src/core/hid/hid_core.h | 10 +-
.../hle/service/am/applets/applet_controller.cpp | 14 +-
src/input_common/main.cpp | 10 ++
src/yuzu/applets/qt_controller.cpp | 143 +++++++++------------
src/yuzu/applets/qt_controller.h | 14 +-
src/yuzu/applets/qt_software_keyboard.cpp | 21 +--
src/yuzu/configuration/configure_input.cpp | 17 ++-
.../configure_input_player_widget.cpp | 4 +-
src/yuzu/main.cpp | 11 +-
12 files changed, 141 insertions(+), 127 deletions(-)
(limited to 'src/yuzu/configuration')
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 7b0c4a49b..662260327 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -91,7 +91,6 @@ void EmulatedController::ReloadFromSettings() {
}
void EmulatedController::ReloadInput() {
- // LOG_ERROR(Service_HID, "reload config {}", NpadIdTypeToIndex(npad_id_type));
// If you load any device here add the equivalent to the UnloadInput() function
const auto left_side = button_params[Settings::NativeButton::ZL];
const auto right_side = button_params[Settings::NativeButton::ZR];
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index 3a0b20cf8..f3ee70726 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -329,7 +329,7 @@ private:
* @param type: Input type of the event to trigger
* @param is_service_update: indicates if this event should be sended to only services
*/
- void TriggerOnChange(ControllerTriggerType type, bool is_service_update);
+ void TriggerOnChange(ControllerTriggerType type, bool is_service_update);
NpadIdType npad_id_type;
NpadType npad_type{NpadType::None};
diff --git a/src/core/hid/hid_core.cpp b/src/core/hid/hid_core.cpp
index ee76db110..bd17081bd 100644
--- a/src/core/hid/hid_core.cpp
+++ b/src/core/hid/hid_core.cpp
@@ -111,6 +111,27 @@ NpadStyleTag HIDCore::GetSupportedStyleTag() const {
return supported_style_tag;
}
+s8 HIDCore::GetPlayerCount() const {
+ s8 active_players = 0;
+ for (std::size_t player_index = 0; player_index < 8; player_index++) {
+ const auto* controller = GetEmulatedControllerByIndex(player_index);
+ if (controller->IsConnected()) {
+ active_players++;
+ }
+ }
+ return active_players;
+}
+
+NpadIdType HIDCore::GetFirstNpadId() const {
+ for (std::size_t player_index = 0; player_index < 10; player_index++) {
+ const auto* controller = GetEmulatedControllerByIndex(player_index);
+ if (controller->IsConnected()) {
+ return controller->GetNpadIdType();
+ }
+ }
+ return NpadIdType::Player1;
+}
+
void HIDCore::ReloadInputDevices() {
player_1->ReloadFromSettings();
player_2->ReloadFromSettings();
diff --git a/src/core/hid/hid_core.h b/src/core/hid/hid_core.h
index f11f48b61..196466a72 100644
--- a/src/core/hid/hid_core.h
+++ b/src/core/hid/hid_core.h
@@ -35,10 +35,16 @@ public:
void SetSupportedStyleTag(NpadStyleTag style_tag);
NpadStyleTag GetSupportedStyleTag() const;
- // Reloads all input devices from settings
+ /// Counts the connected players from P1-P8
+ s8 GetPlayerCount() const;
+
+ /// Returns the first connected npad id
+ NpadIdType GetFirstNpadId() const;
+
+ /// Reloads all input devices from settings
void ReloadInputDevices();
- // Removes all callbacks from input common
+ /// Removes all callbacks from input common
void UnloadInputDevices();
private:
diff --git a/src/core/hle/service/am/applets/applet_controller.cpp b/src/core/hle/service/am/applets/applet_controller.cpp
index c1b6cd126..658265a00 100644
--- a/src/core/hle/service/am/applets/applet_controller.cpp
+++ b/src/core/hle/service/am/applets/applet_controller.cpp
@@ -243,19 +243,11 @@ void Controller::Execute() {
void Controller::ConfigurationComplete() {
ControllerSupportResultInfo result_info{};
- const auto& players = Settings::values.players.GetValue();
-
// If enable_single_mode is enabled, player_count is 1 regardless of any other parameters.
// Otherwise, only count connected players from P1-P8.
- result_info.player_count =
- is_single_mode
- ? 1
- : static_cast(std::count_if(players.begin(), players.end() - 2,
- [](const auto& player) { return player.connected; }));
-
- result_info.selected_id = HID::Controller_NPad::IndexToNPad(std::distance(
- players.begin(), std::find_if(players.begin(), players.end(),
- [](const auto& player) { return player.connected; })));
+ result_info.player_count = is_single_mode ? 1 : system.HIDCore().GetPlayerCount();
+
+ result_info.selected_id = static_cast(system.HIDCore().GetFirstNpadId());
result_info.result = 0;
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index 7807dd38f..b048783c9 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -32,12 +32,17 @@ struct InputSubsystem::Impl {
keyboard = std::make_shared("keyboard");
keyboard->SetMappingCallback(mapping_callback);
keyboard_factory = std::make_shared(keyboard);
+ keyboard_output_factory = std::make_shared(keyboard);
Input::RegisterFactory(keyboard->GetEngineName(), keyboard_factory);
+ Input::RegisterFactory(keyboard->GetEngineName(),
+ keyboard_output_factory);
mouse = std::make_shared("mouse");
mouse->SetMappingCallback(mapping_callback);
mouse_factory = std::make_shared(mouse);
+ mouse_output_factory = std::make_shared(mouse);
Input::RegisterFactory(mouse->GetEngineName(), mouse_factory);
+ Input::RegisterFactory