mirror of
https://github.com/glfw/glfw.git
synced 2024-11-25 22:14:34 +00:00
parent
fec6f187d1
commit
a97477337d
@ -72,6 +72,7 @@ GLFW bundles a number of dependencies in the `deps/` directory.
|
|||||||
- [Cocoa] Bugfix: The `GLFW_AUTO_ICONIFY` window hint was ignored
|
- [Cocoa] Bugfix: The `GLFW_AUTO_ICONIFY` window hint was ignored
|
||||||
- [Cocoa] Bugfix: Resizing a window to its minimum size would segfault
|
- [Cocoa] Bugfix: Resizing a window to its minimum size would segfault
|
||||||
- [Cocoa] Bugfix: Creating or showing a window would make its context current
|
- [Cocoa] Bugfix: Creating or showing a window would make its context current
|
||||||
|
- [Cocoa] Bugfix: Joysticks connected after `glfwInit` were not detected
|
||||||
- [X11] Bugfix: `glfwInit` would segfault on systems without RandR
|
- [X11] Bugfix: `glfwInit` would segfault on systems without RandR
|
||||||
- [X11] Bugfix: The response to `_NET_WM_PING` was sent to the wrong window
|
- [X11] Bugfix: The response to `_NET_WM_PING` was sent to the wrong window
|
||||||
- [X11] Bugfix: Character input via XIM did not work in many cases
|
- [X11] Bugfix: Character input via XIM did not work in many cases
|
||||||
@ -142,6 +143,7 @@ skills.
|
|||||||
- heromyth
|
- heromyth
|
||||||
- Lucas Hinderberger
|
- Lucas Hinderberger
|
||||||
- Paul Holden
|
- Paul Holden
|
||||||
|
- Aaron Jacobs
|
||||||
- Toni Jovanoski
|
- Toni Jovanoski
|
||||||
- Arseny Kapoulkine
|
- Arseny Kapoulkine
|
||||||
- Osman Keskin
|
- Osman Keskin
|
||||||
|
@ -53,7 +53,6 @@ typedef struct _GLFWjoydevice
|
|||||||
unsigned char* buttons;
|
unsigned char* buttons;
|
||||||
} _GLFWjoydevice;
|
} _GLFWjoydevice;
|
||||||
|
|
||||||
|
|
||||||
// IOKit-specific joystick API data
|
// IOKit-specific joystick API data
|
||||||
//
|
//
|
||||||
typedef struct _GLFWjoystickIOKit
|
typedef struct _GLFWjoystickIOKit
|
||||||
@ -63,7 +62,6 @@ typedef struct _GLFWjoystickIOKit
|
|||||||
IOHIDManagerRef managerRef;
|
IOHIDManagerRef managerRef;
|
||||||
} _GLFWjoystickIOKit;
|
} _GLFWjoystickIOKit;
|
||||||
|
|
||||||
|
|
||||||
void _glfwInitJoysticks(void);
|
void _glfwInitJoysticks(void);
|
||||||
void _glfwTerminateJoysticks(void);
|
void _glfwTerminateJoysticks(void);
|
||||||
|
|
||||||
|
@ -57,7 +57,8 @@ static void getElementsCFArrayHandler(const void* value, void* parameter);
|
|||||||
|
|
||||||
// Adds an element to the specified joystick
|
// Adds an element to the specified joystick
|
||||||
//
|
//
|
||||||
static void addJoystickElement(_GLFWjoydevice* joystick, IOHIDElementRef elementRef)
|
static void addJoystickElement(_GLFWjoydevice* joystick,
|
||||||
|
IOHIDElementRef elementRef)
|
||||||
{
|
{
|
||||||
IOHIDElementType elementType;
|
IOHIDElementType elementType;
|
||||||
long usagePage, usage;
|
long usagePage, usage;
|
||||||
@ -70,7 +71,9 @@ static void addJoystickElement(_GLFWjoydevice* joystick, IOHIDElementRef element
|
|||||||
if ((elementType != kIOHIDElementTypeInput_Axis) &&
|
if ((elementType != kIOHIDElementTypeInput_Axis) &&
|
||||||
(elementType != kIOHIDElementTypeInput_Button) &&
|
(elementType != kIOHIDElementTypeInput_Button) &&
|
||||||
(elementType != kIOHIDElementTypeInput_Misc))
|
(elementType != kIOHIDElementTypeInput_Misc))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (usagePage)
|
switch (usagePage)
|
||||||
{
|
{
|
||||||
@ -122,7 +125,10 @@ static void addJoystickElement(_GLFWjoydevice* joystick, IOHIDElementRef element
|
|||||||
static void getElementsCFArrayHandler(const void* value, void* parameter)
|
static void getElementsCFArrayHandler(const void* value, void* parameter)
|
||||||
{
|
{
|
||||||
if (CFGetTypeID(value) == IOHIDElementGetTypeID())
|
if (CFGetTypeID(value) == IOHIDElementGetTypeID())
|
||||||
addJoystickElement((_GLFWjoydevice*) parameter, (IOHIDElementRef) value);
|
{
|
||||||
|
addJoystickElement((_GLFWjoydevice*) parameter,
|
||||||
|
(IOHIDElementRef) value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the value of the specified element of the specified joystick
|
// Returns the value of the specified element of the specified joystick
|
||||||
@ -202,8 +208,8 @@ static void pollJoystickEvents(void)
|
|||||||
|
|
||||||
for (i = 0; i < CFArrayGetCount(joystick->buttonElements); i++)
|
for (i = 0; i < CFArrayGetCount(joystick->buttonElements); i++)
|
||||||
{
|
{
|
||||||
_GLFWjoyelement* button =
|
_GLFWjoyelement* button = (_GLFWjoyelement*)
|
||||||
(_GLFWjoyelement*) CFArrayGetValueAtIndex(joystick->buttonElements, i);
|
CFArrayGetValueAtIndex(joystick->buttonElements, i);
|
||||||
|
|
||||||
if (getElementValue(joystick, button))
|
if (getElementValue(joystick, button))
|
||||||
joystick->buttons[buttonIndex++] = GLFW_PRESS;
|
joystick->buttons[buttonIndex++] = GLFW_PRESS;
|
||||||
@ -213,8 +219,8 @@ static void pollJoystickEvents(void)
|
|||||||
|
|
||||||
for (i = 0; i < CFArrayGetCount(joystick->axisElements); i++)
|
for (i = 0; i < CFArrayGetCount(joystick->axisElements); i++)
|
||||||
{
|
{
|
||||||
_GLFWjoyelement* axis =
|
_GLFWjoyelement* axis = (_GLFWjoyelement*)
|
||||||
(_GLFWjoyelement*) CFArrayGetValueAtIndex(joystick->axisElements, i);
|
CFArrayGetValueAtIndex(joystick->axisElements, i);
|
||||||
|
|
||||||
long value = getElementValue(joystick, axis);
|
long value = getElementValue(joystick, axis);
|
||||||
long readScale = axis->maxReport - axis->minReport;
|
long readScale = axis->maxReport - axis->minReport;
|
||||||
@ -227,8 +233,8 @@ static void pollJoystickEvents(void)
|
|||||||
|
|
||||||
for (i = 0; i < CFArrayGetCount(joystick->hatElements); i++)
|
for (i = 0; i < CFArrayGetCount(joystick->hatElements); i++)
|
||||||
{
|
{
|
||||||
_GLFWjoyelement* hat =
|
_GLFWjoyelement* hat = (_GLFWjoyelement*)
|
||||||
(_GLFWjoyelement*) CFArrayGetValueAtIndex(joystick->hatElements, i);
|
CFArrayGetValueAtIndex(joystick->hatElements, i);
|
||||||
|
|
||||||
// Bit fields of button presses for each direction, including nil
|
// Bit fields of button presses for each direction, including nil
|
||||||
const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 };
|
const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 };
|
||||||
@ -250,7 +256,10 @@ static void pollJoystickEvents(void)
|
|||||||
|
|
||||||
// Callback for user-initiated joystick addition
|
// Callback for user-initiated joystick addition
|
||||||
//
|
//
|
||||||
static void matchCallback(void* context, IOReturn result, void* sender, IOHIDDeviceRef deviceRef)
|
static void matchCallback(void* context,
|
||||||
|
IOReturn result,
|
||||||
|
void* sender,
|
||||||
|
IOHIDDeviceRef deviceRef)
|
||||||
{
|
{
|
||||||
_GLFWjoydevice* joystick;
|
_GLFWjoydevice* joystick;
|
||||||
int joy;
|
int joy;
|
||||||
@ -280,7 +289,8 @@ static void matchCallback(void* context, IOReturn result, void* sender, IOHIDDev
|
|||||||
joystick->present = GL_TRUE;
|
joystick->present = GL_TRUE;
|
||||||
joystick->deviceRef = deviceRef;
|
joystick->deviceRef = deviceRef;
|
||||||
|
|
||||||
CFStringRef name = IOHIDDeviceGetProperty(deviceRef, CFSTR(kIOHIDProductKey));
|
CFStringRef name = IOHIDDeviceGetProperty(deviceRef,
|
||||||
|
CFSTR(kIOHIDProductKey));
|
||||||
CFStringGetCString(name,
|
CFStringGetCString(name,
|
||||||
joystick->name,
|
joystick->name,
|
||||||
sizeof(joystick->name),
|
sizeof(joystick->name),
|
||||||
@ -290,7 +300,9 @@ static void matchCallback(void* context, IOReturn result, void* sender, IOHIDDev
|
|||||||
joystick->buttonElements = CFArrayCreateMutable(NULL, 0, NULL);
|
joystick->buttonElements = CFArrayCreateMutable(NULL, 0, NULL);
|
||||||
joystick->hatElements = CFArrayCreateMutable(NULL, 0, NULL);
|
joystick->hatElements = CFArrayCreateMutable(NULL, 0, NULL);
|
||||||
|
|
||||||
CFArrayRef arrayRef = IOHIDDeviceCopyMatchingElements(deviceRef, NULL, kIOHIDOptionsTypeNone);
|
CFArrayRef arrayRef = IOHIDDeviceCopyMatchingElements(deviceRef,
|
||||||
|
NULL,
|
||||||
|
kIOHIDOptionsTypeNone);
|
||||||
CFRange range = { 0, CFArrayGetCount(arrayRef) };
|
CFRange range = { 0, CFArrayGetCount(arrayRef) };
|
||||||
CFArrayApplyFunction(arrayRef,
|
CFArrayApplyFunction(arrayRef,
|
||||||
range,
|
range,
|
||||||
@ -307,41 +319,56 @@ static void matchCallback(void* context, IOReturn result, void* sender, IOHIDDev
|
|||||||
|
|
||||||
// Callback for user-initiated joystick removal
|
// Callback for user-initiated joystick removal
|
||||||
//
|
//
|
||||||
static void removeCallback(void* context, IOReturn result, void* sender, IOHIDDeviceRef deviceRef)
|
static void removeCallback(void* context,
|
||||||
|
IOReturn result,
|
||||||
|
void* sender,
|
||||||
|
IOHIDDeviceRef deviceRef)
|
||||||
{
|
{
|
||||||
int joy;
|
int joy;
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) {
|
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
||||||
|
{
|
||||||
_GLFWjoydevice* joystick = _glfw.iokit_js.devices + joy;
|
_GLFWjoydevice* joystick = _glfw.iokit_js.devices + joy;
|
||||||
|
if (joystick->deviceRef == deviceRef)
|
||||||
if (joystick->deviceRef == deviceRef) {
|
{
|
||||||
removeJoystick(joystick);
|
removeJoystick(joystick);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a dictionary to match against devices with the specified usage page and usage
|
// Creates a dictionary to match against devices with the specified usage page
|
||||||
|
// and usage
|
||||||
//
|
//
|
||||||
static CFMutableDictionaryRef createMatchingDictionary(long usagePage, long usage)
|
static CFMutableDictionaryRef createMatchingDictionary(long usagePage,
|
||||||
|
long usage)
|
||||||
{
|
{
|
||||||
CFMutableDictionaryRef result = CFDictionaryCreateMutable(kCFAllocatorDefault,
|
CFMutableDictionaryRef result =
|
||||||
|
CFDictionaryCreateMutable(kCFAllocatorDefault,
|
||||||
0,
|
0,
|
||||||
&kCFTypeDictionaryKeyCallBacks,
|
&kCFTypeDictionaryKeyCallBacks,
|
||||||
&kCFTypeDictionaryValueCallBacks);
|
&kCFTypeDictionaryValueCallBacks);
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
CFNumberRef pageRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usagePage);
|
CFNumberRef pageRef = CFNumberCreate(kCFAllocatorDefault,
|
||||||
|
kCFNumberIntType,
|
||||||
|
&usagePage);
|
||||||
if (pageRef)
|
if (pageRef)
|
||||||
{
|
{
|
||||||
CFDictionarySetValue(result, CFSTR(kIOHIDDeviceUsagePageKey), pageRef);
|
CFDictionarySetValue(result,
|
||||||
|
CFSTR(kIOHIDDeviceUsagePageKey),
|
||||||
|
pageRef);
|
||||||
CFRelease(pageRef);
|
CFRelease(pageRef);
|
||||||
|
|
||||||
CFNumberRef usageRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
|
CFNumberRef usageRef = CFNumberCreate(kCFAllocatorDefault,
|
||||||
|
kCFNumberIntType,
|
||||||
|
&usage);
|
||||||
if (usageRef)
|
if (usageRef)
|
||||||
{
|
{
|
||||||
CFDictionarySetValue(result, CFSTR(kIOHIDDeviceUsageKey), usageRef);
|
CFDictionarySetValue(result,
|
||||||
|
CFSTR(kIOHIDDeviceUsageKey),
|
||||||
|
usageRef);
|
||||||
CFRelease(usageRef);
|
CFRelease(usageRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -350,6 +377,7 @@ static CFMutableDictionaryRef createMatchingDictionary(long usagePage, long usag
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
////// GLFW internal API //////
|
////// GLFW internal API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -363,24 +391,31 @@ void _glfwInitJoysticks(void)
|
|||||||
_glfw.iokit_js.managerRef = IOHIDManagerCreate(kCFAllocatorDefault,
|
_glfw.iokit_js.managerRef = IOHIDManagerCreate(kCFAllocatorDefault,
|
||||||
kIOHIDOptionsTypeNone);
|
kIOHIDOptionsTypeNone);
|
||||||
|
|
||||||
matchingCFArrayRef = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
|
matchingCFArrayRef = CFArrayCreateMutable(kCFAllocatorDefault,
|
||||||
|
0,
|
||||||
|
&kCFTypeArrayCallBacks);
|
||||||
if (matchingCFArrayRef)
|
if (matchingCFArrayRef)
|
||||||
{
|
{
|
||||||
CFDictionaryRef matchingCFDictRef = createMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick);
|
CFDictionaryRef matchingCFDictRef =
|
||||||
|
createMatchingDictionary(kHIDPage_GenericDesktop,
|
||||||
|
kHIDUsage_GD_Joystick);
|
||||||
if (matchingCFDictRef)
|
if (matchingCFDictRef)
|
||||||
{
|
{
|
||||||
CFArrayAppendValue(matchingCFArrayRef, matchingCFDictRef);
|
CFArrayAppendValue(matchingCFArrayRef, matchingCFDictRef);
|
||||||
CFRelease(matchingCFDictRef);
|
CFRelease(matchingCFDictRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
matchingCFDictRef = createMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad);
|
matchingCFDictRef = createMatchingDictionary(kHIDPage_GenericDesktop,
|
||||||
|
kHIDUsage_GD_GamePad);
|
||||||
if (matchingCFDictRef)
|
if (matchingCFDictRef)
|
||||||
{
|
{
|
||||||
CFArrayAppendValue(matchingCFArrayRef, matchingCFDictRef);
|
CFArrayAppendValue(matchingCFArrayRef, matchingCFDictRef);
|
||||||
CFRelease(matchingCFDictRef);
|
CFRelease(matchingCFDictRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
matchingCFDictRef = createMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController);
|
matchingCFDictRef =
|
||||||
|
createMatchingDictionary(kHIDPage_GenericDesktop,
|
||||||
|
kHIDUsage_GD_MultiAxisController);
|
||||||
if (matchingCFDictRef)
|
if (matchingCFDictRef)
|
||||||
{
|
{
|
||||||
CFArrayAppendValue(matchingCFArrayRef, matchingCFDictRef);
|
CFArrayAppendValue(matchingCFArrayRef, matchingCFDictRef);
|
||||||
@ -388,17 +423,23 @@ void _glfwInitJoysticks(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IOHIDManagerSetDeviceMatchingMultiple(_glfw.iokit_js.managerRef, matchingCFArrayRef);
|
IOHIDManagerSetDeviceMatchingMultiple(_glfw.iokit_js.managerRef,
|
||||||
|
matchingCFArrayRef);
|
||||||
CFRelease(matchingCFArrayRef);
|
CFRelease(matchingCFArrayRef);
|
||||||
|
|
||||||
IOHIDManagerRegisterDeviceMatchingCallback(_glfw.iokit_js.managerRef, &matchCallback, NULL);
|
IOHIDManagerRegisterDeviceMatchingCallback(_glfw.iokit_js.managerRef,
|
||||||
IOHIDManagerRegisterDeviceRemovalCallback(_glfw.iokit_js.managerRef, &removeCallback, NULL);
|
&matchCallback, NULL);
|
||||||
|
IOHIDManagerRegisterDeviceRemovalCallback(_glfw.iokit_js.managerRef,
|
||||||
|
&removeCallback, NULL);
|
||||||
|
|
||||||
IOHIDManagerScheduleWithRunLoop(_glfw.iokit_js.managerRef, CFRunLoopGetMain(), kCFRunLoopDefaultMode);
|
IOHIDManagerScheduleWithRunLoop(_glfw.iokit_js.managerRef,
|
||||||
|
CFRunLoopGetMain(),
|
||||||
|
kCFRunLoopDefaultMode);
|
||||||
|
|
||||||
IOHIDManagerOpen(_glfw.iokit_js.managerRef, kIOHIDOptionsTypeNone);
|
IOHIDManagerOpen(_glfw.iokit_js.managerRef, kIOHIDOptionsTypeNone);
|
||||||
|
|
||||||
// Execute the run loop once in order to register any initially-attached joysticks
|
// Execute the run loop once in order to register any initially-attached
|
||||||
|
// joysticks
|
||||||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false);
|
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user