2009-03-10 20:59:20 +01:00
|
|
|
/* DirectInput Joystick device for Mac OS/X
|
|
|
|
*
|
|
|
|
* Copyright 1998 Marcus Meissner
|
|
|
|
* Copyright 1998,1999 Lionel Ulmer
|
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
|
|
|
* Copyright 2009 CodeWeavers, Aric Stewart
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2011-01-24 19:32:15 +01:00
|
|
|
#if defined(HAVE_IOKIT_HID_IOHIDLIB_H)
|
2009-03-10 20:59:20 +01:00
|
|
|
#define ULONG __carbon_ULONG
|
|
|
|
#define E_INVALIDARG __carbon_E_INVALIDARG
|
|
|
|
#define E_OUTOFMEMORY __carbon_E_OUTOFMEMORY
|
|
|
|
#define E_HANDLE __carbon_E_HANDLE
|
|
|
|
#define E_ACCESSDENIED __carbon_E_ACCESSDENIED
|
|
|
|
#define E_UNEXPECTED __carbon_E_UNEXPECTED
|
|
|
|
#define E_FAIL __carbon_E_FAIL
|
|
|
|
#define E_ABORT __carbon_E_ABORT
|
|
|
|
#define E_POINTER __carbon_E_POINTER
|
|
|
|
#define E_NOINTERFACE __carbon_E_NOINTERFACE
|
|
|
|
#define E_NOTIMPL __carbon_E_NOTIMPL
|
|
|
|
#define S_FALSE __carbon_S_FALSE
|
|
|
|
#define S_OK __carbon_S_OK
|
|
|
|
#define HRESULT_FACILITY __carbon_HRESULT_FACILITY
|
|
|
|
#define IS_ERROR __carbon_IS_ERROR
|
|
|
|
#define FAILED __carbon_FAILED
|
|
|
|
#define SUCCEEDED __carbon_SUCCEEDED
|
|
|
|
#define MAKE_HRESULT __carbon_MAKE_HRESULT
|
|
|
|
#define HRESULT __carbon_HRESULT
|
|
|
|
#define STDMETHODCALLTYPE __carbon_STDMETHODCALLTYPE
|
|
|
|
#include <IOKit/hid/IOHIDLib.h>
|
|
|
|
#undef ULONG
|
|
|
|
#undef E_INVALIDARG
|
|
|
|
#undef E_OUTOFMEMORY
|
|
|
|
#undef E_HANDLE
|
|
|
|
#undef E_ACCESSDENIED
|
|
|
|
#undef E_UNEXPECTED
|
|
|
|
#undef E_FAIL
|
|
|
|
#undef E_ABORT
|
|
|
|
#undef E_POINTER
|
|
|
|
#undef E_NOINTERFACE
|
|
|
|
#undef E_NOTIMPL
|
|
|
|
#undef S_FALSE
|
|
|
|
#undef S_OK
|
|
|
|
#undef HRESULT_FACILITY
|
|
|
|
#undef IS_ERROR
|
|
|
|
#undef FAILED
|
|
|
|
#undef SUCCEEDED
|
|
|
|
#undef MAKE_HRESULT
|
|
|
|
#undef HRESULT
|
|
|
|
#undef STDMETHODCALLTYPE
|
2011-01-24 19:32:15 +01:00
|
|
|
#endif /* HAVE_IOKIT_HID_IOHIDLIB_H */
|
2009-03-10 20:59:20 +01:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "dinput.h"
|
|
|
|
|
|
|
|
#include "dinput_private.h"
|
|
|
|
#include "device_private.h"
|
|
|
|
#include "joystick_private.h"
|
|
|
|
|
2009-03-11 16:49:55 +01:00
|
|
|
#ifdef HAVE_IOHIDMANAGERCREATE
|
2009-03-10 20:59:20 +01:00
|
|
|
|
2011-11-12 23:49:26 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dinput);
|
|
|
|
|
2009-03-10 20:59:20 +01:00
|
|
|
static IOHIDManagerRef gIOHIDManagerRef = NULL;
|
2010-09-21 04:25:27 +02:00
|
|
|
static CFArrayRef gCollections = NULL;
|
2009-03-10 20:59:20 +01:00
|
|
|
|
|
|
|
typedef struct JoystickImpl JoystickImpl;
|
|
|
|
static const IDirectInputDevice8AVtbl JoystickAvt;
|
|
|
|
static const IDirectInputDevice8WVtbl JoystickWvt;
|
|
|
|
|
|
|
|
struct JoystickImpl
|
|
|
|
{
|
|
|
|
struct JoystickGenericImpl generic;
|
|
|
|
|
|
|
|
/* osx private */
|
|
|
|
int id;
|
|
|
|
CFMutableArrayRef elementCFArrayRef;
|
|
|
|
ObjProps **propmap;
|
|
|
|
};
|
|
|
|
|
2011-01-09 23:43:48 +01:00
|
|
|
static inline JoystickImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface)
|
|
|
|
{
|
2011-01-09 23:44:19 +01:00
|
|
|
return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface),
|
|
|
|
JoystickGenericImpl, base), JoystickImpl, generic);
|
2011-01-09 23:43:48 +01:00
|
|
|
}
|
|
|
|
static inline JoystickImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface)
|
|
|
|
{
|
2011-01-09 23:44:19 +01:00
|
|
|
return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface),
|
|
|
|
JoystickGenericImpl, base), JoystickImpl, generic);
|
2011-01-09 23:43:48 +01:00
|
|
|
}
|
|
|
|
|
2009-03-10 20:59:20 +01:00
|
|
|
static const GUID DInput_Wine_OsX_Joystick_GUID = { /* 59CAD8F6-E617-41E2-8EB7-47B23EEEDC5A */
|
|
|
|
0x59CAD8F6, 0xE617, 0x41E2, {0x8E, 0xB7, 0x47, 0xB2, 0x3E, 0xEE, 0xDC, 0x5A}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void CFSetApplierFunctionCopyToCFArray(const void *value, void *context)
|
|
|
|
{
|
|
|
|
CFArrayAppendValue( ( CFMutableArrayRef ) context, value );
|
|
|
|
}
|
|
|
|
|
|
|
|
static CFMutableDictionaryRef creates_osx_device_match(int usage)
|
|
|
|
{
|
|
|
|
CFMutableDictionaryRef result;
|
|
|
|
|
|
|
|
result = CFDictionaryCreateMutable( kCFAllocatorDefault, 0,
|
|
|
|
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );
|
|
|
|
|
|
|
|
if ( result )
|
|
|
|
{
|
|
|
|
int number = kHIDPage_GenericDesktop;
|
|
|
|
CFNumberRef pageCFNumberRef = CFNumberCreate( kCFAllocatorDefault,
|
|
|
|
kCFNumberIntType, &number);
|
|
|
|
|
|
|
|
if ( pageCFNumberRef )
|
|
|
|
{
|
|
|
|
CFNumberRef usageCFNumberRef;
|
|
|
|
|
|
|
|
CFDictionarySetValue( result, CFSTR( kIOHIDDeviceUsagePageKey ),
|
|
|
|
pageCFNumberRef );
|
|
|
|
CFRelease( pageCFNumberRef );
|
|
|
|
|
|
|
|
usageCFNumberRef = CFNumberCreate( kCFAllocatorDefault,
|
|
|
|
kCFNumberIntType, &usage);
|
|
|
|
if ( usageCFNumberRef )
|
|
|
|
{
|
|
|
|
CFDictionarySetValue( result, CFSTR( kIOHIDDeviceUsageKey ),
|
|
|
|
usageCFNumberRef );
|
|
|
|
CFRelease( usageCFNumberRef );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-12 10:10:44 +01:00
|
|
|
ERR("CFNumberCreate() failed.\n");
|
2009-03-10 20:59:20 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-12 10:10:44 +01:00
|
|
|
ERR("CFNumberCreate failed.\n");
|
2009-03-10 20:59:20 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-12 10:10:44 +01:00
|
|
|
ERR("CFDictionaryCreateMutable failed.\n");
|
2009-03-10 20:59:20 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-09-21 04:25:27 +02:00
|
|
|
static CFIndex find_top_level(IOHIDDeviceRef tIOHIDDeviceRef, CFArrayRef topLevels)
|
|
|
|
{
|
|
|
|
CFArrayRef gElementCFArrayRef;
|
|
|
|
CFIndex numTops = 0;
|
|
|
|
|
|
|
|
if (!tIOHIDDeviceRef)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
gElementCFArrayRef = IOHIDDeviceCopyMatchingElements(tIOHIDDeviceRef, NULL, 0);
|
|
|
|
|
|
|
|
if (gElementCFArrayRef)
|
|
|
|
{
|
|
|
|
CFIndex idx, cnt = CFArrayGetCount(gElementCFArrayRef);
|
|
|
|
for (idx=0; idx<cnt; idx++)
|
|
|
|
{
|
|
|
|
IOHIDElementRef tIOHIDElementRef = (IOHIDElementRef)CFArrayGetValueAtIndex(gElementCFArrayRef, idx);
|
|
|
|
int eleType = IOHIDElementGetType(tIOHIDElementRef);
|
|
|
|
|
|
|
|
/* Check for top-level gaming device collections */
|
|
|
|
if (eleType == kIOHIDElementTypeCollection && IOHIDElementGetParent(tIOHIDElementRef) == 0)
|
|
|
|
{
|
|
|
|
int tUsagePage = IOHIDElementGetUsagePage(tIOHIDElementRef);
|
|
|
|
int tUsage = IOHIDElementGetUsage(tIOHIDElementRef);
|
|
|
|
|
|
|
|
if (tUsagePage == kHIDPage_GenericDesktop &&
|
|
|
|
(tUsage == kHIDUsage_GD_Joystick || tUsage == kHIDUsage_GD_GamePad))
|
|
|
|
{
|
|
|
|
CFArrayAppendValue((CFMutableArrayRef)topLevels, tIOHIDElementRef);
|
|
|
|
numTops++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return numTops;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_element_children(IOHIDElementRef tElement, CFArrayRef childElements)
|
|
|
|
{
|
|
|
|
CFIndex idx, cnt;
|
|
|
|
CFArrayRef tElementChildrenArray = IOHIDElementGetChildren(tElement);
|
|
|
|
|
|
|
|
cnt = CFArrayGetCount(tElementChildrenArray);
|
|
|
|
if (cnt < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Either add the element to the array or grab its children */
|
|
|
|
for (idx=0; idx<cnt; idx++)
|
|
|
|
{
|
|
|
|
IOHIDElementRef tChildElementRef;
|
|
|
|
|
|
|
|
tChildElementRef = (IOHIDElementRef)CFArrayGetValueAtIndex(tElementChildrenArray, idx);
|
|
|
|
if (IOHIDElementGetType(tChildElementRef) == kIOHIDElementTypeCollection)
|
|
|
|
get_element_children(tChildElementRef, childElements);
|
|
|
|
else
|
|
|
|
CFArrayAppendValue((CFMutableArrayRef)childElements, tChildElementRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-10 20:59:20 +01:00
|
|
|
static int find_osx_devices(void)
|
|
|
|
{
|
|
|
|
IOReturn tIOReturn;
|
|
|
|
CFMutableDictionaryRef result;
|
|
|
|
CFSetRef devset;
|
|
|
|
CFArrayRef matching;
|
|
|
|
|
|
|
|
gIOHIDManagerRef = IOHIDManagerCreate( kCFAllocatorDefault, 0L );
|
|
|
|
tIOReturn = IOHIDManagerOpen( gIOHIDManagerRef, 0L);
|
|
|
|
if ( kIOReturnSuccess != tIOReturn )
|
|
|
|
{
|
2009-04-20 15:10:22 +02:00
|
|
|
ERR("Couldn't open IOHIDManager.\n");
|
2009-03-10 20:59:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
matching = CFArrayCreateMutable( kCFAllocatorDefault, 0,
|
|
|
|
&kCFTypeArrayCallBacks );
|
|
|
|
|
|
|
|
/* build matching dictionary */
|
2010-09-21 04:25:27 +02:00
|
|
|
result = creates_osx_device_match(kHIDUsage_GD_Joystick);
|
2009-03-10 20:59:20 +01:00
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
CFRelease(matching);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
CFArrayAppendValue( ( CFMutableArrayRef )matching, result );
|
2010-09-21 04:25:27 +02:00
|
|
|
result = creates_osx_device_match(kHIDUsage_GD_GamePad);
|
2009-03-10 20:59:20 +01:00
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
CFRelease(matching);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
CFArrayAppendValue( ( CFMutableArrayRef )matching, result );
|
|
|
|
|
|
|
|
IOHIDManagerSetDeviceMatchingMultiple( gIOHIDManagerRef, matching);
|
|
|
|
devset = IOHIDManagerCopyDevices( gIOHIDManagerRef );
|
|
|
|
if (devset)
|
|
|
|
{
|
2010-09-21 04:25:27 +02:00
|
|
|
CFIndex countDevices, countCollections, idx;
|
|
|
|
CFArrayRef gDevices = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
|
2009-03-10 20:59:20 +01:00
|
|
|
CFSetApplyFunction(devset, CFSetApplierFunctionCopyToCFArray, (void*)gDevices);
|
|
|
|
CFRelease( devset);
|
2010-09-21 04:25:27 +02:00
|
|
|
countDevices = CFArrayGetCount(gDevices);
|
2009-03-10 20:59:20 +01:00
|
|
|
|
2010-09-21 04:25:27 +02:00
|
|
|
gCollections = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
|
|
|
|
if (!gCollections)
|
|
|
|
return 0;
|
2009-03-10 20:59:20 +01:00
|
|
|
|
2010-09-21 04:25:27 +02:00
|
|
|
countCollections = 0;
|
|
|
|
for (idx = 0; idx < countDevices; idx++)
|
|
|
|
{
|
|
|
|
CFIndex tTop;
|
|
|
|
IOHIDDeviceRef tDevice;
|
|
|
|
|
|
|
|
tDevice = (IOHIDDeviceRef) CFArrayGetValueAtIndex(gDevices, idx);
|
|
|
|
tTop = find_top_level(tDevice, gCollections);
|
|
|
|
countCollections += tTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(gDevices);
|
|
|
|
|
|
|
|
TRACE("found %i device(s), %i collection(s)\n",(int)countDevices,(int)countCollections);
|
|
|
|
return (int)countCollections;
|
2009-03-10 20:59:20 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_osx_device_name(int id, char *name, int length)
|
|
|
|
{
|
|
|
|
CFStringRef str;
|
2010-09-21 04:25:27 +02:00
|
|
|
IOHIDElementRef tIOHIDElementRef;
|
2009-03-10 20:59:20 +01:00
|
|
|
IOHIDDeviceRef tIOHIDDeviceRef;
|
|
|
|
|
2010-09-21 04:25:27 +02:00
|
|
|
if (!gCollections)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
tIOHIDElementRef = (IOHIDElementRef)CFArrayGetValueAtIndex(gCollections, id);
|
|
|
|
|
|
|
|
if (!tIOHIDElementRef)
|
|
|
|
{
|
|
|
|
ERR("Invalid Element requested %i\n",id);
|
2009-03-10 20:59:20 +01:00
|
|
|
return 0;
|
2010-09-21 04:25:27 +02:00
|
|
|
}
|
2009-03-10 20:59:20 +01:00
|
|
|
|
2010-09-21 04:25:27 +02:00
|
|
|
tIOHIDDeviceRef = IOHIDElementGetDevice(tIOHIDElementRef);
|
2009-03-10 20:59:20 +01:00
|
|
|
|
|
|
|
if (name)
|
|
|
|
name[0] = 0;
|
|
|
|
|
|
|
|
if (!tIOHIDDeviceRef)
|
|
|
|
{
|
|
|
|
ERR("Invalid Device requested %i\n",id);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
str = IOHIDDeviceGetProperty(tIOHIDDeviceRef, CFSTR( kIOHIDProductKey ));
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
CFIndex len = CFStringGetLength(str);
|
|
|
|
if (length >= len)
|
|
|
|
{
|
|
|
|
CFStringGetCString(str,name,length,kCFStringEncodingASCII);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return (len+1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-12 14:03:04 +01:00
|
|
|
static void insert_sort_button(int header, IOHIDElementRef tIOHIDElementRef,
|
|
|
|
CFMutableArrayRef elementCFArrayRef, int index,
|
|
|
|
int target)
|
|
|
|
{
|
|
|
|
IOHIDElementRef targetElement;
|
|
|
|
int usage;
|
|
|
|
|
|
|
|
CFArraySetValueAtIndex(elementCFArrayRef, header+index, NULL);
|
|
|
|
targetElement = ( IOHIDElementRef ) CFArrayGetValueAtIndex( elementCFArrayRef, header+target);
|
|
|
|
if (targetElement == NULL)
|
|
|
|
{
|
|
|
|
CFArraySetValueAtIndex(elementCFArrayRef, header+target,tIOHIDElementRef);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
usage = IOHIDElementGetUsage( targetElement );
|
|
|
|
usage --; /* usage 1 based index */
|
|
|
|
|
|
|
|
insert_sort_button(header, targetElement, elementCFArrayRef, target, usage);
|
|
|
|
CFArraySetValueAtIndex(elementCFArrayRef, header+target,tIOHIDElementRef);
|
|
|
|
}
|
|
|
|
|
2009-03-10 20:59:56 +01:00
|
|
|
static void get_osx_device_elements(JoystickImpl *device, int axis_map[8])
|
2009-03-10 20:59:20 +01:00
|
|
|
{
|
2010-09-21 04:25:27 +02:00
|
|
|
IOHIDElementRef tIOHIDElementRef;
|
2009-03-10 20:59:20 +01:00
|
|
|
CFArrayRef gElementCFArrayRef;
|
|
|
|
DWORD axes = 0;
|
2009-03-10 21:00:03 +01:00
|
|
|
DWORD sliders = 0;
|
2009-03-10 20:59:20 +01:00
|
|
|
DWORD buttons = 0;
|
|
|
|
DWORD povs = 0;
|
|
|
|
|
|
|
|
device->elementCFArrayRef = NULL;
|
|
|
|
|
2010-09-21 04:25:27 +02:00
|
|
|
if (!gCollections)
|
2009-03-10 20:59:20 +01:00
|
|
|
return;
|
|
|
|
|
2010-09-21 04:25:27 +02:00
|
|
|
tIOHIDElementRef = (IOHIDElementRef)CFArrayGetValueAtIndex(gCollections, device->id);
|
2009-03-10 20:59:20 +01:00
|
|
|
|
2010-09-21 04:25:27 +02:00
|
|
|
if (!tIOHIDElementRef)
|
2009-03-10 20:59:20 +01:00
|
|
|
return;
|
|
|
|
|
2010-09-21 04:25:27 +02:00
|
|
|
gElementCFArrayRef = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
|
|
|
|
get_element_children(tIOHIDElementRef, gElementCFArrayRef);
|
2009-03-10 20:59:20 +01:00
|
|
|
|
|
|
|
if (gElementCFArrayRef)
|
|
|
|
{
|
|
|
|
CFIndex idx, cnt = CFArrayGetCount( gElementCFArrayRef );
|
|
|
|
/* build our element array in the order that dinput expects */
|
|
|
|
device->elementCFArrayRef = CFArrayCreateMutable(NULL,0,NULL);
|
|
|
|
|
|
|
|
for ( idx = 0; idx < cnt; idx++ )
|
|
|
|
{
|
|
|
|
IOHIDElementRef tIOHIDElementRef = ( IOHIDElementRef ) CFArrayGetValueAtIndex( gElementCFArrayRef, idx );
|
|
|
|
int eleType = IOHIDElementGetType( tIOHIDElementRef );
|
|
|
|
switch(eleType)
|
|
|
|
{
|
|
|
|
case kIOHIDElementTypeInput_Button:
|
|
|
|
{
|
2009-03-11 21:06:31 +01:00
|
|
|
int usagePage = IOHIDElementGetUsagePage( tIOHIDElementRef );
|
|
|
|
if (usagePage != kHIDPage_Button)
|
|
|
|
{
|
2011-07-30 12:03:08 +02:00
|
|
|
/* avoid strange elements found on the 360 controller */
|
2009-03-11 21:06:31 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-03-10 20:59:20 +01:00
|
|
|
if (buttons < 128)
|
|
|
|
{
|
|
|
|
CFArrayInsertValueAtIndex(device->elementCFArrayRef, (axes+povs+buttons), tIOHIDElementRef);
|
|
|
|
buttons++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-03-10 20:59:28 +01:00
|
|
|
case kIOHIDElementTypeInput_Axis:
|
|
|
|
{
|
|
|
|
CFArrayInsertValueAtIndex(device->elementCFArrayRef, axes, tIOHIDElementRef);
|
|
|
|
axes++;
|
|
|
|
break;
|
|
|
|
}
|
2009-03-10 20:59:35 +01:00
|
|
|
case kIOHIDElementTypeInput_Misc:
|
|
|
|
{
|
|
|
|
uint32_t usage = IOHIDElementGetUsage( tIOHIDElementRef );
|
|
|
|
switch(usage)
|
|
|
|
{
|
|
|
|
case kHIDUsage_GD_Hatswitch:
|
|
|
|
{
|
|
|
|
CFArrayInsertValueAtIndex(device->elementCFArrayRef, (axes+povs), tIOHIDElementRef);
|
|
|
|
povs++;
|
|
|
|
break;
|
|
|
|
}
|
2009-03-10 21:00:03 +01:00
|
|
|
case kHIDUsage_GD_Slider:
|
|
|
|
sliders ++;
|
|
|
|
if (sliders > 2)
|
|
|
|
break;
|
|
|
|
/* fallthrough, sliders are axis */
|
2009-03-10 20:59:41 +01:00
|
|
|
case kHIDUsage_GD_X:
|
|
|
|
case kHIDUsage_GD_Y:
|
|
|
|
case kHIDUsage_GD_Z:
|
2009-03-10 20:59:49 +01:00
|
|
|
case kHIDUsage_GD_Rx:
|
|
|
|
case kHIDUsage_GD_Ry:
|
|
|
|
case kHIDUsage_GD_Rz:
|
2009-03-10 20:59:41 +01:00
|
|
|
{
|
|
|
|
CFArrayInsertValueAtIndex(device->elementCFArrayRef, axes, tIOHIDElementRef);
|
2009-03-10 20:59:56 +01:00
|
|
|
axis_map[axes]=usage;
|
2009-03-10 20:59:41 +01:00
|
|
|
axes++;
|
|
|
|
break;
|
|
|
|
}
|
2009-03-10 20:59:35 +01:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled usage %i\n",usage);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-03-10 20:59:20 +01:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled type %i\n",eleType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
device->generic.devcaps.dwAxes = axes;
|
|
|
|
device->generic.devcaps.dwButtons = buttons;
|
|
|
|
device->generic.devcaps.dwPOVs = povs;
|
2009-03-12 14:03:04 +01:00
|
|
|
|
|
|
|
/* Sort buttons into correct order */
|
|
|
|
for (buttons = 0; buttons < device->generic.devcaps.dwButtons; buttons++)
|
|
|
|
{
|
|
|
|
IOHIDElementRef tIOHIDElementRef = ( IOHIDElementRef ) CFArrayGetValueAtIndex( device->elementCFArrayRef, axes+povs+buttons);
|
|
|
|
uint32_t usage = IOHIDElementGetUsage( tIOHIDElementRef );
|
|
|
|
usage --; /* usage is 1 indexed we need 0 indexed */
|
|
|
|
if (usage == buttons)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
insert_sort_button(axes+povs, tIOHIDElementRef, device->elementCFArrayRef,buttons,usage);
|
|
|
|
}
|
2009-03-10 20:59:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void get_osx_device_elements_props(JoystickImpl *device)
|
|
|
|
{
|
|
|
|
CFArrayRef gElementCFArrayRef = device->elementCFArrayRef;
|
|
|
|
|
|
|
|
if (gElementCFArrayRef)
|
|
|
|
{
|
|
|
|
CFIndex idx, cnt = CFArrayGetCount( gElementCFArrayRef );
|
|
|
|
|
|
|
|
for ( idx = 0; idx < cnt; idx++ )
|
|
|
|
{
|
|
|
|
IOHIDElementRef tIOHIDElementRef = ( IOHIDElementRef ) CFArrayGetValueAtIndex( gElementCFArrayRef, idx );
|
|
|
|
|
|
|
|
device->generic.props[idx].lDevMin = IOHIDElementGetLogicalMin(tIOHIDElementRef);
|
|
|
|
device->generic.props[idx].lDevMax = IOHIDElementGetLogicalMax(tIOHIDElementRef);
|
|
|
|
device->generic.props[idx].lMin = 0;
|
|
|
|
device->generic.props[idx].lMax = 0xffff;
|
|
|
|
device->generic.props[idx].lDeadZone = 0;
|
|
|
|
device->generic.props[idx].lSaturation = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-03 15:25:11 +01:00
|
|
|
static void poll_osx_device_state(LPDIRECTINPUTDEVICE8A iface)
|
2009-03-10 20:59:20 +01:00
|
|
|
{
|
2011-01-09 23:43:48 +01:00
|
|
|
JoystickImpl *device = impl_from_IDirectInputDevice8A(iface);
|
2010-09-21 04:25:27 +02:00
|
|
|
IOHIDElementRef tIOHIDTopElementRef;
|
2009-03-10 20:59:20 +01:00
|
|
|
IOHIDDeviceRef tIOHIDDeviceRef;
|
|
|
|
CFArrayRef gElementCFArrayRef = device->elementCFArrayRef;
|
|
|
|
|
|
|
|
TRACE("polling device %i\n",device->id);
|
|
|
|
|
2010-09-21 04:25:27 +02:00
|
|
|
if (!gCollections)
|
2009-03-10 20:59:20 +01:00
|
|
|
return;
|
|
|
|
|
2010-09-21 04:25:27 +02:00
|
|
|
tIOHIDTopElementRef = (IOHIDElementRef) CFArrayGetValueAtIndex(gCollections, device->id);
|
|
|
|
tIOHIDDeviceRef = IOHIDElementGetDevice(tIOHIDTopElementRef);
|
2009-03-10 20:59:20 +01:00
|
|
|
|
|
|
|
if (!tIOHIDDeviceRef)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gElementCFArrayRef)
|
|
|
|
{
|
|
|
|
int button_idx = 0;
|
2009-03-10 20:59:35 +01:00
|
|
|
int pov_idx = 0;
|
2009-03-10 21:00:03 +01:00
|
|
|
int slider_idx = 0;
|
2011-06-16 21:11:46 +02:00
|
|
|
int inst_id;
|
2009-03-10 20:59:20 +01:00
|
|
|
CFIndex idx, cnt = CFArrayGetCount( gElementCFArrayRef );
|
|
|
|
|
|
|
|
for ( idx = 0; idx < cnt; idx++ )
|
|
|
|
{
|
|
|
|
IOHIDValueRef valueRef;
|
2011-06-16 21:11:46 +02:00
|
|
|
int val, oldVal, newVal;
|
2009-03-10 20:59:20 +01:00
|
|
|
IOHIDElementRef tIOHIDElementRef = ( IOHIDElementRef ) CFArrayGetValueAtIndex( gElementCFArrayRef, idx );
|
|
|
|
int eleType = IOHIDElementGetType( tIOHIDElementRef );
|
|
|
|
|
|
|
|
switch(eleType)
|
|
|
|
{
|
|
|
|
case kIOHIDElementTypeInput_Button:
|
|
|
|
if(button_idx < 128)
|
|
|
|
{
|
|
|
|
IOHIDDeviceGetValue(tIOHIDDeviceRef, tIOHIDElementRef, &valueRef);
|
|
|
|
val = IOHIDValueGetIntegerValue(valueRef);
|
2011-06-16 21:11:46 +02:00
|
|
|
newVal = val ? 0x80 : 0x0;
|
|
|
|
oldVal = device->generic.js.rgbButtons[button_idx];
|
|
|
|
device->generic.js.rgbButtons[button_idx] = newVal;
|
|
|
|
if (oldVal != newVal)
|
|
|
|
{
|
|
|
|
inst_id = DIDFT_MAKEINSTANCE(button_idx) | DIDFT_PSHBUTTON;
|
|
|
|
queue_event(iface,inst_id,newVal,GetCurrentTime(),device->generic.base.dinput->evsequence++);
|
|
|
|
}
|
2009-03-10 20:59:20 +01:00
|
|
|
button_idx ++;
|
|
|
|
}
|
|
|
|
break;
|
2009-03-10 20:59:35 +01:00
|
|
|
case kIOHIDElementTypeInput_Misc:
|
|
|
|
{
|
|
|
|
uint32_t usage = IOHIDElementGetUsage( tIOHIDElementRef );
|
|
|
|
switch(usage)
|
|
|
|
{
|
|
|
|
case kHIDUsage_GD_Hatswitch:
|
|
|
|
{
|
|
|
|
IOHIDDeviceGetValue(tIOHIDDeviceRef, tIOHIDElementRef, &valueRef);
|
|
|
|
val = IOHIDValueGetIntegerValue(valueRef);
|
2011-06-16 21:11:46 +02:00
|
|
|
oldVal = device->generic.js.rgdwPOV[pov_idx];
|
2009-03-10 20:59:35 +01:00
|
|
|
if (val >= 8)
|
2011-06-16 21:11:46 +02:00
|
|
|
newVal = -1;
|
2009-03-10 20:59:35 +01:00
|
|
|
else
|
2011-06-16 21:11:46 +02:00
|
|
|
newVal = val * 4500;
|
|
|
|
device->generic.js.rgdwPOV[pov_idx] = newVal;
|
|
|
|
if (oldVal != newVal)
|
|
|
|
{
|
|
|
|
inst_id = DIDFT_MAKEINSTANCE(pov_idx) | DIDFT_POV;
|
|
|
|
queue_event(iface,inst_id,newVal,GetCurrentTime(),device->generic.base.dinput->evsequence++);
|
|
|
|
}
|
2009-03-10 20:59:35 +01:00
|
|
|
pov_idx ++;
|
|
|
|
break;
|
|
|
|
}
|
2009-03-10 20:59:41 +01:00
|
|
|
case kHIDUsage_GD_X:
|
|
|
|
case kHIDUsage_GD_Y:
|
|
|
|
case kHIDUsage_GD_Z:
|
2009-03-10 20:59:49 +01:00
|
|
|
case kHIDUsage_GD_Rx:
|
|
|
|
case kHIDUsage_GD_Ry:
|
|
|
|
case kHIDUsage_GD_Rz:
|
2009-03-10 21:00:03 +01:00
|
|
|
case kHIDUsage_GD_Slider:
|
2009-03-10 20:59:41 +01:00
|
|
|
{
|
2011-06-16 21:11:46 +02:00
|
|
|
int wine_obj = -1;
|
|
|
|
|
2009-03-10 20:59:41 +01:00
|
|
|
IOHIDDeviceGetValue(tIOHIDDeviceRef, tIOHIDElementRef, &valueRef);
|
|
|
|
val = IOHIDValueGetIntegerValue(valueRef);
|
2011-06-16 21:11:46 +02:00
|
|
|
newVal = joystick_map_axis(&device->generic.props[idx], val);
|
2009-03-10 20:59:41 +01:00
|
|
|
switch (usage)
|
|
|
|
{
|
|
|
|
case kHIDUsage_GD_X:
|
2011-06-16 21:11:46 +02:00
|
|
|
wine_obj = 0;
|
|
|
|
oldVal = device->generic.js.lX;
|
|
|
|
device->generic.js.lX = newVal;
|
2009-03-10 20:59:41 +01:00
|
|
|
break;
|
|
|
|
case kHIDUsage_GD_Y:
|
2011-06-16 21:11:46 +02:00
|
|
|
wine_obj = 1;
|
|
|
|
oldVal = device->generic.js.lY;
|
|
|
|
device->generic.js.lY = newVal;
|
2009-03-10 20:59:41 +01:00
|
|
|
break;
|
|
|
|
case kHIDUsage_GD_Z:
|
2011-06-16 21:11:46 +02:00
|
|
|
wine_obj = 2;
|
|
|
|
oldVal = device->generic.js.lZ;
|
|
|
|
device->generic.js.lZ = newVal;
|
2009-03-10 20:59:49 +01:00
|
|
|
break;
|
|
|
|
case kHIDUsage_GD_Rx:
|
2011-06-16 21:11:46 +02:00
|
|
|
wine_obj = 3;
|
|
|
|
oldVal = device->generic.js.lRx;
|
|
|
|
device->generic.js.lRx = newVal;
|
2009-03-10 20:59:49 +01:00
|
|
|
break;
|
|
|
|
case kHIDUsage_GD_Ry:
|
2011-06-16 21:11:46 +02:00
|
|
|
wine_obj = 4;
|
|
|
|
oldVal = device->generic.js.lRy;
|
|
|
|
device->generic.js.lRy = newVal;
|
2009-03-10 20:59:49 +01:00
|
|
|
break;
|
|
|
|
case kHIDUsage_GD_Rz:
|
2011-06-16 21:11:46 +02:00
|
|
|
wine_obj = 5;
|
|
|
|
oldVal = device->generic.js.lRz;
|
|
|
|
device->generic.js.lRz = newVal;
|
2009-03-10 20:59:41 +01:00
|
|
|
break;
|
2009-03-10 21:00:03 +01:00
|
|
|
case kHIDUsage_GD_Slider:
|
2011-06-16 21:11:46 +02:00
|
|
|
wine_obj = 6 + slider_idx;
|
|
|
|
oldVal = device->generic.js.rglSlider[slider_idx];
|
|
|
|
device->generic.js.rglSlider[slider_idx] = newVal;
|
2009-03-10 21:00:03 +01:00
|
|
|
slider_idx ++;
|
|
|
|
break;
|
2009-03-10 20:59:41 +01:00
|
|
|
}
|
2011-06-16 21:11:46 +02:00
|
|
|
if ((wine_obj != -1) &&
|
|
|
|
(oldVal != newVal))
|
|
|
|
{
|
|
|
|
inst_id = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;
|
|
|
|
queue_event(iface,inst_id,newVal,GetCurrentTime(),device->generic.base.dinput->evsequence++);
|
|
|
|
}
|
|
|
|
|
2009-03-10 20:59:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-03-10 20:59:35 +01:00
|
|
|
default:
|
|
|
|
FIXME("unhandled usage %i\n",usage);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-03-10 20:59:20 +01:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled type %i\n",eleType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT find_joystick_devices(void)
|
|
|
|
{
|
|
|
|
static INT joystick_devices_count = -1;
|
|
|
|
|
|
|
|
if (joystick_devices_count != -1) return joystick_devices_count;
|
|
|
|
|
|
|
|
joystick_devices_count = find_osx_devices();
|
|
|
|
|
|
|
|
return joystick_devices_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
|
|
|
|
{
|
|
|
|
if (id >= find_joystick_devices()) return FALSE;
|
|
|
|
|
|
|
|
if (dwFlags & DIEDFL_FORCEFEEDBACK) {
|
|
|
|
WARN("force feedback not supported\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dwDevType == 0) ||
|
|
|
|
((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
|
|
|
|
(((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800)))
|
|
|
|
{
|
|
|
|
/* Return joystick */
|
|
|
|
lpddi->guidInstance = DInput_Wine_OsX_Joystick_GUID;
|
|
|
|
lpddi->guidInstance.Data3 = id;
|
|
|
|
lpddi->guidProduct = DInput_Wine_OsX_Joystick_GUID;
|
|
|
|
/* we only support traditional joysticks for now */
|
|
|
|
if (version >= 0x0800)
|
|
|
|
lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
|
|
|
|
else
|
|
|
|
lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
|
|
|
|
sprintf(lpddi->tszInstanceName, "Joystick %d", id);
|
|
|
|
|
|
|
|
/* get the device name */
|
|
|
|
get_osx_device_name(id, lpddi->tszProductName, MAX_PATH);
|
|
|
|
|
|
|
|
lpddi->guidFFDriver = GUID_NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
|
|
|
|
{
|
|
|
|
char name[MAX_PATH];
|
|
|
|
char friendly[32];
|
|
|
|
|
|
|
|
if (id >= find_joystick_devices()) return FALSE;
|
|
|
|
|
|
|
|
if (dwFlags & DIEDFL_FORCEFEEDBACK) {
|
|
|
|
WARN("force feedback not supported\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dwDevType == 0) ||
|
|
|
|
((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
|
|
|
|
(((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))) {
|
|
|
|
/* Return joystick */
|
|
|
|
lpddi->guidInstance = DInput_Wine_OsX_Joystick_GUID;
|
|
|
|
lpddi->guidInstance.Data3 = id;
|
|
|
|
lpddi->guidProduct = DInput_Wine_OsX_Joystick_GUID;
|
|
|
|
/* we only support traditional joysticks for now */
|
|
|
|
if (version >= 0x0800)
|
|
|
|
lpddi->dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
|
|
|
|
else
|
|
|
|
lpddi->dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
|
|
|
|
sprintf(friendly, "Joystick %d", id);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, friendly, -1, lpddi->tszInstanceName, MAX_PATH);
|
|
|
|
/* get the device name */
|
|
|
|
get_osx_device_name(id, name, MAX_PATH);
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, name, -1, lpddi->tszProductName, MAX_PATH);
|
|
|
|
lpddi->guidFFDriver = GUID_NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:19 +01:00
|
|
|
static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
|
|
|
|
JoystickImpl **pdev, unsigned short index)
|
2009-03-10 20:59:20 +01:00
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
JoystickImpl* newDevice;
|
|
|
|
char name[MAX_PATH];
|
|
|
|
HRESULT hr;
|
|
|
|
LPDIDATAFORMAT df = NULL;
|
|
|
|
int idx = 0;
|
2009-03-10 20:59:56 +01:00
|
|
|
int axis_map[8]; /* max axes */
|
2009-03-10 21:00:03 +01:00
|
|
|
int slider_count = 0;
|
2009-03-10 20:59:20 +01:00
|
|
|
|
2011-01-09 23:44:19 +01:00
|
|
|
TRACE("%s %p %p %hu\n", debugstr_guid(rguid), dinput, pdev, index);
|
2009-03-10 20:59:20 +01:00
|
|
|
|
|
|
|
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
|
|
|
|
if (newDevice == 0) {
|
|
|
|
WARN("out of memory\n");
|
|
|
|
*pdev = 0;
|
|
|
|
return DIERR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
newDevice->id = index;
|
|
|
|
|
2009-04-20 04:33:22 +02:00
|
|
|
newDevice->generic.guidInstance = DInput_Wine_OsX_Joystick_GUID;
|
|
|
|
newDevice->generic.guidInstance.Data3 = index;
|
2009-03-10 20:59:20 +01:00
|
|
|
newDevice->generic.guidProduct = DInput_Wine_OsX_Joystick_GUID;
|
|
|
|
newDevice->generic.joy_polldev = poll_osx_device_state;
|
|
|
|
|
|
|
|
/* get the device name */
|
|
|
|
get_osx_device_name(index, name, MAX_PATH);
|
|
|
|
TRACE("Name %s\n",name);
|
|
|
|
|
|
|
|
/* copy the device name */
|
|
|
|
newDevice->generic.name = HeapAlloc(GetProcessHeap(),0,strlen(name) + 1);
|
|
|
|
strcpy(newDevice->generic.name, name);
|
|
|
|
|
2009-03-10 20:59:56 +01:00
|
|
|
memset(axis_map, 0, sizeof(axis_map));
|
|
|
|
get_osx_device_elements(newDevice, axis_map);
|
2009-03-10 20:59:20 +01:00
|
|
|
|
|
|
|
TRACE("%i axes %i buttons %i povs\n",newDevice->generic.devcaps.dwAxes,newDevice->generic.devcaps.dwButtons,newDevice->generic.devcaps.dwPOVs);
|
|
|
|
|
|
|
|
if (newDevice->generic.devcaps.dwButtons > 128)
|
|
|
|
{
|
|
|
|
WARN("Can't support %d buttons. Clamping down to 128\n", newDevice->generic.devcaps.dwButtons);
|
|
|
|
newDevice->generic.devcaps.dwButtons = 128;
|
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:19 +01:00
|
|
|
newDevice->generic.base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt;
|
|
|
|
newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt;
|
2009-03-10 20:59:20 +01:00
|
|
|
newDevice->generic.base.ref = 1;
|
|
|
|
newDevice->generic.base.dinput = dinput;
|
|
|
|
newDevice->generic.base.guid = *rguid;
|
|
|
|
InitializeCriticalSection(&newDevice->generic.base.crit);
|
|
|
|
newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit");
|
|
|
|
|
|
|
|
/* Create copy of default data format */
|
|
|
|
if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto FAILED;
|
|
|
|
memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
|
|
|
|
|
|
|
|
df->dwNumObjs = newDevice->generic.devcaps.dwAxes + newDevice->generic.devcaps.dwPOVs + newDevice->generic.devcaps.dwButtons;
|
|
|
|
if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto FAILED;
|
|
|
|
|
|
|
|
for (i = 0; i < newDevice->generic.devcaps.dwAxes; i++)
|
|
|
|
{
|
2009-03-10 20:59:56 +01:00
|
|
|
int wine_obj = -1;
|
|
|
|
switch (axis_map[i])
|
|
|
|
{
|
|
|
|
case kHIDUsage_GD_X: wine_obj = 0; break;
|
|
|
|
case kHIDUsage_GD_Y: wine_obj = 1; break;
|
|
|
|
case kHIDUsage_GD_Z: wine_obj = 2; break;
|
|
|
|
case kHIDUsage_GD_Rx: wine_obj = 3; break;
|
|
|
|
case kHIDUsage_GD_Ry: wine_obj = 4; break;
|
|
|
|
case kHIDUsage_GD_Rz: wine_obj = 5; break;
|
2009-03-10 21:00:03 +01:00
|
|
|
case kHIDUsage_GD_Slider:
|
|
|
|
wine_obj = 6 + slider_count;
|
|
|
|
slider_count++;
|
|
|
|
break;
|
2009-03-10 20:59:56 +01:00
|
|
|
}
|
|
|
|
if (wine_obj < 0 ) continue;
|
|
|
|
|
|
|
|
memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize);
|
|
|
|
df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;
|
2009-03-10 20:59:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < newDevice->generic.devcaps.dwPOVs; i++)
|
|
|
|
{
|
|
|
|
memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + 8], df->dwObjSize);
|
|
|
|
df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_POV;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < newDevice->generic.devcaps.dwButtons; i++)
|
|
|
|
{
|
|
|
|
memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + 12], df->dwObjSize);
|
|
|
|
df->rgodf[idx ].pguid = &GUID_Button;
|
|
|
|
df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
|
|
|
|
}
|
|
|
|
newDevice->generic.base.data_format.wine_df = df;
|
|
|
|
|
|
|
|
/* initialize default properties */
|
|
|
|
get_osx_device_elements_props(newDevice);
|
|
|
|
|
2011-01-09 23:43:09 +01:00
|
|
|
IDirectInput_AddRef(&newDevice->generic.base.dinput->IDirectInput7A_iface);
|
2009-03-10 20:59:20 +01:00
|
|
|
|
2011-01-19 05:06:37 +01:00
|
|
|
EnterCriticalSection(&dinput->crit);
|
|
|
|
list_add_tail(&dinput->devices_list, &newDevice->generic.base.entry);
|
|
|
|
LeaveCriticalSection(&dinput->crit);
|
|
|
|
|
2009-03-10 20:59:20 +01:00
|
|
|
newDevice->generic.devcaps.dwSize = sizeof(newDevice->generic.devcaps);
|
|
|
|
newDevice->generic.devcaps.dwFlags = DIDC_ATTACHED;
|
|
|
|
if (newDevice->generic.base.dinput->dwVersion >= 0x0800)
|
|
|
|
newDevice->generic.devcaps.dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
|
|
|
|
else
|
|
|
|
newDevice->generic.devcaps.dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
|
|
|
|
newDevice->generic.devcaps.dwFFSamplePeriod = 0;
|
|
|
|
newDevice->generic.devcaps.dwFFMinTimeResolution = 0;
|
|
|
|
newDevice->generic.devcaps.dwFirmwareRevision = 0;
|
|
|
|
newDevice->generic.devcaps.dwHardwareRevision = 0;
|
|
|
|
newDevice->generic.devcaps.dwFFDriverVersion = 0;
|
|
|
|
|
|
|
|
if (TRACE_ON(dinput)) {
|
|
|
|
_dump_DIDATAFORMAT(newDevice->generic.base.data_format.wine_df);
|
|
|
|
_dump_DIDEVCAPS(&newDevice->generic.devcaps);
|
|
|
|
}
|
|
|
|
|
2011-01-09 23:44:19 +01:00
|
|
|
*pdev = newDevice;
|
2009-03-10 20:59:20 +01:00
|
|
|
|
|
|
|
return DI_OK;
|
|
|
|
|
|
|
|
FAILED:
|
|
|
|
hr = DIERR_OUTOFMEMORY;
|
|
|
|
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
|
|
|
|
HeapFree(GetProcessHeap(), 0, df);
|
|
|
|
release_DataFormat(&newDevice->generic.base.data_format);
|
|
|
|
HeapFree(GetProcessHeap(),0,newDevice->generic.name);
|
|
|
|
HeapFree(GetProcessHeap(),0,newDevice);
|
|
|
|
*pdev = 0;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* get_joystick_index : Get the joystick index from a given GUID
|
|
|
|
*/
|
|
|
|
static unsigned short get_joystick_index(REFGUID guid)
|
|
|
|
{
|
|
|
|
GUID wine_joystick = DInput_Wine_OsX_Joystick_GUID;
|
|
|
|
GUID dev_guid = *guid;
|
|
|
|
|
|
|
|
wine_joystick.Data3 = 0;
|
|
|
|
dev_guid.Data3 = 0;
|
|
|
|
|
|
|
|
/* for the standard joystick GUID use index 0 */
|
|
|
|
if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
|
|
|
|
|
|
|
|
/* for the wine joystick GUIDs use the index stored in Data3 */
|
|
|
|
if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3;
|
|
|
|
|
|
|
|
return 0xffff;
|
|
|
|
}
|
|
|
|
|
2011-01-23 20:44:20 +01:00
|
|
|
static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
|
2009-03-10 20:59:20 +01:00
|
|
|
{
|
|
|
|
unsigned short index;
|
|
|
|
int joystick_devices_count;
|
|
|
|
|
2011-01-23 20:44:20 +01:00
|
|
|
TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
|
2009-03-10 20:59:20 +01:00
|
|
|
*pdev = NULL;
|
|
|
|
|
|
|
|
if ((joystick_devices_count = find_joystick_devices()) == 0)
|
|
|
|
return DIERR_DEVICENOTREG;
|
|
|
|
|
|
|
|
if ((index = get_joystick_index(rguid)) < 0xffff &&
|
|
|
|
joystick_devices_count && index < joystick_devices_count)
|
|
|
|
{
|
2011-01-23 20:44:20 +01:00
|
|
|
JoystickImpl *This;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (riid == NULL)
|
|
|
|
;/* nothing */
|
|
|
|
else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice8A, riid))
|
2009-03-10 20:59:20 +01:00
|
|
|
{
|
2011-01-23 20:44:20 +01:00
|
|
|
unicode = 0;
|
2009-03-10 20:59:20 +01:00
|
|
|
}
|
2011-01-23 20:44:20 +01:00
|
|
|
else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
|
|
|
|
IsEqualGUID(&IID_IDirectInputDevice8W, riid))
|
2009-03-10 20:59:20 +01:00
|
|
|
{
|
2011-01-23 20:44:20 +01:00
|
|
|
unicode = 1;
|
2009-03-10 20:59:20 +01:00
|
|
|
}
|
2011-01-23 20:44:20 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("no interface\n");
|
|
|
|
return DIERR_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = alloc_device(rguid, dinput, &This, index);
|
|
|
|
if (!This) return hr;
|
|
|
|
|
|
|
|
if (unicode)
|
|
|
|
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
|
|
|
|
else
|
|
|
|
*pdev = &This->generic.base.IDirectInputDevice8A_iface;
|
|
|
|
return hr;
|
2009-03-10 20:59:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return DIERR_DEVICENOTREG;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct dinput_device joystick_osx_device = {
|
|
|
|
"Wine OS X joystick driver",
|
|
|
|
joydev_enum_deviceA,
|
|
|
|
joydev_enum_deviceW,
|
2011-01-23 20:44:20 +01:00
|
|
|
joydev_create_device
|
2009-03-10 20:59:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const IDirectInputDevice8AVtbl JoystickAvt =
|
|
|
|
{
|
|
|
|
IDirectInputDevice2AImpl_QueryInterface,
|
|
|
|
IDirectInputDevice2AImpl_AddRef,
|
|
|
|
IDirectInputDevice2AImpl_Release,
|
|
|
|
JoystickAGenericImpl_GetCapabilities,
|
|
|
|
IDirectInputDevice2AImpl_EnumObjects,
|
|
|
|
JoystickAGenericImpl_GetProperty,
|
|
|
|
JoystickAGenericImpl_SetProperty,
|
2009-04-20 04:33:25 +02:00
|
|
|
IDirectInputDevice2AImpl_Acquire,
|
|
|
|
IDirectInputDevice2AImpl_Unacquire,
|
2009-03-10 20:59:20 +01:00
|
|
|
JoystickAGenericImpl_GetDeviceState,
|
|
|
|
IDirectInputDevice2AImpl_GetDeviceData,
|
|
|
|
IDirectInputDevice2AImpl_SetDataFormat,
|
|
|
|
IDirectInputDevice2AImpl_SetEventNotification,
|
|
|
|
IDirectInputDevice2AImpl_SetCooperativeLevel,
|
|
|
|
JoystickAGenericImpl_GetObjectInfo,
|
|
|
|
JoystickAGenericImpl_GetDeviceInfo,
|
|
|
|
IDirectInputDevice2AImpl_RunControlPanel,
|
|
|
|
IDirectInputDevice2AImpl_Initialize,
|
|
|
|
IDirectInputDevice2AImpl_CreateEffect,
|
|
|
|
IDirectInputDevice2AImpl_EnumEffects,
|
|
|
|
IDirectInputDevice2AImpl_GetEffectInfo,
|
|
|
|
IDirectInputDevice2AImpl_GetForceFeedbackState,
|
|
|
|
IDirectInputDevice2AImpl_SendForceFeedbackCommand,
|
|
|
|
IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
|
|
|
|
IDirectInputDevice2AImpl_Escape,
|
|
|
|
JoystickAGenericImpl_Poll,
|
|
|
|
IDirectInputDevice2AImpl_SendDeviceData,
|
|
|
|
IDirectInputDevice7AImpl_EnumEffectsInFile,
|
|
|
|
IDirectInputDevice7AImpl_WriteEffectToFile,
|
2011-07-12 03:36:56 +02:00
|
|
|
JoystickAGenericImpl_BuildActionMap,
|
|
|
|
JoystickAGenericImpl_SetActionMap,
|
2009-03-10 20:59:20 +01:00
|
|
|
IDirectInputDevice8AImpl_GetImageInfo
|
|
|
|
};
|
|
|
|
|
|
|
|
static const IDirectInputDevice8WVtbl JoystickWvt =
|
|
|
|
{
|
|
|
|
IDirectInputDevice2WImpl_QueryInterface,
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice2WImpl_AddRef,
|
|
|
|
IDirectInputDevice2WImpl_Release,
|
2011-01-09 23:44:05 +01:00
|
|
|
JoystickWGenericImpl_GetCapabilities,
|
2009-03-10 20:59:20 +01:00
|
|
|
IDirectInputDevice2WImpl_EnumObjects,
|
2011-01-09 23:44:05 +01:00
|
|
|
JoystickWGenericImpl_GetProperty,
|
|
|
|
JoystickWGenericImpl_SetProperty,
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice2WImpl_Acquire,
|
|
|
|
IDirectInputDevice2WImpl_Unacquire,
|
2011-01-09 23:44:05 +01:00
|
|
|
JoystickWGenericImpl_GetDeviceState,
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice2WImpl_GetDeviceData,
|
|
|
|
IDirectInputDevice2WImpl_SetDataFormat,
|
|
|
|
IDirectInputDevice2WImpl_SetEventNotification,
|
|
|
|
IDirectInputDevice2WImpl_SetCooperativeLevel,
|
2009-03-10 20:59:20 +01:00
|
|
|
JoystickWGenericImpl_GetObjectInfo,
|
|
|
|
JoystickWGenericImpl_GetDeviceInfo,
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice2WImpl_RunControlPanel,
|
|
|
|
IDirectInputDevice2WImpl_Initialize,
|
|
|
|
IDirectInputDevice2WImpl_CreateEffect,
|
2009-03-10 20:59:20 +01:00
|
|
|
IDirectInputDevice2WImpl_EnumEffects,
|
|
|
|
IDirectInputDevice2WImpl_GetEffectInfo,
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice2WImpl_GetForceFeedbackState,
|
|
|
|
IDirectInputDevice2WImpl_SendForceFeedbackCommand,
|
|
|
|
IDirectInputDevice2WImpl_EnumCreatedEffectObjects,
|
|
|
|
IDirectInputDevice2WImpl_Escape,
|
2011-01-09 23:44:05 +01:00
|
|
|
JoystickWGenericImpl_Poll,
|
2011-01-09 23:43:55 +01:00
|
|
|
IDirectInputDevice2WImpl_SendDeviceData,
|
2009-03-10 20:59:20 +01:00
|
|
|
IDirectInputDevice7WImpl_EnumEffectsInFile,
|
|
|
|
IDirectInputDevice7WImpl_WriteEffectToFile,
|
2011-07-12 03:36:56 +02:00
|
|
|
JoystickWGenericImpl_BuildActionMap,
|
|
|
|
JoystickWGenericImpl_SetActionMap,
|
2009-03-10 20:59:20 +01:00
|
|
|
IDirectInputDevice8WImpl_GetImageInfo
|
|
|
|
};
|
|
|
|
|
2009-03-11 16:49:55 +01:00
|
|
|
#else /* HAVE_IOHIDMANAGERCREATE */
|
2009-03-10 20:59:20 +01:00
|
|
|
|
|
|
|
const struct dinput_device joystick_osx_device = {
|
|
|
|
"Wine OS X joystick driver",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-03-11 16:49:55 +01:00
|
|
|
#endif /* HAVE_IOHIDMANAGERCREATE */
|