Add support to click touchpad using back button on other controllers

Takes the back button and allows the user to change the behavior of how it clicks the touchpad. The current options are left, right, center, and none.
This commit is contained in:
fireph 2024-10-05 21:26:20 -07:00
commit 41882a1da5
5 changed files with 89 additions and 15 deletions

View file

@ -41,6 +41,7 @@ static std::string logFilter;
static std::string logType = "async"; static std::string logType = "async";
static std::string userName = "shadPS4"; static std::string userName = "shadPS4";
static std::string updateChannel; static std::string updateChannel;
static std::string backButtonBehavior = "Touchpad Left";
static bool useSpecialPad = false; static bool useSpecialPad = false;
static int specialPadClass = 1; static int specialPadClass = 1;
static bool isDebugDump = false; static bool isDebugDump = false;
@ -123,6 +124,10 @@ std::string getUpdateChannel() {
return updateChannel; return updateChannel;
} }
std::string getBackButtonBehavior() {
return backButtonBehavior;
}
bool getUseSpecialPad() { bool getUseSpecialPad() {
return useSpecialPad; return useSpecialPad;
} }
@ -275,6 +280,10 @@ void setUpdateChannel(const std::string& type) {
updateChannel = type; updateChannel = type;
} }
void setBackButtonBehavior(const std::string& type) {
backButtonBehavior = type;
}
void setUseSpecialPad(bool use) { void setUseSpecialPad(bool use) {
useSpecialPad = use; useSpecialPad = use;
} }
@ -435,6 +444,7 @@ void load(const std::filesystem::path& path) {
} }
isShowSplash = toml::find_or<bool>(general, "showSplash", true); isShowSplash = toml::find_or<bool>(general, "showSplash", true);
isAutoUpdate = toml::find_or<bool>(general, "autoUpdate", false); isAutoUpdate = toml::find_or<bool>(general, "autoUpdate", false);
backButtonBehavior = toml::find_or<std::string>(general, "backButtonBehavior", "Touchpad Left");
} }
if (data.contains("Input")) { if (data.contains("Input")) {
@ -533,6 +543,7 @@ void save(const std::filesystem::path& path) {
data["General"]["updateChannel"] = updateChannel; data["General"]["updateChannel"] = updateChannel;
data["General"]["showSplash"] = isShowSplash; data["General"]["showSplash"] = isShowSplash;
data["General"]["autoUpdate"] = isAutoUpdate; data["General"]["autoUpdate"] = isAutoUpdate;
data["General"]["backButtonBehavior"] = backButtonBehavior;
data["Input"]["useSpecialPad"] = useSpecialPad; data["Input"]["useSpecialPad"] = useSpecialPad;
data["Input"]["specialPadClass"] = specialPadClass; data["Input"]["specialPadClass"] = specialPadClass;
data["GPU"]["screenWidth"] = screenWidth; data["GPU"]["screenWidth"] = screenWidth;
@ -591,6 +602,7 @@ void setDefaultValues() {
} else { } else {
updateChannel = "Nightly"; updateChannel = "Nightly";
} }
backButtonBehavior = "Touchpad Left";
useSpecialPad = false; useSpecialPad = false;
specialPadClass = 1; specialPadClass = 1;
isDebugDump = false; isDebugDump = false;

View file

@ -20,6 +20,7 @@ std::string getLogFilter();
std::string getLogType(); std::string getLogType();
std::string getUserName(); std::string getUserName();
std::string getUpdateChannel(); std::string getUpdateChannel();
std::string getBackButtonBehavior();
bool getUseSpecialPad(); bool getUseSpecialPad();
int getSpecialPadClass(); int getSpecialPadClass();
@ -54,6 +55,7 @@ void setLanguage(u32 language);
void setNeoMode(bool enable); void setNeoMode(bool enable);
void setUserName(const std::string& type); void setUserName(const std::string& type);
void setUpdateChannel(const std::string& type); void setUpdateChannel(const std::string& type);
void setBackButtonBehavior(const std::string& type);
void setUseSpecialPad(bool use); void setUseSpecialPad(bool use);
void setSpecialPadClass(int type); void setSpecialPadClass(int type);

View file

@ -151,6 +151,10 @@ SettingsDialog::SettingsDialog(std::span<const QString> physical_devices, QWidge
Config::setBGMvolume(val); Config::setBGMvolume(val);
BackgroundMusicPlayer::getInstance().setVolume(val); BackgroundMusicPlayer::getInstance().setVolume(val);
}); });
connect(ui->backButtonBehaviorComboBox, &QComboBox::currentTextChanged, this, [](const QString& text) {
Config::setBackButtonBehavior(text.toStdString());
});
} }
// GPU TAB // GPU TAB
@ -258,6 +262,8 @@ void SettingsDialog::LoadValuesFromConfig() {
} }
} }
ui->updateComboBox->setCurrentText(QString::fromStdString(updateChannel)); ui->updateComboBox->setCurrentText(QString::fromStdString(updateChannel));
ui->backButtonBehaviorComboBox->setCurrentText(QString::fromStdString(Config::getBackButtonBehavior()));
} }
void SettingsDialog::InitializeEmulatorLanguages() { void SettingsDialog::InitializeEmulatorLanguages() {

View file

@ -442,20 +442,64 @@
</layout> </layout>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer"> <layout class="QVBoxLayout" name="ControllerTabLayoutRight" stretch="1">
<property name="orientation"> <item>
<enum>Qt::Orientation::Horizontal</enum> <widget class="QGroupBox" name="ControllerGroupBox">
</property> <property name="sizePolicy">
<property name="sizeType"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<enum>QSizePolicy::Policy::Expanding</enum> <horstretch>0</horstretch>
</property> <verstretch>0</verstretch>
<property name="sizeHint" stdset="0"> </sizepolicy>
<size> </property>
<width>0</width> <property name="title">
<height>0</height> <string>Controller Settings</string>
</size> </property>
</property> <widget class="QGroupBox" name="backButtonBehaviorGroupBox">
</spacer> <property name="geometry">
<rect>
<x>12</x>
<y>30</y>
<width>241</width>
<height>65</height>
</rect>
</property>
<property name="title">
<string>Back Button Behavior</string>
</property>
<widget class="QComboBox" name="backButtonBehaviorComboBox">
<property name="geometry">
<rect>
<x>12</x>
<y>30</y>
<width>217</width>
<height>28</height>
</rect>
</property>
<item>
<property name="text">
<string>Touchpad Left</string>
</property>
</item>
<item>
<property name="text">
<string>Touchpad Right</string>
</property>
</item>
<item>
<property name="text">
<string>Touchpad Center</string>
</property>
</item>
<item>
<property name="text">
<string>None</string>
</property>
</item>
</widget>
</widget>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>

View file

@ -330,7 +330,17 @@ void WindowSDL::onGamepadEvent(const SDL_Event* event) {
case SDL_EVENT_GAMEPAD_BUTTON_UP: case SDL_EVENT_GAMEPAD_BUTTON_UP:
button = sdlGamepadToOrbisButton(event->gbutton.button); button = sdlGamepadToOrbisButton(event->gbutton.button);
if (button != 0) { if (button != 0) {
controller->CheckButton(0, button, event->type == SDL_EVENT_GAMEPAD_BUTTON_DOWN); if (event->gbutton.button == SDL_GAMEPAD_BUTTON_BACK) {
std::string backButtonBehavior = Config::getBackButtonBehavior();
if (backButtonBehavior != "None") {
float x = backButtonBehavior == "Touchpad Left" ? 0.25f : (backButtonBehavior == "Touchpad Right" ? 0.75f : 0.5f);
// trigger a touchpad event so that the touchpad emulation for back button works
controller->SetTouchpadState(0, true, x, 0.5f);
controller->CheckButton(0, button, event->type == SDL_EVENT_GAMEPAD_BUTTON_DOWN);
}
} else {
controller->CheckButton(0, button, event->type == SDL_EVENT_GAMEPAD_BUTTON_DOWN);
}
} }
if (SDL_GetCursor() != NULL) { if (SDL_GetCursor() != NULL) {
SDL_HideCursor(); SDL_HideCursor();