Compare commits

..

6 Commits

Author SHA1 Message Date
NovaChild
6f7ab5869a
Merge 7680a3253d into c650473fdc 2026-04-08 07:58:38 +00:00
David Griswold
7680a3253d analog_from_keyboard display fix, build error fix 2026-04-08 10:58:31 +03:00
David Griswold
354b8d765a fix profiles not saving correctly 2026-04-08 10:58:30 +03:00
David Griswold
81602a89a4 honor shortcut context with controller hotkeys 2026-04-08 10:58:30 +03:00
David Griswold
fa379a4a3c Add "Press A (right) button" command to input automap that will map in nintendo layout if the user has a nintendo layout / prefers to match letters rather than position. 2026-04-08 10:58:29 +03:00
David Griswold
c9aaec5469 controller hotkey support and SDL refactor to use GameController API,
which adds more user-readable names to controller input maps
2026-04-08 10:58:28 +03:00
4 changed files with 28 additions and 12 deletions

View File

@ -78,6 +78,16 @@ static QString ButtonToText(const Common::ParamPackage& param) {
}
static QString AnalogToText(const Common::ParamPackage& param, const std::string& dir) {
// If this is an analog stick made from buttons, keyboards will need to be handled
// here at the frontend rather than at InputCommon
// It might be nice to move the GetKeyName code to input_common, but would need a non-QT way of
// doing it
if (param.Get("engine", "") == "analog_from_button") {
auto dirParam = Common::ParamPackage(param.Get(dir, ""));
if (dirParam.Get("engine", "") == "keyboard") {
return GetKeyName(dirParam.Get("code", 0));
}
}
return QString::fromStdString(InputCommon::AnalogToText(param, dir));
}

View File

@ -61,12 +61,12 @@ void ControllerHotkeyMonitor::checkAllButtons() {
if (it.hk->action) {
it.hk->action->trigger();
}
for (auto const& [name, hotkey_shortcut] : it.hk->shortcuts) {
for (auto const& [hotkey_name, hotkey_shortcut] : it.hk->shortcuts) {
if (hotkey_shortcut && hotkey_shortcut->isEnabled()) {
QWidget* parent = qobject_cast<QWidget*>(hotkey_shortcut->parent());
if (!parent)
continue;
if (name == QStringLiteral("move down")) {
if (hotkey_name == QStringLiteral("move down")) {
std::cout << "move down triggered before context check" << std::endl;
}
bool shouldFire = true;

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <iostream>
#include <memory>
#include <thread>
#include "common/param_package.h"
@ -75,9 +76,10 @@ std::string ButtonToText(const Common::ParamPackage& param) {
return "[not set]";
}
const auto engine_str = param.Get("engine", "");
// keyboard should be handled by the frontend
// if this is a keyboard string, return the param package back as a string
// to be handled at the frontend
if (engine_str == "keyboard") {
return "keyboard code " + param.Get("code", 0);
return param.Serialize();
}
if (engine_str == "sdl") {

View File

@ -463,7 +463,8 @@ public:
: joysticks(joysticks_), button(button_), isController(isController_), port(port_) {}
bool GetStatus() const override {
if (port >= 0 && joysticks && joysticks->size() > port && joysticks->at(port)) {
if (port >= 0 && joysticks && static_cast<int>(joysticks->size()) > port &&
joysticks->at(port)) {
return joysticks->at(port)->GetButton(button, isController);
}
for (const auto& joystick : *joysticks) {
@ -489,7 +490,8 @@ public:
: joysticks(joysticks_), hat(hat_), direction(direction_), port(port_) {}
bool GetStatus() const override {
if (port >= 0 && joysticks && joysticks->size() > port && joysticks->at(port)) {
if (port >= 0 && joysticks && static_cast<int>(joysticks->size()) > port &&
joysticks->at(port)) {
return joysticks->at(port)->GetHatDirection(hat, direction);
}
for (const auto& joystick : *joysticks) {
@ -515,7 +517,8 @@ public:
trigger_if_greater(trigger_if_greater_), isController(isController_), port(port_) {}
bool GetStatus() const override {
if (port >= 0 && joysticks && joysticks->size() > port && joysticks->at(port)) {
if (port >= 0 && joysticks && static_cast<int>(joysticks->size()) > port &&
joysticks->at(port)) {
return joysticks->at(port)->GetAxis(axis, isController);
}
for (const auto& joystick : *joysticks) {
@ -548,7 +551,8 @@ public:
std::tuple<float, float> GetStatus() const override {
float rMax = 0.0f, xMax = 0.0f, yMax = 0.0f;
if (port >= 0 && joysticks && joysticks->size() > port && joysticks->at(port)) {
if (port >= 0 && joysticks && static_cast<int>(joysticks->size()) > port &&
joysticks->at(port)) {
const auto [x, y] = joysticks->at(port)->GetAnalog(axis_x, axis_y, isController);
const float r = std::sqrt((x * x) + (y * y));
if (r > deadzone) {
@ -663,7 +667,6 @@ public:
}
if (params.Has("axis")) {
bool controller = params.Get("api", "joystick") == "controller";
const int axis = params.Get("axis", 0);
const float threshold = params.Get("threshold", 0.5f);
const std::string direction_name = params.Get("direction", "");
@ -730,7 +733,8 @@ public:
auto joysticks = state.GetJoysticksByGUID(guid);
if (joysticks->empty())
return std::make_unique<SDLMotion>(nullptr);
auto joystick = joysticks->size() > port ? joysticks->at(port) : joysticks->at(0);
auto joystick =
static_cast<int>(joysticks->size()) > port ? joysticks->at(port) : joysticks->at(0);
return std::make_unique<SDLMotion>(joystick);
}
@ -755,7 +759,8 @@ public:
const int port = params.Get("port", 0);
const int touchpad = params.Get("touchpad", 0);
auto joysticks = state.GetJoysticksByGUID(guid);
auto joystick = joysticks->size() > port ? joysticks->at(port) : joysticks->at(0);
auto joystick =
static_cast<int>(joysticks->size()) > port ? joysticks->at(port) : joysticks->at(0);
return std::make_unique<SDLTouch>(joystick, touchpad);
}
@ -975,7 +980,6 @@ public:
auto id = event.jaxis.which;
auto value = event.jaxis.value;
auto timestamp = event.jaxis.timestamp;
auto button = event.jbutton.button;
bool controller = false;
switch (event.type) {
case SDL_CONTROLLERAXISMOTION: {