mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00:00 
			
		
		
		
	InputCommon: add Keyboard
This commit is contained in:
		
							parent
							
								
									70420272ca
								
							
						
					
					
						commit
						38e800f70d
					
				
					 17 changed files with 254 additions and 85 deletions
				
			
		|  | @ -97,7 +97,7 @@ if (APPLE) | |||
| else() | ||||
|     add_executable(citra-qt ${SRCS} ${HEADERS} ${UI_HDRS}) | ||||
| endif() | ||||
| target_link_libraries(citra-qt core video_core audio_core common) | ||||
| target_link_libraries(citra-qt core video_core audio_core common input_common) | ||||
| target_link_libraries(citra-qt ${OPENGL_gl_LIBRARY} ${CITRA_QT_LIBS}) | ||||
| target_link_libraries(citra-qt ${PLATFORM_LIBRARIES} Threads::Threads) | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,7 +13,8 @@ | |||
| #include "common/scm_rev.h" | ||||
| #include "common/string_util.h" | ||||
| #include "core/core.h" | ||||
| #include "core/frontend/key_map.h" | ||||
| #include "input_common/keyboard.h" | ||||
| #include "input_common/main.h" | ||||
| #include "video_core/debug_utils/debug_utils.h" | ||||
| #include "video_core/video_core.h" | ||||
| 
 | ||||
|  | @ -99,14 +100,17 @@ private: | |||
| }; | ||||
| 
 | ||||
| GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) | ||||
|     : QWidget(parent), child(nullptr), keyboard_id(0), emu_thread(emu_thread) { | ||||
|     : QWidget(parent), child(nullptr), emu_thread(emu_thread) { | ||||
| 
 | ||||
|     std::string window_title = Common::StringFromFormat("Citra %s| %s-%s", Common::g_build_name, | ||||
|                                                         Common::g_scm_branch, Common::g_scm_desc); | ||||
|     setWindowTitle(QString::fromStdString(window_title)); | ||||
| 
 | ||||
|     keyboard_id = KeyMap::NewDeviceId(); | ||||
|     ReloadSetKeymaps(); | ||||
|     InputCommon::Init(); | ||||
| } | ||||
| 
 | ||||
| GRenderWindow::~GRenderWindow() { | ||||
|     InputCommon::Shutdown(); | ||||
| } | ||||
| 
 | ||||
| void GRenderWindow::moveContext() { | ||||
|  | @ -197,11 +201,11 @@ void GRenderWindow::closeEvent(QCloseEvent* event) { | |||
| } | ||||
| 
 | ||||
| void GRenderWindow::keyPressEvent(QKeyEvent* event) { | ||||
|     KeyMap::PressKey(*this, {event->key(), keyboard_id}); | ||||
|     InputCommon::GetKeyboard()->PressKey(event->key()); | ||||
| } | ||||
| 
 | ||||
| void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { | ||||
|     KeyMap::ReleaseKey(*this, {event->key(), keyboard_id}); | ||||
|     InputCommon::GetKeyboard()->ReleaseKey(event->key()); | ||||
| } | ||||
| 
 | ||||
| void GRenderWindow::mousePressEvent(QMouseEvent* event) { | ||||
|  | @ -230,14 +234,7 @@ void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) { | |||
|         motion_emu->EndTilt(); | ||||
| } | ||||
| 
 | ||||
| void GRenderWindow::ReloadSetKeymaps() { | ||||
|     KeyMap::ClearKeyMapping(keyboard_id); | ||||
|     for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { | ||||
|         KeyMap::SetKeyMapping( | ||||
|             {Settings::values.input_mappings[Settings::NativeInput::All[i]], keyboard_id}, | ||||
|             KeyMap::mapping_targets[i]); | ||||
|     } | ||||
| } | ||||
| void GRenderWindow::ReloadSetKeymaps() {} | ||||
| 
 | ||||
| void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) { | ||||
|     NotifyClientAreaSizeChanged(std::make_pair(width, height)); | ||||
|  |  | |||
|  | @ -104,6 +104,7 @@ class GRenderWindow : public QWidget, public EmuWindow { | |||
| 
 | ||||
| public: | ||||
|     GRenderWindow(QWidget* parent, EmuThread* emu_thread); | ||||
|     ~GRenderWindow(); | ||||
| 
 | ||||
|     // EmuWindow implementation
 | ||||
|     void SwapBuffers() override; | ||||
|  | @ -127,7 +128,7 @@ public: | |||
|     void mouseMoveEvent(QMouseEvent* event) override; | ||||
|     void mouseReleaseEvent(QMouseEvent* event) override; | ||||
| 
 | ||||
|     void ReloadSetKeymaps() override; | ||||
|     void ReloadSetKeymaps(); | ||||
| 
 | ||||
|     void OnClientAreaResized(unsigned width, unsigned height); | ||||
| 
 | ||||
|  | @ -152,9 +153,6 @@ private: | |||
| 
 | ||||
|     QByteArray geometry; | ||||
| 
 | ||||
|     /// Device id of keyboard for use with KeyMap
 | ||||
|     int keyboard_id; | ||||
| 
 | ||||
|     EmuThread* emu_thread; | ||||
| 
 | ||||
|     /// Motion sensors emulation
 | ||||
|  |  | |||
|  | @ -6,6 +6,7 @@ | |||
| #include "citra_qt/config.h" | ||||
| #include "citra_qt/ui_settings.h" | ||||
| #include "common/file_util.h" | ||||
| #include "input_common/main.h" | ||||
| 
 | ||||
| Config::Config() { | ||||
|     // TODO: Don't hardcode the path; let the frontend decide where to put the config files.
 | ||||
|  | @ -16,25 +17,23 @@ Config::Config() { | |||
|     Reload(); | ||||
| } | ||||
| 
 | ||||
| const std::array<QVariant, Settings::NativeInput::NUM_INPUTS> Config::defaults = { | ||||
|     // directly mapped keys
 | ||||
|     Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, Qt::Key_Q, Qt::Key_W, Qt::Key_1, Qt::Key_2, | ||||
|     Qt::Key_M, Qt::Key_N, Qt::Key_B, Qt::Key_T, Qt::Key_G, Qt::Key_F, Qt::Key_H, Qt::Key_I, | ||||
|     Qt::Key_K, Qt::Key_J, Qt::Key_L, | ||||
| 
 | ||||
|     // indirectly mapped keys
 | ||||
|     Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, Qt::Key_D, | ||||
| const std::array<int, Settings::NativeButton::NumButtons> Config::default_buttons = { | ||||
|     Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, Qt::Key_T, Qt::Key_G, Qt::Key_F, Qt::Key_H, | ||||
|     Qt::Key_Q, Qt::Key_W, Qt::Key_M, Qt::Key_N, Qt::Key_1, Qt::Key_2, Qt::Key_B, | ||||
| }; | ||||
| 
 | ||||
| void Config::ReadValues() { | ||||
|     qt_config->beginGroup("Controls"); | ||||
|     for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { | ||||
|         Settings::values.input_mappings[Settings::NativeInput::All[i]] = | ||||
|             qt_config->value(QString::fromStdString(Settings::NativeInput::Mapping[i]), defaults[i]) | ||||
|                 .toInt(); | ||||
|     for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { | ||||
|         std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); | ||||
|         Settings::values.buttons[i] = | ||||
|             qt_config | ||||
|                 ->value(Settings::NativeButton::mapping[i], QString::fromStdString(default_param)) | ||||
|                 .toString() | ||||
|                 .toStdString(); | ||||
|         if (Settings::values.buttons[i].empty()) | ||||
|             Settings::values.buttons[i] = default_param; | ||||
|     } | ||||
|     Settings::values.pad_circle_modifier_scale = | ||||
|         qt_config->value("pad_circle_modifier_scale", 0.5).toFloat(); | ||||
|     qt_config->endGroup(); | ||||
| 
 | ||||
|     qt_config->beginGroup("Core"); | ||||
|  | @ -155,12 +154,10 @@ void Config::ReadValues() { | |||
| 
 | ||||
| void Config::SaveValues() { | ||||
|     qt_config->beginGroup("Controls"); | ||||
|     for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { | ||||
|         qt_config->setValue(QString::fromStdString(Settings::NativeInput::Mapping[i]), | ||||
|                             Settings::values.input_mappings[Settings::NativeInput::All[i]]); | ||||
|     for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { | ||||
|         qt_config->setValue(QString::fromStdString(Settings::NativeButton::mapping[i]), | ||||
|                             QString::fromStdString(Settings::values.buttons[i])); | ||||
|     } | ||||
|     qt_config->setValue("pad_circle_modifier_scale", | ||||
|                         (double)Settings::values.pad_circle_modifier_scale); | ||||
|     qt_config->endGroup(); | ||||
| 
 | ||||
|     qt_config->beginGroup("Core"); | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <array> | ||||
| #include <string> | ||||
| #include <QVariant> | ||||
| #include "core/settings.h" | ||||
|  | @ -23,5 +24,5 @@ public: | |||
| 
 | ||||
|     void Reload(); | ||||
|     void Save(); | ||||
|     static const std::array<QVariant, Settings::NativeInput::NUM_INPUTS> defaults; | ||||
|     static const std::array<int, Settings::NativeButton::NumButtons> default_buttons; | ||||
| }; | ||||
|  |  | |||
|  | @ -92,14 +92,7 @@ void ConfigureInput::loadConfiguration() { | |||
|     updateButtonLabels(); | ||||
| } | ||||
| 
 | ||||
| void ConfigureInput::restoreDefaults() { | ||||
|     for (const auto& input_id : Settings::NativeInput::All) { | ||||
|         const size_t index = static_cast<size_t>(input_id); | ||||
|         key_map[input_id] = static_cast<Qt::Key>(Config::defaults[index].toInt()); | ||||
|     } | ||||
|     updateButtonLabels(); | ||||
|     applyConfiguration(); | ||||
| } | ||||
| void ConfigureInput::restoreDefaults() {} | ||||
| 
 | ||||
| void ConfigureInput::updateButtonLabels() { | ||||
|     for (const auto& input_id : Settings::NativeInput::All) { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue