From 7c9c2209316a558e5d5a3b2f17a42190016a9fe5 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Sun, 14 Jul 2024 12:27:08 -0700 Subject: [PATCH] macOS: Fix keyboard settings warning --- macosx/mac-joypad.h | 2 +- macosx/mac-joypad.mm | 47 ++++++++++++++++++++++++++++++++++++++++++-- macosx/mac-os.mm | 2 +- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/macosx/mac-joypad.h b/macosx/mac-joypad.h index 1f77a39c..366f8cf3 100755 --- a/macosx/mac-joypad.h +++ b/macosx/mac-joypad.h @@ -131,7 +131,7 @@ bool SetButtonCodeForJoypadControl(uint32 vendorID, uint32 productID, uint32 ind void ClearButtonCodeForJoypad(uint32 vendorID, uint32 productID, uint32 index, S9xButtonCode buttonCode); void ClearJoypad(uint32 vendorID, uint32 productID, uint32 index); -std::unordered_map GetJuypadButtons(uint32 vendorID, uint32 productID, uint32 index); +std::unordered_map GetJoypadButtons(uint32 vendorID, uint32 productID, uint32 index); std::string LabelForInput(uint32 vendorID, uint32 productID, uint32 cookie, int32 value); diff --git a/macosx/mac-joypad.mm b/macosx/mac-joypad.mm index 253238c8..db4ea912 100755 --- a/macosx/mac-joypad.mm +++ b/macosx/mac-joypad.mm @@ -684,7 +684,7 @@ void ClearJoypad(uint32 vendorID, uint32 productID, uint32 index) } } -std::unordered_map GetJuypadButtons(uint32 vendorID, uint32 productID, uint32 index) +std::unordered_map GetJoypadButtons(uint32 vendorID, uint32 productID, uint32 index) { struct JoypadDevice device; device.vendorID = vendorID; @@ -712,7 +712,50 @@ void SetUpHID (void) { IOHIDManagerRegisterInputValueCallback(hidManager, gamepadAction, NULL); IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetMain(), kCFRunLoopDefaultMode); - IOHIDManagerSetDeviceMatching(hidManager, NULL); + + CFMutableArrayRef matching = CFArrayCreateMutable(kCFAllocatorDefault, 4, &kCFTypeArrayCallBacks); + + uint32 page = kHIDPage_GenericDesktop; + uint32 usage = kHIDUsage_GD_Joystick; + CFNumberRef pageRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page); + CFNumberRef usageRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage); + + CFMutableDictionaryRef entry = CFDictionaryCreateMutable(kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + CFDictionarySetValue(entry, CFSTR(kIOHIDDeviceUsagePageKey), (void *)pageRef); + CFDictionarySetValue(entry, CFSTR(kIOHIDDeviceUsageKey), (void *)usageRef); + CFArrayAppendValue(matching, entry); + CFRelease(usageRef); + CFRelease(entry); + + usage = kHIDUsage_GD_GamePad; + usageRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage); + entry = CFDictionaryCreateMutable(kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + CFDictionarySetValue(entry, CFSTR(kIOHIDDeviceUsagePageKey), (void *)pageRef); + CFDictionarySetValue(entry, CFSTR(kIOHIDDeviceUsageKey), (void *)usageRef); + CFArrayAppendValue(matching, entry); + CFRelease(usageRef); + CFRelease(entry); + + usage = kHIDUsage_GD_MultiAxisController; + usageRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage); + entry = CFDictionaryCreateMutable(kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + CFDictionarySetValue(entry, CFSTR(kIOHIDDeviceUsagePageKey), (void *)pageRef); + CFDictionarySetValue(entry, CFSTR(kIOHIDDeviceUsageKey), (void *)usageRef); + CFArrayAppendValue(matching, entry); + CFRelease(usageRef); + CFRelease(pageRef); + CFRelease(entry); + + uint32 vendor = 0x28DE; // Valve, apparently + CFNumberRef vendorRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &vendor); + entry = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + CFDictionarySetValue(entry, CFSTR(kIOHIDVendorIDKey), (void *)pageRef); + CFArrayAppendValue(matching, entry); + CFRelease(vendorRef); + CFRelease(entry); + + IOHIDManagerSetDeviceMatchingMultiple(hidManager, matching); + CFRelease(matching); ParseDefaults(); diff --git a/macosx/mac-os.mm b/macosx/mac-os.mm index 8b5a7814..7bd51581 100644 --- a/macosx/mac-os.mm +++ b/macosx/mac-os.mm @@ -3286,7 +3286,7 @@ void QuitWithFatalError ( NSString *message) { pthread_mutex_lock(&keyLock); NSMutableArray *inputs = [NSMutableArray new]; - std::unordered_map buttonCodeMap = GetJuypadButtons(vendorID, productID, index); + std::unordered_map buttonCodeMap = GetJoypadButtons(vendorID, productID, index); for (auto it = buttonCodeMap.begin(); it != buttonCodeMap.end(); ++it) { S9xJoypadInput *input = [S9xJoypadInput new];