2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

core: hid: Fix native mouse mappings

This commit is contained in:
Narr the Reg 2023-02-21 12:41:34 -06:00
parent 8f3e2a1b48
commit 9477181d09
5 changed files with 62 additions and 63 deletions

View file

@ -19,52 +19,53 @@ void EmulatedDevices::ReloadFromSettings() {
void EmulatedDevices::ReloadInput() { void EmulatedDevices::ReloadInput() {
// If you load any device here add the equivalent to the UnloadInput() function // If you load any device here add the equivalent to the UnloadInput() function
// Native Mouse is mapped on port 1, pad 0
const Common::ParamPackage mouse_params{"engine:mouse,port:1,pad:0"};
// Keyboard keys is mapped on port 1, pad 0 for normal keys, pad 1 for moddifier keys
const Common::ParamPackage keyboard_params{"engine:keyboard,port:1"};
std::size_t key_index = 0; std::size_t key_index = 0;
for (auto& mouse_device : mouse_button_devices) { for (auto& mouse_device : mouse_button_devices) {
Common::ParamPackage mouse_params; Common::ParamPackage mouse_button_params = mouse_params;
mouse_params.Set("engine", "mouse"); mouse_button_params.Set("button", static_cast<int>(key_index));
mouse_params.Set("button", static_cast<int>(key_index)); mouse_device = Common::Input::CreateInputDevice(mouse_button_params);
mouse_device = Common::Input::CreateInputDevice(mouse_params);
key_index++; key_index++;
} }
mouse_stick_device = Common::ParamPackage mouse_position_params = mouse_params;
Common::Input::CreateInputDeviceFromString("engine:mouse,axis_x:0,axis_y:1"); mouse_position_params.Set("axis_x", 0);
mouse_position_params.Set("axis_y", 1);
mouse_position_params.Set("deadzone", 0.0f);
mouse_position_params.Set("range", 1.0f);
mouse_position_params.Set("threshold", 0.0f);
mouse_stick_device = Common::Input::CreateInputDevice(mouse_position_params);
// First two axis are reserved for mouse position // First two axis are reserved for mouse position
key_index = 2; key_index = 2;
for (auto& mouse_device : mouse_analog_devices) { for (auto& mouse_device : mouse_wheel_devices) {
// Mouse axis are only mapped on port 1, pad 0 Common::ParamPackage mouse_wheel_params = mouse_params;
Common::ParamPackage mouse_params; mouse_wheel_params.Set("axis", static_cast<int>(key_index));
mouse_params.Set("engine", "mouse"); mouse_device = Common::Input::CreateInputDevice(mouse_wheel_params);
mouse_params.Set("axis", static_cast<int>(key_index));
mouse_params.Set("port", 1);
mouse_params.Set("pad", 0);
mouse_device = Common::Input::CreateInputDevice(mouse_params);
key_index++; key_index++;
} }
key_index = 0; key_index = 0;
for (auto& keyboard_device : keyboard_devices) { for (auto& keyboard_device : keyboard_devices) {
// Keyboard keys are only mapped on port 1, pad 0 Common::ParamPackage keyboard_key_params = keyboard_params;
Common::ParamPackage keyboard_params; keyboard_key_params.Set("button", static_cast<int>(key_index));
keyboard_params.Set("engine", "keyboard"); keyboard_key_params.Set("pad", 0);
keyboard_params.Set("button", static_cast<int>(key_index)); keyboard_device = Common::Input::CreateInputDevice(keyboard_key_params);
keyboard_params.Set("port", 1);
keyboard_params.Set("pad", 0);
keyboard_device = Common::Input::CreateInputDevice(keyboard_params);
key_index++; key_index++;
} }
key_index = 0; key_index = 0;
for (auto& keyboard_device : keyboard_modifier_devices) { for (auto& keyboard_device : keyboard_modifier_devices) {
// Keyboard moddifiers are only mapped on port 1, pad 1 Common::ParamPackage keyboard_moddifier_params = keyboard_params;
Common::ParamPackage keyboard_params; keyboard_moddifier_params.Set("button", static_cast<int>(key_index));
keyboard_params.Set("engine", "keyboard"); keyboard_moddifier_params.Set("pad", 1);
keyboard_params.Set("button", static_cast<int>(key_index)); keyboard_device = Common::Input::CreateInputDevice(keyboard_moddifier_params);
keyboard_params.Set("port", 1);
keyboard_params.Set("pad", 1);
keyboard_device = Common::Input::CreateInputDevice(keyboard_params);
key_index++; key_index++;
} }
@ -80,14 +81,14 @@ void EmulatedDevices::ReloadInput() {
}); });
} }
for (std::size_t index = 0; index < mouse_analog_devices.size(); ++index) { for (std::size_t index = 0; index < mouse_wheel_devices.size(); ++index) {
if (!mouse_analog_devices[index]) { if (!mouse_wheel_devices[index]) {
continue; continue;
} }
mouse_analog_devices[index]->SetCallback({ mouse_wheel_devices[index]->SetCallback({
.on_change = .on_change =
[this, index](const Common::Input::CallbackStatus& callback) { [this, index](const Common::Input::CallbackStatus& callback) {
SetMouseAnalog(callback, index); SetMouseWheel(callback, index);
}, },
}); });
} }
@ -95,7 +96,9 @@ void EmulatedDevices::ReloadInput() {
if (mouse_stick_device) { if (mouse_stick_device) {
mouse_stick_device->SetCallback({ mouse_stick_device->SetCallback({
.on_change = .on_change =
[this](const Common::Input::CallbackStatus& callback) { SetMouseStick(callback); }, [this](const Common::Input::CallbackStatus& callback) {
SetMousePosition(callback);
},
}); });
} }
@ -128,7 +131,7 @@ void EmulatedDevices::UnloadInput() {
for (auto& button : mouse_button_devices) { for (auto& button : mouse_button_devices) {
button.reset(); button.reset();
} }
for (auto& analog : mouse_analog_devices) { for (auto& analog : mouse_wheel_devices) {
analog.reset(); analog.reset();
} }
mouse_stick_device.reset(); mouse_stick_device.reset();
@ -362,18 +365,18 @@ void EmulatedDevices::SetMouseButton(const Common::Input::CallbackStatus& callba
TriggerOnChange(DeviceTriggerType::Mouse); TriggerOnChange(DeviceTriggerType::Mouse);
} }
void EmulatedDevices::SetMouseAnalog(const Common::Input::CallbackStatus& callback, void EmulatedDevices::SetMouseWheel(const Common::Input::CallbackStatus& callback,
std::size_t index) { std::size_t index) {
if (index >= device_status.mouse_analog_values.size()) { if (index >= device_status.mouse_wheel_values.size()) {
return; return;
} }
std::unique_lock lock{mutex}; std::unique_lock lock{mutex};
const auto analog_value = TransformToAnalog(callback); const auto analog_value = TransformToAnalog(callback);
device_status.mouse_analog_values[index] = analog_value; device_status.mouse_wheel_values[index] = analog_value;
if (is_configuring) { if (is_configuring) {
device_status.mouse_position_state = {}; device_status.mouse_wheel_state = {};
lock.unlock(); lock.unlock();
TriggerOnChange(DeviceTriggerType::Mouse); TriggerOnChange(DeviceTriggerType::Mouse);
return; return;
@ -392,7 +395,7 @@ void EmulatedDevices::SetMouseAnalog(const Common::Input::CallbackStatus& callba
TriggerOnChange(DeviceTriggerType::Mouse); TriggerOnChange(DeviceTriggerType::Mouse);
} }
void EmulatedDevices::SetMouseStick(const Common::Input::CallbackStatus& callback) { void EmulatedDevices::SetMousePosition(const Common::Input::CallbackStatus& callback) {
std::unique_lock lock{mutex}; std::unique_lock lock{mutex};
const auto touch_value = TransformToTouch(callback); const auto touch_value = TransformToTouch(callback);

View file

@ -23,7 +23,7 @@ using KeyboardModifierDevices = std::array<std::unique_ptr<Common::Input::InputD
Settings::NativeKeyboard::NumKeyboardMods>; Settings::NativeKeyboard::NumKeyboardMods>;
using MouseButtonDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, using MouseButtonDevices = std::array<std::unique_ptr<Common::Input::InputDevice>,
Settings::NativeMouseButton::NumMouseButtons>; Settings::NativeMouseButton::NumMouseButtons>;
using MouseAnalogDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, using MouseWheelDevices = std::array<std::unique_ptr<Common::Input::InputDevice>,
Settings::NativeMouseWheel::NumMouseWheels>; Settings::NativeMouseWheel::NumMouseWheels>;
using MouseStickDevice = std::unique_ptr<Common::Input::InputDevice>; using MouseStickDevice = std::unique_ptr<Common::Input::InputDevice>;
@ -36,7 +36,7 @@ using KeyboardModifierValues =
std::array<Common::Input::ButtonStatus, Settings::NativeKeyboard::NumKeyboardMods>; std::array<Common::Input::ButtonStatus, Settings::NativeKeyboard::NumKeyboardMods>;
using MouseButtonValues = using MouseButtonValues =
std::array<Common::Input::ButtonStatus, Settings::NativeMouseButton::NumMouseButtons>; std::array<Common::Input::ButtonStatus, Settings::NativeMouseButton::NumMouseButtons>;
using MouseAnalogValues = using MouseWheelValues =
std::array<Common::Input::AnalogStatus, Settings::NativeMouseWheel::NumMouseWheels>; std::array<Common::Input::AnalogStatus, Settings::NativeMouseWheel::NumMouseWheels>;
using MouseStickValue = Common::Input::TouchStatus; using MouseStickValue = Common::Input::TouchStatus;
@ -50,7 +50,7 @@ struct DeviceStatus {
KeyboardValues keyboard_values{}; KeyboardValues keyboard_values{};
KeyboardModifierValues keyboard_moddifier_values{}; KeyboardModifierValues keyboard_moddifier_values{};
MouseButtonValues mouse_button_values{}; MouseButtonValues mouse_button_values{};
MouseAnalogValues mouse_analog_values{}; MouseWheelValues mouse_wheel_values{};
MouseStickValue mouse_stick_value{}; MouseStickValue mouse_stick_value{};
// Data for HID serices // Data for HID serices
@ -111,15 +111,6 @@ public:
/// Reverts any mapped changes made that weren't saved /// Reverts any mapped changes made that weren't saved
void RestoreConfig(); void RestoreConfig();
// Returns the current mapped ring device
Common::ParamPackage GetRingParam() const;
/**
* Updates the current mapped ring device
* @param param ParamPackage with ring sensor data to be mapped
*/
void SetRingParam(Common::ParamPackage param);
/// Returns the latest status of button input from the keyboard with parameters /// Returns the latest status of button input from the keyboard with parameters
KeyboardValues GetKeyboardValues() const; KeyboardValues GetKeyboardValues() const;
@ -187,19 +178,13 @@ private:
* @param callback A CallbackStatus containing the wheel status * @param callback A CallbackStatus containing the wheel status
* @param index wheel ID to be updated * @param index wheel ID to be updated
*/ */
void SetMouseAnalog(const Common::Input::CallbackStatus& callback, std::size_t index); void SetMouseWheel(const Common::Input::CallbackStatus& callback, std::size_t index);
/** /**
* Updates the mouse position status of the mouse device * Updates the mouse position status of the mouse device
* @param callback A CallbackStatus containing the position status * @param callback A CallbackStatus containing the position status
*/ */
void SetMouseStick(const Common::Input::CallbackStatus& callback); void SetMousePosition(const Common::Input::CallbackStatus& callback);
/**
* Updates the ring analog sensor status of the ring controller
* @param callback A CallbackStatus containing the force status
*/
void SetRingAnalog(const Common::Input::CallbackStatus& callback);
/** /**
* Triggers a callback that something has changed on the device status * Triggers a callback that something has changed on the device status
@ -212,7 +197,7 @@ private:
KeyboardDevices keyboard_devices; KeyboardDevices keyboard_devices;
KeyboardModifierDevices keyboard_modifier_devices; KeyboardModifierDevices keyboard_modifier_devices;
MouseButtonDevices mouse_button_devices; MouseButtonDevices mouse_button_devices;
MouseAnalogDevices mouse_analog_devices; MouseWheelDevices mouse_wheel_devices;
MouseStickDevice mouse_stick_device; MouseStickDevice mouse_stick_device;
mutable std::mutex mutex; mutable std::mutex mutex;

View file

@ -65,6 +65,11 @@ void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
} }
void Controller_Gesture::ReadTouchInput() { void Controller_Gesture::ReadTouchInput() {
if (!Settings::values.touchscreen.enabled) {
fingers = {};
return;
}
const auto touch_status = console->GetTouch(); const auto touch_status = console->GetTouch();
for (std::size_t id = 0; id < fingers.size(); ++id) { for (std::size_t id = 0; id < fingers.size(); ++id) {
fingers[id] = touch_status[id]; fingers[id] = touch_status[id];

View file

@ -33,10 +33,11 @@ void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
return; return;
} }
next_state = {};
const auto& last_entry = shared_memory->mouse_lifo.ReadCurrentEntry().state; const auto& last_entry = shared_memory->mouse_lifo.ReadCurrentEntry().state;
next_state.sampling_number = last_entry.sampling_number + 1; next_state.sampling_number = last_entry.sampling_number + 1;
next_state.attribute.raw = 0;
if (Settings::values.mouse_enabled) { if (Settings::values.mouse_enabled) {
const auto& mouse_button_state = emulated_devices->GetMouseButtons(); const auto& mouse_button_state = emulated_devices->GetMouseButtons();
const auto& mouse_position_state = emulated_devices->GetMousePosition(); const auto& mouse_position_state = emulated_devices->GetMousePosition();

View file

@ -58,6 +58,11 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
} }
if (!finger.pressed && current_touch.pressed) { if (!finger.pressed && current_touch.pressed) {
// Ignore all touch fingers if disabled
if (!Settings::values.touchscreen.enabled) {
continue;
}
finger.attribute.start_touch.Assign(1); finger.attribute.start_touch.Assign(1);
finger.pressed = true; finger.pressed = true;
finger.position = current_touch.position; finger.position = current_touch.position;