|
@@ -12,77 +12,21 @@
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
#include "inputDeviceManager.h"
|
|
#include "inputDeviceManager.h"
|
|
|
-#include "ioKitInputDevice.h"
|
|
|
|
|
|
|
+#include "ioKitInputDeviceManager.h"
|
|
|
#include "linuxInputDeviceManager.h"
|
|
#include "linuxInputDeviceManager.h"
|
|
|
#include "winInputDeviceManager.h"
|
|
#include "winInputDeviceManager.h"
|
|
|
#include "throw_event.h"
|
|
#include "throw_event.h"
|
|
|
|
|
|
|
|
-InputDeviceManager *InputDeviceManager::_global_ptr = NULL;
|
|
|
|
|
|
|
+InputDeviceManager *InputDeviceManager::_global_ptr = nullptr;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 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
|
|
|
* listening for future device connect events.
|
|
* listening for future device connect events.
|
|
|
*/
|
|
*/
|
|
|
-#if defined(__APPLE__)
|
|
|
|
|
-InputDeviceManager::
|
|
|
|
|
-InputDeviceManager() {
|
|
|
|
|
- _hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
|
|
|
|
|
- if (!_hid_manager) {
|
|
|
|
|
- device_cat.error()
|
|
|
|
|
- << "Failed to create an IOHIDManager.\n";
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // The types of devices we're interested in.
|
|
|
|
|
- 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;
|
|
|
|
|
-
|
|
|
|
|
- // 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);
|
|
|
|
|
- while (*usage) {
|
|
|
|
|
- CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
|
|
|
|
|
- CFNumberRef page_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
|
|
|
|
|
- CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsagePageKey), page_ref);
|
|
|
|
|
- CFRelease(page_ref);
|
|
|
|
|
- CFNumberRef usage_ref = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, usage);
|
|
|
|
|
- CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsageKey), usage_ref);
|
|
|
|
|
- CFRelease(usage_ref);
|
|
|
|
|
- CFArrayAppendValue(match, dict);
|
|
|
|
|
- CFRelease(dict);
|
|
|
|
|
- ++usage;
|
|
|
|
|
- }
|
|
|
|
|
- IOHIDManagerSetDeviceMatchingMultiple(_hid_manager, match);
|
|
|
|
|
- CFRelease(match);
|
|
|
|
|
-
|
|
|
|
|
- IOHIDManagerRegisterDeviceMatchingCallback(_hid_manager, on_match_device, this);
|
|
|
|
|
- IOHIDManagerScheduleWithRunLoop(_hid_manager, CFRunLoopGetMain(), kCFRunLoopCommonModes);
|
|
|
|
|
- IOHIDManagerOpen(_hid_manager, kIOHIDOptionsTypeNone);
|
|
|
|
|
-}
|
|
|
|
|
-#else
|
|
|
|
|
InputDeviceManager::
|
|
InputDeviceManager::
|
|
|
InputDeviceManager() : _lock("InputDeviceManager") {
|
|
InputDeviceManager() : _lock("InputDeviceManager") {
|
|
|
}
|
|
}
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * Closes any resources that the device manager was using to listen for events.
|
|
|
|
|
- */
|
|
|
|
|
-InputDeviceManager::
|
|
|
|
|
-~InputDeviceManager() {
|
|
|
|
|
-#if defined(__APPLE__)
|
|
|
|
|
- IOHIDManagerUnscheduleFromRunLoop(_hid_manager, CFRunLoopGetMain(), kCFRunLoopCommonModes);
|
|
|
|
|
- IOHIDManagerClose(_hid_manager, kIOHIDOptionsTypeNone);
|
|
|
|
|
- CFRelease(_hid_manager);
|
|
|
|
|
-#endif
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Creates the global input manager.
|
|
* Creates the global input manager.
|
|
@@ -91,6 +35,8 @@ void InputDeviceManager::
|
|
|
make_global_ptr() {
|
|
make_global_ptr() {
|
|
|
#ifdef _WIN32
|
|
#ifdef _WIN32
|
|
|
_global_ptr = new WinInputDeviceManager;
|
|
_global_ptr = new WinInputDeviceManager;
|
|
|
|
|
+#elif defined(__APPLE__)
|
|
|
|
|
+ _global_ptr = new IOKitInputDeviceManager;
|
|
|
#elif defined(PHAVE_LINUX_INPUT_H)
|
|
#elif defined(PHAVE_LINUX_INPUT_H)
|
|
|
_global_ptr = new LinuxInputDeviceManager;
|
|
_global_ptr = new LinuxInputDeviceManager;
|
|
|
#else
|
|
#else
|