diff options
| author | 2023-05-16 10:06:15 -0400 | |
|---|---|---|
| committer | 2023-05-16 10:06:15 -0400 | |
| commit | a540d248f3eca41544f685b5efb71165f0a050a2 (patch) | |
| tree | cf2f104a368873ae57bf363239934173cd8f3113 /src | |
| parent | Merge pull request #10181 from lat9nq/intel-compute-toggle (diff) | |
| parent | Allow fully customisable controller hotkeys (diff) | |
| download | yuzu-a540d248f3eca41544f685b5efb71165f0a050a2.tar.gz yuzu-a540d248f3eca41544f685b5efb71165f0a050a2.tar.xz yuzu-a540d248f3eca41544f685b5efb71165f0a050a2.zip | |
Merge pull request #10107 from grimkor/allow-fully-customised-hotkeys
Allow fully customised controller hotkeys
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/configure_hotkeys.cpp | 65 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_hotkeys.h | 2 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 18 | ||||
| -rw-r--r-- | src/yuzu/main.h | 3 |
4 files changed, 56 insertions, 32 deletions
diff --git a/src/yuzu/configuration/configure_hotkeys.cpp b/src/yuzu/configuration/configure_hotkeys.cpp index daa77a8f8..0b2a965f8 100644 --- a/src/yuzu/configuration/configure_hotkeys.cpp +++ b/src/yuzu/configuration/configure_hotkeys.cpp | |||
| @@ -48,7 +48,9 @@ ConfigureHotkeys::ConfigureHotkeys(Core::HID::HIDCore& hid_core, QWidget* parent | |||
| 48 | 48 | ||
| 49 | connect(poll_timer.get(), &QTimer::timeout, [this] { | 49 | connect(poll_timer.get(), &QTimer::timeout, [this] { |
| 50 | const auto buttons = controller->GetNpadButtons(); | 50 | const auto buttons = controller->GetNpadButtons(); |
| 51 | if (buttons.raw != Core::HID::NpadButton::None) { | 51 | const auto home_pressed = controller->GetHomeButtons().home != 0; |
| 52 | const auto capture_pressed = controller->GetCaptureButtons().capture != 0; | ||
| 53 | if (home_pressed || capture_pressed) { | ||
| 52 | SetPollingResult(buttons.raw, false); | 54 | SetPollingResult(buttons.raw, false); |
| 53 | return; | 55 | return; |
| 54 | } | 56 | } |
| @@ -154,8 +156,10 @@ void ConfigureHotkeys::ConfigureController(QModelIndex index) { | |||
| 154 | model->setData(index, previous_key); | 156 | model->setData(index, previous_key); |
| 155 | return; | 157 | return; |
| 156 | } | 158 | } |
| 157 | 159 | const auto home_pressed = this->controller->GetHomeButtons().home != 0; | |
| 158 | const QString button_string = tr("Home+%1").arg(GetButtonName(button)); | 160 | const auto capture_pressed = this->controller->GetCaptureButtons().capture != 0; |
| 161 | const QString button_string = | ||
| 162 | GetButtonCombinationName(button, home_pressed, capture_pressed); | ||
| 159 | 163 | ||
| 160 | const auto [key_sequence_used, used_action] = IsUsedControllerKey(button_string); | 164 | const auto [key_sequence_used, used_action] = IsUsedControllerKey(button_string); |
| 161 | 165 | ||
| @@ -174,72 +178,83 @@ void ConfigureHotkeys::ConfigureController(QModelIndex index) { | |||
| 174 | poll_timer->start(200); // Check for new inputs every 200ms | 178 | poll_timer->start(200); // Check for new inputs every 200ms |
| 175 | // We need to disable configuration to be able to read npad buttons | 179 | // We need to disable configuration to be able to read npad buttons |
| 176 | controller->DisableConfiguration(); | 180 | controller->DisableConfiguration(); |
| 177 | controller->DisableSystemButtons(); | ||
| 178 | } | 181 | } |
| 179 | 182 | ||
| 180 | void ConfigureHotkeys::SetPollingResult(Core::HID::NpadButton button, const bool cancel) { | 183 | void ConfigureHotkeys::SetPollingResult(Core::HID::NpadButton button, const bool cancel) { |
| 181 | timeout_timer->stop(); | 184 | timeout_timer->stop(); |
| 182 | poll_timer->stop(); | 185 | poll_timer->stop(); |
| 186 | (*input_setter)(button, cancel); | ||
| 183 | // Re-Enable configuration | 187 | // Re-Enable configuration |
| 184 | controller->EnableConfiguration(); | 188 | controller->EnableConfiguration(); |
| 185 | controller->EnableSystemButtons(); | ||
| 186 | |||
| 187 | (*input_setter)(button, cancel); | ||
| 188 | 189 | ||
| 189 | input_setter = std::nullopt; | 190 | input_setter = std::nullopt; |
| 190 | } | 191 | } |
| 191 | 192 | ||
| 192 | QString ConfigureHotkeys::GetButtonName(Core::HID::NpadButton button) const { | 193 | QString ConfigureHotkeys::GetButtonCombinationName(Core::HID::NpadButton button, |
| 194 | const bool home = false, | ||
| 195 | const bool capture = false) const { | ||
| 193 | Core::HID::NpadButtonState state{button}; | 196 | Core::HID::NpadButtonState state{button}; |
| 197 | QString button_combination; | ||
| 198 | if (home) { | ||
| 199 | button_combination.append(QStringLiteral("Home+")); | ||
| 200 | } | ||
| 201 | if (capture) { | ||
| 202 | button_combination.append(QStringLiteral("Screenshot+")); | ||
| 203 | } | ||
| 194 | if (state.a) { | 204 | if (state.a) { |
| 195 | return QStringLiteral("A"); | 205 | button_combination.append(QStringLiteral("A+")); |
| 196 | } | 206 | } |
| 197 | if (state.b) { | 207 | if (state.b) { |
| 198 | return QStringLiteral("B"); | 208 | button_combination.append(QStringLiteral("B+")); |
| 199 | } | 209 | } |
| 200 | if (state.x) { | 210 | if (state.x) { |
| 201 | return QStringLiteral("X"); | 211 | button_combination.append(QStringLiteral("X+")); |
| 202 | } | 212 | } |
| 203 | if (state.y) { | 213 | if (state.y) { |
| 204 | return QStringLiteral("Y"); | 214 | button_combination.append(QStringLiteral("Y+")); |
| 205 | } | 215 | } |
| 206 | if (state.l || state.right_sl || state.left_sl) { | 216 | if (state.l || state.right_sl || state.left_sl) { |
| 207 | return QStringLiteral("L"); | 217 | button_combination.append(QStringLiteral("L+")); |
| 208 | } | 218 | } |
| 209 | if (state.r || state.right_sr || state.left_sr) { | 219 | if (state.r || state.right_sr || state.left_sr) { |
| 210 | return QStringLiteral("R"); | 220 | button_combination.append(QStringLiteral("R+")); |
| 211 | } | 221 | } |
| 212 | if (state.zl) { | 222 | if (state.zl) { |
| 213 | return QStringLiteral("ZL"); | 223 | button_combination.append(QStringLiteral("ZL+")); |
| 214 | } | 224 | } |
| 215 | if (state.zr) { | 225 | if (state.zr) { |
| 216 | return QStringLiteral("ZR"); | 226 | button_combination.append(QStringLiteral("ZR+")); |
| 217 | } | 227 | } |
| 218 | if (state.left) { | 228 | if (state.left) { |
| 219 | return QStringLiteral("Dpad_Left"); | 229 | button_combination.append(QStringLiteral("Dpad_Left+")); |
| 220 | } | 230 | } |
| 221 | if (state.right) { | 231 | if (state.right) { |
| 222 | return QStringLiteral("Dpad_Right"); | 232 | button_combination.append(QStringLiteral("Dpad_Right+")); |
| 223 | } | 233 | } |
| 224 | if (state.up) { | 234 | if (state.up) { |
| 225 | return QStringLiteral("Dpad_Up"); | 235 | button_combination.append(QStringLiteral("Dpad_Up+")); |
| 226 | } | 236 | } |
| 227 | if (state.down) { | 237 | if (state.down) { |
| 228 | return QStringLiteral("Dpad_Down"); | 238 | button_combination.append(QStringLiteral("Dpad_Down+")); |
| 229 | } | 239 | } |
| 230 | if (state.stick_l) { | 240 | if (state.stick_l) { |
| 231 | return QStringLiteral("Left_Stick"); | 241 | button_combination.append(QStringLiteral("Left_Stick+")); |
| 232 | } | 242 | } |
| 233 | if (state.stick_r) { | 243 | if (state.stick_r) { |
| 234 | return QStringLiteral("Right_Stick"); | 244 | button_combination.append(QStringLiteral("Right_Stick+")); |
| 235 | } | 245 | } |
| 236 | if (state.minus) { | 246 | if (state.minus) { |
| 237 | return QStringLiteral("Minus"); | 247 | button_combination.append(QStringLiteral("Minus+")); |
| 238 | } | 248 | } |
| 239 | if (state.plus) { | 249 | if (state.plus) { |
| 240 | return QStringLiteral("Plus"); | 250 | button_combination.append(QStringLiteral("Plus+")); |
| 251 | } | ||
| 252 | if (button_combination.isEmpty()) { | ||
| 253 | return tr("Invalid"); | ||
| 254 | } else { | ||
| 255 | button_combination.chop(1); | ||
| 256 | return button_combination; | ||
| 241 | } | 257 | } |
| 242 | return tr("Invalid"); | ||
| 243 | } | 258 | } |
| 244 | 259 | ||
| 245 | std::pair<bool, QString> ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const { | 260 | std::pair<bool, QString> ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const { |
diff --git a/src/yuzu/configuration/configure_hotkeys.h b/src/yuzu/configuration/configure_hotkeys.h index e8e414320..5fd1bcbfe 100644 --- a/src/yuzu/configuration/configure_hotkeys.h +++ b/src/yuzu/configuration/configure_hotkeys.h | |||
| @@ -59,7 +59,7 @@ private: | |||
| 59 | QStandardItemModel* model; | 59 | QStandardItemModel* model; |
| 60 | 60 | ||
| 61 | void SetPollingResult(Core::HID::NpadButton button, bool cancel); | 61 | void SetPollingResult(Core::HID::NpadButton button, bool cancel); |
| 62 | QString GetButtonName(Core::HID::NpadButton button) const; | 62 | QString GetButtonCombinationName(Core::HID::NpadButton button, bool home, bool capture) const; |
| 63 | Core::HID::EmulatedController* controller; | 63 | Core::HID::EmulatedController* controller; |
| 64 | std::unique_ptr<QTimer> timeout_timer; | 64 | std::unique_ptr<QTimer> timeout_timer; |
| 65 | std::unique_ptr<QTimer> poll_timer; | 65 | std::unique_ptr<QTimer> poll_timer; |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index d932e33a7..4489f43af 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -1164,7 +1164,8 @@ void GMainWindow::InitializeRecentFileMenuActions() { | |||
| 1164 | UpdateRecentFiles(); | 1164 | UpdateRecentFiles(); |
| 1165 | } | 1165 | } |
| 1166 | 1166 | ||
| 1167 | void GMainWindow::LinkActionShortcut(QAction* action, const QString& action_name) { | 1167 | void GMainWindow::LinkActionShortcut(QAction* action, const QString& action_name, |
| 1168 | const bool tas_allowed) { | ||
| 1168 | static const QString main_window = QStringLiteral("Main Window"); | 1169 | static const QString main_window = QStringLiteral("Main Window"); |
| 1169 | action->setShortcut(hotkey_registry.GetKeySequence(main_window, action_name)); | 1170 | action->setShortcut(hotkey_registry.GetKeySequence(main_window, action_name)); |
| 1170 | action->setShortcutContext(hotkey_registry.GetShortcutContext(main_window, action_name)); | 1171 | action->setShortcutContext(hotkey_registry.GetShortcutContext(main_window, action_name)); |
| @@ -1176,7 +1177,14 @@ void GMainWindow::LinkActionShortcut(QAction* action, const QString& action_name | |||
| 1176 | const auto* controller_hotkey = | 1177 | const auto* controller_hotkey = |
| 1177 | hotkey_registry.GetControllerHotkey(main_window, action_name, controller); | 1178 | hotkey_registry.GetControllerHotkey(main_window, action_name, controller); |
| 1178 | connect( | 1179 | connect( |
| 1179 | controller_hotkey, &ControllerShortcut::Activated, this, [action] { action->trigger(); }, | 1180 | controller_hotkey, &ControllerShortcut::Activated, this, |
| 1181 | [action, tas_allowed, this] { | ||
| 1182 | auto [tas_status, current_tas_frame, total_tas_frames] = | ||
| 1183 | input_subsystem->GetTas()->GetStatus(); | ||
| 1184 | if (tas_allowed || tas_status == InputCommon::TasInput::TasState::Stopped) { | ||
| 1185 | action->trigger(); | ||
| 1186 | } | ||
| 1187 | }, | ||
| 1180 | Qt::QueuedConnection); | 1188 | Qt::QueuedConnection); |
| 1181 | } | 1189 | } |
| 1182 | 1190 | ||
| @@ -1193,9 +1201,9 @@ void GMainWindow::InitializeHotkeys() { | |||
| 1193 | LinkActionShortcut(ui->action_Show_Status_Bar, QStringLiteral("Toggle Status Bar")); | 1201 | LinkActionShortcut(ui->action_Show_Status_Bar, QStringLiteral("Toggle Status Bar")); |
| 1194 | LinkActionShortcut(ui->action_Fullscreen, QStringLiteral("Fullscreen")); | 1202 | LinkActionShortcut(ui->action_Fullscreen, QStringLiteral("Fullscreen")); |
| 1195 | LinkActionShortcut(ui->action_Capture_Screenshot, QStringLiteral("Capture Screenshot")); | 1203 | LinkActionShortcut(ui->action_Capture_Screenshot, QStringLiteral("Capture Screenshot")); |
| 1196 | LinkActionShortcut(ui->action_TAS_Start, QStringLiteral("TAS Start/Stop")); | 1204 | LinkActionShortcut(ui->action_TAS_Start, QStringLiteral("TAS Start/Stop"), true); |
| 1197 | LinkActionShortcut(ui->action_TAS_Record, QStringLiteral("TAS Record")); | 1205 | LinkActionShortcut(ui->action_TAS_Record, QStringLiteral("TAS Record"), true); |
| 1198 | LinkActionShortcut(ui->action_TAS_Reset, QStringLiteral("TAS Reset")); | 1206 | LinkActionShortcut(ui->action_TAS_Reset, QStringLiteral("TAS Reset"), true); |
| 1199 | 1207 | ||
| 1200 | static const QString main_window = QStringLiteral("Main Window"); | 1208 | static const QString main_window = QStringLiteral("Main Window"); |
| 1201 | const auto connect_shortcut = [&]<typename Fn>(const QString& action_name, const Fn& function) { | 1209 | const auto connect_shortcut = [&]<typename Fn>(const QString& action_name, const Fn& function) { |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 7b23f2a59..17631a2d9 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -214,7 +214,8 @@ public slots: | |||
| 214 | 214 | ||
| 215 | private: | 215 | private: |
| 216 | /// Updates an action's shortcut and text to reflect an updated hotkey from the hotkey registry. | 216 | /// Updates an action's shortcut and text to reflect an updated hotkey from the hotkey registry. |
| 217 | void LinkActionShortcut(QAction* action, const QString& action_name); | 217 | void LinkActionShortcut(QAction* action, const QString& action_name, |
| 218 | const bool tas_allowed = false); | ||
| 218 | 219 | ||
| 219 | void RegisterMetaTypes(); | 220 | void RegisterMetaTypes(); |
| 220 | 221 | ||