[v1 2/3] dinput: Use copy_device_name in get_osx_device_name via helper function

David Lawrie david.dljunk at gmail.com
Fri Aug 26 20:40:45 CDT 2016


Lowers number of independent methods to get device name

greater consistency

added function needed for disabling joysticks via wine registry

Tested on OS X 10.10.5.

Signed-off-by: David Lawrie <david.dljunk at gmail.com>
---
 dlls/dinput/joystick_osx.c | 45 ++++++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c
index 7685e0f..8d623dc0 100644
--- a/dlls/dinput/joystick_osx.c
+++ b/dlls/dinput/joystick_osx.c
@@ -225,6 +225,28 @@ static CFStringRef copy_device_name(IOHIDDeviceRef device)
     return name;
 }
 
+static void char_device_name_length(IOHIDDeviceRef device, char *name, int max_length)
+{
+    CFStringRef str = copy_device_name(device);
+    CFIndex len = CFStringGetLength(str);
+
+    if (name)
+        name[0] = 0;
+
+    if (max_length >= len)
+    {
+        CFStringGetCString(str,name,max_length,kCFStringEncodingASCII);
+        CFRelease(str);
+    }
+    else
+    {
+        CFStringRef substr = CFStringCreateWithSubstring(kCFAllocatorDefault, str, CFRangeMake(0, max_length));
+        CFRelease(str);
+        CFStringGetCString(substr,name,max_length,kCFStringEncodingASCII);
+        CFRelease(substr);
+    }
+}
+
 static long get_device_location_ID(IOHIDDeviceRef device)
 {
     return get_device_property_long(device, CFSTR(kIOHIDLocationIDKey));
@@ -566,34 +588,15 @@ fail:
     return 0;
 }
 
-static int get_osx_device_name(int id, char *name, int length)
+static void get_osx_device_name(int id, char *name, int length)
 {
-    CFStringRef str;
     IOHIDDeviceRef hid_device;
 
     hid_device = get_device_ref(id);
 
     TRACE("id %d hid_device %s\n", id, debugstr_device(hid_device));
 
-    if (name)
-        name[0] = 0;
-
-    if (!hid_device)
-        return 0;
-
-    str = IOHIDDeviceGetProperty(hid_device, CFSTR( kIOHIDProductKey ));
-    if (str)
-    {
-        CFIndex len = CFStringGetLength(str);
-        if (length >= len)
-        {
-            CFStringGetCString(str,name,length,kCFStringEncodingASCII);
-            return len;
-        }
-        else
-            return (len+1);
-    }
-    return 0;
+    char_device_name_length(hid_device, name, length);
 }
 
 static CFComparisonResult button_usage_comparator(const void *val1, const void *val2, void *context)
-- 
1.7.12.4 (Apple Git-37)




More information about the wine-patches mailing list