Skip to content

Commit

Permalink
macOS: Fix keyboard settings warning
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBuckley committed Jul 14, 2024
1 parent 43b6efb commit 7c9c220
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion macosx/mac-joypad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<struct JoypadInput, S9xButtonCode> GetJuypadButtons(uint32 vendorID, uint32 productID, uint32 index);
std::unordered_map<struct JoypadInput, S9xButtonCode> GetJoypadButtons(uint32 vendorID, uint32 productID, uint32 index);

std::string LabelForInput(uint32 vendorID, uint32 productID, uint32 cookie, int32 value);

Expand Down
47 changes: 45 additions & 2 deletions macosx/mac-joypad.mm
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ void ClearJoypad(uint32 vendorID, uint32 productID, uint32 index)
}
}

std::unordered_map<struct JoypadInput, S9xButtonCode> GetJuypadButtons(uint32 vendorID, uint32 productID, uint32 index)
std::unordered_map<struct JoypadInput, S9xButtonCode> GetJoypadButtons(uint32 vendorID, uint32 productID, uint32 index)
{
struct JoypadDevice device;
device.vendorID = vendorID;
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion macosx/mac-os.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3286,7 +3286,7 @@ - (void)clearJoypadForVendorID:(uint32)vendorID productID:(uint32)productID inde
{
pthread_mutex_lock(&keyLock);
NSMutableArray<S9xJoypadInput *> *inputs = [NSMutableArray new];
std::unordered_map<struct JoypadInput, S9xButtonCode> buttonCodeMap = GetJuypadButtons(vendorID, productID, index);
std::unordered_map<struct JoypadInput, S9xButtonCode> buttonCodeMap = GetJoypadButtons(vendorID, productID, index);
for (auto it = buttonCodeMap.begin(); it != buttonCodeMap.end(); ++it)
{
S9xJoypadInput *input = [S9xJoypadInput new];
Expand Down

0 comments on commit 7c9c220

Please sign in to comment.