summaryrefslogtreecommitdiffstats
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/drivers/gc_adapter.cpp16
-rw-r--r--src/input_common/drivers/gc_adapter.h2
-rw-r--r--src/input_common/drivers/keyboard.cpp5
-rw-r--r--src/input_common/drivers/keyboard.h5
-rw-r--r--src/input_common/drivers/mouse.cpp5
-rw-r--r--src/input_common/drivers/mouse.h5
-rw-r--r--src/input_common/drivers/sdl_driver.cpp33
-rw-r--r--src/input_common/drivers/sdl_driver.h2
-rw-r--r--src/input_common/drivers/tas_input.cpp5
-rw-r--r--src/input_common/drivers/tas_input.h5
-rw-r--r--src/input_common/drivers/touch_screen.cpp5
-rw-r--r--src/input_common/drivers/touch_screen.h5
-rw-r--r--src/input_common/drivers/udp_client.cpp16
-rw-r--r--src/input_common/drivers/udp_client.h2
-rw-r--r--src/input_common/input_engine.cpp5
-rw-r--r--src/input_common/input_engine.h10
-rw-r--r--src/input_common/input_mapping.cpp5
-rw-r--r--src/input_common/input_mapping.h5
-rw-r--r--src/input_common/input_poller.cpp5
-rw-r--r--src/input_common/input_poller.h5
-rw-r--r--src/input_common/main.cpp29
-rw-r--r--src/input_common/main.h3
22 files changed, 136 insertions, 42 deletions
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp
index 155caae42..8abd41726 100644
--- a/src/input_common/drivers/gc_adapter.cpp
+++ b/src/input_common/drivers/gc_adapter.cpp
@@ -524,4 +524,20 @@ Common::Input::ButtonNames GCAdapter::GetUIName(const Common::ParamPackage& para
return Common::Input::ButtonNames::Invalid;
}
+bool GCAdapter::IsStickInverted(const Common::ParamPackage& params) {
+ if (!params.Has("port")) {
+ return false;
+ }
+
+ const auto x_axis = static_cast<PadAxes>(params.Get("axis_x", 0));
+ const auto y_axis = static_cast<PadAxes>(params.Get("axis_y", 0));
+ if (x_axis != PadAxes::StickY && x_axis != PadAxes::SubstickY) {
+ return false;
+ }
+ if (y_axis != PadAxes::StickX && y_axis != PadAxes::SubstickX) {
+ return false;
+ }
+ return true;
+}
+
} // namespace InputCommon
diff --git a/src/input_common/drivers/gc_adapter.h b/src/input_common/drivers/gc_adapter.h
index 43ad58c85..894ab65a4 100644
--- a/src/input_common/drivers/gc_adapter.h
+++ b/src/input_common/drivers/gc_adapter.h
@@ -35,6 +35,8 @@ public:
AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override;
Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override;
+ bool IsStickInverted(const Common::ParamPackage& params) override;
+
private:
enum class PadButton {
Undefined = 0x0000,
diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp
index 59e3d9cc0..71e612fbf 100644
--- a/src/input_common/drivers/keyboard.cpp
+++ b/src/input_common/drivers/keyboard.cpp
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/param_package.h"
#include "common/settings_input.h"
diff --git a/src/input_common/drivers/keyboard.h b/src/input_common/drivers/keyboard.h
index 3856c882c..62436dba4 100644
--- a/src/input_common/drivers/keyboard.h
+++ b/src/input_common/drivers/keyboard.h
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp
index 3c9a4e747..4909fa8d7 100644
--- a/src/input_common/drivers/mouse.cpp
+++ b/src/input_common/drivers/mouse.cpp
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#include <stop_token>
#include <thread>
diff --git a/src/input_common/drivers/mouse.h b/src/input_common/drivers/mouse.h
index c5833b8ed..286ce1cf6 100644
--- a/src/input_common/drivers/mouse.h
+++ b/src/input_common/drivers/mouse.h
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index b3e4c3f64..a5c63e74a 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -934,4 +934,37 @@ u8 SDLDriver::GetHatButtonId(const std::string& direction_name) const {
return direction;
}
+bool SDLDriver::IsStickInverted(const Common::ParamPackage& params) {
+ if (!params.Has("guid") || !params.Has("port")) {
+ return false;
+ }
+ const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0));
+ if (joystick == nullptr) {
+ return false;
+ }
+ auto* controller = joystick->GetSDLGameController();
+ if (controller == nullptr) {
+ return false;
+ }
+
+ const auto& axis_x = params.Get("axis_x", 0);
+ const auto& axis_y = params.Get("axis_y", 0);
+ const auto& binding_left_x =
+ SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX);
+ const auto& binding_right_x =
+ SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX);
+ const auto& binding_left_y =
+ SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTY);
+ const auto& binding_right_y =
+ SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTY);
+
+ if (axis_x != binding_left_y.value.axis && axis_x != binding_right_y.value.axis) {
+ return false;
+ }
+ if (axis_y != binding_left_x.value.axis && axis_y != binding_right_x.value.axis) {
+ return false;
+ }
+ return true;
+}
+
} // namespace InputCommon
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h
index 4cde3606f..dcd0d1e64 100644
--- a/src/input_common/drivers/sdl_driver.h
+++ b/src/input_common/drivers/sdl_driver.h
@@ -58,6 +58,8 @@ public:
std::string GetHatButtonName(u8 direction_value) const override;
u8 GetHatButtonId(const std::string& direction_name) const override;
+ bool IsStickInverted(const Common::ParamPackage& params) override;
+
Common::Input::VibrationError SetRumble(
const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override;
diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cpp
index 944e141bf..66dbefe00 100644
--- a/src/input_common/drivers/tas_input.cpp
+++ b/src/input_common/drivers/tas_input.cpp
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2+
-// Refer to the license.txt file included.
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later.
#include <cstring>
#include <fmt/format.h>
diff --git a/src/input_common/drivers/tas_input.h b/src/input_common/drivers/tas_input.h
index 4b4e6c417..38a27a230 100644
--- a/src/input_common/drivers/tas_input.h
+++ b/src/input_common/drivers/tas_input.h
@@ -1,6 +1,5 @@
-// Copyright 2020 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
+// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
diff --git a/src/input_common/drivers/touch_screen.cpp b/src/input_common/drivers/touch_screen.cpp
index 30c727df4..8acbe4584 100644
--- a/src/input_common/drivers/touch_screen.cpp
+++ b/src/input_common/drivers/touch_screen.cpp
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/param_package.h"
#include "input_common/drivers/touch_screen.h"
diff --git a/src/input_common/drivers/touch_screen.h b/src/input_common/drivers/touch_screen.h
index bf395c40b..193478ead 100644
--- a/src/input_common/drivers/touch_screen.h
+++ b/src/input_common/drivers/touch_screen.h
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp
index 9780ead10..825262a07 100644
--- a/src/input_common/drivers/udp_client.cpp
+++ b/src/input_common/drivers/udp_client.cpp
@@ -547,6 +547,22 @@ Common::Input::ButtonNames UDPClient::GetUIName(const Common::ParamPackage& para
return Common::Input::ButtonNames::Invalid;
}
+bool UDPClient::IsStickInverted(const Common::ParamPackage& params) {
+ if (!params.Has("guid") || !params.Has("port") || !params.Has("pad")) {
+ return false;
+ }
+
+ const auto x_axis = static_cast<PadAxes>(params.Get("axis_x", 0));
+ const auto y_axis = static_cast<PadAxes>(params.Get("axis_y", 0));
+ if (x_axis != PadAxes::LeftStickY && x_axis != PadAxes::RightStickY) {
+ return false;
+ }
+ if (y_axis != PadAxes::LeftStickX && y_axis != PadAxes::RightStickX) {
+ return false;
+ }
+ return true;
+}
+
void TestCommunication(const std::string& host, u16 port,
const std::function<void()>& success_callback,
const std::function<void()>& failure_callback) {
diff --git a/src/input_common/drivers/udp_client.h b/src/input_common/drivers/udp_client.h
index c7cc7d846..dece2a45b 100644
--- a/src/input_common/drivers/udp_client.h
+++ b/src/input_common/drivers/udp_client.h
@@ -64,6 +64,8 @@ public:
MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& params) override;
Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override;
+ bool IsStickInverted(const Common::ParamPackage& params) override;
+
private:
enum class PadButton {
Undefined = 0x0000,
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp
index a16cca33d..12214d146 100644
--- a/src/input_common/input_engine.cpp
+++ b/src/input_common/input_engine.cpp
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/logging/log.h"
#include "input_common/input_engine.h"
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h
index f44e0799b..13295bd49 100644
--- a/src/input_common/input_engine.h
+++ b/src/input_common/input_engine.h
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
@@ -157,6 +156,11 @@ public:
return 0;
}
+ /// Returns true if axis of a stick aren't mapped in the correct direction
+ virtual bool IsStickInverted([[maybe_unused]] const Common::ParamPackage& params) {
+ return false;
+ }
+
void PreSetController(const PadIdentifier& identifier);
void PreSetButton(const PadIdentifier& identifier, int button);
void PreSetHatButton(const PadIdentifier& identifier, int button);
diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp
index fb78093b8..0fa4b1ddb 100644
--- a/src/input_common/input_mapping.cpp
+++ b/src/input_common/input_mapping.cpp
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/settings.h"
#include "input_common/input_engine.h"
diff --git a/src/input_common/input_mapping.h b/src/input_common/input_mapping.h
index e0dfbc7ad..79bd083e0 100644
--- a/src/input_common/input_mapping.h
+++ b/src/input_common/input_mapping.h
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp
index 82b585ff2..99d6c3cd6 100644
--- a/src/input_common/input_poller.cpp
+++ b/src/input_common/input_poller.cpp
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/common_types.h"
#include "common/input.h"
diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h
index 8a0977d58..6ebe0dbf5 100644
--- a/src/input_common/input_poller.h
+++ b/src/input_common/input_poller.h
@@ -1,6 +1,5 @@
-// Copyright 2021 yuzu Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included
+// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index 28769c6d8..21834fb6b 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -241,6 +241,28 @@ struct InputSubsystem::Impl {
return Common::Input::ButtonNames::Invalid;
}
+ bool IsStickInverted(const Common::ParamPackage& params) {
+ const std::string engine = params.Get("engine", "");
+ if (engine == mouse->GetEngineName()) {
+ return mouse->IsStickInverted(params);
+ }
+ if (engine == gcadapter->GetEngineName()) {
+ return gcadapter->IsStickInverted(params);
+ }
+ if (engine == udp_client->GetEngineName()) {
+ return udp_client->IsStickInverted(params);
+ }
+ if (engine == tas_input->GetEngineName()) {
+ return tas_input->IsStickInverted(params);
+ }
+#ifdef HAVE_SDL2
+ if (engine == sdl->GetEngineName()) {
+ return sdl->IsStickInverted(params);
+ }
+#endif
+ return false;
+ }
+
bool IsController(const Common::ParamPackage& params) {
const std::string engine = params.Get("engine", "");
if (engine == mouse->GetEngineName()) {
@@ -384,6 +406,13 @@ bool InputSubsystem::IsController(const Common::ParamPackage& params) const {
return impl->IsController(params);
}
+bool InputSubsystem::IsStickInverted(const Common::ParamPackage& params) const {
+ if (params.Has("axis_x") && params.Has("axis_y")) {
+ return impl->IsStickInverted(params);
+ }
+ return false;
+}
+
void InputSubsystem::ReloadInputDevices() {
impl->udp_client.get()->ReloadSockets();
}
diff --git a/src/input_common/main.h b/src/input_common/main.h
index baf107e0f..147c310c4 100644
--- a/src/input_common/main.h
+++ b/src/input_common/main.h
@@ -119,6 +119,9 @@ public:
/// Returns true if device is a controller.
[[nodiscard]] bool IsController(const Common::ParamPackage& params) const;
+ /// Returns true if axis of a stick aren't mapped in the correct direction
+ [[nodiscard]] bool IsStickInverted(const Common::ParamPackage& device) const;
+
/// Reloads the input devices.
void ReloadInputDevices();