summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
diff options
context:
space:
mode:
authorScott Mansell <phiren@gmail.com>2015-08-02 21:40:49 +1200
committerScott Mansell <phiren@gmail.com>2015-08-02 21:40:49 +1200
commit5097a22844b850b429872f4de390bd958b11a616 (patch)
treefc6d196037a392e77f082cc282dc027cc1673185 /Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
parent8dd9d35689d1c619e5e97eedce52f0041b16ffea (diff)
parent2722f3f337f2a0b6b7d01f4c45a362d75f779664 (diff)
Merge pull request #2794 from randomstuff/evdev-stable
Stable device identifier for evdev
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
index 25fa21a74b..e7a0ae2525 100644
--- a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
@@ -15,8 +15,28 @@ namespace ciface
namespace evdev
{
+static std::string GetName(const std::string& devnode)
+{
+ int fd = open(devnode.c_str(), O_RDWR|O_NONBLOCK);
+ libevdev* dev = nullptr;
+ int ret = libevdev_new_from_fd(fd, &dev);
+ if (ret != 0)
+ {
+ close(fd);
+ return std::string();
+ }
+ std::string res = libevdev_get_name(dev);
+ libevdev_free(dev);
+ close(fd);
+ return std::move(res);
+}
+
void Init(std::vector<Core::Device*> &controllerDevices)
{
+ // this is used to number the joysticks
+ // multiple joysticks with the same name shall get unique ids starting at 0
+ std::map<std::string, int> name_counts;
+
int num_controllers = 0;
// We use Udev to find any devices. In the future this will allow for hotplugging.
@@ -46,7 +66,8 @@ void Init(std::vector<Core::Device*> &controllerDevices)
{
// Unfortunately udev gives us no way to filter out the non event device interfaces.
// So we open it and see if it works with evdev ioctls or not.
- evdevDevice* input = new evdevDevice(devnode, num_controllers);
+ std::string name = GetName(devnode);
+ evdevDevice* input = new evdevDevice(devnode, name_counts[name]++);
if (input->IsInteresting())
{