Browse Source

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
rdb 3 years ago
parent
commit
38bea01dab
1 changed files with 23 additions and 4 deletions
  1. 23 4
      panda/src/device/ioKitInputDeviceManager.cxx

+ 23 - 4
panda/src/device/ioKitInputDeviceManager.cxx

@@ -16,6 +16,18 @@
 
 
 #if defined(__APPLE__) && !defined(CPPPARSER)
 #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
  * Initializes the input device manager by scanning which devices are currently
  * connected and setting up any platform-dependent structures necessary for
  * connected and setting up any platform-dependent structures necessary for
@@ -34,15 +46,22 @@ IOKitInputDeviceManager() {
   int page = kHIDPage_GenericDesktop;
   int page = kHIDPage_GenericDesktop;
   int usages[] = {kHIDUsage_GD_GamePad,
   int usages[] = {kHIDUsage_GD_GamePad,
                   kHIDUsage_GD_Joystick,
                   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
   // This giant mess is necessary to create an array of match dictionaries
   // that will match the devices we're interested in.
   // that will match the devices we're interested in.
   CFMutableArrayRef match = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
   CFMutableArrayRef match = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
   nassertv(match);
   nassertv(match);
+  int *usage = usages;
   while (*usage) {
   while (*usage) {
     CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
     CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
     CFNumberRef page_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
     CFNumberRef page_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);