From 7c0b81f9a5ff4424f526e4f180d0994626f1f261 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 2 Aug 2015 21:40:49 +1200 Subject: [PATCH] Merge pull request #2794 from randomstuff/evdev-stable Stable device identifier for evdev --- .../ControllerInterface/evdev/evdev.cpp | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp index 7f4f9d21c1..f8cf3a2dcd 100644 --- a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp +++ b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp @@ -14,8 +14,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 &controllerDevices) { + // this is used to number the joysticks + // multiple joysticks with the same name shall get unique ids starting at 0 + std::map name_counts; + int num_controllers = 0; // We use Udev to find any devices. In the future this will allow for hotplugging. @@ -45,7 +65,8 @@ void Init(std::vector &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()) {