Skip to content

Commit cffa1de

Browse files
rbernonivyl
authored andcommitted
winebus: Use a vendor specific usage for gamepad guide buttons.
To avoid exposing it with the other buttons, the XUSB / GIP frontends don't expose it to applications (for instance in Windows.Gaming.Input). (cherry picked from commit 9206673) CW-Bug-Id: #25366 CW-Bug-Id: #25325
1 parent d2e3832 commit cffa1de

5 files changed

Lines changed: 34 additions & 25 deletions

File tree

dlls/dinput/joystick_hid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ static HRESULT hid_joystick_read( IDirectInputDevice8W *iface )
14041404
{
14051405
usages = impl->usages_buf + count;
14061406
if (usages->UsagePage != HID_USAGE_PAGE_BUTTON)
1407-
FIXME( "unimplemented usage page %x.\n", usages->UsagePage );
1407+
WARN( "unimplemented usage page %x.\n", usages->UsagePage );
14081408
else if (usages->Usage >= 128)
14091409
FIXME( "ignoring extraneous button %d.\n", usages->Usage );
14101410
else

dlls/winebus.sys/bus_sdl.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -880,29 +880,31 @@ static BOOL set_report_from_controller_event(struct sdl_device *impl, SDL_Event
880880
SDL_ControllerButtonEvent *ie = &event->cbutton;
881881
int button;
882882

883-
switch ((button = ie->button))
883+
switch (ie->button)
884884
{
885-
case SDL_CONTROLLER_BUTTON_DPAD_UP:
886-
hid_device_move_hatswitch(iface, 0, 0, ie->state ? -1 : +1);
887-
break;
888-
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
889-
hid_device_move_hatswitch(iface, 0, 0, ie->state ? +1 : -1);
890-
break;
891-
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
892-
hid_device_move_hatswitch(iface, 0, ie->state ? -1 : +1, 0);
893-
break;
894-
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
895-
hid_device_move_hatswitch(iface, 0, ie->state ? +1 : -1, 0);
896-
break;
885+
case SDL_CONTROLLER_BUTTON_A: button = 0; break;
886+
case SDL_CONTROLLER_BUTTON_B: button = 1; break;
887+
case SDL_CONTROLLER_BUTTON_X: button = 2; break;
888+
case SDL_CONTROLLER_BUTTON_Y: button = 3; break;
897889
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: button = 4; break;
898890
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: button = 5; break;
899891
case SDL_CONTROLLER_BUTTON_BACK: button = 6; break;
900892
case SDL_CONTROLLER_BUTTON_START: button = 7; break;
901893
case SDL_CONTROLLER_BUTTON_LEFTSTICK: button = 8; break;
902894
case SDL_CONTROLLER_BUTTON_RIGHTSTICK: button = 9; break;
903-
case SDL_CONTROLLER_BUTTON_GUIDE: button = 10; break;
895+
case SDL_CONTROLLER_BUTTON_DPAD_UP: button = 10; break;
896+
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: button = 11; break;
897+
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: button = 12; break;
898+
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: button = 13; break;
899+
case SDL_CONTROLLER_BUTTON_GUIDE: button = 16; break;
900+
default: button = -1; break;
904901
}
905902

903+
if (button == -1) break;
904+
if (button == 10) hid_device_move_hatswitch(iface, 0, 0, ie->state ? -1 : +1);
905+
if (button == 11) hid_device_move_hatswitch(iface, 0, 0, ie->state ? +1 : -1);
906+
if (button == 12) hid_device_move_hatswitch(iface, 0, ie->state ? -1 : +1, 0);
907+
if (button == 13) hid_device_move_hatswitch(iface, 0, ie->state ? +1 : -1, 0);
906908
hid_device_set_button(iface, button, ie->state);
907909
bus_event_queue_input_report(&event_queue, iface, state->report_buf, state->report_len);
908910
break;

dlls/winebus.sys/bus_udev.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,8 @@ static void set_abs_axis_value(struct unix_device *iface, int code, int value)
857857
if (!(code = impl->hat_map[code - ABS_HAT0X])) return;
858858
if (impl->is_gamepad)
859859
{
860-
hid_device_set_button(iface, 11, value < 0);
861-
hid_device_set_button(iface, 12, value > 0);
860+
hid_device_set_button(iface, 10, value < 0);
861+
hid_device_set_button(iface, 11, value > 0);
862862
}
863863
hid_device_set_hatswitch_y(iface, code - 1, value);
864864
}
@@ -867,8 +867,8 @@ static void set_abs_axis_value(struct unix_device *iface, int code, int value)
867867
if (!(code = impl->hat_map[code - ABS_HAT0X])) return;
868868
if (impl->is_gamepad)
869869
{
870-
hid_device_set_button(iface, 13, value < 0);
871-
hid_device_set_button(iface, 14, value > 0);
870+
hid_device_set_button(iface, 12, value < 0);
871+
hid_device_set_button(iface, 13, value > 0);
872872
}
873873
hid_device_set_hatswitch_x(iface, code - 1, value);
874874
}
@@ -989,10 +989,10 @@ static BOOL set_report_from_event(struct unix_device *iface, struct input_event
989989
if (!(button = impl->button_map[ie->code])) return FALSE;
990990
if (impl->is_gamepad && !impl->hat_count)
991991
{
992-
if (button == 12) hid_device_set_hatswitch_y(iface, 0, -1);
993-
if (button == 13) hid_device_set_hatswitch_y(iface, 0, +1);
994-
if (button == 14) hid_device_set_hatswitch_x(iface, 0, -1);
995-
if (button == 15) hid_device_set_hatswitch_x(iface, 0, +1);
992+
if (button == 11) hid_device_set_hatswitch_y(iface, 0, -1);
993+
if (button == 12) hid_device_set_hatswitch_y(iface, 0, +1);
994+
if (button == 13) hid_device_set_hatswitch_x(iface, 0, -1);
995+
if (button == 14) hid_device_set_hatswitch_x(iface, 0, +1);
996996
}
997997
hid_device_set_button(iface, button - 1, ie->value);
998998
return FALSE;
@@ -1640,6 +1640,7 @@ static NTSTATUS lnxev_device_create(struct udev_device *dev, int fd, const char
16401640
if (!test_bit(info.key, button)) continue;
16411641
if (impl->button_count > (impl->hat_count ? 10 : 14)) break;
16421642
impl->button_map[button] = ++impl->button_count;
1643+
if (impl->hat_count && impl->button_count == 11) impl->button_map[button] = 17;
16431644
}
16441645

16451646
for (int i = BTN_MISC; i < KEY_MAX; i++)
@@ -1648,6 +1649,7 @@ static NTSTATUS lnxev_device_create(struct udev_device *dev, int fd, const char
16481649
if (impl->button_count > (impl->hat_count ? 10 : 14)) break;
16491650
if (!test_bit(info.key, i)) continue;
16501651
impl->button_map[i] = ++impl->button_count;
1652+
if (impl->hat_count && impl->button_count == 11) impl->button_map[i] = 17;
16511653
}
16521654
}
16531655

