Merge pull request #3973 from phire/StripSpaces

Strip whitespace from Evdev and OSX controller names.
This commit is contained in:
Scott Mansell 2016-07-12 14:44:47 +12:00 committed by GitHub
commit 6b48b62872
3 changed files with 10 additions and 6 deletions

View File

@ -6,6 +6,8 @@
#include <Foundation/Foundation.h> #include <Foundation/Foundation.h>
#include <IOKit/hid/IOHIDLib.h> #include <IOKit/hid/IOHIDLib.h>
#include "Common/StringUtil.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/OSX/OSX.h" #include "InputCommon/ControllerInterface/OSX/OSX.h"
#include "InputCommon/ControllerInterface/OSX/OSXJoystick.h" #include "InputCommon/ControllerInterface/OSX/OSXJoystick.h"
@ -137,7 +139,7 @@ static void DeviceMatching_callback(void* inContext, IOReturn inResult, void* in
IOHIDDeviceRef inIOHIDDeviceRef) IOHIDDeviceRef inIOHIDDeviceRef)
{ {
NSString* pName = (NSString*)IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDProductKey)); NSString* pName = (NSString*)IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDProductKey));
std::string name = (pName != nullptr) ? [pName UTF8String] : "Unknown device"; std::string name = (pName != nullptr) ? StripSpaces([pName UTF8String]) : "Unknown device";
DeviceDebugPrint(inIOHIDDeviceRef); DeviceDebugPrint(inIOHIDDeviceRef);

View File

@ -7,6 +7,7 @@
#include <Foundation/Foundation.h> #include <Foundation/Foundation.h>
#include <IOKit/hid/IOHIDLib.h> #include <IOKit/hid/IOHIDLib.h>
#include "Common/StringUtil.h"
#include "InputCommon/ControllerInterface/OSX/OSXJoystick.h" #include "InputCommon/ControllerInterface/OSX/OSXJoystick.h"
namespace ciface namespace ciface
@ -110,7 +111,7 @@ std::string Joystick::Button::GetName() const
{ {
std::ostringstream s; std::ostringstream s;
s << IOHIDElementGetUsage(m_element); s << IOHIDElementGetUsage(m_element);
return std::string("Button ") + s.str(); return std::string("Button ") + StripSpaces(s.str());
} }
Joystick::Axis::Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction dir) Joystick::Axis::Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction dir)
@ -150,7 +151,7 @@ Joystick::Axis::Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction d
{ {
std::ostringstream s; std::ostringstream s;
s << usage; s << usage;
description = s.str(); description = StripSpaces(s.str());
break; break;
} }
} }

View File

@ -10,6 +10,7 @@
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/MathUtil.h" #include "Common/MathUtil.h"
#include "Common/StringUtil.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/evdev/evdev.h" #include "InputCommon/ControllerInterface/evdev/evdev.h"
@ -97,7 +98,7 @@ evdevDevice::evdevDevice(const std::string& devnode, int id) : m_devfile(devnode
return; return;
} }
m_name = libevdev_get_name(m_dev); m_name = StripSpaces(libevdev_get_name(m_dev));
// Controller buttons (and keyboard keys) // Controller buttons (and keyboard keys)
int num_buttons = 0; int num_buttons = 0;
@ -165,7 +166,7 @@ std::string evdevDevice::Button::GetName() const
{ {
const char* name = libevdev_event_code_get_name(EV_KEY, m_code); const char* name = libevdev_event_code_get_name(EV_KEY, m_code);
if (name) if (name)
return std::string(name); return StripSpaces(name);
} }
// But controllers use codes above 0x100, and the standard label often doesn't match. // But controllers use codes above 0x100, and the standard label often doesn't match.
// We are better off with Button 0 and so on. // We are better off with Button 0 and so on.
@ -223,7 +224,7 @@ std::string evdevDevice::ForceFeedback::GetName() const
{ {
const char* name = libevdev_event_code_get_name(EV_FF, m_type); const char* name = libevdev_event_code_get_name(EV_FF, m_type);
if (name) if (name)
return std::string(name); return StripSpaces(name);
return "Unknown"; return "Unknown";
} }
} }