From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winebus.sys/bus_sdl.c | 42 ++++----------------------------- dlls/winebus.sys/hid.c | 18 ++++++++++++++ dlls/winebus.sys/unix_private.h | 1 + 3 files changed, 24 insertions(+), 37 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index dd8a1eb24b9..6e2c8bef3e4 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -382,50 +382,18 @@ static NTSTATUS build_joystick_report_descriptor(struct unix_device *iface) static NTSTATUS build_controller_report_descriptor(struct unix_device *iface) { const USAGE_AND_PAGE device_usage = {.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_GAMEPAD}; - static const USAGE left_axis_usages[] = {HID_USAGE_GENERIC_X, HID_USAGE_GENERIC_Y}; - static const USAGE right_axis_usages[] = {HID_USAGE_GENERIC_RX, HID_USAGE_GENERIC_RY}; - static const USAGE trigger_axis_usages[] = {HID_USAGE_GENERIC_Z, HID_USAGE_GENERIC_RZ}; struct sdl_device *impl = impl_from_unix_device(iface); - ULONG i, button_count = SDL_CONTROLLER_BUTTON_MAX - 1; BOOL state;
C_ASSERT(SDL_CONTROLLER_AXIS_MAX == 6);
- if (!hid_device_begin_report_descriptor(iface, &device_usage)) - return STATUS_NO_MEMORY; - - if (!hid_device_begin_input_report(iface, &device_usage)) - return STATUS_NO_MEMORY; - - if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, left_axis_usages, - FALSE, -32768, 32767)) - return STATUS_NO_MEMORY; - - if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, right_axis_usages, - FALSE, -32768, 32767)) - return STATUS_NO_MEMORY; - - if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, trigger_axis_usages, - FALSE, 0, 32767)) - return STATUS_NO_MEMORY; - - if (!hid_device_add_hatswitch(iface, 1)) - return STATUS_NO_MEMORY; - - if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, button_count)) - return STATUS_NO_MEMORY; - - if (!hid_device_end_input_report(iface)) - return STATUS_NO_MEMORY; - - if (!descriptor_add_haptic(impl, FALSE)) - return STATUS_NO_MEMORY; - - if (!hid_device_end_report_descriptor(iface)) - return STATUS_NO_MEMORY; + if (!hid_device_begin_report_descriptor(iface, &device_usage)) return STATUS_NO_MEMORY; + if (!hid_device_add_gamepad(iface)) return STATUS_NO_MEMORY; + if (!descriptor_add_haptic(impl, FALSE)) return STATUS_NO_MEMORY; + if (!hid_device_end_report_descriptor(iface)) return STATUS_NO_MEMORY;
/* Initialize axis in the report */ - for (i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) + for (int i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) hid_device_set_abs_axis(iface, i, pSDL_GameControllerGetAxis(impl->sdl_controller, i));
state = pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_UP); diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c index e2f667fd1ea..5b274d20e18 100644 --- a/dlls/winebus.sys/hid.c +++ b/dlls/winebus.sys/hid.c @@ -343,6 +343,24 @@ BOOL hid_device_add_axes(struct unix_device *iface, BYTE count, USAGE usage_page return TRUE; }
+BOOL hid_device_add_gamepad(struct unix_device *iface) +{ + static const USAGE_AND_PAGE device_usage = {.UsagePage = HID_USAGE_PAGE_GENERIC, .Usage = HID_USAGE_GENERIC_GAMEPAD}; + static const USAGE left[] = {HID_USAGE_GENERIC_X, HID_USAGE_GENERIC_Y}; + static const USAGE right[] = {HID_USAGE_GENERIC_RX, HID_USAGE_GENERIC_RY}; + static const USAGE trigger[] = {HID_USAGE_GENERIC_Z, HID_USAGE_GENERIC_RZ}; + + if (!hid_device_begin_input_report(iface, &device_usage)) return FALSE; + if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, left, FALSE, -32768, 32767)) return FALSE; + if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, right, FALSE, -32768, 32767)) return FALSE; + if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, trigger, FALSE, 0, 32767)) return FALSE; + if (!hid_device_add_hatswitch(iface, 1)) return FALSE; + if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, 15)) return FALSE; + if (!hid_device_end_input_report(iface)) return FALSE; + + return TRUE; +} + #pragma pack(push,1) struct hid_haptics_intensity { diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index 5c39cae1409..11328caee08 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -253,6 +253,7 @@ extern BOOL hid_device_add_hatswitch(struct unix_device *iface, INT count); extern BOOL hid_device_add_axes(struct unix_device *iface, BYTE count, USAGE usage_page, const USAGE *usages, BOOL rel, LONG min, LONG max);
+extern BOOL hid_device_add_gamepad(struct unix_device *iface); extern BOOL hid_device_add_haptics(struct unix_device *iface); extern BOOL hid_device_add_physical(struct unix_device *iface, USAGE *usages, USHORT count, USHORT axes_count);