Skip to content

Commit

Permalink
SDL 2.0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
FrodeSolheim committed Dec 19, 2021
1 parent 596d803 commit 00cdb53
Showing 1 changed file with 2 additions and 66 deletions.
68 changes: 2 additions & 66 deletions fsdeps/packages/SDL2
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set -e
# Dependency: pulseaudio?
# Dependency: wayland?

PACKAGE=SDL2-2.0.16
CHECKSUM=65be9ff6004034b5b2ce9927b5a4db1814930f169c4b2dae0a1e4697075f287b
PACKAGE=SDL2-2.0.18
CHECKSUM=94d40cd73dbfa10bb6eadfbc28f355992bb2d6ef6761ad9d4074eff95ee5711c
REVISION=0

. fsdeps/dep.sh
Expand All @@ -19,70 +19,6 @@ rm -Rf fsdeps/_build && mkdir fsdeps/_build && cd fsdeps/_build
tar xf ../_sources/$PACKAGE.tar.gz
cd $PACKAGE

if [ "`uname`" = "xxx-Darwin" ]; then
patch -p1 <<EOF
diff --git a/src/hidapi/mac/hid.c b/src/hidapi/mac/hid.c
index 1ad042d49..9ab934cab 100644
--- a/src/hidapi/mac/hid.c
+++ b/src/hidapi/mac/hid.c
@@ -399,6 +399,28 @@ static void hid_device_removal_callback(void *context, IOReturn result,
}
}
+static CFDictionaryRef CreateHIDDeviceMatchDictionary(const int page, const int usage)
+{
+ CFDictionaryRef retval = NULL;
+ CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
+ CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
+ const void *keys[2] = { (void *) CFSTR(kIOHIDDeviceUsagePageKey), (void *) CFSTR(kIOHIDDeviceUsageKey) };
+ const void *vals[2] = { (void *) pageNumRef, (void *) usageNumRef };
+
+ if (pageNumRef && usageNumRef) {
+ retval = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+ }
+
+ if (pageNumRef) {
+ CFRelease(pageNumRef);
+ }
+ if (usageNumRef) {
+ CFRelease(usageNumRef);
+ }
+
+ return retval;
+}
+
/* Initialize the IOHIDManager. Return 0 for success and -1 for failure. */
static int init_hid_manager(void)
{
@@ -406,7 +428,24 @@ static int init_hid_manager(void)
/* Initialize all the HID Manager Objects */
hid_mgr = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (hid_mgr) {
- IOHIDManagerSetDeviceMatching(hid_mgr, NULL);
+
+ /* Enumerating all HID devices results in macOS asking permission for the SDL
+ application to monitor all keystrokes! Therefore we need to enumerate only the
+ types of devices we need. */
+ const void *device_types[] = {
+ (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick),
+ (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad),
+ (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController),
+ };
+ CFArrayRef array = CFArrayCreate(kCFAllocatorDefault, device_types, 3, &kCFTypeArrayCallBacks);
+
+ IOHIDManagerSetDeviceMatchingMultiple(hid_mgr, array);
+
+ CFRelease(array);
+ CFRelease(device_types[0]);
+ CFRelease(device_types[1]);
+ CFRelease(device_types[2]);
+
IOHIDManagerScheduleWithRunLoop(hid_mgr, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDManagerRegisterDeviceRemovalCallback(hid_mgr, hid_device_removal_callback, NULL);
return 0;
EOF
fi

if [ "`uname`" = "Darwin" ]; then
python3 ../../replace.py \
src/video/cocoa/SDL_cocoaevents.m \
Expand Down

0 comments on commit 00cdb53

Please sign in to comment.