diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/hid/hid_core.h | 2 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.cpp | 93 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.h | 2 |
3 files changed, 58 insertions, 39 deletions
diff --git a/src/core/hid/hid_core.h b/src/core/hid/hid_core.h index 1fe2fd89b..609f40f3b 100644 --- a/src/core/hid/hid_core.h +++ b/src/core/hid/hid_core.h | |||
| @@ -52,7 +52,7 @@ public: | |||
| 52 | void UnloadInputDevices(); | 52 | void UnloadInputDevices(); |
| 53 | 53 | ||
| 54 | /// Number of emulated controllers | 54 | /// Number of emulated controllers |
| 55 | const std::size_t available_controllers{10}; | 55 | static constexpr std::size_t available_controllers{10}; |
| 56 | 56 | ||
| 57 | private: | 57 | private: |
| 58 | std::unique_ptr<EmulatedController> player_1; | 58 | std::unique_ptr<EmulatedController> player_1; |
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 7390fc5bd..5e19f8cb1 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -613,69 +613,88 @@ int GRenderWindow::QtKeyToSwitchKey(Qt::Key qt_key) { | |||
| 613 | } | 613 | } |
| 614 | } | 614 | } |
| 615 | 615 | ||
| 616 | int GRenderWindow::QtModifierToSwitchModifier(quint32 qt_modifiers) { | 616 | int GRenderWindow::QtModifierToSwitchModifier(Qt::KeyboardModifiers qt_modifiers) { |
| 617 | int modifier = 0; | 617 | int modifier = 0; |
| 618 | // The values are obtained through testing, Qt doesn't seem to provide a proper enum | 618 | |
| 619 | if ((qt_modifiers & 0x1) != 0) { | 619 | if ((qt_modifiers & Qt::KeyboardModifier::ShiftModifier) != 0) { |
| 620 | modifier |= 1 << Settings::NativeKeyboard::LeftShift; | 620 | modifier |= 1 << Settings::NativeKeyboard::LeftShift; |
| 621 | } | 621 | } |
| 622 | if ((qt_modifiers & 0x2) != 0) { | 622 | if ((qt_modifiers & Qt::KeyboardModifier::ControlModifier) != 0) { |
| 623 | modifier |= 1 << Settings::NativeKeyboard::LeftControl; | 623 | modifier |= 1 << Settings::NativeKeyboard::LeftControl; |
| 624 | } | 624 | } |
| 625 | if ((qt_modifiers & 0x4) != 0) { | 625 | if ((qt_modifiers & Qt::KeyboardModifier::AltModifier) != 0) { |
| 626 | modifier |= 1 << Settings::NativeKeyboard::LeftAlt; | 626 | modifier |= 1 << Settings::NativeKeyboard::LeftAlt; |
| 627 | } | 627 | } |
| 628 | if ((qt_modifiers & 0x08) != 0) { | 628 | if ((qt_modifiers & Qt::KeyboardModifier::MetaModifier) != 0) { |
| 629 | modifier |= 1 << Settings::NativeKeyboard::LeftMeta; | 629 | modifier |= 1 << Settings::NativeKeyboard::LeftMeta; |
| 630 | } | 630 | } |
| 631 | if ((qt_modifiers & 0x10) != 0) { | 631 | |
| 632 | modifier |= 1 << Settings::NativeKeyboard::RightShift; | 632 | // TODO: These keys can't be obtained with Qt::KeyboardModifier |
| 633 | } | 633 | |
| 634 | if ((qt_modifiers & 0x20) != 0) { | 634 | // if ((qt_modifiers & 0x10) != 0) { |
| 635 | modifier |= 1 << Settings::NativeKeyboard::RightControl; | 635 | // modifier |= 1 << Settings::NativeKeyboard::RightShift; |
| 636 | } | 636 | // } |
| 637 | if ((qt_modifiers & 0x40) != 0) { | 637 | // if ((qt_modifiers & 0x20) != 0) { |
| 638 | modifier |= 1 << Settings::NativeKeyboard::RightAlt; | 638 | // modifier |= 1 << Settings::NativeKeyboard::RightControl; |
| 639 | } | 639 | // } |
| 640 | if ((qt_modifiers & 0x80) != 0) { | 640 | // if ((qt_modifiers & 0x40) != 0) { |
| 641 | modifier |= 1 << Settings::NativeKeyboard::RightMeta; | 641 | // modifier |= 1 << Settings::NativeKeyboard::RightAlt; |
| 642 | } | 642 | // } |
| 643 | if ((qt_modifiers & 0x100) != 0) { | 643 | // if ((qt_modifiers & 0x80) != 0) { |
| 644 | modifier |= 1 << Settings::NativeKeyboard::CapsLock; | 644 | // modifier |= 1 << Settings::NativeKeyboard::RightMeta; |
| 645 | } | 645 | // } |
| 646 | if ((qt_modifiers & 0x200) != 0) { | 646 | // if ((qt_modifiers & 0x100) != 0) { |
| 647 | modifier |= 1 << Settings::NativeKeyboard::NumLock; | 647 | // modifier |= 1 << Settings::NativeKeyboard::CapsLock; |
| 648 | } | 648 | // } |
| 649 | // Verify the last two keys | 649 | // if ((qt_modifiers & 0x200) != 0) { |
| 650 | if ((qt_modifiers & 0x400) != 0) { | 650 | // modifier |= 1 << Settings::NativeKeyboard::NumLock; |
| 651 | modifier |= 1 << Settings::NativeKeyboard::Katakana; | 651 | // } |
| 652 | } | 652 | // if ((qt_modifiers & ???) != 0) { |
| 653 | if ((qt_modifiers & 0x800) != 0) { | 653 | // modifier |= 1 << Settings::NativeKeyboard::ScrollLock; |
| 654 | modifier |= 1 << Settings::NativeKeyboard::Hiragana; | 654 | // } |
| 655 | } | 655 | // if ((qt_modifiers & ???) != 0) { |
| 656 | // modifier |= 1 << Settings::NativeKeyboard::Katakana; | ||
| 657 | // } | ||
| 658 | // if ((qt_modifiers & ???) != 0) { | ||
| 659 | // modifier |= 1 << Settings::NativeKeyboard::Hiragana; | ||
| 660 | // } | ||
| 656 | return modifier; | 661 | return modifier; |
| 657 | } | 662 | } |
| 658 | 663 | ||
| 659 | void GRenderWindow::keyPressEvent(QKeyEvent* event) { | 664 | void GRenderWindow::keyPressEvent(QKeyEvent* event) { |
| 665 | /** | ||
| 666 | * This feature can be enhanced with the following functions, but they do not provide | ||
| 667 | * cross-platform behavior. | ||
| 668 | * | ||
| 669 | * event->nativeVirtualKey() can distinguish between keys on the numpad. | ||
| 670 | * event->nativeModifiers() can distinguish between left and right keys and numlock, | ||
| 671 | * capslock, scroll lock. | ||
| 672 | */ | ||
| 660 | if (!event->isAutoRepeat()) { | 673 | if (!event->isAutoRepeat()) { |
| 661 | const auto modifier = QtModifierToSwitchModifier(event->nativeModifiers()); | 674 | const auto modifier = QtModifierToSwitchModifier(event->modifiers()); |
| 662 | // Replace event->key() with event->nativeVirtualKey() since the second one provides raw key | ||
| 663 | // buttons | ||
| 664 | const auto key = QtKeyToSwitchKey(Qt::Key(event->key())); | 675 | const auto key = QtKeyToSwitchKey(Qt::Key(event->key())); |
| 665 | input_subsystem->GetKeyboard()->SetKeyboardModifiers(modifier); | 676 | input_subsystem->GetKeyboard()->SetKeyboardModifiers(modifier); |
| 666 | input_subsystem->GetKeyboard()->PressKeyboardKey(key); | 677 | input_subsystem->GetKeyboard()->PressKeyboardKey(key); |
| 667 | // This is used for gamepads | 678 | // This is used for gamepads that can have any key mapped |
| 668 | input_subsystem->GetKeyboard()->PressKey(event->key()); | 679 | input_subsystem->GetKeyboard()->PressKey(event->key()); |
| 669 | } | 680 | } |
| 670 | } | 681 | } |
| 671 | 682 | ||
| 672 | void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { | 683 | void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { |
| 684 | /** | ||
| 685 | * This feature can be enhanced with the following functions, but they do not provide | ||
| 686 | * cross-platform behavior. | ||
| 687 | * | ||
| 688 | * event->nativeVirtualKey() can distinguish between keys on the numpad. | ||
| 689 | * event->nativeModifiers() can distinguish between left and right buttons and numlock, | ||
| 690 | * capslock, scroll lock. | ||
| 691 | */ | ||
| 673 | if (!event->isAutoRepeat()) { | 692 | if (!event->isAutoRepeat()) { |
| 674 | const auto modifier = QtModifierToSwitchModifier(event->nativeModifiers()); | 693 | const auto modifier = QtModifierToSwitchModifier(event->modifiers()); |
| 675 | const auto key = QtKeyToSwitchKey(Qt::Key(event->key())); | 694 | const auto key = QtKeyToSwitchKey(Qt::Key(event->key())); |
| 676 | input_subsystem->GetKeyboard()->SetKeyboardModifiers(modifier); | 695 | input_subsystem->GetKeyboard()->SetKeyboardModifiers(modifier); |
| 677 | input_subsystem->GetKeyboard()->ReleaseKeyboardKey(key); | 696 | input_subsystem->GetKeyboard()->ReleaseKeyboardKey(key); |
| 678 | // This is used for gamepads | 697 | // This is used for gamepads that can have any key mapped |
| 679 | input_subsystem->GetKeyboard()->ReleaseKey(event->key()); | 698 | input_subsystem->GetKeyboard()->ReleaseKey(event->key()); |
| 680 | } | 699 | } |
| 681 | } | 700 | } |
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index 81e3c4eb0..c8a2c59b4 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h | |||
| @@ -162,7 +162,7 @@ public: | |||
| 162 | static int QtKeyToSwitchKey(Qt::Key qt_keys); | 162 | static int QtKeyToSwitchKey(Qt::Key qt_keys); |
| 163 | 163 | ||
| 164 | /// Converts a Qt modifier keys into NativeKeyboard modifier keys | 164 | /// Converts a Qt modifier keys into NativeKeyboard modifier keys |
| 165 | static int QtModifierToSwitchModifier(quint32 qt_modifiers); | 165 | static int QtModifierToSwitchModifier(Qt::KeyboardModifiers qt_modifiers); |
| 166 | 166 | ||
| 167 | void keyPressEvent(QKeyEvent* event) override; | 167 | void keyPressEvent(QKeyEvent* event) override; |
| 168 | void keyReleaseEvent(QKeyEvent* event) override; | 168 | void keyReleaseEvent(QKeyEvent* event) override; |