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

winebus.sys: Implement SOCD neutral cleaning for hatswitches.

parent 4ca954ad
......@@ -382,6 +382,8 @@ static NTSTATUS build_controller_report_descriptor(struct unix_device *iface)
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))
......@@ -420,14 +422,15 @@ static NTSTATUS build_controller_report_descriptor(struct unix_device *iface)
/* Initialize axis in the report */
for (i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++)
hid_device_set_abs_axis(iface, i, pSDL_GameControllerGetAxis(impl->sdl_controller, i));
if (pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_UP))
hid_device_set_hatswitch_y(iface, 0, -1);
if (pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_DOWN))
hid_device_set_hatswitch_y(iface, 0, +1);
if (pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_LEFT))
hid_device_set_hatswitch_x(iface, 0, -1);
if (pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_RIGHT))
hid_device_set_hatswitch_x(iface, 0, +1);
state = pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_UP);
hid_device_move_hatswitch(iface, 0, 0, state ? -1 : +1);
state = pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
hid_device_move_hatswitch(iface, 0, 0, state ? +1 : -1);
state = pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
hid_device_move_hatswitch(iface, 0, state ? -1 : +1, 0);
state = pSDL_GameControllerGetButton(impl->sdl_controller, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
hid_device_move_hatswitch(iface, 0, state ? +1 : -1, 0);
return STATUS_SUCCESS;
}
......@@ -873,16 +876,16 @@ static BOOL set_report_from_controller_event(struct sdl_device *impl, SDL_Event
switch ((button = ie->button))
{
case SDL_CONTROLLER_BUTTON_DPAD_UP:
hid_device_set_hatswitch_y(iface, 0, ie->state ? -1 : 0);
hid_device_move_hatswitch(iface, 0, 0, ie->state ? -1 : +1);
break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
hid_device_set_hatswitch_y(iface, 0, ie->state ? +1 : 0);
hid_device_move_hatswitch(iface, 0, 0, ie->state ? +1 : -1);
break;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
hid_device_set_hatswitch_x(iface, 0, ie->state ? -1 : 0);
hid_device_move_hatswitch(iface, 0, ie->state ? -1 : +1, 0);
break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
hid_device_set_hatswitch_x(iface, 0, ie->state ? +1 : 0);
hid_device_move_hatswitch(iface, 0, ie->state ? +1 : -1, 0);
break;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: button = 4; break;
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: button = 5; break;
......
......@@ -1453,6 +1453,17 @@ BOOL hid_device_set_hatswitch_y(struct unix_device *iface, ULONG index, LONG new
return TRUE;
}
BOOL hid_device_move_hatswitch(struct unix_device *iface, ULONG index, LONG x, LONG y)
{
struct hid_device_state *state = &iface->hid_device_state;
ULONG offset = state->hatswitch_start + index;
LONG old_x, old_y;
if (index > state->hatswitch_count) return FALSE;
hatswitch_decompose(state->report_buf[offset], &old_x, &old_y);
hatswitch_compose(old_x + x, old_y + y, &state->report_buf[offset]);
return TRUE;
}
BOOL hid_device_sync_report(struct unix_device *iface)
{
BOOL dropped;
......
......@@ -257,6 +257,7 @@ extern BOOL hid_device_set_rel_axis(struct unix_device *iface, ULONG index, LONG
extern BOOL hid_device_set_button(struct unix_device *iface, ULONG index, BOOL is_set) DECLSPEC_HIDDEN;
extern BOOL hid_device_set_hatswitch_x(struct unix_device *iface, ULONG index, LONG new_x) DECLSPEC_HIDDEN;
extern BOOL hid_device_set_hatswitch_y(struct unix_device *iface, ULONG index, LONG new_y) DECLSPEC_HIDDEN;
extern BOOL hid_device_move_hatswitch(struct unix_device *iface, ULONG index, LONG x, LONG y) DECLSPEC_HIDDEN;
extern BOOL hid_device_sync_report(struct unix_device *iface) DECLSPEC_HIDDEN;
extern void hid_device_drop_report(struct unix_device *iface) DECLSPEC_HIDDEN;
......
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