summaryrefslogtreecommitdiffstats
path: root/src/citra_qt
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt')
-rw-r--r--src/citra_qt/CMakeLists.txt2
-rw-r--r--src/citra_qt/bootmanager.cpp26
-rw-r--r--src/citra_qt/bootmanager.h6
-rw-r--r--src/citra_qt/config.cpp62
-rw-r--r--src/citra_qt/config.h5
-rw-r--r--src/citra_qt/configure_input.cpp178
-rw-r--r--src/citra_qt/configure_input.h34
7 files changed, 204 insertions, 109 deletions
diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt
index 15a6ccf9a..2b1c59a92 100644
--- a/src/citra_qt/CMakeLists.txt
+++ b/src/citra_qt/CMakeLists.txt
@@ -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)
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp
index 69d18cf0c..28264df9a 100644
--- a/src/citra_qt/bootmanager.cpp
+++ b/src/citra_qt/bootmanager.cpp
@@ -13,7 +13,9 @@
#include "common/scm_rev.h"
#include "common/string_util.h"
#include "core/core.h"
-#include "core/frontend/key_map.h"
+#include "core/settings.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 +101,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 +202,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 +235,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));
diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h
index 7dac1c480..923a5b456 100644
--- a/src/citra_qt/bootmanager.h
+++ b/src/citra_qt/bootmanager.h
@@ -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
diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp
index 5fe57dfa2..6ccfa1577 100644
--- a/src/citra_qt/config.cpp
+++ b/src/citra_qt/config.cpp
@@ -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,46 @@ 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,
};
+const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> Config::default_analogs{{
+ {
+ Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, Qt::Key_D,
+ },
+ {
+ Qt::Key_I, Qt::Key_K, Qt::Key_J, Qt::Key_L, Qt::Key_D,
+ },
+}};
+
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;
+ }
+
+ for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
+ std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
+ default_analogs[i][0], default_analogs[i][1], default_analogs[i][2],
+ default_analogs[i][3], default_analogs[i][4], 0.5f);
+ Settings::values.analogs[i] =
+ qt_config
+ ->value(Settings::NativeAnalog::mapping[i], QString::fromStdString(default_param))
+ .toString()
+ .toStdString();
+ if (Settings::values.analogs[i].empty())
+ Settings::values.analogs[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 +177,14 @@ 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]));
+ }
+ for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
+ qt_config->setValue(QString::fromStdString(Settings::NativeAnalog::mapping[i]),
+ QString::fromStdString(Settings::values.analogs[i]));
}
- qt_config->setValue("pad_circle_modifier_scale",
- (double)Settings::values.pad_circle_modifier_scale);
qt_config->endGroup();
qt_config->beginGroup("Core");
diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h
index 79c901804..cbf745ea2 100644
--- a/src/citra_qt/config.h
+++ b/src/citra_qt/config.h
@@ -4,6 +4,7 @@
#pragma once
+#include <array>
#include <string>
#include <QVariant>
#include "core/settings.h"
@@ -23,5 +24,7 @@ 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;
+ static const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> default_analogs;
};
diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp
index c29652f32..b59713e2c 100644
--- a/src/citra_qt/configure_input.cpp
+++ b/src/citra_qt/configure_input.cpp
@@ -2,13 +2,21 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <algorithm>
#include <memory>
#include <utility>
#include <QTimer>
#include "citra_qt/config.h"
#include "citra_qt/configure_input.h"
+#include "common/param_package.h"
+#include "input_common/main.h"
-static QString getKeyName(Qt::Key key_code) {
+const std::array<std::string, ConfigureInput::ANALOG_SUB_BUTTONS_NUM>
+ ConfigureInput::analog_sub_buttons{{
+ "up", "down", "left", "right", "modifier",
+ }};
+
+static QString getKeyName(int key_code) {
switch (key_code) {
case Qt::Key_Shift:
return QObject::tr("Shift");
@@ -23,6 +31,20 @@ static QString getKeyName(Qt::Key key_code) {
}
}
+static void SetButtonKey(int key, Common::ParamPackage& button_param) {
+ button_param = Common::ParamPackage{InputCommon::GenerateKeyboardParam(key)};
+}
+
+static void SetAnalogKey(int key, Common::ParamPackage& analog_param,
+ const std::string& button_name) {
+ if (analog_param.Get("engine", "") != "analog_from_button") {
+ analog_param = {
+ {"engine", "analog_from_button"}, {"modifier_scale", "0.5"},
+ };
+ }
+ analog_param.Set(button_name, InputCommon::GenerateKeyboardParam(key));
+}
+
ConfigureInput::ConfigureInput(QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()),
timer(std::make_unique<QTimer>()) {
@@ -31,36 +53,41 @@ ConfigureInput::ConfigureInput(QWidget* parent)
setFocusPolicy(Qt::ClickFocus);
button_map = {
- {Settings::NativeInput::Values::A, ui->buttonA},
- {Settings::NativeInput::Values::B, ui->buttonB},
- {Settings::NativeInput::Values::X, ui->buttonX},
- {Settings::NativeInput::Values::Y, ui->buttonY},
- {Settings::NativeInput::Values::L, ui->buttonL},
- {Settings::NativeInput::Values::R, ui->buttonR},
- {Settings::NativeInput::Values::ZL, ui->buttonZL},
- {Settings::NativeInput::Values::ZR, ui->buttonZR},
- {Settings::NativeInput::Values::START, ui->buttonStart},
- {Settings::NativeInput::Values::SELECT, ui->buttonSelect},
- {Settings::NativeInput::Values::HOME, ui->buttonHome},
- {Settings::NativeInput::Values::DUP, ui->buttonDpadUp},
- {Settings::NativeInput::Values::DDOWN, ui->buttonDpadDown},
- {Settings::NativeInput::Values::DLEFT, ui->buttonDpadLeft},
- {Settings::NativeInput::Values::DRIGHT, ui->buttonDpadRight},
- {Settings::NativeInput::Values::CUP, ui->buttonCStickUp},
- {Settings::NativeInput::Values::CDOWN, ui->buttonCStickDown},
- {Settings::NativeInput::Values::CLEFT, ui->buttonCStickLeft},
- {Settings::NativeInput::Values::CRIGHT, ui->buttonCStickRight},
- {Settings::NativeInput::Values::CIRCLE_UP, ui->buttonCircleUp},
- {Settings::NativeInput::Values::CIRCLE_DOWN, ui->buttonCircleDown},
- {Settings::NativeInput::Values::CIRCLE_LEFT, ui->buttonCircleLeft},
- {Settings::NativeInput::Values::CIRCLE_RIGHT, ui->buttonCircleRight},
- {Settings::NativeInput::Values::CIRCLE_MODIFIER, ui->buttonCircleMod},
+ ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp,
+ ui->buttonDpadDown, ui->buttonDpadLeft, ui->buttonDpadRight, ui->buttonL, ui->buttonR,
+ ui->buttonStart, ui->buttonSelect, ui->buttonZL, ui->buttonZR, ui->buttonHome,
};
- for (const auto& entry : button_map) {
- const Settings::NativeInput::Values input_id = entry.first;
- connect(entry.second, &QPushButton::released,
- [this, input_id]() { handleClick(input_id); });
+ analog_map = {{
+ {
+ ui->buttonCircleUp, ui->buttonCircleDown, ui->buttonCircleLeft, ui->buttonCircleRight,
+ ui->buttonCircleMod,
+ },
+ {
+ ui->buttonCStickUp, ui->buttonCStickDown, ui->buttonCStickLeft, ui->buttonCStickRight,
+ nullptr,
+ },
+ }};
+
+ for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) {
+ if (button_map[button_id])
+ connect(button_map[button_id], &QPushButton::released, [=]() {
+ handleClick(button_map[button_id],
+ [=](int key) { SetButtonKey(key, buttons_param[button_id]); });
+ });
+ }
+
+ for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) {
+ for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) {
+ if (analog_map[analog_id][sub_button_id] != nullptr) {
+ connect(analog_map[analog_id][sub_button_id], &QPushButton::released, [=]() {
+ handleClick(analog_map[analog_id][sub_button_id], [=](int key) {
+ SetAnalogKey(key, analogs_param[analog_id],
+ analog_sub_buttons[sub_button_id]);
+ });
+ });
+ }
+ }
}
connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); });
@@ -69,50 +96,93 @@ ConfigureInput::ConfigureInput(QWidget* parent)
connect(timer.get(), &QTimer::timeout, [this]() {
releaseKeyboard();
releaseMouse();
- current_input_id = boost::none;
+ key_setter = boost::none;
updateButtonLabels();
});
this->loadConfiguration();
+
+ // TODO(wwylele): enable these when the input emulation for them is implemented
+ ui->buttonZL->setEnabled(false);
+ ui->buttonZR->setEnabled(false);
+ ui->buttonHome->setEnabled(false);
+ ui->buttonCStickUp->setEnabled(false);
+ ui->buttonCStickDown->setEnabled(false);
+ ui->buttonCStickLeft->setEnabled(false);
+ ui->buttonCStickRight->setEnabled(false);
}
void ConfigureInput::applyConfiguration() {
- for (const auto& input_id : Settings::NativeInput::All) {
- const size_t index = static_cast<size_t>(input_id);
- Settings::values.input_mappings[index] = static_cast<int>(key_map[input_id]);
- }
+ std::transform(buttons_param.begin(), buttons_param.end(), Settings::values.buttons.begin(),
+ [](const Common::ParamPackage& param) { return param.Serialize(); });
+ std::transform(analogs_param.begin(), analogs_param.end(), Settings::values.analogs.begin(),
+ [](const Common::ParamPackage& param) { return param.Serialize(); });
+
Settings::Apply();
}
void ConfigureInput::loadConfiguration() {
- 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>(Settings::values.input_mappings[index]);
- }
+ std::transform(Settings::values.buttons.begin(), Settings::values.buttons.end(),
+ buttons_param.begin(),
+ [](const std::string& str) { return Common::ParamPackage(str); });
+ std::transform(Settings::values.analogs.begin(), Settings::values.analogs.end(),
+ analogs_param.begin(),
+ [](const std::string& str) { return Common::ParamPackage(str); });
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());
+ for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) {
+ SetButtonKey(Config::default_buttons[button_id], buttons_param[button_id]);
+ }
+
+ for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) {
+ for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) {
+ SetAnalogKey(Config::default_analogs[analog_id][sub_button_id],
+ analogs_param[analog_id], analog_sub_buttons[sub_button_id]);
+ }
}
updateButtonLabels();
applyConfiguration();
}
void ConfigureInput::updateButtonLabels() {
- for (const auto& input_id : Settings::NativeInput::All) {
- button_map[input_id]->setText(getKeyName(key_map[input_id]));
+ QString non_keyboard(tr("[non-keyboard]"));
+
+ auto KeyToText = [&non_keyboard](const Common::ParamPackage& param) {
+ if (param.Get("engine", "") != "keyboard") {
+ return non_keyboard;
+ } else {
+ return getKeyName(param.Get("code", 0));
+ }
+ };
+
+ for (int button = 0; button < Settings::NativeButton::NumButtons; button++) {
+ button_map[button]->setText(KeyToText(buttons_param[button]));
+ }
+
+ for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) {
+ if (analogs_param[analog_id].Get("engine", "") != "analog_from_button") {
+ for (QPushButton* button : analog_map[analog_id]) {
+ if (button)
+ button->setText(non_keyboard);
+ }
+ } else {
+ for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) {
+ Common::ParamPackage param(
+ analogs_param[analog_id].Get(analog_sub_buttons[sub_button_id], ""));
+ if (analog_map[analog_id][sub_button_id])
+ analog_map[analog_id][sub_button_id]->setText(KeyToText(param));
+ }
+ }
}
}
-void ConfigureInput::handleClick(Settings::NativeInput::Values input_id) {
- QPushButton* button = button_map[input_id];
+void ConfigureInput::handleClick(QPushButton* button, std::function<void(int)> new_key_setter) {
button->setText(tr("[press key]"));
button->setFocus();
- current_input_id = input_id;
+ key_setter = new_key_setter;
grabKeyboard();
grabMouse();
@@ -123,23 +193,13 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event) {
releaseKeyboard();
releaseMouse();
- if (!current_input_id || !event)
+ if (!key_setter || !event)
return;
if (event->key() != Qt::Key_Escape)
- setInput(*current_input_id, static_cast<Qt::Key>(event->key()));
+ (*key_setter)(event->key());
updateButtonLabels();
- current_input_id = boost::none;
+ key_setter = boost::none;
timer->stop();
}
-
-void ConfigureInput::setInput(Settings::NativeInput::Values input_id, Qt::Key key_pressed) {
- // Remove duplicates
- for (auto& pair : key_map) {
- if (pair.second == key_pressed)
- pair.second = Qt::Key_unknown;
- }
-
- key_map[input_id] = key_pressed;
-}
diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h
index bc343db83..c950fbcb4 100644
--- a/src/citra_qt/configure_input.h
+++ b/src/citra_qt/configure_input.h
@@ -4,10 +4,14 @@
#pragma once
+#include <array>
+#include <functional>
#include <memory>
+#include <string>
#include <QKeyEvent>
#include <QWidget>
#include <boost/optional.hpp>
+#include "common/param_package.h"
#include "core/settings.h"
#include "ui_configure_input.h"
@@ -31,15 +35,25 @@ public:
private:
std::unique_ptr<Ui::ConfigureInput> ui;
- /// This input is currently awaiting configuration.
- /// (i.e.: its corresponding QPushButton has been pressed.)
- boost::optional<Settings::NativeInput::Values> current_input_id;
std::unique_ptr<QTimer> timer;
- /// Each input is represented by a QPushButton.
- std::map<Settings::NativeInput::Values, QPushButton*> button_map;
- /// Each input is configured to respond to the press of a Qt::Key.
- std::map<Settings::NativeInput::Values, Qt::Key> key_map;
+ /// This will be the the setting function when an input is awaiting configuration.
+ boost::optional<std::function<void(int)>> key_setter;
+
+ std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param;
+ std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param;
+
+ static constexpr int ANALOG_SUB_BUTTONS_NUM = 5;
+
+ /// Each button input is represented by a QPushButton.
+ std::array<QPushButton*, Settings::NativeButton::NumButtons> button_map;
+
+ /// Each analog input is represented by five QPushButtons which represents up, down, left, right
+ /// and modifier
+ std::array<std::array<QPushButton*, ANALOG_SUB_BUTTONS_NUM>, Settings::NativeAnalog::NumAnalogs>
+ analog_map;
+
+ static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons;
/// Load configuration settings.
void loadConfiguration();
@@ -48,10 +62,8 @@ private:
/// Update UI to reflect current configuration.
void updateButtonLabels();
- /// Called when the button corresponding to input_id was pressed.
- void handleClick(Settings::NativeInput::Values input_id);
+ /// Called when the button was pressed.
+ void handleClick(QPushButton* button, std::function<void(int)> new_key_setter);
/// Handle key press events.
void keyPressEvent(QKeyEvent* event) override;
- /// Configure input input_id to respond to key key_pressed.
- void setInput(Settings::NativeInput::Values input_id, Qt::Key key_pressed);
};