mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Reformat all the things. Have fun with merge conflicts.
This commit is contained in:
@ -10,11 +10,9 @@ namespace ciface
|
||||
{
|
||||
namespace OSX
|
||||
{
|
||||
|
||||
void Init(std::vector<Core::Device*>& devices, void *window);
|
||||
void Init(std::vector<Core::Device*>& devices, void* window);
|
||||
void DeInit();
|
||||
|
||||
void DeviceElementDebugPrint(const void *, void *);
|
||||
|
||||
void DeviceElementDebugPrint(const void*, void*);
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,13 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <IOKit/hid/IOHIDLib.h>
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
#include "InputCommon/ControllerInterface/OSX/OSX.h"
|
||||
#include "InputCommon/ControllerInterface/OSX/OSXKeyboard.h"
|
||||
#include "InputCommon/ControllerInterface/OSX/OSXJoystick.h"
|
||||
#include "InputCommon/ControllerInterface/OSX/OSXKeyboard.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
@ -16,103 +16,94 @@ namespace ciface
|
||||
{
|
||||
namespace OSX
|
||||
{
|
||||
|
||||
|
||||
static IOHIDManagerRef HIDManager = nullptr;
|
||||
static CFStringRef OurRunLoop = CFSTR("DolphinOSXInput");
|
||||
static std::map<std::string, int> kbd_name_counts, joy_name_counts;
|
||||
|
||||
void DeviceElementDebugPrint(const void *value, void *context)
|
||||
void DeviceElementDebugPrint(const void* value, void* context)
|
||||
{
|
||||
IOHIDElementRef e = (IOHIDElementRef)value;
|
||||
bool recurse = false;
|
||||
if (context)
|
||||
recurse = *(bool*)context;
|
||||
IOHIDElementRef e = (IOHIDElementRef)value;
|
||||
bool recurse = false;
|
||||
if (context)
|
||||
recurse = *(bool*)context;
|
||||
|
||||
std::string type = "";
|
||||
switch (IOHIDElementGetType(e))
|
||||
{
|
||||
case kIOHIDElementTypeInput_Axis:
|
||||
type = "axis";
|
||||
break;
|
||||
case kIOHIDElementTypeInput_Button:
|
||||
type = "button";
|
||||
break;
|
||||
case kIOHIDElementTypeInput_Misc:
|
||||
type = "misc";
|
||||
break;
|
||||
case kIOHIDElementTypeInput_ScanCodes:
|
||||
type = "scancodes";
|
||||
break;
|
||||
case kIOHIDElementTypeOutput:
|
||||
type = "output";
|
||||
break;
|
||||
case kIOHIDElementTypeFeature:
|
||||
type = "feature";
|
||||
break;
|
||||
case kIOHIDElementTypeCollection:
|
||||
type = "collection";
|
||||
break;
|
||||
}
|
||||
std::string type = "";
|
||||
switch (IOHIDElementGetType(e))
|
||||
{
|
||||
case kIOHIDElementTypeInput_Axis:
|
||||
type = "axis";
|
||||
break;
|
||||
case kIOHIDElementTypeInput_Button:
|
||||
type = "button";
|
||||
break;
|
||||
case kIOHIDElementTypeInput_Misc:
|
||||
type = "misc";
|
||||
break;
|
||||
case kIOHIDElementTypeInput_ScanCodes:
|
||||
type = "scancodes";
|
||||
break;
|
||||
case kIOHIDElementTypeOutput:
|
||||
type = "output";
|
||||
break;
|
||||
case kIOHIDElementTypeFeature:
|
||||
type = "feature";
|
||||
break;
|
||||
case kIOHIDElementTypeCollection:
|
||||
type = "collection";
|
||||
break;
|
||||
}
|
||||
|
||||
std::string c_type = "";
|
||||
if (type == "collection")
|
||||
{
|
||||
switch (IOHIDElementGetCollectionType(e))
|
||||
{
|
||||
case kIOHIDElementCollectionTypePhysical:
|
||||
c_type = "physical";
|
||||
break;
|
||||
case kIOHIDElementCollectionTypeApplication:
|
||||
c_type = "application";
|
||||
break;
|
||||
case kIOHIDElementCollectionTypeLogical:
|
||||
c_type = "logical";
|
||||
break;
|
||||
case kIOHIDElementCollectionTypeReport:
|
||||
c_type = "report";
|
||||
break;
|
||||
case kIOHIDElementCollectionTypeNamedArray:
|
||||
c_type = "namedArray";
|
||||
break;
|
||||
case kIOHIDElementCollectionTypeUsageSwitch:
|
||||
c_type = "usageSwitch";
|
||||
break;
|
||||
case kIOHIDElementCollectionTypeUsageModifier:
|
||||
c_type = "usageModifier";
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::string c_type = "";
|
||||
if (type == "collection")
|
||||
{
|
||||
switch (IOHIDElementGetCollectionType(e))
|
||||
{
|
||||
case kIOHIDElementCollectionTypePhysical:
|
||||
c_type = "physical";
|
||||
break;
|
||||
case kIOHIDElementCollectionTypeApplication:
|
||||
c_type = "application";
|
||||
break;
|
||||
case kIOHIDElementCollectionTypeLogical:
|
||||
c_type = "logical";
|
||||
break;
|
||||
case kIOHIDElementCollectionTypeReport:
|
||||
c_type = "report";
|
||||
break;
|
||||
case kIOHIDElementCollectionTypeNamedArray:
|
||||
c_type = "namedArray";
|
||||
break;
|
||||
case kIOHIDElementCollectionTypeUsageSwitch:
|
||||
c_type = "usageSwitch";
|
||||
break;
|
||||
case kIOHIDElementCollectionTypeUsageModifier:
|
||||
c_type = "usageModifier";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
c_type.append(" ");
|
||||
NSLog(@"%s%s%spage: 0x%x usage: 0x%x name: %@ "
|
||||
"lmin: %ld lmax: %ld pmin: %ld pmax: %ld",
|
||||
type.c_str(),
|
||||
type == "collection" ? ":" : "",
|
||||
type == "collection" ? c_type.c_str() : " ",
|
||||
IOHIDElementGetUsagePage(e),
|
||||
IOHIDElementGetUsage(e),
|
||||
IOHIDElementGetName(e), // usually just nullptr
|
||||
IOHIDElementGetLogicalMin(e),
|
||||
IOHIDElementGetLogicalMax(e),
|
||||
IOHIDElementGetPhysicalMin(e),
|
||||
IOHIDElementGetPhysicalMax(e));
|
||||
c_type.append(" ");
|
||||
NSLog(@"%s%s%spage: 0x%x usage: 0x%x name: %@ "
|
||||
"lmin: %ld lmax: %ld pmin: %ld pmax: %ld",
|
||||
type.c_str(), type == "collection" ? ":" : "", type == "collection" ? c_type.c_str() : " ",
|
||||
IOHIDElementGetUsagePage(e), IOHIDElementGetUsage(e),
|
||||
IOHIDElementGetName(e), // usually just nullptr
|
||||
IOHIDElementGetLogicalMin(e), IOHIDElementGetLogicalMax(e), IOHIDElementGetPhysicalMin(e),
|
||||
IOHIDElementGetPhysicalMax(e));
|
||||
|
||||
if ((type == "collection") && recurse)
|
||||
{
|
||||
CFArrayRef elements = IOHIDElementGetChildren(e);
|
||||
CFRange range = {0, CFArrayGetCount(elements)};
|
||||
// this leaks...but it's just debug code, right? :D
|
||||
CFArrayApplyFunction(elements, range,
|
||||
DeviceElementDebugPrint, nullptr);
|
||||
}
|
||||
if ((type == "collection") && recurse)
|
||||
{
|
||||
CFArrayRef elements = IOHIDElementGetChildren(e);
|
||||
CFRange range = {0, CFArrayGetCount(elements)};
|
||||
// this leaks...but it's just debug code, right? :D
|
||||
CFArrayApplyFunction(elements, range, DeviceElementDebugPrint, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
static void DeviceDebugPrint(IOHIDDeviceRef device)
|
||||
{
|
||||
#if 0
|
||||
#define shortlog(x) NSLog(@"%s: %@", \
|
||||
x, IOHIDDeviceGetProperty(device, CFSTR(x)));
|
||||
#define shortlog(x) NSLog(@"%s: %@", x, IOHIDDeviceGetProperty(device, CFSTR(x)));
|
||||
NSLog(@"-------------------------");
|
||||
NSLog(@"Got Device: %@",
|
||||
IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)));
|
||||
@ -139,81 +130,68 @@ static void DeviceDebugPrint(IOHIDDeviceRef device)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void *g_window;
|
||||
static void* g_window;
|
||||
|
||||
static void DeviceMatching_callback(void* inContext,
|
||||
IOReturn inResult,
|
||||
void *inSender,
|
||||
IOHIDDeviceRef inIOHIDDeviceRef)
|
||||
static void DeviceMatching_callback(void* inContext, IOReturn inResult, void* inSender,
|
||||
IOHIDDeviceRef inIOHIDDeviceRef)
|
||||
{
|
||||
NSString *pName = (NSString *)
|
||||
IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDProductKey));
|
||||
std::string name = (pName != nullptr) ? [pName UTF8String] : "Unknown device";
|
||||
NSString* pName = (NSString*)IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDProductKey));
|
||||
std::string name = (pName != nullptr) ? [pName UTF8String] : "Unknown device";
|
||||
|
||||
DeviceDebugPrint(inIOHIDDeviceRef);
|
||||
DeviceDebugPrint(inIOHIDDeviceRef);
|
||||
|
||||
std::vector<Core::Device*> *devices =
|
||||
(std::vector<Core::Device*> *)inContext;
|
||||
std::vector<Core::Device*>* devices = (std::vector<Core::Device*>*)inContext;
|
||||
|
||||
// Add to the devices vector if it's of a type we want
|
||||
if (IOHIDDeviceConformsTo(inIOHIDDeviceRef,
|
||||
kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard))
|
||||
devices->push_back(new Keyboard(inIOHIDDeviceRef,
|
||||
name, kbd_name_counts[name]++, g_window));
|
||||
// Add to the devices vector if it's of a type we want
|
||||
if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard))
|
||||
devices->push_back(new Keyboard(inIOHIDDeviceRef, name, kbd_name_counts[name]++, g_window));
|
||||
#if 0
|
||||
else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef,
|
||||
kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse))
|
||||
devices->push_back(new Mouse(inIOHIDDeviceRef,
|
||||
name, mouse_name_counts[name]++));
|
||||
#endif
|
||||
else
|
||||
devices->push_back(new Joystick(inIOHIDDeviceRef,
|
||||
name, joy_name_counts[name]++));
|
||||
else
|
||||
devices->push_back(new Joystick(inIOHIDDeviceRef, name, joy_name_counts[name]++));
|
||||
}
|
||||
|
||||
void Init(std::vector<Core::Device*>& devices, void *window)
|
||||
void Init(std::vector<Core::Device*>& devices, void* window)
|
||||
{
|
||||
HIDManager = IOHIDManagerCreate(kCFAllocatorDefault,
|
||||
kIOHIDOptionsTypeNone);
|
||||
if (!HIDManager)
|
||||
NSLog(@"Failed to create HID Manager reference");
|
||||
HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
|
||||
if (!HIDManager)
|
||||
NSLog(@"Failed to create HID Manager reference");
|
||||
|
||||
g_window = window;
|
||||
g_window = window;
|
||||
|
||||
IOHIDManagerSetDeviceMatching(HIDManager, nullptr);
|
||||
IOHIDManagerSetDeviceMatching(HIDManager, nullptr);
|
||||
|
||||
// Callbacks for acquisition or loss of a matching device
|
||||
IOHIDManagerRegisterDeviceMatchingCallback(HIDManager,
|
||||
DeviceMatching_callback, (void *)&devices);
|
||||
// Callbacks for acquisition or loss of a matching device
|
||||
IOHIDManagerRegisterDeviceMatchingCallback(HIDManager, DeviceMatching_callback, (void*)&devices);
|
||||
|
||||
// Match devices that are plugged in right now
|
||||
IOHIDManagerScheduleWithRunLoop(HIDManager,
|
||||
CFRunLoopGetCurrent(), OurRunLoop);
|
||||
if (IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone) !=
|
||||
kIOReturnSuccess)
|
||||
NSLog(@"Failed to open HID Manager");
|
||||
// Match devices that are plugged in right now
|
||||
IOHIDManagerScheduleWithRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop);
|
||||
if (IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess)
|
||||
NSLog(@"Failed to open HID Manager");
|
||||
|
||||
kbd_name_counts.clear();
|
||||
joy_name_counts.clear();
|
||||
kbd_name_counts.clear();
|
||||
joy_name_counts.clear();
|
||||
|
||||
// Wait while current devices are initialized
|
||||
while (CFRunLoopRunInMode(OurRunLoop, 0, TRUE) ==
|
||||
kCFRunLoopRunHandledSource) {};
|
||||
// Wait while current devices are initialized
|
||||
while (CFRunLoopRunInMode(OurRunLoop, 0, TRUE) == kCFRunLoopRunHandledSource)
|
||||
{
|
||||
};
|
||||
|
||||
// Things should be configured now
|
||||
// Disable hotplugging and other scheduling
|
||||
IOHIDManagerRegisterDeviceMatchingCallback(HIDManager, nullptr, nullptr);
|
||||
IOHIDManagerUnscheduleFromRunLoop(HIDManager,
|
||||
CFRunLoopGetCurrent(), OurRunLoop);
|
||||
// Things should be configured now
|
||||
// Disable hotplugging and other scheduling
|
||||
IOHIDManagerRegisterDeviceMatchingCallback(HIDManager, nullptr, nullptr);
|
||||
IOHIDManagerUnscheduleFromRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop);
|
||||
}
|
||||
|
||||
void DeInit()
|
||||
{
|
||||
// This closes all devices as well
|
||||
IOHIDManagerClose(HIDManager, kIOHIDOptionsTypeNone);
|
||||
CFRelease(HIDManager);
|
||||
}
|
||||
|
||||
|
||||
// This closes all devices as well
|
||||
IOHIDManagerClose(HIDManager, kIOHIDOptionsTypeNone);
|
||||
CFRelease(HIDManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,81 +13,79 @@ namespace ciface
|
||||
{
|
||||
namespace OSX
|
||||
{
|
||||
|
||||
class Joystick : public ForceFeedback::ForceFeedbackDevice
|
||||
{
|
||||
private:
|
||||
class Button : public Input
|
||||
{
|
||||
public:
|
||||
Button(IOHIDElementRef element, IOHIDDeviceRef device)
|
||||
: m_element(element), m_device(device) {}
|
||||
std::string GetName() const override;
|
||||
ControlState GetState() const override;
|
||||
private:
|
||||
const IOHIDElementRef m_element;
|
||||
const IOHIDDeviceRef m_device;
|
||||
};
|
||||
class Button : public Input
|
||||
{
|
||||
public:
|
||||
Button(IOHIDElementRef element, IOHIDDeviceRef device) : m_element(element), m_device(device) {}
|
||||
std::string GetName() const override;
|
||||
ControlState GetState() const override;
|
||||
|
||||
class Axis : public Input
|
||||
{
|
||||
public:
|
||||
enum direction
|
||||
{
|
||||
positive = 0,
|
||||
negative
|
||||
};
|
||||
private:
|
||||
const IOHIDElementRef m_element;
|
||||
const IOHIDDeviceRef m_device;
|
||||
};
|
||||
|
||||
Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction dir);
|
||||
std::string GetName() const override;
|
||||
ControlState GetState() const override;
|
||||
class Axis : public Input
|
||||
{
|
||||
public:
|
||||
enum direction
|
||||
{
|
||||
positive = 0,
|
||||
negative
|
||||
};
|
||||
|
||||
private:
|
||||
const IOHIDElementRef m_element;
|
||||
const IOHIDDeviceRef m_device;
|
||||
std::string m_name;
|
||||
const direction m_direction;
|
||||
float m_neutral;
|
||||
float m_scale;
|
||||
};
|
||||
Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction dir);
|
||||
std::string GetName() const override;
|
||||
ControlState GetState() const override;
|
||||
|
||||
class Hat : public Input
|
||||
{
|
||||
public:
|
||||
enum direction
|
||||
{
|
||||
up = 0,
|
||||
right,
|
||||
down,
|
||||
left
|
||||
};
|
||||
private:
|
||||
const IOHIDElementRef m_element;
|
||||
const IOHIDDeviceRef m_device;
|
||||
std::string m_name;
|
||||
const direction m_direction;
|
||||
float m_neutral;
|
||||
float m_scale;
|
||||
};
|
||||
|
||||
Hat(IOHIDElementRef element, IOHIDDeviceRef device, direction dir);
|
||||
std::string GetName() const override;
|
||||
ControlState GetState() const override;
|
||||
class Hat : public Input
|
||||
{
|
||||
public:
|
||||
enum direction
|
||||
{
|
||||
up = 0,
|
||||
right,
|
||||
down,
|
||||
left
|
||||
};
|
||||
|
||||
private:
|
||||
const IOHIDElementRef m_element;
|
||||
const IOHIDDeviceRef m_device;
|
||||
const char* m_name;
|
||||
const direction m_direction;
|
||||
};
|
||||
Hat(IOHIDElementRef element, IOHIDDeviceRef device, direction dir);
|
||||
std::string GetName() const override;
|
||||
ControlState GetState() const override;
|
||||
|
||||
private:
|
||||
const IOHIDElementRef m_element;
|
||||
const IOHIDDeviceRef m_device;
|
||||
const char* m_name;
|
||||
const direction m_direction;
|
||||
};
|
||||
|
||||
public:
|
||||
Joystick(IOHIDDeviceRef device, std::string name, int index);
|
||||
~Joystick();
|
||||
Joystick(IOHIDDeviceRef device, std::string name, int index);
|
||||
~Joystick();
|
||||
|
||||
std::string GetName() const override;
|
||||
std::string GetSource() const override;
|
||||
int GetId() const override;
|
||||
std::string GetName() const override;
|
||||
std::string GetSource() const override;
|
||||
int GetId() const override;
|
||||
|
||||
private:
|
||||
const IOHIDDeviceRef m_device;
|
||||
const std::string m_device_name;
|
||||
const int m_index;
|
||||
const IOHIDDeviceRef m_device;
|
||||
const std::string m_device_name;
|
||||
const int m_index;
|
||||
|
||||
ForceFeedback::FFDeviceAdapterReference m_ff_device;
|
||||
ForceFeedback::FFDeviceAdapterReference m_ff_device;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -13,281 +13,266 @@ namespace ciface
|
||||
{
|
||||
namespace OSX
|
||||
{
|
||||
|
||||
|
||||
Joystick::Joystick(IOHIDDeviceRef device, std::string name, int index)
|
||||
: m_device(device)
|
||||
, m_device_name(name)
|
||||
, m_index(index)
|
||||
, m_ff_device(nullptr)
|
||||
: m_device(device), m_device_name(name), m_index(index), m_ff_device(nullptr)
|
||||
{
|
||||
// Buttons
|
||||
NSDictionary *buttonDict = @{
|
||||
@kIOHIDElementTypeKey : @(kIOHIDElementTypeInput_Button),
|
||||
@kIOHIDElementUsagePageKey : @(kHIDPage_Button)
|
||||
};
|
||||
// Buttons
|
||||
NSDictionary* buttonDict = @{
|
||||
@kIOHIDElementTypeKey : @(kIOHIDElementTypeInput_Button),
|
||||
@kIOHIDElementUsagePageKey : @(kHIDPage_Button)
|
||||
};
|
||||
|
||||
CFArrayRef buttons = IOHIDDeviceCopyMatchingElements(m_device,
|
||||
(CFDictionaryRef)buttonDict, kIOHIDOptionsTypeNone);
|
||||
CFArrayRef buttons =
|
||||
IOHIDDeviceCopyMatchingElements(m_device, (CFDictionaryRef)buttonDict, kIOHIDOptionsTypeNone);
|
||||
|
||||
if (buttons)
|
||||
{
|
||||
for (int i = 0; i < CFArrayGetCount(buttons); i++)
|
||||
{
|
||||
IOHIDElementRef e =
|
||||
(IOHIDElementRef)CFArrayGetValueAtIndex(buttons, i);
|
||||
//DeviceElementDebugPrint(e, nullptr);
|
||||
if (buttons)
|
||||
{
|
||||
for (int i = 0; i < CFArrayGetCount(buttons); i++)
|
||||
{
|
||||
IOHIDElementRef e = (IOHIDElementRef)CFArrayGetValueAtIndex(buttons, i);
|
||||
// DeviceElementDebugPrint(e, nullptr);
|
||||
|
||||
AddInput(new Button(e, m_device));
|
||||
}
|
||||
CFRelease(buttons);
|
||||
}
|
||||
AddInput(new Button(e, m_device));
|
||||
}
|
||||
CFRelease(buttons);
|
||||
}
|
||||
|
||||
// Axes
|
||||
NSDictionary *axisDict = @{
|
||||
@kIOHIDElementTypeKey : @(kIOHIDElementTypeInput_Misc)
|
||||
};
|
||||
// Axes
|
||||
NSDictionary* axisDict = @{ @kIOHIDElementTypeKey : @(kIOHIDElementTypeInput_Misc) };
|
||||
|
||||
CFArrayRef axes = IOHIDDeviceCopyMatchingElements(m_device,
|
||||
(CFDictionaryRef)axisDict, kIOHIDOptionsTypeNone);
|
||||
CFArrayRef axes =
|
||||
IOHIDDeviceCopyMatchingElements(m_device, (CFDictionaryRef)axisDict, kIOHIDOptionsTypeNone);
|
||||
|
||||
if (axes)
|
||||
{
|
||||
for (int i = 0; i < CFArrayGetCount(axes); i++)
|
||||
{
|
||||
IOHIDElementRef e =
|
||||
(IOHIDElementRef)CFArrayGetValueAtIndex(axes, i);
|
||||
//DeviceElementDebugPrint(e, nullptr);
|
||||
if (axes)
|
||||
{
|
||||
for (int i = 0; i < CFArrayGetCount(axes); i++)
|
||||
{
|
||||
IOHIDElementRef e = (IOHIDElementRef)CFArrayGetValueAtIndex(axes, i);
|
||||
// DeviceElementDebugPrint(e, nullptr);
|
||||
|
||||
if (IOHIDElementGetUsage(e) == kHIDUsage_GD_Hatswitch)
|
||||
{
|
||||
AddInput(new Hat(e, m_device, Hat::up));
|
||||
AddInput(new Hat(e, m_device, Hat::right));
|
||||
AddInput(new Hat(e, m_device, Hat::down));
|
||||
AddInput(new Hat(e, m_device, Hat::left));
|
||||
}
|
||||
else
|
||||
{
|
||||
AddAnalogInputs(new Axis(e, m_device, Axis::negative),
|
||||
new Axis(e, m_device, Axis::positive));
|
||||
}
|
||||
}
|
||||
CFRelease(axes);
|
||||
}
|
||||
if (IOHIDElementGetUsage(e) == kHIDUsage_GD_Hatswitch)
|
||||
{
|
||||
AddInput(new Hat(e, m_device, Hat::up));
|
||||
AddInput(new Hat(e, m_device, Hat::right));
|
||||
AddInput(new Hat(e, m_device, Hat::down));
|
||||
AddInput(new Hat(e, m_device, Hat::left));
|
||||
}
|
||||
else
|
||||
{
|
||||
AddAnalogInputs(new Axis(e, m_device, Axis::negative),
|
||||
new Axis(e, m_device, Axis::positive));
|
||||
}
|
||||
}
|
||||
CFRelease(axes);
|
||||
}
|
||||
|
||||
// Force Feedback
|
||||
FFCAPABILITIES ff_caps;
|
||||
if (SUCCEEDED(ForceFeedback::FFDeviceAdapter::Create(IOHIDDeviceGetService(m_device), &m_ff_device)) &&
|
||||
SUCCEEDED(FFDeviceGetForceFeedbackCapabilities(m_ff_device->m_device, &ff_caps)))
|
||||
{
|
||||
InitForceFeedback(m_ff_device, ff_caps.numFfAxes);
|
||||
}
|
||||
// Force Feedback
|
||||
FFCAPABILITIES ff_caps;
|
||||
if (SUCCEEDED(
|
||||
ForceFeedback::FFDeviceAdapter::Create(IOHIDDeviceGetService(m_device), &m_ff_device)) &&
|
||||
SUCCEEDED(FFDeviceGetForceFeedbackCapabilities(m_ff_device->m_device, &ff_caps)))
|
||||
{
|
||||
InitForceFeedback(m_ff_device, ff_caps.numFfAxes);
|
||||
}
|
||||
}
|
||||
|
||||
Joystick::~Joystick()
|
||||
{
|
||||
if (m_ff_device)
|
||||
m_ff_device->Release();
|
||||
if (m_ff_device)
|
||||
m_ff_device->Release();
|
||||
}
|
||||
|
||||
std::string Joystick::GetName() const
|
||||
{
|
||||
return m_device_name;
|
||||
return m_device_name;
|
||||
}
|
||||
|
||||
std::string Joystick::GetSource() const
|
||||
{
|
||||
return "Input";
|
||||
return "Input";
|
||||
}
|
||||
|
||||
int Joystick::GetId() const
|
||||
{
|
||||
return m_index;
|
||||
return m_index;
|
||||
}
|
||||
|
||||
ControlState Joystick::Button::GetState() const
|
||||
{
|
||||
IOHIDValueRef value;
|
||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
||||
return IOHIDValueGetIntegerValue(value);
|
||||
else
|
||||
return 0;
|
||||
IOHIDValueRef value;
|
||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
||||
return IOHIDValueGetIntegerValue(value);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string Joystick::Button::GetName() const
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << IOHIDElementGetUsage(m_element);
|
||||
return std::string("Button ") + s.str();
|
||||
std::ostringstream s;
|
||||
s << IOHIDElementGetUsage(m_element);
|
||||
return std::string("Button ") + s.str();
|
||||
}
|
||||
|
||||
Joystick::Axis::Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction dir)
|
||||
: m_element(element)
|
||||
, m_device(device)
|
||||
, m_direction(dir)
|
||||
: m_element(element), m_device(device), m_direction(dir)
|
||||
{
|
||||
// Need to parse the element a bit first
|
||||
std::string description("unk");
|
||||
// Need to parse the element a bit first
|
||||
std::string description("unk");
|
||||
|
||||
int const usage = IOHIDElementGetUsage(m_element);
|
||||
switch (usage)
|
||||
{
|
||||
case kHIDUsage_GD_X:
|
||||
description = "X";
|
||||
break;
|
||||
case kHIDUsage_GD_Y:
|
||||
description = "Y";
|
||||
break;
|
||||
case kHIDUsage_GD_Z:
|
||||
description = "Z";
|
||||
break;
|
||||
case kHIDUsage_GD_Rx:
|
||||
description = "Rx";
|
||||
break;
|
||||
case kHIDUsage_GD_Ry:
|
||||
description = "Ry";
|
||||
break;
|
||||
case kHIDUsage_GD_Rz:
|
||||
description = "Rz";
|
||||
break;
|
||||
case kHIDUsage_GD_Wheel:
|
||||
description = "Wheel";
|
||||
break;
|
||||
case kHIDUsage_Csmr_ACPan:
|
||||
description = "Pan";
|
||||
break;
|
||||
default:
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << usage;
|
||||
description = s.str();
|
||||
break;
|
||||
}
|
||||
}
|
||||
int const usage = IOHIDElementGetUsage(m_element);
|
||||
switch (usage)
|
||||
{
|
||||
case kHIDUsage_GD_X:
|
||||
description = "X";
|
||||
break;
|
||||
case kHIDUsage_GD_Y:
|
||||
description = "Y";
|
||||
break;
|
||||
case kHIDUsage_GD_Z:
|
||||
description = "Z";
|
||||
break;
|
||||
case kHIDUsage_GD_Rx:
|
||||
description = "Rx";
|
||||
break;
|
||||
case kHIDUsage_GD_Ry:
|
||||
description = "Ry";
|
||||
break;
|
||||
case kHIDUsage_GD_Rz:
|
||||
description = "Rz";
|
||||
break;
|
||||
case kHIDUsage_GD_Wheel:
|
||||
description = "Wheel";
|
||||
break;
|
||||
case kHIDUsage_Csmr_ACPan:
|
||||
description = "Pan";
|
||||
break;
|
||||
default:
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << usage;
|
||||
description = s.str();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_name = std::string("Axis ") + description;
|
||||
m_name.append((m_direction == positive) ? "+" : "-");
|
||||
m_name = std::string("Axis ") + description;
|
||||
m_name.append((m_direction == positive) ? "+" : "-");
|
||||
|
||||
m_neutral = (IOHIDElementGetLogicalMax(m_element) +
|
||||
IOHIDElementGetLogicalMin(m_element)) / 2.;
|
||||
m_scale = 1 / fabs(IOHIDElementGetLogicalMax(m_element) - m_neutral);
|
||||
m_neutral = (IOHIDElementGetLogicalMax(m_element) + IOHIDElementGetLogicalMin(m_element)) / 2.;
|
||||
m_scale = 1 / fabs(IOHIDElementGetLogicalMax(m_element) - m_neutral);
|
||||
}
|
||||
|
||||
ControlState Joystick::Axis::GetState() const
|
||||
{
|
||||
IOHIDValueRef value;
|
||||
IOHIDValueRef value;
|
||||
|
||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
||||
{
|
||||
// IOHIDValueGetIntegerValue() crashes when trying
|
||||
// to convert unusually large element values.
|
||||
if (IOHIDValueGetLength(value) > 2)
|
||||
return 0;
|
||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
||||
{
|
||||
// IOHIDValueGetIntegerValue() crashes when trying
|
||||
// to convert unusually large element values.
|
||||
if (IOHIDValueGetLength(value) > 2)
|
||||
return 0;
|
||||
|
||||
float position = IOHIDValueGetIntegerValue(value);
|
||||
float position = IOHIDValueGetIntegerValue(value);
|
||||
|
||||
if (m_direction == positive && position > m_neutral)
|
||||
return (position - m_neutral) * m_scale;
|
||||
if (m_direction == negative && position < m_neutral)
|
||||
return (m_neutral - position) * m_scale;
|
||||
}
|
||||
if (m_direction == positive && position > m_neutral)
|
||||
return (position - m_neutral) * m_scale;
|
||||
if (m_direction == negative && position < m_neutral)
|
||||
return (m_neutral - position) * m_scale;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string Joystick::Axis::GetName() const
|
||||
{
|
||||
return m_name;
|
||||
return m_name;
|
||||
}
|
||||
|
||||
Joystick::Hat::Hat(IOHIDElementRef element, IOHIDDeviceRef device, direction dir)
|
||||
: m_element(element)
|
||||
, m_device(device)
|
||||
, m_direction(dir)
|
||||
: m_element(element), m_device(device), m_direction(dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case up:
|
||||
m_name = "Up";
|
||||
break;
|
||||
case right:
|
||||
m_name = "Right";
|
||||
break;
|
||||
case down:
|
||||
m_name = "Down";
|
||||
break;
|
||||
case left:
|
||||
m_name = "Left";
|
||||
break;
|
||||
default:
|
||||
m_name = "unk";
|
||||
}
|
||||
switch (dir)
|
||||
{
|
||||
case up:
|
||||
m_name = "Up";
|
||||
break;
|
||||
case right:
|
||||
m_name = "Right";
|
||||
break;
|
||||
case down:
|
||||
m_name = "Down";
|
||||
break;
|
||||
case left:
|
||||
m_name = "Left";
|
||||
break;
|
||||
default:
|
||||
m_name = "unk";
|
||||
}
|
||||
}
|
||||
|
||||
ControlState Joystick::Hat::GetState() const
|
||||
{
|
||||
IOHIDValueRef value;
|
||||
IOHIDValueRef value;
|
||||
|
||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
||||
{
|
||||
int position = IOHIDValueGetIntegerValue(value);
|
||||
int min = IOHIDElementGetLogicalMin(m_element);
|
||||
int max = IOHIDElementGetLogicalMax(m_element);
|
||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
||||
{
|
||||
int position = IOHIDValueGetIntegerValue(value);
|
||||
int min = IOHIDElementGetLogicalMin(m_element);
|
||||
int max = IOHIDElementGetLogicalMax(m_element);
|
||||
|
||||
// if the position is outside the min or max, don't register it as a valid button press
|
||||
if (position < min || position > max)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// if the position is outside the min or max, don't register it as a valid button press
|
||||
if (position < min || position > max)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// normalize the position so that its lowest value is 0
|
||||
position -= min;
|
||||
// normalize the position so that its lowest value is 0
|
||||
position -= min;
|
||||
|
||||
switch (position)
|
||||
{
|
||||
case 0:
|
||||
if (m_direction == up)
|
||||
return 1;
|
||||
break;
|
||||
case 1:
|
||||
if (m_direction == up || m_direction == right)
|
||||
return 1;
|
||||
break;
|
||||
case 2:
|
||||
if (m_direction == right)
|
||||
return 1;
|
||||
break;
|
||||
case 3:
|
||||
if (m_direction == right || m_direction == down)
|
||||
return 1;
|
||||
break;
|
||||
case 4:
|
||||
if (m_direction == down)
|
||||
return 1;
|
||||
break;
|
||||
case 5:
|
||||
if (m_direction == down || m_direction == left)
|
||||
return 1;
|
||||
break;
|
||||
case 6:
|
||||
if (m_direction == left)
|
||||
return 1;
|
||||
break;
|
||||
case 7:
|
||||
if (m_direction == left || m_direction == up)
|
||||
return 1;
|
||||
break;
|
||||
};
|
||||
}
|
||||
switch (position)
|
||||
{
|
||||
case 0:
|
||||
if (m_direction == up)
|
||||
return 1;
|
||||
break;
|
||||
case 1:
|
||||
if (m_direction == up || m_direction == right)
|
||||
return 1;
|
||||
break;
|
||||
case 2:
|
||||
if (m_direction == right)
|
||||
return 1;
|
||||
break;
|
||||
case 3:
|
||||
if (m_direction == right || m_direction == down)
|
||||
return 1;
|
||||
break;
|
||||
case 4:
|
||||
if (m_direction == down)
|
||||
return 1;
|
||||
break;
|
||||
case 5:
|
||||
if (m_direction == down || m_direction == left)
|
||||
return 1;
|
||||
break;
|
||||
case 6:
|
||||
if (m_direction == left)
|
||||
return 1;
|
||||
break;
|
||||
case 7:
|
||||
if (m_direction == left || m_direction == up)
|
||||
return 1;
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string Joystick::Hat::GetName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
return m_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,67 +12,71 @@ namespace ciface
|
||||
{
|
||||
namespace OSX
|
||||
{
|
||||
|
||||
class Keyboard : public Core::Device
|
||||
{
|
||||
private:
|
||||
class Key : public Input
|
||||
{
|
||||
public:
|
||||
Key(IOHIDElementRef element, IOHIDDeviceRef device);
|
||||
std::string GetName() const override;
|
||||
ControlState GetState() const override;
|
||||
private:
|
||||
const IOHIDElementRef m_element;
|
||||
const IOHIDDeviceRef m_device;
|
||||
std::string m_name;
|
||||
};
|
||||
class Key : public Input
|
||||
{
|
||||
public:
|
||||
Key(IOHIDElementRef element, IOHIDDeviceRef device);
|
||||
std::string GetName() const override;
|
||||
ControlState GetState() const override;
|
||||
|
||||
class Cursor : public Input
|
||||
{
|
||||
public:
|
||||
Cursor(u8 index, const float& axis, const bool positive) : m_axis(axis), m_index(index), m_positive(positive) {}
|
||||
std::string GetName() const override;
|
||||
bool IsDetectable() override { return false; }
|
||||
ControlState GetState() const override;
|
||||
private:
|
||||
const float& m_axis;
|
||||
const u8 m_index;
|
||||
const bool m_positive;
|
||||
};
|
||||
private:
|
||||
const IOHIDElementRef m_element;
|
||||
const IOHIDDeviceRef m_device;
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
class Button : public Input
|
||||
{
|
||||
public:
|
||||
Button(u8 index, const unsigned char& button) : m_button(button), m_index(index) {}
|
||||
std::string GetName() const override;
|
||||
ControlState GetState() const override;
|
||||
private:
|
||||
const unsigned char& m_button;
|
||||
const u8 m_index;
|
||||
};
|
||||
class Cursor : public Input
|
||||
{
|
||||
public:
|
||||
Cursor(u8 index, const float& axis, const bool positive)
|
||||
: m_axis(axis), m_index(index), m_positive(positive)
|
||||
{
|
||||
}
|
||||
std::string GetName() const override;
|
||||
bool IsDetectable() override { return false; }
|
||||
ControlState GetState() const override;
|
||||
|
||||
private:
|
||||
const float& m_axis;
|
||||
const u8 m_index;
|
||||
const bool m_positive;
|
||||
};
|
||||
|
||||
class Button : public Input
|
||||
{
|
||||
public:
|
||||
Button(u8 index, const unsigned char& button) : m_button(button), m_index(index) {}
|
||||
std::string GetName() const override;
|
||||
ControlState GetState() const override;
|
||||
|
||||
private:
|
||||
const unsigned char& m_button;
|
||||
const u8 m_index;
|
||||
};
|
||||
|
||||
public:
|
||||
void UpdateInput() override;
|
||||
void UpdateInput() override;
|
||||
|
||||
Keyboard(IOHIDDeviceRef device, std::string name, int index, void *window);
|
||||
Keyboard(IOHIDDeviceRef device, std::string name, int index, void* window);
|
||||
|
||||
std::string GetName() const override;
|
||||
std::string GetSource() const override;
|
||||
int GetId() const override;
|
||||
std::string GetName() const override;
|
||||
std::string GetSource() const override;
|
||||
int GetId() const override;
|
||||
|
||||
private:
|
||||
struct
|
||||
{
|
||||
float x, y;
|
||||
} m_cursor;
|
||||
struct
|
||||
{
|
||||
float x, y;
|
||||
} m_cursor;
|
||||
|
||||
const IOHIDDeviceRef m_device;
|
||||
const std::string m_device_name;
|
||||
int m_index;
|
||||
uint32_t m_windowid;
|
||||
unsigned char m_mousebuttons[3];
|
||||
const IOHIDDeviceRef m_device;
|
||||
const std::string m_device_name;
|
||||
int m_index;
|
||||
uint32_t m_windowid;
|
||||
unsigned char m_mousebuttons[3];
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <IOKit/hid/IOHIDLib.h>
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
#include "InputCommon/ControllerInterface/OSX/OSXKeyboard.h"
|
||||
|
||||
@ -14,261 +14,259 @@ namespace ciface
|
||||
{
|
||||
namespace OSX
|
||||
{
|
||||
|
||||
Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index, void *window)
|
||||
: m_device(device)
|
||||
, m_device_name(name)
|
||||
, m_index(index)
|
||||
Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index, void* window)
|
||||
: m_device(device), m_device_name(name), m_index(index)
|
||||
{
|
||||
// This class should only recieve Keyboard or Keypad devices
|
||||
// Now, filter on just the buttons we can handle sanely
|
||||
NSDictionary *matchingElements = @{
|
||||
@kIOHIDElementTypeKey : @(kIOHIDElementTypeInput_Button),
|
||||
@kIOHIDElementMinKey : @0,
|
||||
@kIOHIDElementMaxKey : @1
|
||||
};
|
||||
// This class should only recieve Keyboard or Keypad devices
|
||||
// Now, filter on just the buttons we can handle sanely
|
||||
NSDictionary* matchingElements = @{
|
||||
@kIOHIDElementTypeKey : @(kIOHIDElementTypeInput_Button),
|
||||
@kIOHIDElementMinKey : @0,
|
||||
@kIOHIDElementMaxKey : @1
|
||||
};
|
||||
|
||||
CFArrayRef elements = IOHIDDeviceCopyMatchingElements(m_device,
|
||||
(CFDictionaryRef)matchingElements, kIOHIDOptionsTypeNone);
|
||||
CFArrayRef elements = IOHIDDeviceCopyMatchingElements(m_device, (CFDictionaryRef)matchingElements,
|
||||
kIOHIDOptionsTypeNone);
|
||||
|
||||
if (elements)
|
||||
{
|
||||
for (int i = 0; i < CFArrayGetCount(elements); i++)
|
||||
{
|
||||
IOHIDElementRef e =
|
||||
(IOHIDElementRef)CFArrayGetValueAtIndex(elements, i);
|
||||
//DeviceElementDebugPrint(e, nullptr);
|
||||
if (elements)
|
||||
{
|
||||
for (int i = 0; i < CFArrayGetCount(elements); i++)
|
||||
{
|
||||
IOHIDElementRef e = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i);
|
||||
// DeviceElementDebugPrint(e, nullptr);
|
||||
|
||||
AddInput(new Key(e, m_device));
|
||||
}
|
||||
CFRelease(elements);
|
||||
}
|
||||
AddInput(new Key(e, m_device));
|
||||
}
|
||||
CFRelease(elements);
|
||||
}
|
||||
|
||||
m_windowid = [[reinterpret_cast<NSView*>(window) window] windowNumber];
|
||||
m_windowid = [[reinterpret_cast<NSView*>(window) window] windowNumber];
|
||||
|
||||
// cursor, with a hax for-loop
|
||||
for (unsigned int i=0; i<4; ++i)
|
||||
AddInput(new Cursor(!!(i&2), (&m_cursor.x)[i/2], !!(i&1)));
|
||||
// cursor, with a hax for-loop
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
AddInput(new Cursor(!!(i & 2), (&m_cursor.x)[i / 2], !!(i & 1)));
|
||||
|
||||
for (u8 i = 0; i < sizeof(m_mousebuttons) / sizeof(m_mousebuttons[0]); ++i)
|
||||
AddInput(new Button(i, m_mousebuttons[i]));
|
||||
for (u8 i = 0; i < sizeof(m_mousebuttons) / sizeof(m_mousebuttons[0]); ++i)
|
||||
AddInput(new Button(i, m_mousebuttons[i]));
|
||||
}
|
||||
|
||||
void Keyboard::UpdateInput()
|
||||
{
|
||||
CGRect bounds = CGRectZero;
|
||||
uint32_t windowid[1] = { m_windowid };
|
||||
CFArrayRef windowArray = CFArrayCreate(nullptr, (const void **) windowid, 1, nullptr);
|
||||
CFArrayRef windowDescriptions = CGWindowListCreateDescriptionFromArray(windowArray);
|
||||
CFDictionaryRef windowDescription = (CFDictionaryRef) CFArrayGetValueAtIndex((CFArrayRef) windowDescriptions, 0);
|
||||
CGRect bounds = CGRectZero;
|
||||
uint32_t windowid[1] = {m_windowid};
|
||||
CFArrayRef windowArray = CFArrayCreate(nullptr, (const void**)windowid, 1, nullptr);
|
||||
CFArrayRef windowDescriptions = CGWindowListCreateDescriptionFromArray(windowArray);
|
||||
CFDictionaryRef windowDescription =
|
||||
(CFDictionaryRef)CFArrayGetValueAtIndex((CFArrayRef)windowDescriptions, 0);
|
||||
|
||||
if (CFDictionaryContainsKey(windowDescription, kCGWindowBounds))
|
||||
{
|
||||
CFDictionaryRef boundsDictionary = (CFDictionaryRef) CFDictionaryGetValue(windowDescription, kCGWindowBounds);
|
||||
if (CFDictionaryContainsKey(windowDescription, kCGWindowBounds))
|
||||
{
|
||||
CFDictionaryRef boundsDictionary =
|
||||
(CFDictionaryRef)CFDictionaryGetValue(windowDescription, kCGWindowBounds);
|
||||
|
||||
if (boundsDictionary != nullptr)
|
||||
CGRectMakeWithDictionaryRepresentation(boundsDictionary, &bounds);
|
||||
}
|
||||
if (boundsDictionary != nullptr)
|
||||
CGRectMakeWithDictionaryRepresentation(boundsDictionary, &bounds);
|
||||
}
|
||||
|
||||
CFRelease(windowDescriptions);
|
||||
CFRelease(windowArray);
|
||||
CFRelease(windowDescriptions);
|
||||
CFRelease(windowArray);
|
||||
|
||||
CGEventRef event = CGEventCreate(nil);
|
||||
CGPoint loc = CGEventGetLocation(event);
|
||||
CFRelease(event);
|
||||
CGEventRef event = CGEventCreate(nil);
|
||||
CGPoint loc = CGEventGetLocation(event);
|
||||
CFRelease(event);
|
||||
|
||||
loc.x -= bounds.origin.x;
|
||||
loc.y -= bounds.origin.y;
|
||||
m_cursor.x = loc.x / bounds.size.width * 2 - 1.0;
|
||||
m_cursor.y = loc.y / bounds.size.height * 2 - 1.0;
|
||||
loc.x -= bounds.origin.x;
|
||||
loc.y -= bounds.origin.y;
|
||||
m_cursor.x = loc.x / bounds.size.width * 2 - 1.0;
|
||||
m_cursor.y = loc.y / bounds.size.height * 2 - 1.0;
|
||||
|
||||
m_mousebuttons[0] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonLeft);
|
||||
m_mousebuttons[1] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonRight);
|
||||
m_mousebuttons[2] = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonCenter);
|
||||
m_mousebuttons[0] =
|
||||
CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonLeft);
|
||||
m_mousebuttons[1] =
|
||||
CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonRight);
|
||||
m_mousebuttons[2] =
|
||||
CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonCenter);
|
||||
}
|
||||
|
||||
std::string Keyboard::GetName() const
|
||||
{
|
||||
return m_device_name;
|
||||
return m_device_name;
|
||||
}
|
||||
|
||||
std::string Keyboard::GetSource() const
|
||||
{
|
||||
return "Keyboard";
|
||||
return "Keyboard";
|
||||
}
|
||||
|
||||
int Keyboard::GetId() const
|
||||
{
|
||||
return m_index;
|
||||
return m_index;
|
||||
}
|
||||
|
||||
Keyboard::Key::Key(IOHIDElementRef element, IOHIDDeviceRef device)
|
||||
: m_element(element)
|
||||
, m_device(device)
|
||||
: m_element(element), m_device(device)
|
||||
{
|
||||
static const struct PrettyKeys
|
||||
{
|
||||
const uint32_t code;
|
||||
const char *const name;
|
||||
} named_keys[] = {
|
||||
{ kHIDUsage_KeyboardA, "A" },
|
||||
{ kHIDUsage_KeyboardB, "B" },
|
||||
{ kHIDUsage_KeyboardC, "C" },
|
||||
{ kHIDUsage_KeyboardD, "D" },
|
||||
{ kHIDUsage_KeyboardE, "E" },
|
||||
{ kHIDUsage_KeyboardF, "F" },
|
||||
{ kHIDUsage_KeyboardG, "G" },
|
||||
{ kHIDUsage_KeyboardH, "H" },
|
||||
{ kHIDUsage_KeyboardI, "I" },
|
||||
{ kHIDUsage_KeyboardJ, "J" },
|
||||
{ kHIDUsage_KeyboardK, "K" },
|
||||
{ kHIDUsage_KeyboardL, "L" },
|
||||
{ kHIDUsage_KeyboardM, "M" },
|
||||
{ kHIDUsage_KeyboardN, "N" },
|
||||
{ kHIDUsage_KeyboardO, "O" },
|
||||
{ kHIDUsage_KeyboardP, "P" },
|
||||
{ kHIDUsage_KeyboardQ, "Q" },
|
||||
{ kHIDUsage_KeyboardR, "R" },
|
||||
{ kHIDUsage_KeyboardS, "S" },
|
||||
{ kHIDUsage_KeyboardT, "T" },
|
||||
{ kHIDUsage_KeyboardU, "U" },
|
||||
{ kHIDUsage_KeyboardV, "V" },
|
||||
{ kHIDUsage_KeyboardW, "W" },
|
||||
{ kHIDUsage_KeyboardX, "X" },
|
||||
{ kHIDUsage_KeyboardY, "Y" },
|
||||
{ kHIDUsage_KeyboardZ, "Z" },
|
||||
{ kHIDUsage_Keyboard1, "1" },
|
||||
{ kHIDUsage_Keyboard2, "2" },
|
||||
{ kHIDUsage_Keyboard3, "3" },
|
||||
{ kHIDUsage_Keyboard4, "4" },
|
||||
{ kHIDUsage_Keyboard5, "5" },
|
||||
{ kHIDUsage_Keyboard6, "6" },
|
||||
{ kHIDUsage_Keyboard7, "7" },
|
||||
{ kHIDUsage_Keyboard8, "8" },
|
||||
{ kHIDUsage_Keyboard9, "9" },
|
||||
{ kHIDUsage_Keyboard0, "0" },
|
||||
{ kHIDUsage_KeyboardReturnOrEnter, "Return" },
|
||||
{ kHIDUsage_KeyboardEscape, "Escape" },
|
||||
{ kHIDUsage_KeyboardDeleteOrBackspace, "Backspace" },
|
||||
{ kHIDUsage_KeyboardTab, "Tab" },
|
||||
{ kHIDUsage_KeyboardSpacebar, "Space" },
|
||||
{ kHIDUsage_KeyboardHyphen, "-" },
|
||||
{ kHIDUsage_KeyboardEqualSign, "=" },
|
||||
{ kHIDUsage_KeyboardOpenBracket, "[" },
|
||||
{ kHIDUsage_KeyboardCloseBracket, "]" },
|
||||
{ kHIDUsage_KeyboardBackslash, "\\" },
|
||||
{ kHIDUsage_KeyboardSemicolon, ";" },
|
||||
{ kHIDUsage_KeyboardQuote, "'" },
|
||||
{ kHIDUsage_KeyboardGraveAccentAndTilde, "Tilde" },
|
||||
{ kHIDUsage_KeyboardComma, "," },
|
||||
{ kHIDUsage_KeyboardPeriod, "." },
|
||||
{ kHIDUsage_KeyboardSlash, "/" },
|
||||
{ kHIDUsage_KeyboardCapsLock, "Caps Lock" },
|
||||
{ kHIDUsage_KeyboardF1, "F1" },
|
||||
{ kHIDUsage_KeyboardF2, "F2" },
|
||||
{ kHIDUsage_KeyboardF3, "F3" },
|
||||
{ kHIDUsage_KeyboardF4, "F4" },
|
||||
{ kHIDUsage_KeyboardF5, "F5" },
|
||||
{ kHIDUsage_KeyboardF6, "F6" },
|
||||
{ kHIDUsage_KeyboardF7, "F7" },
|
||||
{ kHIDUsage_KeyboardF8, "F8" },
|
||||
{ kHIDUsage_KeyboardF9, "F9" },
|
||||
{ kHIDUsage_KeyboardF10, "F10" },
|
||||
{ kHIDUsage_KeyboardF11, "F11" },
|
||||
{ kHIDUsage_KeyboardF12, "F12" },
|
||||
{ kHIDUsage_KeyboardInsert, "Insert" },
|
||||
{ kHIDUsage_KeyboardHome, "Home" },
|
||||
{ kHIDUsage_KeyboardPageUp, "Page Up" },
|
||||
{ kHIDUsage_KeyboardDeleteForward, "Delete" },
|
||||
{ kHIDUsage_KeyboardEnd, "End" },
|
||||
{ kHIDUsage_KeyboardPageDown, "Page Down" },
|
||||
{ kHIDUsage_KeyboardRightArrow, "Right Arrow" },
|
||||
{ kHIDUsage_KeyboardLeftArrow, "Left Arrow" },
|
||||
{ kHIDUsage_KeyboardDownArrow, "Down Arrow" },
|
||||
{ kHIDUsage_KeyboardUpArrow, "Up Arrow" },
|
||||
{ kHIDUsage_KeypadSlash, "Keypad /" },
|
||||
{ kHIDUsage_KeypadAsterisk, "Keypad *" },
|
||||
{ kHIDUsage_KeypadHyphen, "Keypad -" },
|
||||
{ kHIDUsage_KeypadPlus, "Keypad +" },
|
||||
{ kHIDUsage_KeypadEnter, "Keypad Enter" },
|
||||
{ kHIDUsage_Keypad1, "Keypad 1" },
|
||||
{ kHIDUsage_Keypad2, "Keypad 2" },
|
||||
{ kHIDUsage_Keypad3, "Keypad 3" },
|
||||
{ kHIDUsage_Keypad4, "Keypad 4" },
|
||||
{ kHIDUsage_Keypad5, "Keypad 5" },
|
||||
{ kHIDUsage_Keypad6, "Keypad 6" },
|
||||
{ kHIDUsage_Keypad7, "Keypad 7" },
|
||||
{ kHIDUsage_Keypad8, "Keypad 8" },
|
||||
{ kHIDUsage_Keypad9, "Keypad 9" },
|
||||
{ kHIDUsage_Keypad0, "Keypad 0" },
|
||||
{ kHIDUsage_KeypadPeriod, "Keypad ." },
|
||||
{ kHIDUsage_KeyboardNonUSBackslash, "Paragraph" },
|
||||
{ kHIDUsage_KeypadEqualSign, "Keypad =" },
|
||||
{ kHIDUsage_KeypadComma, "Keypad ," },
|
||||
{ kHIDUsage_KeyboardLeftControl, "Left Control" },
|
||||
{ kHIDUsage_KeyboardLeftShift, "Left Shift" },
|
||||
{ kHIDUsage_KeyboardLeftAlt, "Left Alt" },
|
||||
{ kHIDUsage_KeyboardLeftGUI, "Left Command" },
|
||||
{ kHIDUsage_KeyboardRightControl, "Right Control" },
|
||||
{ kHIDUsage_KeyboardRightShift, "Right Shift" },
|
||||
{ kHIDUsage_KeyboardRightAlt, "Right Alt" },
|
||||
{ kHIDUsage_KeyboardRightGUI, "Right Command" },
|
||||
{ 184, "Eject" },
|
||||
};
|
||||
static const struct PrettyKeys
|
||||
{
|
||||
const uint32_t code;
|
||||
const char* const name;
|
||||
} named_keys[] = {
|
||||
{kHIDUsage_KeyboardA, "A"},
|
||||
{kHIDUsage_KeyboardB, "B"},
|
||||
{kHIDUsage_KeyboardC, "C"},
|
||||
{kHIDUsage_KeyboardD, "D"},
|
||||
{kHIDUsage_KeyboardE, "E"},
|
||||
{kHIDUsage_KeyboardF, "F"},
|
||||
{kHIDUsage_KeyboardG, "G"},
|
||||
{kHIDUsage_KeyboardH, "H"},
|
||||
{kHIDUsage_KeyboardI, "I"},
|
||||
{kHIDUsage_KeyboardJ, "J"},
|
||||
{kHIDUsage_KeyboardK, "K"},
|
||||
{kHIDUsage_KeyboardL, "L"},
|
||||
{kHIDUsage_KeyboardM, "M"},
|
||||
{kHIDUsage_KeyboardN, "N"},
|
||||
{kHIDUsage_KeyboardO, "O"},
|
||||
{kHIDUsage_KeyboardP, "P"},
|
||||
{kHIDUsage_KeyboardQ, "Q"},
|
||||
{kHIDUsage_KeyboardR, "R"},
|
||||
{kHIDUsage_KeyboardS, "S"},
|
||||
{kHIDUsage_KeyboardT, "T"},
|
||||
{kHIDUsage_KeyboardU, "U"},
|
||||
{kHIDUsage_KeyboardV, "V"},
|
||||
{kHIDUsage_KeyboardW, "W"},
|
||||
{kHIDUsage_KeyboardX, "X"},
|
||||
{kHIDUsage_KeyboardY, "Y"},
|
||||
{kHIDUsage_KeyboardZ, "Z"},
|
||||
{kHIDUsage_Keyboard1, "1"},
|
||||
{kHIDUsage_Keyboard2, "2"},
|
||||
{kHIDUsage_Keyboard3, "3"},
|
||||
{kHIDUsage_Keyboard4, "4"},
|
||||
{kHIDUsage_Keyboard5, "5"},
|
||||
{kHIDUsage_Keyboard6, "6"},
|
||||
{kHIDUsage_Keyboard7, "7"},
|
||||
{kHIDUsage_Keyboard8, "8"},
|
||||
{kHIDUsage_Keyboard9, "9"},
|
||||
{kHIDUsage_Keyboard0, "0"},
|
||||
{kHIDUsage_KeyboardReturnOrEnter, "Return"},
|
||||
{kHIDUsage_KeyboardEscape, "Escape"},
|
||||
{kHIDUsage_KeyboardDeleteOrBackspace, "Backspace"},
|
||||
{kHIDUsage_KeyboardTab, "Tab"},
|
||||
{kHIDUsage_KeyboardSpacebar, "Space"},
|
||||
{kHIDUsage_KeyboardHyphen, "-"},
|
||||
{kHIDUsage_KeyboardEqualSign, "="},
|
||||
{kHIDUsage_KeyboardOpenBracket, "["},
|
||||
{kHIDUsage_KeyboardCloseBracket, "]"},
|
||||
{kHIDUsage_KeyboardBackslash, "\\"},
|
||||
{kHIDUsage_KeyboardSemicolon, ";"},
|
||||
{kHIDUsage_KeyboardQuote, "'"},
|
||||
{kHIDUsage_KeyboardGraveAccentAndTilde, "Tilde"},
|
||||
{kHIDUsage_KeyboardComma, ","},
|
||||
{kHIDUsage_KeyboardPeriod, "."},
|
||||
{kHIDUsage_KeyboardSlash, "/"},
|
||||
{kHIDUsage_KeyboardCapsLock, "Caps Lock"},
|
||||
{kHIDUsage_KeyboardF1, "F1"},
|
||||
{kHIDUsage_KeyboardF2, "F2"},
|
||||
{kHIDUsage_KeyboardF3, "F3"},
|
||||
{kHIDUsage_KeyboardF4, "F4"},
|
||||
{kHIDUsage_KeyboardF5, "F5"},
|
||||
{kHIDUsage_KeyboardF6, "F6"},
|
||||
{kHIDUsage_KeyboardF7, "F7"},
|
||||
{kHIDUsage_KeyboardF8, "F8"},
|
||||
{kHIDUsage_KeyboardF9, "F9"},
|
||||
{kHIDUsage_KeyboardF10, "F10"},
|
||||
{kHIDUsage_KeyboardF11, "F11"},
|
||||
{kHIDUsage_KeyboardF12, "F12"},
|
||||
{kHIDUsage_KeyboardInsert, "Insert"},
|
||||
{kHIDUsage_KeyboardHome, "Home"},
|
||||
{kHIDUsage_KeyboardPageUp, "Page Up"},
|
||||
{kHIDUsage_KeyboardDeleteForward, "Delete"},
|
||||
{kHIDUsage_KeyboardEnd, "End"},
|
||||
{kHIDUsage_KeyboardPageDown, "Page Down"},
|
||||
{kHIDUsage_KeyboardRightArrow, "Right Arrow"},
|
||||
{kHIDUsage_KeyboardLeftArrow, "Left Arrow"},
|
||||
{kHIDUsage_KeyboardDownArrow, "Down Arrow"},
|
||||
{kHIDUsage_KeyboardUpArrow, "Up Arrow"},
|
||||
{kHIDUsage_KeypadSlash, "Keypad /"},
|
||||
{kHIDUsage_KeypadAsterisk, "Keypad *"},
|
||||
{kHIDUsage_KeypadHyphen, "Keypad -"},
|
||||
{kHIDUsage_KeypadPlus, "Keypad +"},
|
||||
{kHIDUsage_KeypadEnter, "Keypad Enter"},
|
||||
{kHIDUsage_Keypad1, "Keypad 1"},
|
||||
{kHIDUsage_Keypad2, "Keypad 2"},
|
||||
{kHIDUsage_Keypad3, "Keypad 3"},
|
||||
{kHIDUsage_Keypad4, "Keypad 4"},
|
||||
{kHIDUsage_Keypad5, "Keypad 5"},
|
||||
{kHIDUsage_Keypad6, "Keypad 6"},
|
||||
{kHIDUsage_Keypad7, "Keypad 7"},
|
||||
{kHIDUsage_Keypad8, "Keypad 8"},
|
||||
{kHIDUsage_Keypad9, "Keypad 9"},
|
||||
{kHIDUsage_Keypad0, "Keypad 0"},
|
||||
{kHIDUsage_KeypadPeriod, "Keypad ."},
|
||||
{kHIDUsage_KeyboardNonUSBackslash, "Paragraph"},
|
||||
{kHIDUsage_KeypadEqualSign, "Keypad ="},
|
||||
{kHIDUsage_KeypadComma, "Keypad ,"},
|
||||
{kHIDUsage_KeyboardLeftControl, "Left Control"},
|
||||
{kHIDUsage_KeyboardLeftShift, "Left Shift"},
|
||||
{kHIDUsage_KeyboardLeftAlt, "Left Alt"},
|
||||
{kHIDUsage_KeyboardLeftGUI, "Left Command"},
|
||||
{kHIDUsage_KeyboardRightControl, "Right Control"},
|
||||
{kHIDUsage_KeyboardRightShift, "Right Shift"},
|
||||
{kHIDUsage_KeyboardRightAlt, "Right Alt"},
|
||||
{kHIDUsage_KeyboardRightGUI, "Right Command"},
|
||||
{184, "Eject"},
|
||||
};
|
||||
|
||||
const uint32_t keycode = IOHIDElementGetUsage(m_element);
|
||||
for (auto & named_key : named_keys)
|
||||
{
|
||||
if (named_key.code == keycode)
|
||||
{
|
||||
m_name = named_key.name;
|
||||
return;
|
||||
}
|
||||
}
|
||||
const uint32_t keycode = IOHIDElementGetUsage(m_element);
|
||||
for (auto& named_key : named_keys)
|
||||
{
|
||||
if (named_key.code == keycode)
|
||||
{
|
||||
m_name = named_key.name;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "Key " << keycode;
|
||||
m_name = ss.str();
|
||||
std::stringstream ss;
|
||||
ss << "Key " << keycode;
|
||||
m_name = ss.str();
|
||||
}
|
||||
|
||||
ControlState Keyboard::Key::GetState() const
|
||||
{
|
||||
IOHIDValueRef value;
|
||||
IOHIDValueRef value;
|
||||
|
||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
||||
return IOHIDValueGetIntegerValue(value);
|
||||
else
|
||||
return 0;
|
||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
||||
return IOHIDValueGetIntegerValue(value);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
ControlState Keyboard::Cursor::GetState() const
|
||||
{
|
||||
return std::max(0.0, ControlState(m_axis) / (m_positive ? 1.0 : -1.0));
|
||||
return std::max(0.0, ControlState(m_axis) / (m_positive ? 1.0 : -1.0));
|
||||
}
|
||||
|
||||
ControlState Keyboard::Button::GetState() const
|
||||
{
|
||||
return (m_button != 0);
|
||||
return (m_button != 0);
|
||||
}
|
||||
|
||||
std::string Keyboard::Cursor::GetName() const
|
||||
{
|
||||
static char tmpstr[] = "Cursor ..";
|
||||
tmpstr[7] = (char)('X' + m_index);
|
||||
tmpstr[8] = (m_positive ? '+' : '-');
|
||||
return tmpstr;
|
||||
static char tmpstr[] = "Cursor ..";
|
||||
tmpstr[7] = (char)('X' + m_index);
|
||||
tmpstr[8] = (m_positive ? '+' : '-');
|
||||
return tmpstr;
|
||||
}
|
||||
|
||||
std::string Keyboard::Button::GetName() const
|
||||
{
|
||||
return std::string("Click ") + char('0' + m_index);
|
||||
return std::string("Click ") + char('0' + m_index);
|
||||
}
|
||||
|
||||
std::string Keyboard::Key::GetName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
return m_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user