diff options
| author | 2020-08-23 08:04:26 -0400 | |
|---|---|---|
| committer | 2020-08-26 02:32:32 -0400 | |
| commit | 1bd70d73c00697f0705ba9b51da5938146224a18 (patch) | |
| tree | f0235849ea00e05eac5e11054e8cd780ef30bfb5 /src | |
| parent | controllers/npad: Fix inconsistencies with controller connection statuses (diff) | |
| download | yuzu-1bd70d73c00697f0705ba9b51da5938146224a18.tar.gz yuzu-1bd70d73c00697f0705ba9b51da5938146224a18.tar.xz yuzu-1bd70d73c00697f0705ba9b51da5938146224a18.zip | |
configuration/input: Add support for mouse button clicks
Supports the Left, Right, Middle, Backward and Forward mouse buttons.
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 41 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.h | 5 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.ui | 2 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_mouse_advanced.cpp | 40 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_mouse_advanced.h | 5 |
5 files changed, 82 insertions, 11 deletions
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 68d0d5db7..bff90a82e 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -86,6 +86,16 @@ constexpr int GetIndexFromControllerType(Settings::ControllerType type) { | |||
| 86 | 86 | ||
| 87 | QString GetKeyName(int key_code) { | 87 | QString GetKeyName(int key_code) { |
| 88 | switch (key_code) { | 88 | switch (key_code) { |
| 89 | case Qt::LeftButton: | ||
| 90 | return QObject::tr("Click 0"); | ||
| 91 | case Qt::RightButton: | ||
| 92 | return QObject::tr("Click 1"); | ||
| 93 | case Qt::MiddleButton: | ||
| 94 | return QObject::tr("Click 2"); | ||
| 95 | case Qt::BackButton: | ||
| 96 | return QObject::tr("Click 3"); | ||
| 97 | case Qt::ForwardButton: | ||
| 98 | return QObject::tr("Click 4"); | ||
| 89 | case Qt::Key_Shift: | 99 | case Qt::Key_Shift: |
| 90 | return QObject::tr("Shift"); | 100 | return QObject::tr("Shift"); |
| 91 | case Qt::Key_Control: | 101 | case Qt::Key_Control: |
| @@ -648,9 +658,9 @@ void ConfigureInputPlayer::HandleClick( | |||
| 648 | button->setText(tr("[waiting]")); | 658 | button->setText(tr("[waiting]")); |
| 649 | button->setFocus(); | 659 | button->setFocus(); |
| 650 | 660 | ||
| 651 | // The first two input devices are always Any and Keyboard. If the user filtered to a | 661 | // The first two input devices are always Any and Keyboard/Mouse. If the user filtered to a |
| 652 | // controller, then they don't want keyboard input | 662 | // controller, then they don't want keyboard/mouse input |
| 653 | want_keyboard_keys = ui->comboDevices->currentIndex() < 2; | 663 | want_keyboard_mouse = ui->comboDevices->currentIndex() < 2; |
| 654 | 664 | ||
| 655 | input_setter = new_input_setter; | 665 | input_setter = new_input_setter; |
| 656 | 666 | ||
| @@ -660,6 +670,9 @@ void ConfigureInputPlayer::HandleClick( | |||
| 660 | poller->Start(); | 670 | poller->Start(); |
| 661 | } | 671 | } |
| 662 | 672 | ||
| 673 | QWidget::grabMouse(); | ||
| 674 | QWidget::grabKeyboard(); | ||
| 675 | |||
| 663 | if (type == InputCommon::Polling::DeviceType::Button) { | 676 | if (type == InputCommon::Polling::DeviceType::Button) { |
| 664 | InputCommon::GetGCButtons()->BeginConfiguration(); | 677 | InputCommon::GetGCButtons()->BeginConfiguration(); |
| 665 | } else { | 678 | } else { |
| @@ -677,6 +690,9 @@ void ConfigureInputPlayer::SetPollingResult(const Common::ParamPackage& params, | |||
| 677 | poller->Stop(); | 690 | poller->Stop(); |
| 678 | } | 691 | } |
| 679 | 692 | ||
| 693 | QWidget::releaseMouse(); | ||
| 694 | QWidget::releaseKeyboard(); | ||
| 695 | |||
| 680 | InputCommon::GetGCButtons()->EndConfiguration(); | 696 | InputCommon::GetGCButtons()->EndConfiguration(); |
| 681 | InputCommon::GetGCAnalogs()->EndConfiguration(); | 697 | InputCommon::GetGCAnalogs()->EndConfiguration(); |
| 682 | 698 | ||
| @@ -688,13 +704,29 @@ void ConfigureInputPlayer::SetPollingResult(const Common::ParamPackage& params, | |||
| 688 | input_setter = std::nullopt; | 704 | input_setter = std::nullopt; |
| 689 | } | 705 | } |
| 690 | 706 | ||
| 707 | void ConfigureInputPlayer::mousePressEvent(QMouseEvent* event) { | ||
| 708 | if (!input_setter || !event) { | ||
| 709 | return; | ||
| 710 | } | ||
| 711 | |||
| 712 | if (want_keyboard_mouse) { | ||
| 713 | SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->button())}, | ||
| 714 | false); | ||
| 715 | } else { | ||
| 716 | // We don't want any mouse buttons, so don't stop polling | ||
| 717 | return; | ||
| 718 | } | ||
| 719 | |||
| 720 | SetPollingResult({}, true); | ||
| 721 | } | ||
| 722 | |||
| 691 | void ConfigureInputPlayer::keyPressEvent(QKeyEvent* event) { | 723 | void ConfigureInputPlayer::keyPressEvent(QKeyEvent* event) { |
| 692 | if (!input_setter || !event) { | 724 | if (!input_setter || !event) { |
| 693 | return; | 725 | return; |
| 694 | } | 726 | } |
| 695 | 727 | ||
| 696 | if (event->key() != Qt::Key_Escape) { | 728 | if (event->key() != Qt::Key_Escape) { |
| 697 | if (want_keyboard_keys) { | 729 | if (want_keyboard_mouse) { |
| 698 | SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->key())}, | 730 | SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->key())}, |
| 699 | false); | 731 | false); |
| 700 | } else { | 732 | } else { |
| @@ -702,6 +734,7 @@ void ConfigureInputPlayer::keyPressEvent(QKeyEvent* event) { | |||
| 702 | return; | 734 | return; |
| 703 | } | 735 | } |
| 704 | } | 736 | } |
| 737 | |||
| 705 | SetPollingResult({}, true); | 738 | SetPollingResult({}, true); |
| 706 | } | 739 | } |
| 707 | 740 | ||
diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h index a86db8200..ca189019d 100644 --- a/src/yuzu/configuration/configure_input_player.h +++ b/src/yuzu/configuration/configure_input_player.h | |||
| @@ -85,6 +85,9 @@ private: | |||
| 85 | /// Finish polling and configure input using the input_setter. | 85 | /// Finish polling and configure input using the input_setter. |
| 86 | void SetPollingResult(const Common::ParamPackage& params, bool abort); | 86 | void SetPollingResult(const Common::ParamPackage& params, bool abort); |
| 87 | 87 | ||
| 88 | /// Handle mouse button press events. | ||
| 89 | void mousePressEvent(QMouseEvent* event) override; | ||
| 90 | |||
| 88 | /// Handle key press events. | 91 | /// Handle key press events. |
| 89 | void keyPressEvent(QKeyEvent* event) override; | 92 | void keyPressEvent(QKeyEvent* event) override; |
| 90 | 93 | ||
| @@ -150,7 +153,7 @@ private: | |||
| 150 | 153 | ||
| 151 | /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false, | 154 | /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false, |
| 152 | /// keyboard events are ignored. | 155 | /// keyboard events are ignored. |
| 153 | bool want_keyboard_keys = false; | 156 | bool want_keyboard_mouse = false; |
| 154 | 157 | ||
| 155 | /// List of physical devices users can map with. If a SDL backed device is selected, then you | 158 | /// List of physical devices users can map with. If a SDL backed device is selected, then you |
| 156 | /// can usue this device to get a default mapping. | 159 | /// can usue this device to get a default mapping. |
diff --git a/src/yuzu/configuration/configure_input_player.ui b/src/yuzu/configuration/configure_input_player.ui index eb826a935..9bc681894 100644 --- a/src/yuzu/configuration/configure_input_player.ui +++ b/src/yuzu/configuration/configure_input_player.ui | |||
| @@ -143,7 +143,7 @@ | |||
| 143 | </item> | 143 | </item> |
| 144 | <item> | 144 | <item> |
| 145 | <property name="text"> | 145 | <property name="text"> |
| 146 | <string>Keyboard</string> | 146 | <string>Keyboard/Mouse</string> |
| 147 | </property> | 147 | </property> |
| 148 | </item> | 148 | </item> |
| 149 | </widget> | 149 | </widget> |
diff --git a/src/yuzu/configuration/configure_mouse_advanced.cpp b/src/yuzu/configuration/configure_mouse_advanced.cpp index 95e1ae873..dcda8ab14 100644 --- a/src/yuzu/configuration/configure_mouse_advanced.cpp +++ b/src/yuzu/configuration/configure_mouse_advanced.cpp | |||
| @@ -18,6 +18,16 @@ | |||
| 18 | 18 | ||
| 19 | static QString GetKeyName(int key_code) { | 19 | static QString GetKeyName(int key_code) { |
| 20 | switch (key_code) { | 20 | switch (key_code) { |
| 21 | case Qt::LeftButton: | ||
| 22 | return QObject::tr("Click 0"); | ||
| 23 | case Qt::RightButton: | ||
| 24 | return QObject::tr("Click 1"); | ||
| 25 | case Qt::MiddleButton: | ||
| 26 | return QObject::tr("Click 2"); | ||
| 27 | case Qt::BackButton: | ||
| 28 | return QObject::tr("Click 3"); | ||
| 29 | case Qt::ForwardButton: | ||
| 30 | return QObject::tr("Click 4"); | ||
| 21 | case Qt::Key_Shift: | 31 | case Qt::Key_Shift: |
| 22 | return QObject::tr("Shift"); | 32 | return QObject::tr("Shift"); |
| 23 | case Qt::Key_Control: | 33 | case Qt::Key_Control: |
| @@ -188,9 +198,9 @@ void ConfigureMouseAdvanced::HandleClick( | |||
| 188 | button->setText(tr("[press key]")); | 198 | button->setText(tr("[press key]")); |
| 189 | button->setFocus(); | 199 | button->setFocus(); |
| 190 | 200 | ||
| 191 | // Keyboard keys can only be used as button devices | 201 | // Keyboard keys or mouse buttons can only be used as button devices |
| 192 | want_keyboard_keys = type == InputCommon::Polling::DeviceType::Button; | 202 | want_keyboard_mouse = type == InputCommon::Polling::DeviceType::Button; |
| 193 | if (want_keyboard_keys) { | 203 | if (want_keyboard_mouse) { |
| 194 | const auto iter = std::find(button_map.begin(), button_map.end(), button); | 204 | const auto iter = std::find(button_map.begin(), button_map.end(), button); |
| 195 | ASSERT(iter != button_map.end()); | 205 | ASSERT(iter != button_map.end()); |
| 196 | const auto index = std::distance(button_map.begin(), iter); | 206 | const auto index = std::distance(button_map.begin(), iter); |
| @@ -205,6 +215,9 @@ void ConfigureMouseAdvanced::HandleClick( | |||
| 205 | poller->Start(); | 215 | poller->Start(); |
| 206 | } | 216 | } |
| 207 | 217 | ||
| 218 | QWidget::grabMouse(); | ||
| 219 | QWidget::grabKeyboard(); | ||
| 220 | |||
| 208 | timeout_timer->start(2500); // Cancel after 2.5 seconds | 221 | timeout_timer->start(2500); // Cancel after 2.5 seconds |
| 209 | poll_timer->start(50); // Check for new inputs every 50ms | 222 | poll_timer->start(50); // Check for new inputs every 50ms |
| 210 | } | 223 | } |
| @@ -216,6 +229,9 @@ void ConfigureMouseAdvanced::SetPollingResult(const Common::ParamPackage& params | |||
| 216 | poller->Stop(); | 229 | poller->Stop(); |
| 217 | } | 230 | } |
| 218 | 231 | ||
| 232 | QWidget::releaseMouse(); | ||
| 233 | QWidget::releaseKeyboard(); | ||
| 234 | |||
| 219 | if (!abort) { | 235 | if (!abort) { |
| 220 | (*input_setter)(params); | 236 | (*input_setter)(params); |
| 221 | } | 237 | } |
| @@ -224,13 +240,29 @@ void ConfigureMouseAdvanced::SetPollingResult(const Common::ParamPackage& params | |||
| 224 | input_setter = std::nullopt; | 240 | input_setter = std::nullopt; |
| 225 | } | 241 | } |
| 226 | 242 | ||
| 243 | void ConfigureMouseAdvanced::mousePressEvent(QMouseEvent* event) { | ||
| 244 | if (!input_setter || !event) { | ||
| 245 | return; | ||
| 246 | } | ||
| 247 | |||
| 248 | if (want_keyboard_mouse) { | ||
| 249 | SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->button())}, | ||
| 250 | false); | ||
| 251 | } else { | ||
| 252 | // We don't want any mouse buttons, so don't stop polling | ||
| 253 | return; | ||
| 254 | } | ||
| 255 | |||
| 256 | SetPollingResult({}, true); | ||
| 257 | } | ||
| 258 | |||
| 227 | void ConfigureMouseAdvanced::keyPressEvent(QKeyEvent* event) { | 259 | void ConfigureMouseAdvanced::keyPressEvent(QKeyEvent* event) { |
| 228 | if (!input_setter || !event) { | 260 | if (!input_setter || !event) { |
| 229 | return; | 261 | return; |
| 230 | } | 262 | } |
| 231 | 263 | ||
| 232 | if (event->key() != Qt::Key_Escape) { | 264 | if (event->key() != Qt::Key_Escape) { |
| 233 | if (want_keyboard_keys) { | 265 | if (want_keyboard_mouse) { |
| 234 | SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->key())}, | 266 | SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->key())}, |
| 235 | false); | 267 | false); |
| 236 | } else { | 268 | } else { |
diff --git a/src/yuzu/configuration/configure_mouse_advanced.h b/src/yuzu/configuration/configure_mouse_advanced.h index 342b82412..e7d27dab7 100644 --- a/src/yuzu/configuration/configure_mouse_advanced.h +++ b/src/yuzu/configuration/configure_mouse_advanced.h | |||
| @@ -49,6 +49,9 @@ private: | |||
| 49 | /// Finish polling and configure input using the input_setter | 49 | /// Finish polling and configure input using the input_setter |
| 50 | void SetPollingResult(const Common::ParamPackage& params, bool abort); | 50 | void SetPollingResult(const Common::ParamPackage& params, bool abort); |
| 51 | 51 | ||
| 52 | /// Handle mouse button press events. | ||
| 53 | void mousePressEvent(QMouseEvent* event) override; | ||
| 54 | |||
| 52 | /// Handle key press events. | 55 | /// Handle key press events. |
| 53 | void keyPressEvent(QKeyEvent* event) override; | 56 | void keyPressEvent(QKeyEvent* event) override; |
| 54 | 57 | ||
| @@ -67,5 +70,5 @@ private: | |||
| 67 | 70 | ||
| 68 | /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false, | 71 | /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false, |
| 69 | /// keyboard events are ignored. | 72 | /// keyboard events are ignored. |
| 70 | bool want_keyboard_keys = false; | 73 | bool want_keyboard_mouse = false; |
| 71 | }; | 74 | }; |