diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt
index e7894ab08a..01c8e8e301 100644
--- a/pcsx2/CMakeLists.txt
+++ b/pcsx2/CMakeLists.txt
@@ -516,8 +516,8 @@ add_custom_command(
# PAD/Linux sources
set(pcsx2PADSources
- PAD/Linux/controller.cpp
- PAD/Linux/GamePad.cpp
+ PAD/Linux/Device.cpp
+ PAD/Linux/InputManager.cpp
PAD/Linux/SDL/joystick.cpp
PAD/Linux/keyboard.cpp
PAD/Linux/KeyStatus.cpp
@@ -527,7 +527,7 @@ set(pcsx2PADSources
PAD/Linux/wx_dialog/opPanel.cpp
PAD/Linux/wx_dialog/GamepadConfiguration.cpp
PAD/Linux/wx_dialog/JoystickConfiguration.cpp
- PAD/Linux/ini.cpp
+ PAD/Linux/Config.cpp
PAD/Linux/linux.cpp
${CMAKE_BINARY_DIR}/pcsx2/PAD/Linux/resources_pad.cpp
)
@@ -535,8 +535,10 @@ set(pcsx2PADSources
# PAD/Linux headers
set(pcsx2PADHeaders
PAD/Linux/bitwise.h
- PAD/Linux/controller.h
- PAD/Linux/GamePad.h
+ PAD/Linux/Config.h
+ PAD/Linux/Device.h
+ PAD/Linux/Global.h
+ PAD/Linux/InputManager.h
PAD/Linux/SDL/joystick.h
PAD/Linux/keyboard.h
PAD/Linux/KeyStatus.h
diff --git a/pcsx2/PAD/Linux/ini.cpp b/pcsx2/PAD/Linux/Config.cpp
similarity index 96%
rename from pcsx2/PAD/Linux/ini.cpp
rename to pcsx2/PAD/Linux/Config.cpp
index 19511176ac..7ce050a982 100644
--- a/pcsx2/PAD/Linux/ini.cpp
+++ b/pcsx2/PAD/Linux/Config.cpp
@@ -13,12 +13,10 @@
* If not, see .
*/
-#include
-
-#include "GamePad.h"
+#include "Global.h"
+#include "Device.h"
#include "keyboard.h"
#include "AppConfig.h"
-#include "PAD.h"
void DefaultKeyboardValues()
{
@@ -59,7 +57,7 @@ void PADSaveConfig()
fprintf(f, "uid[0] = %zu\n", g_conf.get_joy_uid(0));
fprintf(f, "uid[1] = %zu\n", g_conf.get_joy_uid(1));
- for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
+ for (u32 pad = 0; pad < GAMEPAD_NUMBER; pad++)
for (auto const& it : g_conf.keysym_map[pad])
fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it.first, it.second);
@@ -80,7 +78,7 @@ void PADLoadConfig()
wxString iniName(L"PAD.ini");
const std::string iniFile = std::string(GetSettingsFolder().Combine(iniName).GetFullPath()); // default path, just in case
f = fopen(iniFile.c_str(), "r");
- if (f == NULL)
+ if (f == nullptr)
{
printf("OnePAD: failed to load ini %s\n", iniFile.c_str());
PADSaveConfig(); //save and return
@@ -113,6 +111,7 @@ void PADLoadConfig()
u32 pad;
u32 keysym;
u32 index;
+
while (fscanf(f, "PAD %u:KEYSYM 0x%x = %u\n", &pad, &keysym, &index) == 3)
{
set_keyboard_key(pad & 1, keysym, index);
diff --git a/pcsx2/PAD/Linux/controller.h b/pcsx2/PAD/Linux/Config.h
similarity index 83%
rename from pcsx2/PAD/Linux/controller.h
rename to pcsx2/PAD/Linux/Config.h
index 7b2e6a2cd1..26f46f0ed6 100644
--- a/pcsx2/PAD/Linux/controller.h
+++ b/pcsx2/PAD/Linux/Config.h
@@ -14,12 +14,8 @@
*/
#pragma once
-#include // for memset
-#define MAX_KEYS 24
-extern void set_keyboard_key(int pad, int keysym, int index);
-extern int get_keyboard_key(int pad, int keysym);
-extern bool IsAnalogKey(int index);
+#include "Global.h"
class PADconf
{
@@ -58,7 +54,7 @@ public:
packed_options = 0;
ff_intensity = 0x7FFF; // set it at max value by default
sensibility = 100;
- for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
+ for (u32 pad = 0; pad < GAMEPAD_NUMBER; pad++)
{
keysym_map[pad].clear();
}
@@ -123,3 +119,19 @@ public:
}
};
extern PADconf g_conf;
+
+static __forceinline void set_keyboard_key(int pad, int keysym, int index)
+{
+ g_conf.keysym_map[pad][keysym] = index;
+}
+
+static __forceinline int get_keyboard_key(int pad, int keysym)
+{
+ // You must use find instead of []
+ // [] will create an element if the key does not exist and return 0
+ std::map::iterator it = g_conf.keysym_map[pad].find(keysym);
+ if (it != g_conf.keysym_map[pad].end())
+ return it->second;
+ else
+ return -1;
+}
diff --git a/pcsx2/PAD/Linux/GamePad.cpp b/pcsx2/PAD/Linux/Device.cpp
similarity index 63%
rename from pcsx2/PAD/Linux/GamePad.cpp
rename to pcsx2/PAD/Linux/Device.cpp
index 8749765b56..4056e1bdeb 100644
--- a/pcsx2/PAD/Linux/GamePad.cpp
+++ b/pcsx2/PAD/Linux/Device.cpp
@@ -13,60 +13,48 @@
* If not, see .
*/
-#include "GamePad.h"
+#include "Device.h"
#ifdef SDL_BUILD
#include "SDL/joystick.h"
#endif
-std::vector> s_vgamePad;
-
/**
* Following static methods are just forwarders to their backend
* This is where link between agnostic and specific code is done
**/
-/**
- * Find every interesting devices and create right structure for them(depend on backend)
- **/
-void GamePad::EnumerateGamePads(std::vector>& vgamePad)
-{
-#ifdef SDL_BUILD
- JoystickInfo::EnumerateJoysticks(vgamePad);
-#endif
-}
-
/**
* Safely dispatch to the Rumble method above
**/
-void GamePad::DoRumble(unsigned type, unsigned pad)
+void Device::DoRumble(unsigned type, unsigned pad)
{
int index = uid_to_index(pad);
if (index >= 0)
- s_vgamePad[index]->Rumble(type, pad);
+ device_manager->devices[index]->Rumble(type, pad);
}
-size_t GamePad::index_to_uid(int index)
+size_t Device::index_to_uid(int index)
{
- if ((index >= 0) && (index < (int)s_vgamePad.size()))
- return s_vgamePad[index]->GetUniqueIdentifier();
+ if ((index >= 0) && (index < (int)device_manager->devices.size()))
+ return device_manager->devices[index]->GetUniqueIdentifier();
else
return 0;
}
-int GamePad::uid_to_index(int pad)
+int Device::uid_to_index(int pad)
{
size_t uid = g_conf.get_joy_uid(pad);
- for (int i = 0; i < (int)s_vgamePad.size(); ++i)
+ for (int i = 0; i < (int)device_manager->devices.size(); ++i)
{
- if (s_vgamePad[i]->GetUniqueIdentifier() == uid)
+ if (device_manager->devices[i]->GetUniqueIdentifier() == uid)
return i;
}
// Current uid wasn't found maybe the pad was unplugged. Or
// user didn't select it. Fallback to 1st pad for
// 1st player. And 2nd pad for 2nd player.
- if ((int)s_vgamePad.size() > pad)
+ if ((int)device_manager->devices.size() > pad)
return pad;
return -1;
diff --git a/pcsx2/PAD/Linux/GamePad.h b/pcsx2/PAD/Linux/Device.h
similarity index 75%
rename from pcsx2/PAD/Linux/GamePad.h
rename to pcsx2/PAD/Linux/Device.h
index f0d755b422..38e8c2ed12 100644
--- a/pcsx2/PAD/Linux/GamePad.h
+++ b/pcsx2/PAD/Linux/Device.h
@@ -15,38 +15,52 @@
#pragma once
-#include "PAD.h"
-#include "controller.h"
+#include "Global.h"
+#include "InputManager.h"
#ifdef SDL_BUILD
#include
#endif
-class GamePad
+enum DeviceAPI
+{
+ NO_API = 0,
+ KEYBOARD_API = 16,
+ SDL_AUTO = 17
+};
+
+enum DeviceType
+{
+ NO_DEVICE = 0,
+ KEYBOARD = 1,
+ MOUSE = 2,
+ OTHER = 3
+};
+
+class Device
{
public:
- GamePad()
- : m_deadzone(1500)
+ Device()
+ : m_unique_id(0)
+ , m_device_name("")
+ , api(NO_API)
+ , type(NO_DEVICE)
+ , m_deadzone(1500)
, m_no_error(false)
{
}
- virtual ~GamePad()
+ virtual ~Device()
{
}
- GamePad(const GamePad&); // copy constructor
- GamePad& operator=(const GamePad&); // assignment
-
- /*
- * Find every interesting devices and create right structure for them(depend on backend)
- */
- static void EnumerateGamePads(std::vector>& vgamePad);
+ Device(const Device&); // copy constructor
+ Device& operator=(const Device&); // assignment
/*
* Update state of every attached devices
*/
- virtual void UpdateGamePadState() = 0;
+ virtual void UpdateDeviceState() = 0;
/*
* Causes devices to rumble
@@ -82,9 +96,12 @@ public:
return m_no_error;
}
+ size_t m_unique_id;
+ std::string m_device_name;
+ DeviceAPI api;
+ DeviceType type;
+
protected:
int m_deadzone;
bool m_no_error;
};
-
-extern std::vector> s_vgamePad;
diff --git a/pcsx2/PAD/Linux/Global.h b/pcsx2/PAD/Linux/Global.h
new file mode 100644
index 0000000000..b16e0d24b3
--- /dev/null
+++ b/pcsx2/PAD/Linux/Global.h
@@ -0,0 +1,109 @@
+/* PCSX2 - PS2 Emulator for PCs
+ * Copyright (C) 2002-2021 PCSX2 Dev Team
+ *
+ * PCSX2 is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU Lesser General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with PCSX2.
+ * If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+#include
+#include
+#include