It was used for XInput compatibility and is not needed anymore.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_sdl.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index b7734b4016e..bf36830b817 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -424,8 +424,7 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) ext->hat_bit_offs = CONTROLLER_NUM_BUTTONS;
ext->buffer_length = (BUTTON_BIT_COUNT + 7) / 8 - + CONTROLLER_NUM_AXES * sizeof(WORD) - + 2/* unknown constant*/; + + CONTROLLER_NUM_AXES * sizeof(WORD);
TRACE("Report will be %i bytes\n", ext->buffer_length);
@@ -457,10 +456,6 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) return STATUS_NO_MEMORY; }
- /* unknown constant */ - if (!hid_descriptor_add_padding(&ext->desc, 16)) - return STATUS_NO_MEMORY; - if (!descriptor_add_haptic(ext)) return STATUS_NO_MEMORY;
@@ -475,10 +470,6 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext)
set_hat_value(ext, 0, compose_dpad_value(ext->sdl_controller));
- /* unknown constant */ - ext->report_buffer[14] = 0x89; - ext->report_buffer[15] = 0xc5; - return STATUS_SUCCESS;
failed:
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_sdl.c | 40 ++++++++++++++---------------- dlls/winebus.sys/bus_udev.c | 15 +++++------- dlls/winebus.sys/hid.c | 43 ++++----------------------------- dlls/winebus.sys/unix_private.h | 2 +- 4 files changed, 30 insertions(+), 70 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index bf36830b817..a589814ee26 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -51,9 +51,9 @@ #include "hidusage.h"
#ifdef WORDS_BIGENDIAN -# define LE_WORD(x) RtlUshortByteSwap(x) +# define LE_DWORD(x) RtlUlongByteSwap(x) #else -# define LE_WORD(x) (x) +# define LE_DWORD(x) (x) #endif
#include "unix_private.h" @@ -175,24 +175,20 @@ static void set_button_value(struct platform_private *ext, int index, int value)
static void set_axis_value(struct platform_private *ext, int index, short value, BOOL controller) { - WORD *report = (WORD *)(ext->report_buffer + ext->axis_start); + DWORD *report = (DWORD *)(ext->report_buffer + ext->axis_start);
if (controller && (index == SDL_CONTROLLER_AXIS_TRIGGERLEFT || index == SDL_CONTROLLER_AXIS_TRIGGERRIGHT)) - report[index] = LE_WORD(value); + report[index] = LE_DWORD(value); else - report[index] = LE_WORD(value) + 32768; + report[index] = LE_DWORD(value) + 32768; }
static void set_ball_value(struct platform_private *ext, int index, int value1, int value2) { int offset; - offset = ext->ball_start + (index * sizeof(WORD)); - if (value1 > 127) value1 = 127; - if (value1 < -127) value1 = -127; - if (value2 > 127) value2 = 127; - if (value2 < -127) value2 = -127; - *((WORD*)&ext->report_buffer[offset]) = LE_WORD(value1); - *((WORD*)&ext->report_buffer[offset + sizeof(WORD)]) = LE_WORD(value2); + offset = ext->ball_start + (index * sizeof(DWORD)); + *(DWORD *)&ext->report_buffer[offset] = LE_DWORD(value1); + *(DWORD *)&ext->report_buffer[offset + sizeof(DWORD)] = LE_DWORD(value2); }
static void set_hat_value(struct platform_private *ext, int index, int value) @@ -308,7 +304,7 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext) ext->axis_start = report_size; if (axis_count) { - report_size += (sizeof(WORD) * axis_count); + report_size += (sizeof(DWORD) * axis_count); }
ball_count = pSDL_JoystickNumBalls(ext->sdl_joystick); @@ -320,7 +316,7 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext) FIXME("Capping ball + axis at 9\n"); ball_count = (9-axis_count)/2; } - report_size += (sizeof(WORD) * 2 * ball_count); + report_size += (sizeof(DWORD) * 2 * ball_count); }
/* For now lump all buttons just into incremental usages, Ignore Keys */ @@ -340,18 +336,18 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext) if (axis_count == 6 && button_count >= 14) { if (!hid_descriptor_add_axes(&ext->desc, axis_count, HID_USAGE_PAGE_GENERIC, - controller_usages, FALSE, 16, 0, 0xffff)) + controller_usages, FALSE, 0, 0xffff)) return STATUS_NO_MEMORY; } else if (axis_count) { if (!hid_descriptor_add_axes(&ext->desc, axis_count, HID_USAGE_PAGE_GENERIC, - joystick_usages, FALSE, 16, 0, 0xffff)) + joystick_usages, FALSE, 0, 0xffff)) return STATUS_NO_MEMORY; }
if (ball_count && !hid_descriptor_add_axes(&ext->desc, ball_count * 2, HID_USAGE_PAGE_GENERIC, - &joystick_usages[axis_count], TRUE, 8, 0x81, 0x7f)) + &joystick_usages[axis_count], TRUE, INT32_MIN, INT32_MAX)) return STATUS_NO_MEMORY;
if (button_count && !hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) @@ -420,11 +416,11 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) static const int BUTTON_BIT_COUNT = CONTROLLER_NUM_BUTTONS + CONTROLLER_NUM_HATSWITCHES * 4;
ext->axis_start = 0; - ext->button_start = CONTROLLER_NUM_AXES * sizeof(WORD); + ext->button_start = CONTROLLER_NUM_AXES * sizeof(DWORD); ext->hat_bit_offs = CONTROLLER_NUM_BUTTONS;
ext->buffer_length = (BUTTON_BIT_COUNT + 7) / 8 - + CONTROLLER_NUM_AXES * sizeof(WORD); + + CONTROLLER_NUM_AXES * sizeof(DWORD);
TRACE("Report will be %i bytes\n", ext->buffer_length);
@@ -432,15 +428,15 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) return STATUS_NO_MEMORY;
if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, left_axis_usages, - FALSE, 16, 0, 0xffff)) + FALSE, 0, 0xffff)) return STATUS_NO_MEMORY;
if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, right_axis_usages, - FALSE, 16, 0, 0xffff)) + FALSE, 0, 0xffff)) return STATUS_NO_MEMORY;
if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, trigger_axis_usages, - FALSE, 16, 0, 0x7fff)) + FALSE, 0, 0x7fff)) return STATUS_NO_MEMORY;
if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, CONTROLLER_NUM_BUTTONS)) diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 1c1b7da78cf..e62c8c2eda1 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -28,6 +28,7 @@ #include <stdarg.h> #include <stdlib.h> #include <stdio.h> +#include <stdint.h> #ifdef HAVE_UNISTD_H # include <unistd.h> #endif @@ -78,10 +79,8 @@ #endif
#ifdef WORDS_BIGENDIAN -#define LE_WORD(x) RtlUshortByteSwap(x) #define LE_DWORD(x) RtlUlongByteSwap(x) #else -#define LE_WORD(x) (x) #define LE_DWORD(x) (x) #endif
@@ -389,9 +388,7 @@ static void set_rel_axis_value(struct wine_input_private *ext, int code, int val if (code < HID_REL_MAX && REL_TO_HID_MAP[code][0] != 0) { index = ext->rel_map[code]; - if (value > 127) value = 127; - if (value < -127) value = -127; - ext->current_report_buffer[index] = value; + *(DWORD *)&ext->current_report_buffer[index] = LE_DWORD(value); } }
@@ -474,7 +471,7 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u if (!(usage.UsagePage = ABS_TO_HID_MAP[i][0])) continue; if (!(usage.Usage = ABS_TO_HID_MAP[i][1])) continue;
- if (!hid_descriptor_add_axes(&ext->desc, 1, usage.UsagePage, &usage.Usage, FALSE, 32, + if (!hid_descriptor_add_axes(&ext->desc, 1, usage.UsagePage, &usage.Usage, FALSE, LE_DWORD(abs_info[i].minimum), LE_DWORD(abs_info[i].maximum))) return STATUS_NO_MEMORY;
@@ -490,12 +487,12 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u if (!(usage.UsagePage = REL_TO_HID_MAP[i][0])) continue; if (!(usage.Usage = REL_TO_HID_MAP[i][1])) continue;
- if (!hid_descriptor_add_axes(&ext->desc, 1, usage.UsagePage, &usage.Usage, TRUE, 8, - 0x81, 0x7f)) + if (!hid_descriptor_add_axes(&ext->desc, 1, usage.UsagePage, &usage.Usage, TRUE, + INT32_MIN, INT32_MAX)) return STATUS_NO_MEMORY;
ext->rel_map[i] = report_size; - report_size++; + report_size += 4; rel_count++; }
diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c index 0ad5efa2775..feff8aec013 100644 --- a/dlls/winebus.sys/hid.c +++ b/dlls/winebus.sys/hid.c @@ -148,7 +148,7 @@ BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) }
BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page, - const USAGE *usages, BOOL rel, INT size, LONG min, LONG max) + const USAGE *usages, BOOL rel, LONG min, LONG max) { const BYTE template_begin[] = { @@ -159,33 +159,13 @@ BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usag { END_COLLECTION, }; - const BYTE template_1[] = - { - LOGICAL_MINIMUM(1, min), - LOGICAL_MAXIMUM(1, max), - PHYSICAL_MINIMUM(1, min), - PHYSICAL_MAXIMUM(1, max), - REPORT_SIZE(1, size), - REPORT_COUNT(1, count), - INPUT(1, Data|Var|(rel ? Rel : Abs)), - }; - const BYTE template_2[] = - { - LOGICAL_MINIMUM(2, min), - LOGICAL_MAXIMUM(2, max), - PHYSICAL_MINIMUM(2, min), - PHYSICAL_MAXIMUM(2, max), - REPORT_SIZE(1, size), - REPORT_COUNT(1, count), - INPUT(1, Data|Var|(rel ? Rel : Abs)), - }; - const BYTE template_4[] = + const BYTE template[] = { LOGICAL_MINIMUM(4, min), LOGICAL_MAXIMUM(4, max), PHYSICAL_MINIMUM(4, min), PHYSICAL_MAXIMUM(4, max), - REPORT_SIZE(1, size), + REPORT_SIZE(1, 32), REPORT_COUNT(1, count), INPUT(1, Data|Var|(rel ? Rel : Abs)), }; @@ -200,21 +180,8 @@ BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usag return FALSE; }
- if (size >= 16) - { - if (!hid_descriptor_append(desc, template_4, sizeof(template_4))) - return FALSE; - } - else if (size >= 8) - { - if (!hid_descriptor_append(desc, template_2, sizeof(template_2))) - return FALSE; - } - else - { - if (!hid_descriptor_append(desc, template_1, sizeof(template_1))) - return FALSE; - } + if (!hid_descriptor_append(desc, template, sizeof(template))) + return FALSE;
if (!hid_descriptor_append(desc, template_end, sizeof(template_end))) return FALSE; diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index cdc2be9b318..069b6a0964a 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -85,7 +85,7 @@ extern BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_ extern BOOL hid_descriptor_add_padding(struct hid_descriptor *desc, BYTE bitcount) DECLSPEC_HIDDEN; extern BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) DECLSPEC_HIDDEN; extern BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page, - const USAGE *usages, BOOL rel, INT size, LONG min, LONG max) DECLSPEC_HIDDEN; + const USAGE *usages, BOOL rel, LONG min, LONG max) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_haptics(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_sdl.c | 57 +++++++++++-------------------------- dlls/winebus.sys/bus_udev.c | 34 +++++++++++----------- dlls/winebus.sys/hid.c | 2 +- 3 files changed, 35 insertions(+), 58 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index a589814ee26..c83276aa873 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -126,7 +126,7 @@ struct platform_private int button_start; int axis_start; int ball_start; - int hat_bit_offs; /* hatswitches are reported in the same bytes as buttons */ + int hat_start;
struct hid_descriptor desc;
@@ -193,26 +193,8 @@ static void set_ball_value(struct platform_private *ext, int index, int value1,
static void set_hat_value(struct platform_private *ext, int index, int value) { - int byte = ext->button_start + (ext->hat_bit_offs + 4 * index) / 8; - int bit_offs = (ext->hat_bit_offs + 4 * index) % 8; - int num_low_bits, num_high_bits; - unsigned char val, low_mask, high_mask; - - /* 4-bit hatswitch value is packed into button bytes */ - if (bit_offs <= 4) - { - num_low_bits = 4; - num_high_bits = 0; - low_mask = 0xf; - high_mask = 0; - } - else - { - num_low_bits = 8 - bit_offs; - num_high_bits = 4 - num_low_bits; - low_mask = (1 << num_low_bits) - 1; - high_mask = (1 << num_high_bits) - 1; - } + int byte = ext->hat_start + index; + unsigned char val;
switch (value) { @@ -231,13 +213,7 @@ static void set_hat_value(struct platform_private *ext, int index, int value) default: return; }
- ext->report_buffer[byte] &= ~(low_mask << bit_offs); - ext->report_buffer[byte] |= (val & low_mask) << bit_offs; - if (high_mask) - { - ext->report_buffer[byte + 1] &= ~high_mask; - ext->report_buffer[byte + 1] |= val & high_mask; - } + ext->report_buffer[byte] = val; }
static BOOL descriptor_add_haptic(struct platform_private *ext) @@ -319,14 +295,14 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext) report_size += (sizeof(DWORD) * 2 * ball_count); }
+ hat_count = pSDL_JoystickNumHats(ext->sdl_joystick); + ext->hat_start = report_size; + report_size += hat_count; + /* For now lump all buttons just into incremental usages, Ignore Keys */ button_count = pSDL_JoystickNumButtons(ext->sdl_joystick); ext->button_start = report_size; - - hat_count = pSDL_JoystickNumHats(ext->sdl_joystick); - ext->hat_bit_offs = button_count; - - report_size += (button_count + hat_count * 4 + 7) / 8; + report_size += (button_count + 7) / 8;
TRACE("Report will be %i bytes\n", report_size);
@@ -350,10 +326,10 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext) &joystick_usages[axis_count], TRUE, INT32_MIN, INT32_MAX)) return STATUS_NO_MEMORY;
- if (button_count && !hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) + if (hat_count && !hid_descriptor_add_hatswitch(&ext->desc, hat_count)) return STATUS_NO_MEMORY;
- if (hat_count && !hid_descriptor_add_hatswitch(&ext->desc, hat_count)) + if (button_count && !hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) return STATUS_NO_MEMORY;
if (!descriptor_add_haptic(ext)) @@ -413,13 +389,14 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) static const USAGE trigger_axis_usages[] = {HID_USAGE_GENERIC_Z, HID_USAGE_GENERIC_RZ}; INT i;
- static const int BUTTON_BIT_COUNT = CONTROLLER_NUM_BUTTONS + CONTROLLER_NUM_HATSWITCHES * 4; + static const int BUTTON_BIT_COUNT = CONTROLLER_NUM_BUTTONS;
ext->axis_start = 0; - ext->button_start = CONTROLLER_NUM_AXES * sizeof(DWORD); - ext->hat_bit_offs = CONTROLLER_NUM_BUTTONS; + ext->hat_start = CONTROLLER_NUM_AXES * sizeof(DWORD); + ext->button_start = ext->hat_start + CONTROLLER_NUM_HATSWITCHES;
ext->buffer_length = (BUTTON_BIT_COUNT + 7) / 8 + + CONTROLLER_NUM_HATSWITCHES + CONTROLLER_NUM_AXES * sizeof(DWORD);
TRACE("Report will be %i bytes\n", ext->buffer_length); @@ -439,10 +416,10 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) FALSE, 0, 0x7fff)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, CONTROLLER_NUM_BUTTONS)) + if (!hid_descriptor_add_hatswitch(&ext->desc, CONTROLLER_NUM_HATSWITCHES)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_hatswitch(&ext->desc, 1)) + if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, CONTROLLER_NUM_BUTTONS)) return STATUS_NO_MEMORY;
if (BUTTON_BIT_COUNT % 8 != 0) diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index e62c8c2eda1..00c64829172 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -496,6 +496,23 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u rel_count++; }
+ hat_count = 0; + for (i = ABS_HAT0X; i <=ABS_HAT3X; i+=2) + { + if (!test_bit(absbits, i)) continue; + ext->hat_map[i - ABS_HAT0X] = report_size; + ext->hat_values[i - ABS_HAT0X] = 0; + ext->hat_values[i - ABS_HAT0X + 1] = 0; + report_size++; + hat_count++; + } + + if (hat_count) + { + if (!hid_descriptor_add_hatswitch(&ext->desc, hat_count)) + return STATUS_NO_MEMORY; + } + /* For now lump all buttons just into incremental usages, Ignore Keys */ ext->button_start = report_size; button_count = count_buttons(ext->base.device_fd, ext->button_map); @@ -514,23 +531,6 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u report_size += (button_count + 7) / 8; }
- hat_count = 0; - for (i = ABS_HAT0X; i <=ABS_HAT3X; i+=2) - { - if (!test_bit(absbits, i)) continue; - ext->hat_map[i - ABS_HAT0X] = report_size; - ext->hat_values[i - ABS_HAT0X] = 0; - ext->hat_values[i - ABS_HAT0X + 1] = 0; - report_size++; - hat_count++; - } - - if (hat_count) - { - if (!hid_descriptor_add_hatswitch(&ext->desc, hat_count)) - return STATUS_NO_MEMORY; - } - if (!hid_descriptor_end(&ext->desc)) return STATUS_NO_MEMORY;
diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c index feff8aec013..ba9fa4ba12d 100644 --- a/dlls/winebus.sys/hid.c +++ b/dlls/winebus.sys/hid.c @@ -138,7 +138,7 @@ BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) LOGICAL_MAXIMUM(1, 8), PHYSICAL_MINIMUM(1, 0), PHYSICAL_MAXIMUM(2, 8), - REPORT_SIZE(1, 4), + REPORT_SIZE(1, 8), REPORT_COUNT(4, count), UNIT(1, 0x0e /* none */), INPUT(1, Data|Var|Abs|Null),
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_sdl.c | 7 ------- dlls/winebus.sys/bus_udev.c | 7 ------- dlls/winebus.sys/hid.c | 21 +++++++++++---------- dlls/winebus.sys/unix_private.h | 1 - 4 files changed, 11 insertions(+), 25 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index c83276aa873..bebe2eeb0f2 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -422,13 +422,6 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, CONTROLLER_NUM_BUTTONS)) return STATUS_NO_MEMORY;
- if (BUTTON_BIT_COUNT % 8 != 0) - { - /* unused bits between hatswitch and following constant */ - if (!hid_descriptor_add_padding(&ext->desc, 8 - (BUTTON_BIT_COUNT % 8))) - return STATUS_NO_MEMORY; - } - if (!descriptor_add_haptic(ext)) return STATUS_NO_MEMORY;
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 00c64829172..b9e5c968d0c 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -521,13 +521,6 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) return STATUS_NO_MEMORY;
- if (button_count % 8) - { - BYTE padding = 8 - (button_count % 8); - if (!hid_descriptor_add_padding(&ext->desc, padding)) - return STATUS_NO_MEMORY; - } - report_size += (button_count + 7) / 8; }
diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c index ba9fa4ba12d..d2dff7e5a24 100644 --- a/dlls/winebus.sys/hid.c +++ b/dlls/winebus.sys/hid.c @@ -99,6 +99,7 @@ void hid_descriptor_free(struct hid_descriptor *desc) BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page, USAGE usage_min, USAGE usage_max) { + const USHORT count = usage_max - usage_min + 1; const BYTE template[] = { USAGE_PAGE(2, usage_page), @@ -108,24 +109,24 @@ BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page, LOGICAL_MAXIMUM(1, 1), PHYSICAL_MINIMUM(1, 0), PHYSICAL_MAXIMUM(1, 1), - REPORT_COUNT(2, usage_max - usage_min + 1), + REPORT_COUNT(2, count), REPORT_SIZE(1, 1), INPUT(1, Data|Var|Abs), }; - - return hid_descriptor_append(desc, template, sizeof(template)); -} - -BOOL hid_descriptor_add_padding(struct hid_descriptor *desc, BYTE bitcount) -{ - const BYTE template[] = + const BYTE template_pad[] = { - REPORT_COUNT(1, bitcount), + REPORT_COUNT(1, 8 - (count % 8)), REPORT_SIZE(1, 1), INPUT(1, Cnst|Var|Abs), };
- return hid_descriptor_append(desc, template, sizeof(template)); + if (!hid_descriptor_append(desc, template, sizeof(template))) + return FALSE; + + if ((count % 8) && !hid_descriptor_append(desc, template_pad, sizeof(template_pad))) + return FALSE; + + return TRUE; }
BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index 069b6a0964a..cfb56d2d83e 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -82,7 +82,6 @@ extern void hid_descriptor_free(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page, USAGE usage_min, USAGE usage_max) DECLSPEC_HIDDEN; -extern BOOL hid_descriptor_add_padding(struct hid_descriptor *desc, BYTE bitcount) DECLSPEC_HIDDEN; extern BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) DECLSPEC_HIDDEN; extern BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page, const USAGE *usages, BOOL rel, LONG min, LONG max) DECLSPEC_HIDDEN;
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_sdl.c | 73 +++++++++++--------------------------- 1 file changed, 21 insertions(+), 52 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index bebe2eeb0f2..bfa95387afe 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -241,13 +241,10 @@ static BOOL descriptor_add_haptic(struct platform_private *ext) return TRUE; }
-static NTSTATUS build_report_descriptor(struct platform_private *ext) +static NTSTATUS build_joystick_report_descriptor(struct platform_private *ext) { - INT i; - INT report_size; - INT button_count, axis_count, ball_count, hat_count; - static const USAGE device_usage[2] = {HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_GAMEPAD}; - static const USAGE controller_usages[] = { + static const USAGE joystick_usages[] = + { HID_USAGE_GENERIC_X, HID_USAGE_GENERIC_Y, HID_USAGE_GENERIC_Z, @@ -256,19 +253,11 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext) HID_USAGE_GENERIC_RZ, HID_USAGE_GENERIC_SLIDER, HID_USAGE_GENERIC_DIAL, - HID_USAGE_GENERIC_WHEEL}; - static const USAGE joystick_usages[] = { - HID_USAGE_GENERIC_X, - HID_USAGE_GENERIC_Y, - HID_USAGE_GENERIC_Z, - HID_USAGE_GENERIC_RZ, - HID_USAGE_GENERIC_RX, - HID_USAGE_GENERIC_RY, - HID_USAGE_GENERIC_SLIDER, - HID_USAGE_GENERIC_DIAL, - HID_USAGE_GENERIC_WHEEL}; + HID_USAGE_GENERIC_WHEEL + };
- report_size = 0; + int i, report_size = 1; + int button_count, axis_count, ball_count, hat_count;
axis_count = pSDL_JoystickNumAxes(ext->sdl_joystick); if (axis_count > 6) @@ -276,24 +265,17 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext) FIXME("Clamping joystick to 6 axis\n"); axis_count = 6; } - ext->axis_start = report_size; - if (axis_count) - { - report_size += (sizeof(DWORD) * axis_count); - } + report_size += (sizeof(DWORD) * axis_count);
ball_count = pSDL_JoystickNumBalls(ext->sdl_joystick); - ext->ball_start = report_size; - if (ball_count) + if (axis_count + ball_count * 2 > ARRAY_SIZE(joystick_usages)) { - if ((ball_count*2) + axis_count > 9) - { - FIXME("Capping ball + axis at 9\n"); - ball_count = (9-axis_count)/2; - } - report_size += (sizeof(DWORD) * 2 * ball_count); + FIXME("Capping ball + axis at 9\n"); + ball_count = (ARRAY_SIZE(joystick_usages) - axis_count) / 2; } + ext->ball_start = report_size; + report_size += (sizeof(DWORD) * 2 * ball_count);
hat_count = pSDL_JoystickNumHats(ext->sdl_joystick); ext->hat_start = report_size; @@ -306,21 +288,12 @@ static NTSTATUS build_report_descriptor(struct platform_private *ext)
TRACE("Report will be %i bytes\n", report_size);
- if (!hid_descriptor_begin(&ext->desc, device_usage[0], device_usage[1])) + if (!hid_descriptor_begin(&ext->desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_JOYSTICK)) return STATUS_NO_MEMORY;
- if (axis_count == 6 && button_count >= 14) - { - if (!hid_descriptor_add_axes(&ext->desc, axis_count, HID_USAGE_PAGE_GENERIC, - controller_usages, FALSE, 0, 0xffff)) - return STATUS_NO_MEMORY; - } - else if (axis_count) - { - if (!hid_descriptor_add_axes(&ext->desc, axis_count, HID_USAGE_PAGE_GENERIC, - joystick_usages, FALSE, 0, 0xffff)) - return STATUS_NO_MEMORY; - } + if (axis_count && !hid_descriptor_add_axes(&ext->desc, axis_count, HID_USAGE_PAGE_GENERIC, + joystick_usages, FALSE, -32768, 32767)) + return STATUS_NO_MEMORY;
if (ball_count && !hid_descriptor_add_axes(&ext->desc, ball_count * 2, HID_USAGE_PAGE_GENERIC, &joystick_usages[axis_count], TRUE, INT32_MIN, INT32_MAX)) @@ -452,7 +425,7 @@ static NTSTATUS sdl_device_start(struct unix_device *iface) { struct platform_private *ext = impl_from_unix_device(iface); if (ext->sdl_controller) return build_mapped_report_descriptor(ext); - return build_report_descriptor(ext); + return build_joystick_report_descriptor(ext); }
static void sdl_device_stop(struct unix_device *iface) @@ -550,15 +523,11 @@ static const struct unix_device_vtbl sdl_device_vtbl = sdl_device_set_feature_report, };
-static BOOL set_report_from_event(struct platform_private *device, SDL_Event *event) +static BOOL set_report_from_joystick_event(struct platform_private *device, SDL_Event *event) { struct unix_device *iface = &device->unix_device;
- if (device->sdl_controller) - { - /* We want mapped events */ - return TRUE; - } + if (device->sdl_controller) return TRUE; /* use controller events instead */
switch(event->type) { @@ -751,7 +720,7 @@ static void process_device_event(SDL_Event *event) { id = ((SDL_JoyButtonEvent *)event)->which; device = find_device_from_id(id); - if (device) set_report_from_event(device, event); + if (device) set_report_from_joystick_event(device, event); else WARN("failed to find device with id %d\n", id); } else if (event->type >= SDL_CONTROLLERAXISMOTION && event->type <= SDL_CONTROLLERBUTTONUP)
Now that we have xinput.sys for translation there's no need to keep this compatible.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_sdl.c | 99 ++++++++++++++------------------------ 1 file changed, 37 insertions(+), 62 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index bfa95387afe..9f6596f5c7d 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -152,10 +152,6 @@ static struct platform_private *find_device_from_id(SDL_JoystickID id) return NULL; }
-#define CONTROLLER_NUM_BUTTONS 11 -#define CONTROLLER_NUM_AXES 6 -#define CONTROLLER_NUM_HATSWITCHES 1 - static void set_button_value(struct platform_private *ext, int index, int value) { int byte_index = ext->button_start + index / 8; @@ -173,14 +169,10 @@ static void set_button_value(struct platform_private *ext, int index, int value) } }
-static void set_axis_value(struct platform_private *ext, int index, short value, BOOL controller) +static void set_axis_value(struct platform_private *ext, int index, short value) { DWORD *report = (DWORD *)(ext->report_buffer + ext->axis_start); - - if (controller && (index == SDL_CONTROLLER_AXIS_TRIGGERLEFT || index == SDL_CONTROLLER_AXIS_TRIGGERRIGHT)) - report[index] = LE_DWORD(value); - else - report[index] = LE_DWORD(value) + 32768; + report[index] = LE_DWORD(value); }
static void set_ball_value(struct platform_private *ext, int index, int value1, int value2) @@ -316,7 +308,7 @@ static NTSTATUS build_joystick_report_descriptor(struct platform_private *ext)
/* Initialize axis in the report */ for (i = 0; i < axis_count; i++) - set_axis_value(ext, i, pSDL_JoystickGetAxis(ext->sdl_joystick, i), FALSE); + set_axis_value(ext, i, pSDL_JoystickGetAxis(ext->sdl_joystick, i)); for (i = 0; i < hat_count; i++) set_hat_value(ext, i, pSDL_JoystickGetHat(ext->sdl_joystick, i));
@@ -355,22 +347,18 @@ static SHORT compose_dpad_value(SDL_GameController *joystick) return SDL_HAT_CENTERED; }
-static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) +static NTSTATUS build_controller_report_descriptor(struct platform_private *ext) { 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}; - INT i; - - static const int BUTTON_BIT_COUNT = CONTROLLER_NUM_BUTTONS; + ULONG i, button_count = SDL_CONTROLLER_BUTTON_MAX - 1; + C_ASSERT(SDL_CONTROLLER_AXIS_MAX == 6);
ext->axis_start = 0; - ext->hat_start = CONTROLLER_NUM_AXES * sizeof(DWORD); - ext->button_start = ext->hat_start + CONTROLLER_NUM_HATSWITCHES; - - ext->buffer_length = (BUTTON_BIT_COUNT + 7) / 8 - + CONTROLLER_NUM_HATSWITCHES - + CONTROLLER_NUM_AXES * sizeof(DWORD); + ext->hat_start = SDL_CONTROLLER_AXIS_MAX * sizeof(DWORD); + ext->button_start = ext->hat_start + 1; + ext->buffer_length = ext->button_start + (button_count + 7) / 8;
TRACE("Report will be %i bytes\n", ext->buffer_length);
@@ -378,21 +366,21 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) return STATUS_NO_MEMORY;
if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, left_axis_usages, - FALSE, 0, 0xffff)) + FALSE, -32768, 32767)) return STATUS_NO_MEMORY;
if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, right_axis_usages, - FALSE, 0, 0xffff)) + FALSE, -32768, 32767)) return STATUS_NO_MEMORY;
if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, trigger_axis_usages, - FALSE, 0, 0x7fff)) + FALSE, 0, 32767)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_hatswitch(&ext->desc, CONTROLLER_NUM_HATSWITCHES)) + if (!hid_descriptor_add_hatswitch(&ext->desc, 1)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, CONTROLLER_NUM_BUTTONS)) + if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) return STATUS_NO_MEMORY;
if (!descriptor_add_haptic(ext)) @@ -405,8 +393,7 @@ static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext)
/* Initialize axis in the report */ for (i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) - set_axis_value(ext, i, pSDL_GameControllerGetAxis(ext->sdl_controller, i), TRUE); - + set_axis_value(ext, i, pSDL_GameControllerGetAxis(ext->sdl_controller, i)); set_hat_value(ext, 0, compose_dpad_value(ext->sdl_controller));
return STATUS_SUCCESS; @@ -424,7 +411,7 @@ static void sdl_device_destroy(struct unix_device *iface) static NTSTATUS sdl_device_start(struct unix_device *iface) { struct platform_private *ext = impl_from_unix_device(iface); - if (ext->sdl_controller) return build_mapped_report_descriptor(ext); + if (ext->sdl_controller) return build_controller_report_descriptor(ext); return build_joystick_report_descriptor(ext); }
@@ -547,7 +534,7 @@ static BOOL set_report_from_joystick_event(struct platform_private *device, SDL_
if (ie->axis < 6) { - set_axis_value(device, ie->axis, ie->value, FALSE); + set_axis_value(device, ie->axis, ie->value); bus_event_queue_input_report(&event_queue, iface, device->report_buffer, device->buffer_length); } break; @@ -574,7 +561,7 @@ static BOOL set_report_from_joystick_event(struct platform_private *device, SDL_ return FALSE; }
-static BOOL set_mapped_report_from_event(struct platform_private *device, SDL_Event *event) +static BOOL set_report_from_controller_event(struct platform_private *device, SDL_Event *event) { struct unix_device *iface = &device->unix_device;
@@ -583,47 +570,35 @@ static BOOL set_mapped_report_from_event(struct platform_private *device, SDL_Ev case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP: { - int usage = -1; SDL_ControllerButtonEvent *ie = &event->cbutton; + int button;
- switch (ie->button) + switch ((button = ie->button)) { - case SDL_CONTROLLER_BUTTON_A: usage = 0; break; - case SDL_CONTROLLER_BUTTON_B: usage = 1; break; - case SDL_CONTROLLER_BUTTON_X: usage = 2; break; - case SDL_CONTROLLER_BUTTON_Y: usage = 3; break; - case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: usage = 4; break; - case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: usage = 5; break; - case SDL_CONTROLLER_BUTTON_BACK: usage = 6; break; - case SDL_CONTROLLER_BUTTON_START: usage = 7; break; - case SDL_CONTROLLER_BUTTON_LEFTSTICK: usage = 8; break; - case SDL_CONTROLLER_BUTTON_RIGHTSTICK: usage = 9; break; - case SDL_CONTROLLER_BUTTON_GUIDE: usage = 10; break; - - case SDL_CONTROLLER_BUTTON_DPAD_UP: - case SDL_CONTROLLER_BUTTON_DPAD_DOWN: - case SDL_CONTROLLER_BUTTON_DPAD_LEFT: - case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: - set_hat_value(device, 0, compose_dpad_value(device->sdl_controller)); - bus_event_queue_input_report(&event_queue, iface, device->report_buffer, device->buffer_length); - break; - - default: - ERR("Unknown Button %i\n",ie->button); + case SDL_CONTROLLER_BUTTON_DPAD_UP: + case SDL_CONTROLLER_BUTTON_DPAD_DOWN: + case SDL_CONTROLLER_BUTTON_DPAD_LEFT: + case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: + set_hat_value(device, 0, compose_dpad_value(device->sdl_controller)); + break; + case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: button = 4; break; + case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: button = 5; break; + case SDL_CONTROLLER_BUTTON_BACK: button = 6; break; + case SDL_CONTROLLER_BUTTON_START: button = 7; break; + case SDL_CONTROLLER_BUTTON_LEFTSTICK: button = 8; break; + case SDL_CONTROLLER_BUTTON_RIGHTSTICK: button = 9; break; + case SDL_CONTROLLER_BUTTON_GUIDE: button = 10; break; }
- if (usage >= 0) - { - set_button_value(device, usage, ie->state); - bus_event_queue_input_report(&event_queue, iface, device->report_buffer, device->buffer_length); - } + set_button_value(device, button, ie->state); + bus_event_queue_input_report(&event_queue, iface, device->report_buffer, device->buffer_length); break; } case SDL_CONTROLLERAXISMOTION: { SDL_ControllerAxisEvent *ie = &event->caxis;
- set_axis_value(device, ie->axis, ie->value, TRUE); + set_axis_value(device, ie->axis, ie->value); bus_event_queue_input_report(&event_queue, iface, device->report_buffer, device->buffer_length); break; } @@ -727,7 +702,7 @@ static void process_device_event(SDL_Event *event) { id = ((SDL_ControllerButtonEvent *)event)->which; device = find_device_from_id(id); - if (device) set_mapped_report_from_event(device, event); + if (device) set_report_from_controller_event(device, event); else WARN("failed to find device with id %d\n", id); }