summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar bunnei2022-01-11 10:49:23 -0800
committerGravatar GitHub2022-01-11 10:49:23 -0800
commitc65c651b6fb174084a26039ce6ea78e9cd3aedf0 (patch)
tree9790b6abe3e9d05649629fe851031438ed6ad139 /src/core
parentMerge pull request #7683 from liushuyu/fmt-8.1 (diff)
parentyuzu: Add controller hotkeys (diff)
downloadyuzu-c65c651b6fb174084a26039ce6ea78e9cd3aedf0.tar.gz
yuzu-c65c651b6fb174084a26039ce6ea78e9cd3aedf0.tar.xz
yuzu-c65c651b6fb174084a26039ce6ea78e9cd3aedf0.zip
Merge pull request #7633 from german77/hotkeys
yuzu: Add controller hotkeys
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hid/emulated_controller.cpp36
-rw-r--r--src/core/hid/emulated_controller.h20
-rw-r--r--src/core/hid/hid_types.h20
3 files changed, 75 insertions, 1 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 52a56ef1a..13edb7332 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -351,6 +351,19 @@ void EmulatedController::DisableConfiguration() {
351 } 351 }
352} 352}
353 353
354void EmulatedController::EnableSystemButtons() {
355 system_buttons_enabled = true;
356}
357
358void EmulatedController::DisableSystemButtons() {
359 system_buttons_enabled = false;
360}
361
362void EmulatedController::ResetSystemButtons() {
363 controller.home_button_state.home.Assign(false);
364 controller.capture_button_state.capture.Assign(false);
365}
366
354bool EmulatedController::IsConfiguring() const { 367bool EmulatedController::IsConfiguring() const {
355 return is_configuring; 368 return is_configuring;
356} 369}
@@ -600,7 +613,16 @@ void EmulatedController::SetButton(const Common::Input::CallbackStatus& callback
600 controller.npad_button_state.right_sr.Assign(current_status.value); 613 controller.npad_button_state.right_sr.Assign(current_status.value);
601 break; 614 break;
602 case Settings::NativeButton::Home: 615 case Settings::NativeButton::Home:
616 if (!system_buttons_enabled) {
617 break;
618 }
619 controller.home_button_state.home.Assign(current_status.value);
620 break;
603 case Settings::NativeButton::Screenshot: 621 case Settings::NativeButton::Screenshot:
622 if (!system_buttons_enabled) {
623 break;
624 }
625 controller.capture_button_state.capture.Assign(current_status.value);
604 break; 626 break;
605 } 627 }
606 } 628 }
@@ -1081,6 +1103,20 @@ BatteryValues EmulatedController::GetBatteryValues() const {
1081 return controller.battery_values; 1103 return controller.battery_values;
1082} 1104}
1083 1105
1106HomeButtonState EmulatedController::GetHomeButtons() const {
1107 if (is_configuring) {
1108 return {};
1109 }
1110 return controller.home_button_state;
1111}
1112
1113CaptureButtonState EmulatedController::GetCaptureButtons() const {
1114 if (is_configuring) {
1115 return {};
1116 }
1117 return controller.capture_button_state;
1118}
1119
1084NpadButtonState EmulatedController::GetNpadButtons() const { 1120NpadButtonState EmulatedController::GetNpadButtons() const {
1085 if (is_configuring) { 1121 if (is_configuring) {
1086 return {}; 1122 return {};
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index c0994ab4d..a63a83cce 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -101,6 +101,8 @@ struct ControllerStatus {
101 VibrationValues vibration_values{}; 101 VibrationValues vibration_values{};
102 102
103 // Data for HID serices 103 // Data for HID serices
104 HomeButtonState home_button_state{};
105 CaptureButtonState capture_button_state{};
104 NpadButtonState npad_button_state{}; 106 NpadButtonState npad_button_state{};
105 DebugPadButton debug_pad_button_state{}; 107 DebugPadButton debug_pad_button_state{};
106 AnalogSticks analog_stick_state{}; 108 AnalogSticks analog_stick_state{};
@@ -198,6 +200,15 @@ public:
198 /// Returns the emulated controller into normal mode, allowing the modification of the HID state 200 /// Returns the emulated controller into normal mode, allowing the modification of the HID state
199 void DisableConfiguration(); 201 void DisableConfiguration();
200 202
203 /// Enables Home and Screenshot buttons
204 void EnableSystemButtons();
205
206 /// Disables Home and Screenshot buttons
207 void DisableSystemButtons();
208
209 /// Sets Home and Screenshot buttons to false
210 void ResetSystemButtons();
211
201 /// Returns true if the emulated controller is in configuring mode 212 /// Returns true if the emulated controller is in configuring mode
202 bool IsConfiguring() const; 213 bool IsConfiguring() const;
203 214
@@ -261,7 +272,13 @@ public:
261 /// Returns the latest battery status from the controller with parameters 272 /// Returns the latest battery status from the controller with parameters
262 BatteryValues GetBatteryValues() const; 273 BatteryValues GetBatteryValues() const;
263 274
264 /// Returns the latest status of button input for the npad service 275 /// Returns the latest status of button input for the hid::HomeButton service
276 HomeButtonState GetHomeButtons() const;
277
278 /// Returns the latest status of button input for the hid::CaptureButton service
279 CaptureButtonState GetCaptureButtons() const;
280
281 /// Returns the latest status of button input for the hid::Npad service
265 NpadButtonState GetNpadButtons() const; 282 NpadButtonState GetNpadButtons() const;
266 283
267 /// Returns the latest status of button input for the debug pad service 284 /// Returns the latest status of button input for the debug pad service
@@ -383,6 +400,7 @@ private:
383 NpadStyleTag supported_style_tag{NpadStyleSet::All}; 400 NpadStyleTag supported_style_tag{NpadStyleSet::All};
384 bool is_connected{false}; 401 bool is_connected{false};
385 bool is_configuring{false}; 402 bool is_configuring{false};
403 bool system_buttons_enabled{true};
386 f32 motion_sensitivity{0.01f}; 404 f32 motion_sensitivity{0.01f};
387 bool force_update_motion{false}; 405 bool force_update_motion{false};
388 406
diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h
index 4eca68533..778b328b9 100644
--- a/src/core/hid/hid_types.h
+++ b/src/core/hid/hid_types.h
@@ -378,6 +378,26 @@ struct LedPattern {
378 }; 378 };
379}; 379};
380 380
381struct HomeButtonState {
382 union {
383 u64 raw{};
384
385 // Buttons
386 BitField<0, 1, u64> home;
387 };
388};
389static_assert(sizeof(HomeButtonState) == 0x8, "HomeButtonState has incorrect size.");
390
391struct CaptureButtonState {
392 union {
393 u64 raw{};
394
395 // Buttons
396 BitField<0, 1, u64> capture;
397 };
398};
399static_assert(sizeof(CaptureButtonState) == 0x8, "CaptureButtonState has incorrect size.");
400
381struct NpadButtonState { 401struct NpadButtonState {
382 union { 402 union {
383 NpadButton raw{}; 403 NpadButton raw{};