From f4371991fe43380cb8c976212eb9feb3376df6ab Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 2 Feb 2023 22:31:56 +0900 Subject: [PATCH] internal/gamepad: refactoring --- internal/gamepad/api_cf_darwin.go | 73 ++++++++++++++---------------- internal/gamepad/api_hid_darwin.go | 65 +++++++++++--------------- 2 files changed, 60 insertions(+), 78 deletions(-) diff --git a/internal/gamepad/api_cf_darwin.go b/internal/gamepad/api_cf_darwin.go index df026a4a7..4fcef1241 100644 --- a/internal/gamepad/api_cf_darwin.go +++ b/internal/gamepad/api_cf_darwin.go @@ -20,23 +20,25 @@ import ( "github.com/ebitengine/purego" ) -type _CFIndex int64 -type _CFAllocatorRef uintptr -type _CFArrayRef uintptr -type _CFDictionaryRef uintptr -type _CFNumberRef uintptr -type _CFTypeRef uintptr -type _CFRunLoopRef uintptr -type _CFNumberType uintptr -type _CFStringRef uintptr -type _CFArrayCallBacks struct{} -type _CFDictionaryKeyCallBacks struct{} -type _CFDictionaryValueCallBacks struct{} -type _CFRunLoopRunResult int32 -type _CFRunLoopMode = _CFStringRef -type _CFTimeInterval float64 -type _CFTypeID uint64 -type _CFStringEncoding uint32 +type ( + _CFIndex int64 + _CFAllocatorRef uintptr + _CFArrayRef uintptr + _CFDictionaryRef uintptr + _CFNumberRef uintptr + _CFTypeRef uintptr + _CFRunLoopRef uintptr + _CFNumberType uintptr + _CFStringRef uintptr + _CFArrayCallBacks struct{} + _CFDictionaryKeyCallBacks struct{} + _CFDictionaryValueCallBacks struct{} + _CFRunLoopRunResult int32 + _CFRunLoopMode = _CFStringRef + _CFTimeInterval float64 + _CFTypeID uint64 + _CFStringEncoding uint32 +) var kCFAllocatorDefault _CFAllocatorRef = 0 @@ -73,26 +75,17 @@ func init() { purego.RegisterLibFunc(&_CFStringCreateWithCString, corefoundation, "CFStringCreateWithCString") } -var _CFNumberCreate func(allocator _CFAllocatorRef, theType _CFNumberType, valuePtr unsafe.Pointer) _CFNumberRef - -var _CFNumberGetValue func(number _CFNumberRef, theType _CFNumberType, valuePtr unsafe.Pointer) bool - -var _CFArrayCreate func(allocator _CFAllocatorRef, values *unsafe.Pointer, numValues _CFIndex, callbacks *_CFArrayCallBacks) _CFArrayRef - -var _CFArrayGetValueAtIndex func(array _CFArrayRef, index _CFIndex) uintptr - -var _CFArrayGetCount func(array _CFArrayRef) _CFIndex - -var _CFDictionaryCreate func(allocator _CFAllocatorRef, keys *unsafe.Pointer, values *unsafe.Pointer, numValues _CFIndex, keyCallBacks *_CFDictionaryKeyCallBacks, valueCallBacks *_CFDictionaryValueCallBacks) _CFDictionaryRef - -var _CFRelease func(cf _CFTypeRef) - -var _CFRunLoopGetMain func() _CFRunLoopRef - -var _CFRunLoopRunInMode func(mode _CFRunLoopMode, seconds _CFTimeInterval, returnAfterSourceHandled bool) _CFRunLoopRunResult - -var _CFGetTypeID func(cf _CFTypeRef) _CFTypeID - -var _CFStringGetCString func(theString _CFStringRef, buffer []byte, encoding _CFStringEncoding) bool - -var _CFStringCreateWithCString func(alloc _CFAllocatorRef, cstr []byte, encoding _CFStringEncoding) _CFStringRef +var ( + _CFNumberCreate func(allocator _CFAllocatorRef, theType _CFNumberType, valuePtr unsafe.Pointer) _CFNumberRef + _CFNumberGetValue func(number _CFNumberRef, theType _CFNumberType, valuePtr unsafe.Pointer) bool + _CFArrayCreate func(allocator _CFAllocatorRef, values *unsafe.Pointer, numValues _CFIndex, callbacks *_CFArrayCallBacks) _CFArrayRef + _CFArrayGetValueAtIndex func(array _CFArrayRef, index _CFIndex) uintptr + _CFArrayGetCount func(array _CFArrayRef) _CFIndex + _CFDictionaryCreate func(allocator _CFAllocatorRef, keys *unsafe.Pointer, values *unsafe.Pointer, numValues _CFIndex, keyCallBacks *_CFDictionaryKeyCallBacks, valueCallBacks *_CFDictionaryValueCallBacks) _CFDictionaryRef + _CFRelease func(cf _CFTypeRef) + _CFRunLoopGetMain func() _CFRunLoopRef + _CFRunLoopRunInMode func(mode _CFRunLoopMode, seconds _CFTimeInterval, returnAfterSourceHandled bool) _CFRunLoopRunResult + _CFGetTypeID func(cf _CFTypeRef) _CFTypeID + _CFStringGetCString func(theString _CFStringRef, buffer []byte, encoding _CFStringEncoding) bool + _CFStringCreateWithCString func(alloc _CFAllocatorRef, cstr []byte, encoding _CFStringEncoding) _CFStringRef +) diff --git a/internal/gamepad/api_hid_darwin.go b/internal/gamepad/api_hid_darwin.go index 19f8f778f..fa0339e7c 100644 --- a/internal/gamepad/api_hid_darwin.go +++ b/internal/gamepad/api_hid_darwin.go @@ -74,13 +74,15 @@ var ( kIOHIDDeviceUsageKey = []byte("DeviceUsage\x00") ) -type _IOOptionBits uint32 -type _IOHIDManagerRef uintptr -type _IOHIDDeviceRef uintptr -type _IOHIDElementRef uintptr -type _IOHIDValueRef uintptr -type _IOReturn int32 -type _IOHIDElementType uint32 +type ( + _IOOptionBits uint32 + _IOHIDManagerRef uintptr + _IOHIDDeviceRef uintptr + _IOHIDElementRef uintptr + _IOHIDValueRef uintptr + _IOReturn int32 + _IOHIDElementType uint32 +) type _IOHIDDeviceCallback func(context unsafe.Pointer, result _IOReturn, sender unsafe.Pointer, device _IOHIDDeviceRef) @@ -105,34 +107,21 @@ func init() { purego.RegisterLibFunc(&_IOHIDDeviceCopyMatchingElements, iokit, "IOHIDDeviceCopyMatchingElements") } -var _IOHIDElementGetTypeID func() _CFTypeID - -var _IOHIDManagerCreate func(allocator _CFAllocatorRef, options _IOOptionBits) _IOHIDManagerRef - -var _IOHIDDeviceGetProperty func(device _IOHIDDeviceRef, key _CFStringRef) _CFTypeRef - -var _IOHIDManagerOpen func(manager _IOHIDManagerRef, options _IOOptionBits) _IOReturn - -var _IOHIDManagerSetDeviceMatchingMultiple func(manager _IOHIDManagerRef, multiple _CFArrayRef) - -var _IOHIDManagerRegisterDeviceMatchingCallback func(manager _IOHIDManagerRef, callback _IOHIDDeviceCallback, context unsafe.Pointer) - -var _IOHIDManagerRegisterDeviceRemovalCallback func(manager _IOHIDManagerRef, callback _IOHIDDeviceCallback, context unsafe.Pointer) - -var _IOHIDManagerScheduleWithRunLoop func(manager _IOHIDManagerRef, runLoop _CFRunLoopRef, runLoopMode _CFStringRef) - -var _IOHIDElementGetType func(element _IOHIDElementRef) _IOHIDElementType - -var _IOHIDElementGetUsage func(element _IOHIDElementRef) uint32 - -var _IOHIDElementGetUsagePage func(element _IOHIDElementRef) uint32 - -var _IOHIDElementGetLogicalMin func(element _IOHIDElementRef) _CFIndex - -var _IOHIDElementGetLogicalMax func(element _IOHIDElementRef) _CFIndex - -var _IOHIDDeviceGetValue func(device _IOHIDDeviceRef, element _IOHIDElementRef, pValue *_IOHIDValueRef) _IOReturn - -var _IOHIDValueGetIntegerValue func(value _IOHIDValueRef) _CFIndex - -var _IOHIDDeviceCopyMatchingElements func(device _IOHIDDeviceRef, matching _CFDictionaryRef, options _IOOptionBits) _CFArrayRef +var ( + _IOHIDElementGetTypeID func() _CFTypeID + _IOHIDManagerCreate func(allocator _CFAllocatorRef, options _IOOptionBits) _IOHIDManagerRef + _IOHIDDeviceGetProperty func(device _IOHIDDeviceRef, key _CFStringRef) _CFTypeRef + _IOHIDManagerOpen func(manager _IOHIDManagerRef, options _IOOptionBits) _IOReturn + _IOHIDManagerSetDeviceMatchingMultiple func(manager _IOHIDManagerRef, multiple _CFArrayRef) + _IOHIDManagerRegisterDeviceMatchingCallback func(manager _IOHIDManagerRef, callback _IOHIDDeviceCallback, context unsafe.Pointer) + _IOHIDManagerRegisterDeviceRemovalCallback func(manager _IOHIDManagerRef, callback _IOHIDDeviceCallback, context unsafe.Pointer) + _IOHIDManagerScheduleWithRunLoop func(manager _IOHIDManagerRef, runLoop _CFRunLoopRef, runLoopMode _CFStringRef) + _IOHIDElementGetType func(element _IOHIDElementRef) _IOHIDElementType + _IOHIDElementGetUsage func(element _IOHIDElementRef) uint32 + _IOHIDElementGetUsagePage func(element _IOHIDElementRef) uint32 + _IOHIDElementGetLogicalMin func(element _IOHIDElementRef) _CFIndex + _IOHIDElementGetLogicalMax func(element _IOHIDElementRef) _CFIndex + _IOHIDDeviceGetValue func(device _IOHIDDeviceRef, element _IOHIDElementRef, pValue *_IOHIDValueRef) _IOReturn + _IOHIDValueGetIntegerValue func(value _IOHIDValueRef) _CFIndex + _IOHIDDeviceCopyMatchingElements func(device _IOHIDDeviceRef, matching _CFDictionaryRef, options _IOOptionBits) _CFArrayRef +)