dlls/winebus.sys/hid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ BOOL hid_device_add_gamepad(struct unix_device *iface)
357357
if (!hid_device_add_axes(iface, 1, HID_USAGE_PAGE_GENERIC, &lt, FALSE, 0, 32767)) return FALSE;
358358
if (!hid_device_add_axes(iface, 1, HID_USAGE_PAGE_GENERIC, &rt, FALSE, 0, 32767)) return FALSE;
359359
if (!hid_device_add_hatswitch(iface, 1)) return FALSE;
360-
if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, 15)) return FALSE;
360+
if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, 14)) return FALSE;
361+
if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_VENDOR_DEFINED_BEGIN, 1, 8)) return FALSE;
361362
if (!hid_device_end_input_report(iface)) return FALSE;
362363

363364
return TRUE;

dlls/xinput1_3/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,14 @@ static void read_controller_state(struct xinput_controller *controller)
594594
case 8: state.Gamepad.wButtons |= XINPUT_GAMEPAD_START; break;
595595
case 9: state.Gamepad.wButtons |= XINPUT_GAMEPAD_LEFT_THUMB; break;
596596
case 10: state.Gamepad.wButtons |= XINPUT_GAMEPAD_RIGHT_THUMB; break;
597-
case 11: state.Gamepad.wButtons |= XINPUT_GAMEPAD_GUIDE; break;
598597
}
599598
}
600599

600+
button_length = ARRAY_SIZE(buttons);
601+
status = HidP_GetUsages(HidP_Input, HID_USAGE_PAGE_VENDOR_DEFINED_BEGIN, 0, buttons, &button_length, controller->hid.preparsed, report_buf, report_len);
602+
if (status != HIDP_STATUS_SUCCESS) WARN("HidP_GetUsages HID_USAGE_PAGE_VENDOR_DEFINED_BEGIN returned %#lx\n", status);
603+
if (button_length) state.Gamepad.wButtons |= XINPUT_GAMEPAD_GUIDE;
604+
601605
status = HidP_GetUsageValue(HidP_Input, HID_USAGE_PAGE_GENERIC, 0, HID_USAGE_GENERIC_HATSWITCH, &value, controller->hid.preparsed, report_buf, report_len);
602606
if (status != HIDP_STATUS_SUCCESS) WARN("HidP_GetUsageValue HID_USAGE_PAGE_GENERIC / HID_USAGE_GENERIC_HATSWITCH returned %#lx\n", status);
603607
else switch (value)

0 commit comments

Comments
 (0)