From 38bea01dab8f4dedd5fce9f8b9e82cebbf663189 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 22 Jan 2022 15:45:00 +0100 Subject: [PATCH] device: Do not enumerate keyboard/mouse devices on macOS by default This causes an annoying "this app would like to receive keystrokes from any application" alert to be shown Enable iokit-scan-mouse-devices or iokit-scan-keyboard-devices to restore the old behavior --- panda/src/device/ioKitInputDeviceManager.cxx | 27 +++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/panda/src/device/ioKitInputDeviceManager.cxx b/panda/src/device/ioKitInputDeviceManager.cxx index 3f1c807469..aa8d67301c 100644 --- a/panda/src/device/ioKitInputDeviceManager.cxx +++ b/panda/src/device/ioKitInputDeviceManager.cxx @@ -16,6 +16,18 @@ #if defined(__APPLE__) && !defined(CPPPARSER) +static ConfigVariableBool iokit_scan_mouse_devices +("iokit-scan-mouse-devices", false, + PRC_DESC("Set this to true to enable capturing raw mouse data via IOKit on " + "macOS. This is disabled by default because newer macOS versions " + "will prompt the user explicitly for permissions when this is on.")); + +static ConfigVariableBool iokit_scan_keyboard_devices +("iokit-scan-keyboard-devices", false, + PRC_DESC("Set this to true to enable capturing raw keyboard data via IOKit on " + "macOS. This is disabled by default because newer macOS versions " + "will prompt the user explicitly for permissions when this is on.")); + /** * Initializes the input device manager by scanning which devices are currently * connected and setting up any platform-dependent structures necessary for @@ -34,15 +46,22 @@ IOKitInputDeviceManager() { int page = kHIDPage_GenericDesktop; int usages[] = {kHIDUsage_GD_GamePad, kHIDUsage_GD_Joystick, - kHIDUsage_GD_Mouse, - kHIDUsage_GD_Keyboard, - kHIDUsage_GD_MultiAxisController, 0}; - int *usage = usages; + kHIDUsage_GD_MultiAxisController, + 0, 0, 0}; + + int num_usages = 3; + if (iokit_scan_mouse_devices) { + usages[num_usages++] = kHIDUsage_GD_Mouse; + } + if (iokit_scan_keyboard_devices) { + usages[num_usages++] = kHIDUsage_GD_Keyboard; + } // This giant mess is necessary to create an array of match dictionaries // that will match the devices we're interested in. CFMutableArrayRef match = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); nassertv(match); + int *usage = usages; while (*usage) { CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFNumberRef page_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);