1 /* DirectInput Joystick device for Mac OS/X
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
6 * Copyright 2009 CodeWeavers, Aric Stewart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 #if defined(HAVE_IOKIT_HID_IOHIDLIB_H)
28 #define LPDWORD UInt32*
30 #define LPLONG SInt32*
31 #define E_PENDING __carbon_E_PENDING
32 #define ULONG __carbon_ULONG
33 #define E_INVALIDARG __carbon_E_INVALIDARG
34 #define E_OUTOFMEMORY __carbon_E_OUTOFMEMORY
35 #define E_HANDLE __carbon_E_HANDLE
36 #define E_ACCESSDENIED __carbon_E_ACCESSDENIED
37 #define E_UNEXPECTED __carbon_E_UNEXPECTED
38 #define E_FAIL __carbon_E_FAIL
39 #define E_ABORT __carbon_E_ABORT
40 #define E_POINTER __carbon_E_POINTER
41 #define E_NOINTERFACE __carbon_E_NOINTERFACE
42 #define E_NOTIMPL __carbon_E_NOTIMPL
43 #define S_FALSE __carbon_S_FALSE
44 #define S_OK __carbon_S_OK
45 #define HRESULT_FACILITY __carbon_HRESULT_FACILITY
46 #define IS_ERROR __carbon_IS_ERROR
47 #define FAILED __carbon_FAILED
48 #define SUCCEEDED __carbon_SUCCEEDED
49 #define MAKE_HRESULT __carbon_MAKE_HRESULT
50 #define HRESULT __carbon_HRESULT
51 #define STDMETHODCALLTYPE __carbon_STDMETHODCALLTYPE
52 #include <IOKit/IOKitLib.h>
53 #include <IOKit/hid/IOHIDLib.h>
54 #include <ForceFeedback/ForceFeedback.h>
68 #undef HRESULT_FACILITY
74 #undef STDMETHODCALLTYPE
80 #endif /* HAVE_IOKIT_HID_IOHIDLIB_H */
82 #include "wine/debug.h"
83 #include "wine/unicode.h"
90 #include "dinput_private.h"
91 #include "device_private.h"
92 #include "joystick_private.h"
94 #ifdef HAVE_IOHIDMANAGERCREATE
96 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
98 static CFMutableArrayRef device_main_elements
= NULL
;
100 typedef struct JoystickImpl JoystickImpl
;
101 static const IDirectInputDevice8AVtbl JoystickAvt
;
102 static const IDirectInputDevice8WVtbl JoystickWvt
;
106 struct JoystickGenericImpl generic
;
112 FFDeviceObjectReference ff
;
116 static inline JoystickImpl
*impl_from_IDirectInputDevice8A(IDirectInputDevice8A
*iface
)
118 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8A_iface
),
119 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
121 static inline JoystickImpl
*impl_from_IDirectInputDevice8W(IDirectInputDevice8W
*iface
)
123 return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface
, IDirectInputDeviceImpl
, IDirectInputDevice8W_iface
),
124 JoystickGenericImpl
, base
), JoystickImpl
, generic
);
127 typedef struct _EffectImpl
{
128 IDirectInputEffect IDirectInputEffect_iface
;
131 JoystickImpl
*device
;
132 FFEffectObjectReference effect
;
138 static EffectImpl
*impl_from_IDirectInputEffect(IDirectInputEffect
*iface
)
140 return CONTAINING_RECORD(iface
, EffectImpl
, IDirectInputEffect_iface
);
143 static const IDirectInputEffectVtbl EffectVtbl
;
145 static const GUID DInput_Wine_OsX_Joystick_GUID
= { /* 59CAD8F6-E617-41E2-8EB7-47B23EEEDC5A */
146 0x59CAD8F6, 0xE617, 0x41E2, {0x8E, 0xB7, 0x47, 0xB2, 0x3E, 0xEE, 0xDC, 0x5A}
149 static HRESULT
osx_to_win32_hresult(HRESULT in
)
151 /* OSX returns 16-bit COM runtime errors, which we should
152 * convert to win32 */
157 return E_OUTOFMEMORY
;
161 return E_NOINTERFACE
;
171 return E_ACCESSDENIED
;
178 static long get_device_property_long(IOHIDDeviceRef device
, CFStringRef key
)
185 assert(IOHIDDeviceGetTypeID() == CFGetTypeID(device
));
187 ref
= IOHIDDeviceGetProperty(device
, key
);
189 if (ref
&& CFNumberGetTypeID() == CFGetTypeID(ref
))
190 CFNumberGetValue((CFNumberRef
)ref
, kCFNumberLongType
, &result
);
196 static CFStringRef
copy_device_name(IOHIDDeviceRef device
)
204 assert(IOHIDDeviceGetTypeID() == CFGetTypeID(device
));
206 ref_name
= IOHIDDeviceGetProperty(device
, CFSTR(kIOHIDProductKey
));
208 if (ref_name
&& CFStringGetTypeID() == CFGetTypeID(ref_name
))
209 name
= CFStringCreateCopy(kCFAllocatorDefault
, ref_name
);
214 vendID
= get_device_property_long(device
, CFSTR(kIOHIDVendorIDKey
));
215 prodID
= get_device_property_long(device
, CFSTR(kIOHIDProductIDKey
));
216 name
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("0x%04lx 0x%04lx"), vendID
, prodID
);
221 ERR("NULL device\n");
222 name
= CFStringCreateCopy(kCFAllocatorDefault
, CFSTR(""));
228 static long get_device_location_ID(IOHIDDeviceRef device
)
230 return get_device_property_long(device
, CFSTR(kIOHIDLocationIDKey
));
233 static void copy_set_to_array(const void *value
, void *context
)
235 CFArrayAppendValue(context
, value
);
238 static CFComparisonResult
device_name_comparator(IOHIDDeviceRef device1
, IOHIDDeviceRef device2
)
240 CFStringRef name1
= copy_device_name(device1
), name2
= copy_device_name(device2
);
241 CFComparisonResult result
= CFStringCompare(name1
, name2
, (kCFCompareForcedOrdering
| kCFCompareNumerically
));
247 static CFComparisonResult
device_location_name_comparator(const void *val1
, const void *val2
, void *context
)
249 IOHIDDeviceRef device1
= (IOHIDDeviceRef
)val1
, device2
= (IOHIDDeviceRef
)val2
;
250 long loc1
= get_device_location_ID(device1
), loc2
= get_device_location_ID(device2
);
253 return kCFCompareLessThan
;
254 else if (loc1
> loc2
)
255 return kCFCompareGreaterThan
;
256 /* virtual joysticks may not have a kIOHIDLocationIDKey and will default to location ID of 0, this orders virtual joysticks by their name */
257 return device_name_comparator(device1
, device2
);
260 static const char* debugstr_cf(CFTypeRef t
)
265 if (!t
) return "(null)";
267 if (CFGetTypeID(t
) == CFStringGetTypeID())
270 s
= CFCopyDescription(t
);
271 ret
= CFStringGetCStringPtr(s
, kCFStringEncodingUTF8
);
272 if (ret
) ret
= debugstr_a(ret
);
275 const UniChar
* u
= CFStringGetCharactersPtr(s
);
277 ret
= debugstr_wn((const WCHAR
*)u
, CFStringGetLength(s
));
282 int len
= min(CFStringGetLength(s
), ARRAY_SIZE(buf
));
283 CFStringGetCharacters(s
, CFRangeMake(0, len
), buf
);
284 ret
= debugstr_wn(buf
, len
);
286 if (s
!= t
) CFRelease(s
);
290 static const char* debugstr_device(IOHIDDeviceRef device
)
292 return wine_dbg_sprintf("<IOHIDDevice %p product %s IOHIDLocationID %lu>", device
,
293 debugstr_cf(IOHIDDeviceGetProperty(device
, CFSTR(kIOHIDProductKey
))),
294 get_device_location_ID(device
));
297 static const char* debugstr_element(IOHIDElementRef element
)
299 return wine_dbg_sprintf("<IOHIDElement %p type %d usage %u/%u device %p>", element
,
300 IOHIDElementGetType(element
), IOHIDElementGetUsagePage(element
),
301 IOHIDElementGetUsage(element
), IOHIDElementGetDevice(element
));
304 static IOHIDDeviceRef
get_device_ref(int id
)
306 IOHIDElementRef device_main_element
;
307 IOHIDDeviceRef hid_device
;
309 TRACE("id %d\n", id
);
311 if (!device_main_elements
|| id
>= CFArrayGetCount(device_main_elements
))
314 device_main_element
= (IOHIDElementRef
)CFArrayGetValueAtIndex(device_main_elements
, id
);
315 if (!device_main_element
)
317 ERR("Invalid Element requested %i\n",id
);
321 hid_device
= IOHIDElementGetDevice(device_main_element
);
324 ERR("Invalid Device requested %i\n",id
);
328 TRACE("-> %s\n", debugstr_device(hid_device
));
332 static HRESULT
get_ff(IOHIDDeviceRef device
, FFDeviceObjectReference
*ret
)
334 io_service_t service
;
335 CFMutableDictionaryRef matching
;
336 CFTypeRef location_id
;
339 TRACE("device %s\n", debugstr_device(device
));
341 matching
= IOServiceMatching(kIOHIDDeviceKey
);
343 WARN("IOServiceMatching failed, force feedback disabled\n");
344 return DIERR_DEVICENOTREG
;
347 location_id
= IOHIDDeviceGetProperty(device
, CFSTR(kIOHIDLocationIDKey
));
350 WARN("IOHIDDeviceGetProperty failed, force feedback disabled\n");
351 return DIERR_DEVICENOTREG
;
354 CFDictionaryAddValue(matching
, CFSTR(kIOHIDLocationIDKey
), location_id
);
356 service
= IOServiceGetMatchingService(kIOMasterPortDefault
, matching
);
359 hr
= osx_to_win32_hresult(FFCreateDevice(service
, ret
));
361 hr
= FFIsForceFeedback(service
) == FF_OK
? S_OK
: S_FALSE
;
363 IOObjectRelease(service
);
364 TRACE("-> hr 0x%08x *ret %p\n", hr
, ret
? *ret
: NULL
);
368 static CFMutableDictionaryRef
create_osx_device_match(int usage
)
370 CFMutableDictionaryRef result
;
372 TRACE("usage %d\n", usage
);
374 result
= CFDictionaryCreateMutable( kCFAllocatorDefault
, 0,
375 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
379 int number
= kHIDPage_GenericDesktop
;
380 CFNumberRef page
= CFNumberCreate( kCFAllocatorDefault
,
381 kCFNumberIntType
, &number
);
385 CFNumberRef cf_usage
;
387 CFDictionarySetValue( result
, CFSTR( kIOHIDDeviceUsagePageKey
), page
);
390 cf_usage
= CFNumberCreate( kCFAllocatorDefault
,
391 kCFNumberIntType
, &usage
);
394 CFDictionarySetValue( result
, CFSTR( kIOHIDDeviceUsageKey
), cf_usage
);
395 CFRelease( cf_usage
);
399 ERR("CFNumberCreate() failed.\n");
406 ERR("CFNumberCreate failed.\n");
413 ERR("CFDictionaryCreateMutable failed.\n");
420 static CFIndex
find_top_level(IOHIDDeviceRef hid_device
, CFMutableArrayRef main_elements
)
425 TRACE("hid_device %s\n", debugstr_device(hid_device
));
430 elements
= IOHIDDeviceCopyMatchingElements(hid_device
, NULL
, 0);
434 CFIndex idx
, cnt
= CFArrayGetCount(elements
);
435 for (idx
=0; idx
<cnt
; idx
++)
437 IOHIDElementRef element
= (IOHIDElementRef
)CFArrayGetValueAtIndex(elements
, idx
);
438 int type
= IOHIDElementGetType(element
);
440 TRACE("element %s\n", debugstr_element(element
));
442 /* Check for top-level gaming device collections */
443 if (type
== kIOHIDElementTypeCollection
&& IOHIDElementGetParent(element
) == 0)
445 int usage_page
= IOHIDElementGetUsagePage(element
);
446 int usage
= IOHIDElementGetUsage(element
);
448 if (usage_page
== kHIDPage_GenericDesktop
&&
449 (usage
== kHIDUsage_GD_Joystick
|| usage
== kHIDUsage_GD_GamePad
))
451 CFArrayAppendValue(main_elements
, element
);
459 TRACE("-> total %d\n", (int)total
);
463 static void get_element_children(IOHIDElementRef element
, CFMutableArrayRef all_children
)
466 CFArrayRef element_children
= IOHIDElementGetChildren(element
);
468 TRACE("element %s\n", debugstr_element(element
));
470 cnt
= CFArrayGetCount(element_children
);
472 /* Either add the element to the array or grab its children */
473 for (idx
=0; idx
<cnt
; idx
++)
475 IOHIDElementRef child
;
477 child
= (IOHIDElementRef
)CFArrayGetValueAtIndex(element_children
, idx
);
478 TRACE("child %s\n", debugstr_element(child
));
479 if (IOHIDElementGetType(child
) == kIOHIDElementTypeCollection
)
480 get_element_children(child
, all_children
);
482 CFArrayAppendValue(all_children
, child
);
486 static int find_osx_devices(void)
488 IOHIDManagerRef hid_manager
;
489 CFMutableDictionaryRef result
;
491 CFMutableArrayRef matching
;
495 hid_manager
= IOHIDManagerCreate( kCFAllocatorDefault
, 0L );
496 if (IOHIDManagerOpen( hid_manager
, 0 ) != kIOReturnSuccess
)
498 ERR("Couldn't open IOHIDManager.\n");
499 CFRelease( hid_manager
);
503 matching
= CFArrayCreateMutable( kCFAllocatorDefault
, 0,
504 &kCFTypeArrayCallBacks
);
506 /* build matching dictionary */
507 result
= create_osx_device_match(kHIDUsage_GD_Joystick
);
513 CFArrayAppendValue( matching
, result
);
515 result
= create_osx_device_match(kHIDUsage_GD_GamePad
);
521 CFArrayAppendValue( matching
, result
);
524 IOHIDManagerSetDeviceMatchingMultiple( hid_manager
, matching
);
525 CFRelease( matching
);
526 devset
= IOHIDManagerCopyDevices( hid_manager
);
529 CFIndex num_devices
, num_main_elements
, idx
;
530 CFMutableArrayRef devices
;
532 num_devices
= CFSetGetCount(devset
);
533 devices
= CFArrayCreateMutable(kCFAllocatorDefault
, num_devices
, &kCFTypeArrayCallBacks
);
534 CFSetApplyFunction(devset
, copy_set_to_array
, devices
);
536 CFArraySortValues(devices
, CFRangeMake(0, num_devices
), device_location_name_comparator
, NULL
);
538 device_main_elements
= CFArrayCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeArrayCallBacks
);
539 if (!device_main_elements
)
541 CFRelease( devices
);
545 num_main_elements
= 0;
546 for (idx
= 0; idx
< num_devices
; idx
++)
549 IOHIDDeviceRef hid_device
;
551 hid_device
= (IOHIDDeviceRef
) CFArrayGetValueAtIndex(devices
, idx
);
552 TRACE("hid_device %s\n", debugstr_device(hid_device
));
553 top
= find_top_level(hid_device
, device_main_elements
);
554 num_main_elements
+= top
;
559 TRACE("found %i device(s), %i collection(s)\n",(int)num_devices
,(int)num_main_elements
);
560 return (int)num_main_elements
;
564 IOHIDManagerClose( hid_manager
, 0 );
565 CFRelease( hid_manager
);
569 static int get_osx_device_name(int id
, char *name
, int length
)
572 IOHIDDeviceRef hid_device
;
574 hid_device
= get_device_ref(id
);
576 TRACE("id %d hid_device %s\n", id
, debugstr_device(hid_device
));
584 str
= IOHIDDeviceGetProperty(hid_device
, CFSTR( kIOHIDProductKey
));
587 CFIndex len
= CFStringGetLength(str
);
590 CFStringGetCString(str
,name
,length
,kCFStringEncodingASCII
);
599 static CFComparisonResult
button_usage_comparator(const void *val1
, const void *val2
, void *context
)
601 IOHIDElementRef element1
= (IOHIDElementRef
)val1
, element2
= (IOHIDElementRef
)val2
;
602 int usage1
= IOHIDElementGetUsage(element1
), usage2
= IOHIDElementGetUsage(element2
);
605 return kCFCompareLessThan
;
607 return kCFCompareGreaterThan
;
608 return kCFCompareEqualTo
;
611 static void get_osx_device_elements(JoystickImpl
*device
, int axis_map
[8])
613 IOHIDElementRef device_main_element
;
614 CFMutableArrayRef elements
;
617 TRACE("device %p device->id %d\n", device
, device
->id
);
619 device
->elements
= NULL
;
621 if (!device_main_elements
|| device
->id
>= CFArrayGetCount(device_main_elements
))
624 device_main_element
= (IOHIDElementRef
)CFArrayGetValueAtIndex(device_main_elements
, device
->id
);
625 TRACE("device_main_element %s\n", debugstr_element(device_main_element
));
626 if (!device_main_element
)
629 elements
= CFArrayCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeArrayCallBacks
);
630 get_element_children(device_main_element
, elements
);
634 CFIndex idx
, cnt
= CFArrayGetCount( elements
);
635 CFMutableArrayRef axes
= CFArrayCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeArrayCallBacks
);
636 CFMutableArrayRef buttons
= CFArrayCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeArrayCallBacks
);
637 CFMutableArrayRef povs
= CFArrayCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeArrayCallBacks
);
639 for ( idx
= 0; idx
< cnt
; idx
++ )
641 IOHIDElementRef element
= ( IOHIDElementRef
) CFArrayGetValueAtIndex( elements
, idx
);
642 int type
= IOHIDElementGetType( element
);
643 int usage_page
= IOHIDElementGetUsagePage( element
);
645 TRACE("element %s\n", debugstr_element(element
));
647 if (usage_page
>= kHIDPage_VendorDefinedStart
)
649 /* vendor pages can repurpose type ids, resulting in incorrect case matches below (e.g. ds4 controllers) */
655 case kIOHIDElementTypeInput_Button
:
657 TRACE("kIOHIDElementTypeInput_Button usage_page %d\n", usage_page
);
658 if (usage_page
!= kHIDPage_Button
)
660 /* avoid strange elements found on the 360 controller */
664 if (CFArrayGetCount(buttons
) < 128)
665 CFArrayAppendValue(buttons
, element
);
668 case kIOHIDElementTypeInput_Axis
:
670 TRACE("kIOHIDElementTypeInput_Axis\n");
671 CFArrayAppendValue(axes
, element
);
674 case kIOHIDElementTypeInput_Misc
:
676 uint32_t usage
= IOHIDElementGetUsage( element
);
679 case kHIDUsage_GD_Hatswitch
:
681 TRACE("kIOHIDElementTypeInput_Misc / kHIDUsage_GD_Hatswitch\n");
682 CFArrayAppendValue(povs
, element
);
685 case kHIDUsage_GD_Slider
:
689 /* fallthrough, sliders are axis */
693 case kHIDUsage_GD_Rx
:
694 case kHIDUsage_GD_Ry
:
695 case kHIDUsage_GD_Rz
:
697 TRACE("kIOHIDElementTypeInput_Misc / kHIDUsage_GD_* (%d)\n", usage
);
698 axis_map
[CFArrayGetCount(axes
)]=usage
;
699 CFArrayAppendValue(axes
, element
);
703 FIXME("kIOHIDElementTypeInput_Misc / Unhandled usage %i\n", usage
);
708 FIXME("Unhandled type %i\n",type
);
712 /* Sort buttons into correct order */
713 CFArraySortValues(buttons
, CFRangeMake(0, CFArrayGetCount(buttons
)), button_usage_comparator
, NULL
);
715 device
->generic
.devcaps
.dwAxes
= CFArrayGetCount(axes
);
716 device
->generic
.devcaps
.dwButtons
= CFArrayGetCount(buttons
);
717 device
->generic
.devcaps
.dwPOVs
= CFArrayGetCount(povs
);
719 TRACE("axes %u povs %u buttons %u\n", device
->generic
.devcaps
.dwAxes
, device
->generic
.devcaps
.dwPOVs
,
720 device
->generic
.devcaps
.dwButtons
);
722 /* build our element array in the order that dinput expects */
723 CFArrayAppendArray(axes
, povs
, CFRangeMake(0, device
->generic
.devcaps
.dwPOVs
));
724 CFArrayAppendArray(axes
, buttons
, CFRangeMake(0, device
->generic
.devcaps
.dwButtons
));
725 device
->elements
= axes
;
734 device
->generic
.devcaps
.dwAxes
= 0;
735 device
->generic
.devcaps
.dwButtons
= 0;
736 device
->generic
.devcaps
.dwPOVs
= 0;
740 static void get_osx_device_elements_props(JoystickImpl
*device
)
742 TRACE("device %p\n", device
);
744 if (device
->elements
)
746 CFIndex idx
, cnt
= CFArrayGetCount( device
->elements
);
748 for ( idx
= 0; idx
< cnt
; idx
++ )
750 IOHIDElementRef element
= ( IOHIDElementRef
) CFArrayGetValueAtIndex( device
->elements
, idx
);
752 TRACE("element %s\n", debugstr_element(element
));
754 device
->generic
.props
[idx
].lDevMin
= IOHIDElementGetLogicalMin(element
);
755 device
->generic
.props
[idx
].lDevMax
= IOHIDElementGetLogicalMax(element
);
756 device
->generic
.props
[idx
].lMin
= 0;
757 device
->generic
.props
[idx
].lMax
= 0xffff;
758 device
->generic
.props
[idx
].lDeadZone
= 0;
759 device
->generic
.props
[idx
].lSaturation
= 0;
764 static void poll_osx_device_state(LPDIRECTINPUTDEVICE8A iface
)
766 JoystickImpl
*device
= impl_from_IDirectInputDevice8A(iface
);
767 IOHIDElementRef device_main_element
;
768 IOHIDDeviceRef hid_device
;
770 TRACE("device %p device->id %i\n", device
, device
->id
);
772 if (!device_main_elements
|| device
->id
>= CFArrayGetCount(device_main_elements
))
775 device_main_element
= (IOHIDElementRef
) CFArrayGetValueAtIndex(device_main_elements
, device
->id
);
776 hid_device
= IOHIDElementGetDevice(device_main_element
);
777 TRACE("main element %s hid_device %s\n", debugstr_element(device_main_element
), debugstr_device(hid_device
));
781 if (device
->elements
)
787 CFIndex idx
, cnt
= CFArrayGetCount( device
->elements
);
789 for ( idx
= 0; idx
< cnt
; idx
++ )
791 IOHIDValueRef valueRef
;
792 int val
, oldVal
, newVal
;
793 IOHIDElementRef element
= ( IOHIDElementRef
) CFArrayGetValueAtIndex( device
->elements
, idx
);
794 int type
= IOHIDElementGetType( element
);
796 TRACE("element %s\n", debugstr_element(element
));
800 case kIOHIDElementTypeInput_Button
:
801 TRACE("kIOHIDElementTypeInput_Button\n");
804 IOHIDDeviceGetValue(hid_device
, element
, &valueRef
);
805 val
= IOHIDValueGetIntegerValue(valueRef
);
806 newVal
= val
? 0x80 : 0x0;
807 oldVal
= device
->generic
.js
.rgbButtons
[button_idx
];
808 device
->generic
.js
.rgbButtons
[button_idx
] = newVal
;
809 TRACE("valueRef %s val %d oldVal %d newVal %d\n", debugstr_cf(valueRef
), val
, oldVal
, newVal
);
810 if (oldVal
!= newVal
)
812 inst_id
= DIDFT_MAKEINSTANCE(button_idx
) | DIDFT_PSHBUTTON
;
813 queue_event(iface
,inst_id
,newVal
,GetCurrentTime(),device
->generic
.base
.dinput
->evsequence
++);
818 case kIOHIDElementTypeInput_Misc
:
820 uint32_t usage
= IOHIDElementGetUsage( element
);
823 case kHIDUsage_GD_Hatswitch
:
825 TRACE("kIOHIDElementTypeInput_Misc / kHIDUsage_GD_Hatswitch\n");
826 IOHIDDeviceGetValue(hid_device
, element
, &valueRef
);
827 val
= IOHIDValueGetIntegerValue(valueRef
);
828 oldVal
= device
->generic
.js
.rgdwPOV
[pov_idx
];
833 device
->generic
.js
.rgdwPOV
[pov_idx
] = newVal
;
834 TRACE("valueRef %s val %d oldVal %d newVal %d\n", debugstr_cf(valueRef
), val
, oldVal
, newVal
);
835 if (oldVal
!= newVal
)
837 inst_id
= DIDFT_MAKEINSTANCE(pov_idx
) | DIDFT_POV
;
838 queue_event(iface
,inst_id
,newVal
,GetCurrentTime(),device
->generic
.base
.dinput
->evsequence
++);
846 case kHIDUsage_GD_Rx
:
847 case kHIDUsage_GD_Ry
:
848 case kHIDUsage_GD_Rz
:
849 case kHIDUsage_GD_Slider
:
853 IOHIDDeviceGetValue(hid_device
, element
, &valueRef
);
854 val
= IOHIDValueGetIntegerValue(valueRef
);
855 newVal
= joystick_map_axis(&device
->generic
.props
[idx
], val
);
859 TRACE("kIOHIDElementTypeInput_Misc / kHIDUsage_GD_X\n");
861 oldVal
= device
->generic
.js
.lX
;
862 device
->generic
.js
.lX
= newVal
;
865 TRACE("kIOHIDElementTypeInput_Misc / kHIDUsage_GD_Y\n");
867 oldVal
= device
->generic
.js
.lY
;
868 device
->generic
.js
.lY
= newVal
;
871 TRACE("kIOHIDElementTypeInput_Misc / kHIDUsage_GD_Z\n");
873 oldVal
= device
->generic
.js
.lZ
;
874 device
->generic
.js
.lZ
= newVal
;
876 case kHIDUsage_GD_Rx
:
877 TRACE("kIOHIDElementTypeInput_Misc / kHIDUsage_GD_Rx\n");
879 oldVal
= device
->generic
.js
.lRx
;
880 device
->generic
.js
.lRx
= newVal
;
882 case kHIDUsage_GD_Ry
:
883 TRACE("kIOHIDElementTypeInput_Misc / kHIDUsage_GD_Ry\n");
885 oldVal
= device
->generic
.js
.lRy
;
886 device
->generic
.js
.lRy
= newVal
;
888 case kHIDUsage_GD_Rz
:
889 TRACE("kIOHIDElementTypeInput_Misc / kHIDUsage_GD_Rz\n");
891 oldVal
= device
->generic
.js
.lRz
;
892 device
->generic
.js
.lRz
= newVal
;
894 case kHIDUsage_GD_Slider
:
895 TRACE("kIOHIDElementTypeInput_Misc / kHIDUsage_GD_Slider\n");
896 wine_obj
= 6 + slider_idx
;
897 oldVal
= device
->generic
.js
.rglSlider
[slider_idx
];
898 device
->generic
.js
.rglSlider
[slider_idx
] = newVal
;
902 TRACE("valueRef %s val %d oldVal %d newVal %d\n", debugstr_cf(valueRef
), val
, oldVal
, newVal
);
903 if ((wine_obj
!= -1) &&
906 inst_id
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
907 queue_event(iface
,inst_id
,newVal
,GetCurrentTime(),device
->generic
.base
.dinput
->evsequence
++);
913 FIXME("kIOHIDElementTypeInput_Misc / unhandled usage %i\n", usage
);
918 FIXME("Unhandled type %i\n",type
);
924 static INT
find_joystick_devices(void)
926 static INT joystick_devices_count
= -1;
928 if (joystick_devices_count
!= -1) return joystick_devices_count
;
930 joystick_devices_count
= find_osx_devices();
932 return joystick_devices_count
;
935 static DWORD
make_vid_pid(IOHIDDeviceRef device
)
939 vendID
= get_device_property_long(device
, CFSTR(kIOHIDVendorIDKey
));
940 prodID
= get_device_property_long(device
, CFSTR(kIOHIDProductIDKey
));
942 return MAKELONG(vendID
, prodID
);
945 static HRESULT
joydev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
947 IOHIDDeviceRef device
;
949 TRACE("dwDevType %u dwFlags 0x%08x version 0x%04x id %d\n", dwDevType
, dwFlags
, version
, id
);
951 if (id
>= find_joystick_devices()) return E_FAIL
;
953 device
= get_device_ref(id
);
955 if ((dwDevType
== 0) ||
956 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
957 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800)))
959 if (dwFlags
& DIEDFL_FORCEFEEDBACK
) {
962 if(get_ff(device
, NULL
) != S_OK
)
965 /* Return joystick */
966 lpddi
->guidInstance
= DInput_Wine_OsX_Joystick_GUID
;
967 lpddi
->guidInstance
.Data3
= id
;
968 lpddi
->guidProduct
= DInput_Wine_OsX_Joystick_GUID
;
969 lpddi
->guidProduct
.Data1
= make_vid_pid(device
);
970 /* we only support traditional joysticks for now */
971 if (version
>= 0x0800)
972 lpddi
->dwDevType
= DI8DEVTYPE_GAMEPAD
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
974 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_GAMEPAD
<< 8);
975 lpddi
->dwDevType
|= DIDEVTYPE_HID
;
976 lpddi
->wUsagePage
= 0x01; /* Desktop */
977 lpddi
->wUsage
= 0x05; /* Game Pad */
978 sprintf(lpddi
->tszInstanceName
, "Joystick %d", id
);
980 /* get the device name */
981 get_osx_device_name(id
, lpddi
->tszProductName
, MAX_PATH
);
983 lpddi
->guidFFDriver
= GUID_NULL
;
990 static HRESULT
joydev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
994 IOHIDDeviceRef device
;
996 TRACE("dwDevType %u dwFlags 0x%08x version 0x%04x id %d\n", dwDevType
, dwFlags
, version
, id
);
998 if (id
>= find_joystick_devices()) return E_FAIL
;
1000 device
= get_device_ref(id
);
1002 if ((dwDevType
== 0) ||
1003 ((dwDevType
== DIDEVTYPE_JOYSTICK
) && (version
> 0x0300 && version
< 0x0800)) ||
1004 (((dwDevType
== DI8DEVCLASS_GAMECTRL
) || (dwDevType
== DI8DEVTYPE_JOYSTICK
)) && (version
>= 0x0800))) {
1006 if (dwFlags
& DIEDFL_FORCEFEEDBACK
) {
1009 if(get_ff(device
, NULL
) != S_OK
)
1012 /* Return joystick */
1013 lpddi
->guidInstance
= DInput_Wine_OsX_Joystick_GUID
;
1014 lpddi
->guidInstance
.Data3
= id
;
1015 lpddi
->guidProduct
= DInput_Wine_OsX_Joystick_GUID
;
1016 lpddi
->guidProduct
.Data1
= make_vid_pid(device
);
1017 /* we only support traditional joysticks for now */
1018 if (version
>= 0x0800)
1019 lpddi
->dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
1021 lpddi
->dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
1022 sprintf(friendly
, "Joystick %d", id
);
1023 MultiByteToWideChar(CP_ACP
, 0, friendly
, -1, lpddi
->tszInstanceName
, MAX_PATH
);
1024 /* get the device name */
1025 get_osx_device_name(id
, name
, MAX_PATH
);
1027 MultiByteToWideChar(CP_ACP
, 0, name
, -1, lpddi
->tszProductName
, MAX_PATH
);
1028 lpddi
->guidFFDriver
= GUID_NULL
;
1035 static const char *osx_ff_axis_name(UInt8 axis
)
1046 sprintf(ret
, "%u", (unsigned int)axis
);
1050 static BOOL
osx_axis_has_ff(FFCAPABILITIES
*ffcaps
, UInt8 axis
)
1053 for(i
= 0; i
< ffcaps
->numFfAxes
; ++i
)
1054 if(ffcaps
->ffAxes
[i
] == axis
)
1059 static HRESULT
alloc_device(REFGUID rguid
, IDirectInputImpl
*dinput
,
1060 JoystickImpl
**pdev
, unsigned short index
)
1063 IOHIDDeviceRef device
;
1064 JoystickImpl
* newDevice
;
1065 char name
[MAX_PATH
];
1067 LPDIDATAFORMAT df
= NULL
;
1069 int axis_map
[8]; /* max axes */
1070 int slider_count
= 0;
1071 FFCAPABILITIES ffcaps
;
1073 TRACE("%s %p %p %hu\n", debugstr_guid(rguid
), dinput
, pdev
, index
);
1075 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(JoystickImpl
));
1076 if (newDevice
== 0) {
1077 WARN("out of memory\n");
1079 return DIERR_OUTOFMEMORY
;
1082 newDevice
->id
= index
;
1084 device
= get_device_ref(index
);
1086 newDevice
->generic
.guidInstance
= DInput_Wine_OsX_Joystick_GUID
;
1087 newDevice
->generic
.guidInstance
.Data3
= index
;
1088 newDevice
->generic
.guidProduct
= DInput_Wine_OsX_Joystick_GUID
;
1089 newDevice
->generic
.guidProduct
.Data1
= make_vid_pid(device
);
1090 newDevice
->generic
.joy_polldev
= poll_osx_device_state
;
1092 /* get the device name */
1093 get_osx_device_name(index
, name
, MAX_PATH
);
1094 TRACE("Name %s\n",name
);
1096 /* copy the device name */
1097 newDevice
->generic
.name
= HeapAlloc(GetProcessHeap(),0,strlen(name
) + 1);
1098 strcpy(newDevice
->generic
.name
, name
);
1100 list_init(&newDevice
->effects
);
1101 if(get_ff(device
, &newDevice
->ff
) == S_OK
){
1102 newDevice
->generic
.devcaps
.dwFlags
|= DIDC_FORCEFEEDBACK
;
1104 hr
= FFDeviceGetForceFeedbackCapabilities(newDevice
->ff
, &ffcaps
);
1106 TRACE("FF Capabilities:\n");
1107 TRACE("\tsupportedEffects: 0x%x\n", (unsigned int)ffcaps
.supportedEffects
);
1108 TRACE("\temulatedEffects: 0x%x\n", (unsigned int)ffcaps
.emulatedEffects
);
1109 TRACE("\tsubType: 0x%x\n", (unsigned int)ffcaps
.subType
);
1110 TRACE("\tnumFfAxes: %u\n", (unsigned int)ffcaps
.numFfAxes
);
1111 TRACE("\tffAxes: [");
1112 for(i
= 0; i
< ffcaps
.numFfAxes
; ++i
){
1113 TRACE("%s", osx_ff_axis_name(ffcaps
.ffAxes
[i
]));
1114 if(i
< ffcaps
.numFfAxes
- 1)
1118 TRACE("\tstorageCapacity: %u\n", (unsigned int)ffcaps
.storageCapacity
);
1119 TRACE("\tplaybackCapacity: %u\n", (unsigned int)ffcaps
.playbackCapacity
);
1122 hr
= FFDeviceSendForceFeedbackCommand(newDevice
->ff
, FFSFFC_RESET
);
1124 WARN("FFDeviceSendForceFeedbackCommand(FFSFFC_RESET) failed: %08x\n", hr
);
1126 hr
= FFDeviceSendForceFeedbackCommand(newDevice
->ff
, FFSFFC_SETACTUATORSON
);
1128 WARN("FFDeviceSendForceFeedbackCommand(FFSFFC_SETACTUATORSON) failed: %08x\n", hr
);
1131 memset(axis_map
, 0, sizeof(axis_map
));
1132 get_osx_device_elements(newDevice
, axis_map
);
1134 TRACE("%i axes %i buttons %i povs\n",newDevice
->generic
.devcaps
.dwAxes
,newDevice
->generic
.devcaps
.dwButtons
,newDevice
->generic
.devcaps
.dwPOVs
);
1136 if (newDevice
->generic
.devcaps
.dwButtons
> 128)
1138 WARN("Can't support %d buttons. Clamping down to 128\n", newDevice
->generic
.devcaps
.dwButtons
);
1139 newDevice
->generic
.devcaps
.dwButtons
= 128;
1142 newDevice
->generic
.base
.IDirectInputDevice8A_iface
.lpVtbl
= &JoystickAvt
;
1143 newDevice
->generic
.base
.IDirectInputDevice8W_iface
.lpVtbl
= &JoystickWvt
;
1144 newDevice
->generic
.base
.ref
= 1;
1145 newDevice
->generic
.base
.dinput
= dinput
;
1146 newDevice
->generic
.base
.guid
= *rguid
;
1147 InitializeCriticalSection(&newDevice
->generic
.base
.crit
);
1148 newDevice
->generic
.base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": JoystickImpl*->generic.base.crit");
1150 /* Create copy of default data format */
1151 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2
.dwSize
))) goto FAILED
;
1152 memcpy(df
, &c_dfDIJoystick2
, c_dfDIJoystick2
.dwSize
);
1154 df
->dwNumObjs
= newDevice
->generic
.devcaps
.dwAxes
+ newDevice
->generic
.devcaps
.dwPOVs
+ newDevice
->generic
.devcaps
.dwButtons
;
1155 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto FAILED
;
1157 for (i
= 0; i
< newDevice
->generic
.devcaps
.dwAxes
; i
++)
1160 BOOL has_ff
= FALSE
;
1161 switch (axis_map
[i
])
1163 case kHIDUsage_GD_X
:
1165 has_ff
= (newDevice
->ff
!= 0) && osx_axis_has_ff(&ffcaps
, FFJOFS_X
);
1167 case kHIDUsage_GD_Y
:
1169 has_ff
= (newDevice
->ff
!= 0) && osx_axis_has_ff(&ffcaps
, FFJOFS_Y
);
1171 case kHIDUsage_GD_Z
:
1173 has_ff
= (newDevice
->ff
!= 0) && osx_axis_has_ff(&ffcaps
, FFJOFS_Z
);
1175 case kHIDUsage_GD_Rx
:
1177 has_ff
= (newDevice
->ff
!= 0) && osx_axis_has_ff(&ffcaps
, FFJOFS_RX
);
1179 case kHIDUsage_GD_Ry
:
1181 has_ff
= (newDevice
->ff
!= 0) && osx_axis_has_ff(&ffcaps
, FFJOFS_RY
);
1183 case kHIDUsage_GD_Rz
:
1185 has_ff
= (newDevice
->ff
!= 0) && osx_axis_has_ff(&ffcaps
, FFJOFS_RZ
);
1187 case kHIDUsage_GD_Slider
:
1188 wine_obj
= 6 + slider_count
;
1189 has_ff
= (newDevice
->ff
!= 0) && osx_axis_has_ff(&ffcaps
, FFJOFS_SLIDER(slider_count
));
1193 if (wine_obj
< 0 ) continue;
1195 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[wine_obj
], df
->dwObjSize
);
1196 df
->rgodf
[idx
].dwType
= DIDFT_MAKEINSTANCE(wine_obj
) | DIDFT_ABSAXIS
;
1198 df
->rgodf
[idx
].dwFlags
|= DIDOI_FFACTUATOR
;
1202 for (i
= 0; i
< newDevice
->generic
.devcaps
.dwPOVs
; i
++)
1204 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[i
+ 8], df
->dwObjSize
);
1205 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(i
) | DIDFT_POV
;
1208 for (i
= 0; i
< newDevice
->generic
.devcaps
.dwButtons
; i
++)
1210 memcpy(&df
->rgodf
[idx
], &c_dfDIJoystick2
.rgodf
[i
+ 12], df
->dwObjSize
);
1211 df
->rgodf
[idx
].pguid
= &GUID_Button
;
1212 df
->rgodf
[idx
++].dwType
= DIDFT_MAKEINSTANCE(i
) | DIDFT_PSHBUTTON
;
1214 newDevice
->generic
.base
.data_format
.wine_df
= df
;
1216 /* initialize default properties */
1217 get_osx_device_elements_props(newDevice
);
1219 IDirectInput_AddRef(&newDevice
->generic
.base
.dinput
->IDirectInput7A_iface
);
1221 EnterCriticalSection(&dinput
->crit
);
1222 list_add_tail(&dinput
->devices_list
, &newDevice
->generic
.base
.entry
);
1223 LeaveCriticalSection(&dinput
->crit
);
1225 newDevice
->generic
.devcaps
.dwSize
= sizeof(newDevice
->generic
.devcaps
);
1226 newDevice
->generic
.devcaps
.dwFlags
|= DIDC_ATTACHED
;
1227 if (newDevice
->generic
.base
.dinput
->dwVersion
>= 0x0800)
1228 newDevice
->generic
.devcaps
.dwDevType
= DI8DEVTYPE_JOYSTICK
| (DI8DEVTYPEJOYSTICK_STANDARD
<< 8);
1230 newDevice
->generic
.devcaps
.dwDevType
= DIDEVTYPE_JOYSTICK
| (DIDEVTYPEJOYSTICK_TRADITIONAL
<< 8);
1231 newDevice
->generic
.devcaps
.dwFFSamplePeriod
= 0;
1232 newDevice
->generic
.devcaps
.dwFFMinTimeResolution
= 0;
1233 newDevice
->generic
.devcaps
.dwFirmwareRevision
= 0;
1234 newDevice
->generic
.devcaps
.dwHardwareRevision
= 0;
1235 newDevice
->generic
.devcaps
.dwFFDriverVersion
= 0;
1237 if (TRACE_ON(dinput
)) {
1238 TRACE("allocated device %p\n", newDevice
);
1239 _dump_DIDATAFORMAT(newDevice
->generic
.base
.data_format
.wine_df
);
1240 _dump_DIDEVCAPS(&newDevice
->generic
.devcaps
);
1248 hr
= DIERR_OUTOFMEMORY
;
1249 if (newDevice
->ff
) FFReleaseDevice(newDevice
->ff
);
1250 if (newDevice
->elements
) CFRelease(newDevice
->elements
);
1251 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
1252 HeapFree(GetProcessHeap(), 0, df
);
1253 release_DataFormat(&newDevice
->generic
.base
.data_format
);
1254 HeapFree(GetProcessHeap(),0,newDevice
->generic
.name
);
1255 HeapFree(GetProcessHeap(),0,newDevice
);
1261 /******************************************************************************
1262 * get_joystick_index : Get the joystick index from a given GUID
1264 static unsigned short get_joystick_index(REFGUID guid
)
1266 GUID wine_joystick
= DInput_Wine_OsX_Joystick_GUID
;
1267 GUID dev_guid
= *guid
;
1269 wine_joystick
.Data3
= 0;
1272 /* for the standard joystick GUID use index 0 */
1273 if(IsEqualGUID(&GUID_Joystick
,guid
)) return 0;
1275 /* for the wine joystick GUIDs use the index stored in Data3 */
1276 if(IsEqualGUID(&wine_joystick
, &dev_guid
)) return guid
->Data3
;
1281 static HRESULT
joydev_create_device(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPVOID
*pdev
, int unicode
)
1283 unsigned short index
;
1284 int joystick_devices_count
;
1286 TRACE("%p %s %s %p %i\n", dinput
, debugstr_guid(rguid
), debugstr_guid(riid
), pdev
, unicode
);
1289 if ((joystick_devices_count
= find_joystick_devices()) == 0)
1290 return DIERR_DEVICENOTREG
;
1292 if ((index
= get_joystick_index(rguid
)) < 0xffff &&
1293 joystick_devices_count
&& index
< joystick_devices_count
)
1300 else if (IsEqualGUID(&IID_IDirectInputDeviceA
, riid
) ||
1301 IsEqualGUID(&IID_IDirectInputDevice2A
, riid
) ||
1302 IsEqualGUID(&IID_IDirectInputDevice7A
, riid
) ||
1303 IsEqualGUID(&IID_IDirectInputDevice8A
, riid
))
1307 else if (IsEqualGUID(&IID_IDirectInputDeviceW
, riid
) ||
1308 IsEqualGUID(&IID_IDirectInputDevice2W
, riid
) ||
1309 IsEqualGUID(&IID_IDirectInputDevice7W
, riid
) ||
1310 IsEqualGUID(&IID_IDirectInputDevice8W
, riid
))
1316 WARN("no interface\n");
1317 return DIERR_NOINTERFACE
;
1320 hr
= alloc_device(rguid
, dinput
, &This
, index
);
1321 if (!This
) return hr
;
1324 *pdev
= &This
->generic
.base
.IDirectInputDevice8W_iface
;
1326 *pdev
= &This
->generic
.base
.IDirectInputDevice8A_iface
;
1330 return DIERR_DEVICENOTREG
;
1333 static HRESULT
osx_set_autocenter(JoystickImpl
*This
,
1334 const DIPROPDWORD
*header
)
1339 return DIERR_UNSUPPORTED
;
1341 hr
= osx_to_win32_hresult(FFDeviceSetForceFeedbackProperty(This
->ff
, FFPROP_AUTOCENTER
, &v
));
1342 TRACE("returning: %08x\n", hr
);
1346 static HRESULT
osx_set_ffgain(JoystickImpl
*This
, const DIPROPDWORD
*header
)
1351 return DIERR_UNSUPPORTED
;
1353 hr
= osx_to_win32_hresult(FFDeviceSetForceFeedbackProperty(This
->ff
, FFPROP_FFGAIN
, &v
));
1354 TRACE("returning: %08x\n", hr
);
1358 static HRESULT WINAPI
JoystickWImpl_SetProperty(IDirectInputDevice8W
*iface
,
1359 const GUID
*prop
, const DIPROPHEADER
*header
)
1361 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
1363 TRACE("%p %s %p\n", This
, debugstr_guid(prop
), header
);
1365 switch(LOWORD(prop
))
1367 case (DWORD_PTR
)DIPROP_AUTOCENTER
:
1368 return osx_set_autocenter(This
, (const DIPROPDWORD
*)header
);
1369 case (DWORD_PTR
)DIPROP_FFGAIN
:
1370 return osx_set_ffgain(This
, (const DIPROPDWORD
*)header
);
1373 return JoystickWGenericImpl_SetProperty(iface
, prop
, header
);
1376 static HRESULT WINAPI
JoystickAImpl_SetProperty(IDirectInputDevice8A
*iface
,
1377 const GUID
*prop
, const DIPROPHEADER
*header
)
1379 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1381 TRACE("%p %s %p\n", This
, debugstr_guid(prop
), header
);
1383 switch(LOWORD(prop
))
1385 case (DWORD_PTR
)DIPROP_AUTOCENTER
:
1386 return osx_set_autocenter(This
, (const DIPROPDWORD
*)header
);
1387 case (DWORD_PTR
)DIPROP_FFGAIN
:
1388 return osx_set_ffgain(This
, (const DIPROPDWORD
*)header
);
1391 return JoystickAGenericImpl_SetProperty(iface
, prop
, header
);
1394 static CFUUIDRef
effect_win_to_mac(const GUID
*effect
)
1397 if(IsEqualGUID(&GUID_##X, effect)) \
1398 return kFFEffectType_##X##_ID;
1399 DO_MAP(ConstantForce
)
1405 DO_MAP(SawtoothDown
)
1412 WARN("Unknown effect GUID! %s\n", debugstr_guid(effect
));
1416 static HRESULT WINAPI
JoystickWImpl_CreateEffect(IDirectInputDevice8W
*iface
,
1417 const GUID
*type
, const DIEFFECT
*params
, IDirectInputEffect
**out
,
1420 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
1424 TRACE("%p %s %p %p %p\n", iface
, debugstr_guid(type
), params
, out
, outer
);
1425 dump_DIEFFECT(params
, type
, 0);
1428 TRACE("No force feedback support\n");
1430 return DIERR_UNSUPPORTED
;
1434 WARN("aggregation not implemented\n");
1436 effect
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*This
));
1437 effect
->IDirectInputEffect_iface
.lpVtbl
= &EffectVtbl
;
1439 effect
->guid
= *type
;
1440 effect
->device
= This
;
1442 /* Mac's FFEFFECT and Win's DIEFFECT are binary identical. */
1443 hr
= osx_to_win32_hresult(FFDeviceCreateEffect(This
->ff
,
1444 effect_win_to_mac(type
), (FFEFFECT
*)params
, &effect
->effect
));
1446 WARN("FFDeviceCreateEffect failed: %08x\n", hr
);
1447 HeapFree(GetProcessHeap(), 0, effect
);
1451 list_add_tail(&This
->effects
, &effect
->entry
);
1452 *out
= &effect
->IDirectInputEffect_iface
;
1454 TRACE("allocated effect: %p\n", effect
);
1459 static HRESULT WINAPI
JoystickAImpl_CreateEffect(IDirectInputDevice8A
*iface
,
1460 const GUID
*type
, const DIEFFECT
*params
, IDirectInputEffect
**out
,
1463 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1465 TRACE("%p %s %p %p %p\n", iface
, debugstr_guid(type
), params
, out
, outer
);
1467 return JoystickWImpl_CreateEffect(&This
->generic
.base
.IDirectInputDevice8W_iface
,
1468 type
, params
, out
, outer
);
1471 static HRESULT WINAPI
JoystickWImpl_SendForceFeedbackCommand(IDirectInputDevice8W
*iface
,
1474 JoystickImpl
*This
= impl_from_IDirectInputDevice8W(iface
);
1477 TRACE("%p 0x%x\n", This
, flags
);
1482 hr
= osx_to_win32_hresult(FFDeviceSendForceFeedbackCommand(This
->ff
, flags
));
1484 WARN("FFDeviceSendForceFeedbackCommand failed: %08x\n", hr
);
1491 static HRESULT WINAPI
JoystickAImpl_SendForceFeedbackCommand(IDirectInputDevice8A
*iface
,
1494 JoystickImpl
*This
= impl_from_IDirectInputDevice8A(iface
);
1496 TRACE("%p 0x%x\n", This
, flags
);
1498 return JoystickWImpl_SendForceFeedbackCommand(&This
->generic
.base
.IDirectInputDevice8W_iface
, flags
);
1501 const struct dinput_device joystick_osx_device
= {
1502 "Wine OS X joystick driver",
1503 joydev_enum_deviceA
,
1504 joydev_enum_deviceW
,
1505 joydev_create_device
1508 static const IDirectInputDevice8AVtbl JoystickAvt
=
1510 IDirectInputDevice2AImpl_QueryInterface
,
1511 IDirectInputDevice2AImpl_AddRef
,
1512 IDirectInputDevice2AImpl_Release
,
1513 JoystickAGenericImpl_GetCapabilities
,
1514 IDirectInputDevice2AImpl_EnumObjects
,
1515 JoystickAGenericImpl_GetProperty
,
1516 JoystickAImpl_SetProperty
,
1517 IDirectInputDevice2AImpl_Acquire
,
1518 IDirectInputDevice2AImpl_Unacquire
,
1519 JoystickAGenericImpl_GetDeviceState
,
1520 IDirectInputDevice2AImpl_GetDeviceData
,
1521 IDirectInputDevice2AImpl_SetDataFormat
,
1522 IDirectInputDevice2AImpl_SetEventNotification
,
1523 IDirectInputDevice2AImpl_SetCooperativeLevel
,
1524 JoystickAGenericImpl_GetObjectInfo
,
1525 JoystickAGenericImpl_GetDeviceInfo
,
1526 IDirectInputDevice2AImpl_RunControlPanel
,
1527 IDirectInputDevice2AImpl_Initialize
,
1528 JoystickAImpl_CreateEffect
,
1529 IDirectInputDevice2AImpl_EnumEffects
,
1530 IDirectInputDevice2AImpl_GetEffectInfo
,
1531 IDirectInputDevice2AImpl_GetForceFeedbackState
,
1532 JoystickAImpl_SendForceFeedbackCommand
,
1533 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
1534 IDirectInputDevice2AImpl_Escape
,
1535 JoystickAGenericImpl_Poll
,
1536 IDirectInputDevice2AImpl_SendDeviceData
,
1537 IDirectInputDevice7AImpl_EnumEffectsInFile
,
1538 IDirectInputDevice7AImpl_WriteEffectToFile
,
1539 JoystickAGenericImpl_BuildActionMap
,
1540 JoystickAGenericImpl_SetActionMap
,
1541 IDirectInputDevice8AImpl_GetImageInfo
1544 static const IDirectInputDevice8WVtbl JoystickWvt
=
1546 IDirectInputDevice2WImpl_QueryInterface
,
1547 IDirectInputDevice2WImpl_AddRef
,
1548 IDirectInputDevice2WImpl_Release
,
1549 JoystickWGenericImpl_GetCapabilities
,
1550 IDirectInputDevice2WImpl_EnumObjects
,
1551 JoystickWGenericImpl_GetProperty
,
1552 JoystickWImpl_SetProperty
,
1553 IDirectInputDevice2WImpl_Acquire
,
1554 IDirectInputDevice2WImpl_Unacquire
,
1555 JoystickWGenericImpl_GetDeviceState
,
1556 IDirectInputDevice2WImpl_GetDeviceData
,
1557 IDirectInputDevice2WImpl_SetDataFormat
,
1558 IDirectInputDevice2WImpl_SetEventNotification
,
1559 IDirectInputDevice2WImpl_SetCooperativeLevel
,
1560 JoystickWGenericImpl_GetObjectInfo
,
1561 JoystickWGenericImpl_GetDeviceInfo
,
1562 IDirectInputDevice2WImpl_RunControlPanel
,
1563 IDirectInputDevice2WImpl_Initialize
,
1564 JoystickWImpl_CreateEffect
,
1565 IDirectInputDevice2WImpl_EnumEffects
,
1566 IDirectInputDevice2WImpl_GetEffectInfo
,
1567 IDirectInputDevice2WImpl_GetForceFeedbackState
,
1568 JoystickWImpl_SendForceFeedbackCommand
,
1569 IDirectInputDevice2WImpl_EnumCreatedEffectObjects
,
1570 IDirectInputDevice2WImpl_Escape
,
1571 JoystickWGenericImpl_Poll
,
1572 IDirectInputDevice2WImpl_SendDeviceData
,
1573 IDirectInputDevice7WImpl_EnumEffectsInFile
,
1574 IDirectInputDevice7WImpl_WriteEffectToFile
,
1575 JoystickWGenericImpl_BuildActionMap
,
1576 JoystickWGenericImpl_SetActionMap
,
1577 IDirectInputDevice8WImpl_GetImageInfo
1580 static HRESULT WINAPI
effect_QueryInterface(IDirectInputEffect
*iface
,
1581 const GUID
*guid
, void **out
)
1583 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1585 TRACE("%p %s %p\n", This
, debugstr_guid(guid
), out
);
1587 if(IsEqualIID(guid
, &IID_IUnknown
) || IsEqualIID(guid
, &IID_IDirectInputEffect
)){
1589 IDirectInputEffect_AddRef(iface
);
1593 return E_NOINTERFACE
;
1596 static ULONG WINAPI
effect_AddRef(IDirectInputEffect
*iface
)
1598 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1599 ULONG ref
= InterlockedIncrement(&This
->ref
);
1600 TRACE("%p, ref is now: %u\n", This
, ref
);
1604 static ULONG WINAPI
effect_Release(IDirectInputEffect
*iface
)
1606 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1607 ULONG ref
= InterlockedDecrement(&This
->ref
);
1608 TRACE("%p, ref is now: %u\n", This
, ref
);
1611 list_remove(&This
->entry
);
1612 FFDeviceReleaseEffect(This
->device
->ff
, This
->effect
);
1613 HeapFree(GetProcessHeap(), 0, This
);
1619 static HRESULT WINAPI
effect_Initialize(IDirectInputEffect
*iface
, HINSTANCE hinst
,
1620 DWORD version
, const GUID
*guid
)
1622 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1623 TRACE("%p %p 0x%x, %s\n", This
, hinst
, version
, debugstr_guid(guid
));
1627 static HRESULT WINAPI
effect_GetEffectGuid(IDirectInputEffect
*iface
, GUID
*out
)
1629 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1630 TRACE("%p %p\n", This
, out
);
1635 static HRESULT WINAPI
effect_GetParameters(IDirectInputEffect
*iface
,
1636 DIEFFECT
*effect
, DWORD flags
)
1638 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1639 TRACE("%p %p 0x%x\n", This
, effect
, flags
);
1640 return osx_to_win32_hresult(FFEffectGetParameters(This
->effect
, (FFEFFECT
*)effect
, flags
));
1643 static HRESULT WINAPI
effect_SetParameters(IDirectInputEffect
*iface
,
1644 const DIEFFECT
*effect
, DWORD flags
)
1646 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1647 TRACE("%p %p 0x%x\n", This
, effect
, flags
);
1648 dump_DIEFFECT(effect
, &This
->guid
, flags
);
1649 return osx_to_win32_hresult(FFEffectSetParameters(This
->effect
, (FFEFFECT
*)effect
, flags
));
1652 static HRESULT WINAPI
effect_Start(IDirectInputEffect
*iface
, DWORD iterations
,
1655 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1656 TRACE("%p 0x%x 0x%x\n", This
, iterations
, flags
);
1657 return osx_to_win32_hresult(FFEffectStart(This
->effect
, iterations
, flags
));
1660 static HRESULT WINAPI
effect_Stop(IDirectInputEffect
*iface
)
1662 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1663 TRACE("%p\n", This
);
1664 return osx_to_win32_hresult(FFEffectStop(This
->effect
));
1667 static HRESULT WINAPI
effect_GetEffectStatus(IDirectInputEffect
*iface
, DWORD
*flags
)
1669 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1670 TRACE("%p %p\n", This
, flags
);
1671 return osx_to_win32_hresult(FFEffectGetEffectStatus(This
->effect
, (UInt32
*)flags
));
1674 static HRESULT WINAPI
effect_Download(IDirectInputEffect
*iface
)
1676 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1677 TRACE("%p\n", This
);
1678 return osx_to_win32_hresult(FFEffectDownload(This
->effect
));
1681 static HRESULT WINAPI
effect_Unload(IDirectInputEffect
*iface
)
1683 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1684 TRACE("%p\n", This
);
1685 return osx_to_win32_hresult(FFEffectUnload(This
->effect
));
1688 static HRESULT WINAPI
effect_Escape(IDirectInputEffect
*iface
, DIEFFESCAPE
*escape
)
1690 EffectImpl
*This
= impl_from_IDirectInputEffect(iface
);
1691 TRACE("%p %p\n", This
, escape
);
1692 return osx_to_win32_hresult(FFEffectEscape(This
->effect
, (FFEFFESCAPE
*)escape
));
1695 static const IDirectInputEffectVtbl EffectVtbl
= {
1696 effect_QueryInterface
,
1700 effect_GetEffectGuid
,
1701 effect_GetParameters
,
1702 effect_SetParameters
,
1705 effect_GetEffectStatus
,
1711 #else /* HAVE_IOHIDMANAGERCREATE */
1713 const struct dinput_device joystick_osx_device
= {
1714 "Wine OS X joystick driver",
1720 #endif /* HAVE_IOHIDMANAGERCREATE */