Merge pull request #5276 from ligfx/macosheadless

Add headless support on macOS
This commit is contained in:
shuffle2
2017-06-05 20:49:02 -07:00
committed by GitHub
6 changed files with 79 additions and 56 deletions

View File

@ -173,13 +173,21 @@ static void DeviceMatchingCallback(void* inContext, IOReturn inResult, void* inS
// Add a device if it's of a type we want
if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard))
g_controller_interface.AddDevice(std::make_shared<Keyboard>(inIOHIDDeviceRef, name, g_window));
{
if (g_window)
g_controller_interface.AddDevice(
std::make_shared<Keyboard>(inIOHIDDeviceRef, name, g_window));
}
#if 0
else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse))
{
g_controller_interface.AddDevice(new Mouse(inIOHIDDeviceRef, name));
}
#endif
else
{
g_controller_interface.AddDevice(std::make_shared<Joystick>(inIOHIDDeviceRef, name));
}
NOTICE_LOG(SERIALINTERFACE, "Added device: %s", name.c_str());
g_controller_interface.InvokeHotplugCallbacks();
@ -187,12 +195,12 @@ static void DeviceMatchingCallback(void* inContext, IOReturn inResult, void* inS
void Init(void* window)
{
g_window = window;
HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!HIDManager)
ERROR_LOG(SERIALINTERFACE, "Failed to create HID Manager reference");
g_window = window;
IOHIDManagerSetDeviceMatching(HIDManager, nullptr);
if (IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess)
ERROR_LOG(SERIALINTERFACE, "Failed to open HID Manager");

View File

@ -12,6 +12,9 @@ namespace Quartz
{
void PopulateDevices(void* window)
{
if (!window)
return;
g_controller_interface.AddDevice(std::make_shared<KeyboardAndMouse>(window));
}