Controller Remapping GUI v2 (#3144)
Some checks failed
Build and Release / reuse (push) Has been cancelled
Build and Release / clang-format (push) Has been cancelled
Build and Release / get-info (push) Has been cancelled
Build and Release / windows-sdl (push) Has been cancelled
Build and Release / windows-qt (push) Has been cancelled
Build and Release / macos-sdl (push) Has been cancelled
Build and Release / macos-qt (push) Has been cancelled
Build and Release / linux-sdl (push) Has been cancelled
Build and Release / linux-qt (push) Has been cancelled
Build and Release / linux-sdl-gcc (push) Has been cancelled
Build and Release / linux-qt-gcc (push) Has been cancelled
Build and Release / pre-release (push) Has been cancelled

* Remapping GUI V2 - initial commit

* Unmap button with escape key

* Allow combination inputs

* Use separate class for SDL event signals so that i can work with the SDL window event loop

* Automatically pause game when GUI open to better manage event queue

* Move sd;_gamepad_added event from remap object to GUI object to avoid conflicts with sdl window

* Use signals on button/trigger to release to make GUI more responsive

* pause game while KBM window is open for consistency

* don't check gamepad when game is running to avoid conflicts

* Block all other sdl events instead of pausing game, automatic parse inputs after saving

* Don't block window restored or window exposed cases

* Properly exit event loop thread on exit
This commit is contained in:
rainmakerv2 2025-06-27 21:55:52 +08:00 committed by GitHub
parent 09b584b23f
commit fa32537f40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 1194 additions and 601 deletions

View file

@ -1068,6 +1068,8 @@ set(QT_GUI src/qt_gui/about_dialog.cpp
src/qt_gui/gui_settings.h
src/qt_gui/settings.cpp
src/qt_gui/settings.h
src/qt_gui/sdl_event_wrapper.cpp
src/qt_gui/sdl_event_wrapper.h
${EMULATOR}
${RESOURCE_FILES}
${TRANSLATIONS}

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <QDialog>
#include <SDL3/SDL.h>
#include <SDL3/SDL_gamepad.h>
#include "game_info.h"
#include "sdl_event_wrapper.h"
namespace Ui {
class ControlSettings;
@ -11,22 +14,56 @@ class ControlSettings;
class ControlSettings : public QDialog {
Q_OBJECT
public:
explicit ControlSettings(std::shared_ptr<GameInfoClass> game_info_get,
QWidget* parent = nullptr);
explicit ControlSettings(std::shared_ptr<GameInfoClass> game_info_get, bool GameRunning,
std::string GameRunningSerial, QWidget* parent = nullptr);
~ControlSettings();
signals:
void PushGamepadEvent();
void AxisChanged();
private Q_SLOTS:
void SaveControllerConfig(bool CloseOnSave);
void SetDefault();
void UpdateLightbarColor();
void CheckMapping(QPushButton*& button);
void StartTimer(QPushButton*& button, bool isButton);
void ConnectAxisInputs(QPushButton*& button);
private:
std::unique_ptr<Ui::ControlSettings> ui;
std::shared_ptr<GameInfoClass> m_game_info;
bool eventFilter(QObject* obj, QEvent* event) override;
void AddBoxItems();
void SetUIValuestoMappings();
void GetGameTitle();
void CheckGamePad();
void processSDLEvents(int Type, int Input, int Value);
void pollSDLEvents();
void SetMapping(QString input);
void DisableMappingButtons();
void EnableMappingButtons();
void Cleanup();
QList<QPushButton*> ButtonsList;
QList<QPushButton*> AxisList;
QSet<QString> pressedButtons;
std::string RunningGameSerial;
bool GameRunning;
bool L2Pressed = false;
bool R2Pressed = false;
bool EnableButtonMapping = false;
bool EnableAxisMapping = false;
bool MappingCompleted = false;
QString mapping;
int MappingTimer;
QTimer* timer;
QPushButton* MappingButton;
SDL_Gamepad* gamepad = nullptr;
SdlEventWrapper::Wrapper* RemapWrapper;
QFuture<void> Polling;
const std::vector<std::string> ControllerInputs = {
"cross", "circle", "square", "triangle", "l1",
@ -39,29 +76,8 @@ private:
"pad_left", "pad_right", "axis_left_x", "axis_left_y", "axis_right_x",
"axis_right_y", "back"};
const QStringList ButtonOutputs = {"cross",
"circle",
"square",
"triangle",
"l1",
"r1",
"l2",
"r2",
"l3",
"r3",
"options",
"pad_up",
"pad_down",
"pad_left",
"pad_right",
"touchpad_left",
"touchpad_center",
"touchpad_right",
"unmapped"};
const QStringList StickOutputs = {"axis_left_x", "axis_left_y", "axis_right_x", "axis_right_y",
"unmapped"};
protected:
void closeEvent(QCloseEvent* event) override {
Cleanup();
}
};

View file

@ -11,8 +11,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1043</width>
<height>792</height>
<width>1114</width>
<height>794</height>
</rect>
</property>
<property name="windowTitle">
@ -33,8 +33,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1019</width>
<height>732</height>
<width>1094</width>
<height>744</height>
</rect>
</property>
<widget class="QWidget" name="layoutWidget">
@ -42,8 +42,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1021</width>
<height>731</height>
<width>1091</width>
<height>741</height>
</rect>
</property>
<layout class="QHBoxLayout" name="RemapLayout">
@ -110,7 +110,7 @@
<widget class="QGroupBox" name="gb_dpad_up">
<property name="minimumSize">
<size>
<width>124</width>
<width>152</width>
<height>0</height>
</size>
</property>
@ -125,12 +125,9 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QComboBox" name="DpadUpBox">
<property name="editable">
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::SizeAdjustPolicy::AdjustToContents</enum>
<widget class="QPushButton" name="DpadUpButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
@ -161,7 +158,11 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="DpadLeftBox"/>
<widget class="QPushButton" name="DpadLeftButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
@ -185,9 +186,9 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="DpadRightBox">
<property name="editable">
<bool>false</bool>
<widget class="QPushButton" name="DpadRightButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
@ -213,6 +214,12 @@
</property>
<item>
<widget class="QGroupBox" name="gb_dpad_down">
<property name="minimumSize">
<size>
<width>152</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>124</width>
@ -224,21 +231,9 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="DpadDownBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
<widget class="QPushButton" name="DpadDownButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
@ -378,7 +373,7 @@
</property>
<property name="maximumSize">
<size>
<width>124</width>
<width>152</width>
<height>16777215</height>
</size>
</property>
@ -387,9 +382,9 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QComboBox" name="LStickUpBox">
<property name="enabled">
<bool>true</bool>
<widget class="QPushButton" name="LStickUpButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
@ -420,9 +415,9 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="LStickLeftBox">
<property name="enabled">
<bool>true</bool>
<widget class="QPushButton" name="LStickLeftButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
@ -454,9 +449,9 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="LStickRightBox">
<property name="enabled">
<bool>true</bool>
<widget class="QPushButton" name="LStickRightButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
@ -484,7 +479,7 @@
<widget class="QGroupBox" name="gb_left_stick_down">
<property name="minimumSize">
<size>
<width>124</width>
<width>152</width>
<height>0</height>
</size>
</property>
@ -499,15 +494,9 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QComboBox" name="LStickDownBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="editable">
<bool>false</bool>
</property>
<property name="frame">
<bool>false</bool>
<widget class="QPushButton" name="LStickDownButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
@ -618,11 +607,21 @@
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="layout_l1_l2">
<layout class="QVBoxLayout" name="layout_system_buttons">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QGroupBox" name="gb_l1">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>L1 / LB</string>
<string>L1</string>
</property>
<layout class="QVBoxLayout" name="gb_l1_layout">
<property name="leftMargin">
@ -638,82 +637,41 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="LBBox"/>
<widget class="QPushButton" name="L1Button">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_l2">
<property name="title">
<string>L2 / LT</string>
</property>
<layout class="QVBoxLayout" name="gb_l2_layout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="LTBox"/>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="layout_system_buttons">
<item>
<spacer name="verticalSpacer_3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::Preferred</enum>
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<width>133</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>10</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Back</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QComboBox" name="BackBox"/>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="layout_r1_r2">
<item>
<widget class="QGroupBox" name="gb_r1">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>R1 / RB</string>
<string>R1</string>
</property>
<layout class="QVBoxLayout" name="gb_r1_layout">
<property name="leftMargin">
@ -729,7 +687,71 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="RBBox"/>
<widget class="QPushButton" name="R1Button">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<widget class="QGroupBox" name="gb_l2">
<property name="title">
<string>L2</string>
</property>
<layout class="QVBoxLayout" name="gb_l2_layout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QPushButton" name="L2Button">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_start">
<property name="title">
<string>Options</string>
</property>
<layout class="QVBoxLayout" name="gb_start_layout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QPushButton" name="OptionsButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
@ -737,7 +759,7 @@
<item>
<widget class="QGroupBox" name="gb_r2">
<property name="title">
<string>R2 / RT</string>
<string>R2</string>
</property>
<layout class="QVBoxLayout" name="gb_r2_layout">
<property name="leftMargin">
@ -753,7 +775,11 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="RTBox"/>
<widget class="QPushButton" name="R2Button">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
@ -762,6 +788,10 @@
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget_controller" native="true">
<property name="minimumSize">
@ -806,15 +836,23 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_middle_bottom">
<layout class="QVBoxLayout" name="verticalLayout_9">
<property name="spacing">
<number>10</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SizeConstraint::SetDefaultConstraint</enum>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="gb_l3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>L3</string>
</property>
@ -832,37 +870,39 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="LClickBox"/>
<widget class="QPushButton" name="L3Button">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_start">
<property name="title">
<string>Options / Start</string>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<layout class="QVBoxLayout" name="gb_start_layout">
<property name="leftMargin">
<number>5</number>
<property name="sizeType">
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="topMargin">
<number>5</number>
<property name="sizeHint" stdset="0">
<size>
<width>133</width>
<height>20</height>
</size>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="StartBox"/>
</item>
</layout>
</widget>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="gb_r3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>R3</string>
</property>
@ -880,13 +920,71 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="RClickBox"/>
<widget class="QPushButton" name="R3Button">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QGroupBox" name="gb_touchleft">
<property name="title">
<string>Touchpad Left</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="TouchpadLeftButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_touchcenter">
<property name="title">
<string>Touchpad Center</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<widget class="QPushButton" name="TouchpadCenterButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_touchright">
<property name="title">
<string>Touchpad Right</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<widget class="QPushButton" name="TouchpadRightButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
@ -1104,7 +1202,7 @@
</property>
<property name="minimumSize">
<size>
<width>124</width>
<width>152</width>
<height>0</height>
</size>
</property>
@ -1115,19 +1213,13 @@
</size>
</property>
<property name="title">
<string>Triangle / Y</string>
<string>Triangle</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QComboBox" name="YBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QPushButton" name="TriangleButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
@ -1142,7 +1234,7 @@
<item>
<widget class="QGroupBox" name="gb_square">
<property name="title">
<string>Square / X</string>
<string>Square</string>
</property>
<layout class="QVBoxLayout" name="gb_square_layout">
<property name="leftMargin">
@ -1158,7 +1250,11 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="XBox"/>
<widget class="QPushButton" name="SquareButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
@ -1166,7 +1262,7 @@
<item>
<widget class="QGroupBox" name="gb_circle">
<property name="title">
<string>Circle / B</string>
<string>Circle</string>
</property>
<layout class="QVBoxLayout" name="gb_circle_layout">
<property name="leftMargin">
@ -1182,7 +1278,11 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="BBox"/>
<widget class="QPushButton" name="CircleButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
@ -1208,7 +1308,7 @@
<widget class="QGroupBox" name="gb_cross">
<property name="minimumSize">
<size>
<width>124</width>
<width>152</width>
<height>0</height>
</size>
</property>
@ -1219,11 +1319,15 @@
</size>
</property>
<property name="title">
<string>Cross / A</string>
<string>Cross</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QComboBox" name="ABox"/>
<widget class="QPushButton" name="CrossButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
@ -1361,7 +1465,7 @@
</property>
<property name="maximumSize">
<size>
<width>124</width>
<width>152</width>
<height>1231321</height>
</size>
</property>
@ -1370,9 +1474,9 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QComboBox" name="RStickUpBox">
<property name="enabled">
<bool>true</bool>
<widget class="QPushButton" name="RStickUpButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
@ -1403,9 +1507,9 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="RStickLeftBox">
<property name="enabled">
<bool>true</bool>
<widget class="QPushButton" name="RStickLeftButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
@ -1431,7 +1535,11 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="RStickRightBox"/>
<widget class="QPushButton" name="RStickRightButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>
</layout>
</widget>
@ -1457,7 +1565,7 @@
<widget class="QGroupBox" name="gb_right_stick_down">
<property name="minimumSize">
<size>
<width>124</width>
<width>152</width>
<height>0</height>
</size>
</property>
@ -1472,9 +1580,9 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QComboBox" name="RStickDownBox">
<property name="enabled">
<bool>true</bool>
<widget class="QPushButton" name="RStickDownButton">
<property name="text">
<string>unmapped</string>
</property>
</widget>
</item>

View file

@ -7,16 +7,20 @@
#include <QMouseEvent>
#include <QPushButton>
#include <QWheelEvent>
#include <SDL3/SDL_events.h>
#include "common/path_util.h"
#include "input/input_handler.h"
#include "kbm_config_dialog.h"
#include "kbm_gui.h"
#include "kbm_help_dialog.h"
#include "ui_kbm_gui.h"
HelpDialog* HelpWindow;
KBMSettings::KBMSettings(std::shared_ptr<GameInfoClass> game_info_get, QWidget* parent)
: QDialog(parent), m_game_info(game_info_get), ui(new Ui::KBMSettings) {
KBMSettings::KBMSettings(std::shared_ptr<GameInfoClass> game_info_get, bool isGameRunning,
std::string GameRunningSerial, QWidget* parent)
: QDialog(parent), m_game_info(game_info_get), GameRunning(isGameRunning),
RunningGameSerial(GameRunningSerial), ui(new Ui::KBMSettings) {
ui->setupUi(this);
ui->PerGameCheckBox->setChecked(!Config::GetUseUnifiedInputConfig());
@ -271,9 +275,17 @@ void KBMSettings::SaveKBMConfig(bool close_on_save) {
output_string = line.substr(0, equal_pos - 1);
input_string = line.substr(equal_pos + 2);
if (std::find(ControllerInputs.begin(), ControllerInputs.end(), input_string) !=
ControllerInputs.end() ||
output_string == "analog_deadzone" || output_string == "override_controller_color") {
bool controllerInputdetected = false;
for (std::string input : ControllerInputs) {
// Needed to avoid detecting backspace while detecting back
if (input_string.contains(input) && !input_string.contains("backspace")) {
controllerInputdetected = true;
break;
}
}
if (controllerInputdetected || output_string == "analog_deadzone" ||
output_string == "override_controller_color") {
lines.push_back(line);
}
}
@ -324,6 +336,11 @@ QString(tr("Cannot bind any unique input more than once. Duplicate inputs mapped
Config::SetUseUnifiedInputConfig(!ui->PerGameCheckBox->isChecked());
Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml");
if (GameRunning) {
Config::GetUseUnifiedInputConfig() ? Input::ParseInputConfig("default")
: Input::ParseInputConfig(RunningGameSerial);
}
if (close_on_save)
QWidget::close();
}
@ -390,8 +407,16 @@ void KBMSettings::SetUIValuestoMappings(std::string config_id) {
std::string output_string = line.substr(0, equal_pos - 1);
std::string input_string = line.substr(equal_pos + 2);
if (std::find(ControllerInputs.begin(), ControllerInputs.end(), input_string) ==
ControllerInputs.end()) {
bool controllerInputdetected = false;
for (std::string input : ControllerInputs) {
// Needed to avoid detecting backspace while detecting back
if (input_string.contains(input) && !input_string.contains("backspace")) {
controllerInputdetected = true;
break;
}
}
if (!controllerInputdetected) {
if (output_string == "cross") {
ui->CrossButton->setText(QString::fromStdString(input_string));
} else if (output_string == "circle") {
@ -1000,7 +1025,6 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) {
if (event->type() == QEvent::KeyRelease || event->type() == QEvent::MouseButtonRelease)
emit PushKBMEvent();
}
return QDialog::eventFilter(obj, event);
}

View file

@ -23,7 +23,8 @@ class KBMSettings;
class KBMSettings : public QDialog {
Q_OBJECT
public:
explicit KBMSettings(std::shared_ptr<GameInfoClass> game_info_get, QWidget* parent = nullptr);
explicit KBMSettings(std::shared_ptr<GameInfoClass> game_info_get, bool GameRunning,
std::string GameRunningSerial, QWidget* parent = nullptr);
~KBMSettings();
signals:
@ -47,8 +48,11 @@ private:
void DisableMappingButtons();
void EnableMappingButtons();
void SetMapping(QString input);
void Cleanup();
std::string RunningGameSerial;
QSet<QString> pressedKeys;
bool GameRunning;
bool EnableMapping = false;
bool MappingCompleted = false;
bool HelpWindowOpen = false;

View file

@ -473,12 +473,13 @@ void MainWindow::CreateConnects() {
});
connect(ui->controllerButton, &QPushButton::clicked, this, [this]() {
auto configWindow = new ControlSettings(m_game_info, this);
configWindow->exec();
ControlSettings* remapWindow =
new ControlSettings(m_game_info, isGameRunning, runningGameSerial, this);
remapWindow->exec();
});
connect(ui->keyboardButton, &QPushButton::clicked, this, [this]() {
auto kbmWindow = new KBMSettings(m_game_info, this);
auto kbmWindow = new KBMSettings(m_game_info, isGameRunning, runningGameSerial, this);
kbmWindow->exec();
});
@ -846,12 +847,14 @@ void MainWindow::StartGame() {
if (m_game_list_frame->currentItem()) {
int itemID = m_game_list_frame->currentItem()->row();
Common::FS::PathToQString(gamePath, m_game_info->m_games[itemID].path / "eboot.bin");
runningGameSerial = m_game_info->m_games[itemID].serial;
}
} else if (table_mode == 1) {
if (m_game_grid_frame->cellClicked) {
int itemID = (m_game_grid_frame->crtRow * m_game_grid_frame->columnCnt) +
m_game_grid_frame->crtColumn;
Common::FS::PathToQString(gamePath, m_game_info->m_games[itemID].path / "eboot.bin");
runningGameSerial = m_game_info->m_games[itemID].serial;
}
} else {
if (m_elf_viewer->currentItem()) {

View file

@ -75,11 +75,13 @@ private:
void PlayBackgroundMusic();
QIcon RecolorIcon(const QIcon& icon, bool isWhite);
void StartEmulator(std::filesystem::path);
bool isIconBlack = false;
bool isTableList = true;
bool isGameRunning = false;
bool isWhite = false;
bool is_paused = false;
std::string runningGameSerial = "";
QActionGroup* m_icon_size_act_group = nullptr;
QActionGroup* m_list_mode_act_group = nullptr;

View file

@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "sdl_event_wrapper.h"
using namespace SdlEventWrapper;
Wrapper* Wrapper::WrapperInstance = nullptr;
bool Wrapper::wrapperActive = false;
Wrapper::Wrapper(QObject* parent) : QObject(parent) {}
Wrapper* Wrapper::GetInstance() {
if (WrapperInstance == nullptr) {
WrapperInstance = new Wrapper();
}
return WrapperInstance;
}
bool Wrapper::ProcessEvent(SDL_Event* event) {
switch (event->type) {
case SDL_EVENT_WINDOW_RESTORED:
return false;
case SDL_EVENT_WINDOW_EXPOSED:
return false;
case SDL_EVENT_GAMEPAD_ADDED:
return false;
case SDL_EVENT_GAMEPAD_REMOVED:
return false;
case SDL_EVENT_QUIT:
emit SDLEvent(SDL_EVENT_QUIT, 0, 0);
return true;
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
emit SDLEvent(SDL_EVENT_GAMEPAD_BUTTON_DOWN, event->gbutton.button, 0);
return true;
case SDL_EVENT_GAMEPAD_BUTTON_UP:
emit SDLEvent(SDL_EVENT_GAMEPAD_BUTTON_UP, event->gbutton.button, 0);
return true;
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
emit SDLEvent(SDL_EVENT_GAMEPAD_AXIS_MOTION, event->gaxis.axis, event->gaxis.value);
return true;
// block all other SDL events while wrapper is active
default:
return true;
}
}
Wrapper::~Wrapper() {}

View file

@ -0,0 +1,25 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QObject>
#include <SDL3/SDL_events.h>
namespace SdlEventWrapper {
class Wrapper : public QObject {
Q_OBJECT
public:
explicit Wrapper(QObject* parent = nullptr);
~Wrapper();
bool ProcessEvent(SDL_Event* event);
static Wrapper* GetInstance();
static bool wrapperActive;
static Wrapper* WrapperInstance;
signals:
void SDLEvent(int Type, int Input, int Value);
};
} // namespace SdlEventWrapper

View file

@ -20,6 +20,10 @@
#include "sdl_window.h"
#include "video_core/renderdoc.h"
#ifdef ENABLE_QT_GUI
#include "qt_gui/sdl_event_wrapper.h"
#endif
#ifdef __APPLE__
#include "SDL3/SDL_metal.h"
#endif
@ -340,6 +344,13 @@ void WindowSDL::WaitEvent() {
return;
}
#ifdef ENABLE_QT_GUI
if (SdlEventWrapper::Wrapper::wrapperActive) {
if (SdlEventWrapper::Wrapper::GetInstance()->ProcessEvent(&event))
return;
}
#endif
if (ImGui::Core::ProcessEvent(&event)) {
return;
}