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

View file

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

View file

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

View file

@ -442,20 +442,64 @@
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
<layout class="QVBoxLayout" name="ControllerTabLayoutRight" stretch="1">
<item>
<widget class="QGroupBox" name="ControllerGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Controller Settings</string>
</property>
<widget class="QGroupBox" name="backButtonBehaviorGroupBox">
<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>
</layout>
</item>

View file

@ -330,7 +330,17 @@ void WindowSDL::onGamepadEvent(const SDL_Event* event) {
case SDL_EVENT_GAMEPAD_BUTTON_UP:
button = sdlGamepadToOrbisButton(event->gbutton.button);
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) {
SDL_HideCursor();