Commit 83757539 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

winebus.sys: Simplify SDL controller report descriptor creation.

Now that we have xinput.sys for translation there's no need to keep this compatible. Signed-off-by: 's avatarRémi Bernon <rbernon@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 4a15cc9e
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment