Skip to content

Commit

Permalink
Use Xbox 360 gamepad name
Browse files Browse the repository at this point in the history
Some games do not work without a known gamepad name.

Fixes #5362 <#5362>
Refs #5623 comment <#5623 (comment)>
PR #5623 <#5623>

Signed-off-by: Romain Vimont <[email protected]>
  • Loading branch information
Withoutruless authored and rom1v committed Dec 8, 2024
1 parent 0a09518 commit 7418fd0
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 13 deletions.
1 change: 0 additions & 1 deletion app/src/hid/hid_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ struct sc_hid_input {

struct sc_hid_open {
uint16_t hid_id;
const char *name; // pointer to static memory
const uint8_t *report_desc; // pointer to static memory
size_t report_desc_size;
};
Expand Down
6 changes: 0 additions & 6 deletions app/src/hid/hid_gamepad.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,8 @@ sc_hid_gamepad_generate_open(struct sc_hid_gamepad *hid,

sc_hid_gamepad_slot_init(&hid->slots[slot_idx], gamepad_id);

SDL_GameController* game_controller =
SDL_GameControllerFromInstanceID(gamepad_id);
assert(game_controller);
const char *name = SDL_GameControllerName(game_controller);

uint16_t hid_id = sc_hid_gamepad_slot_get_id(slot_idx);
hid_open->hid_id = hid_id;
hid_open->name = name;
hid_open->report_desc = SC_HID_GAMEPAD_REPORT_DESC;
hid_open->report_desc_size = sizeof(SC_HID_GAMEPAD_REPORT_DESC);

Expand Down
1 change: 0 additions & 1 deletion app/src/hid/hid_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ sc_hid_keyboard_generate_input_from_mods(struct sc_hid_input *hid_input,

void sc_hid_keyboard_generate_open(struct sc_hid_open *hid_open) {
hid_open->hid_id = SC_HID_ID_KEYBOARD;
hid_open->name = NULL; // No name specified after "scrcpy"
hid_open->report_desc = SC_HID_KEYBOARD_REPORT_DESC;
hid_open->report_desc_size = sizeof(SC_HID_KEYBOARD_REPORT_DESC);
}
Expand Down
1 change: 0 additions & 1 deletion app/src/hid/hid_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ sc_hid_mouse_generate_input_from_scroll(struct sc_hid_input *hid_input,

void sc_hid_mouse_generate_open(struct sc_hid_open *hid_open) {
hid_open->hid_id = SC_HID_ID_MOUSE;
hid_open->name = NULL; // No name specified after "scrcpy"
hid_open->report_desc = SC_HID_MOUSE_REPORT_DESC;
hid_open->report_desc_size = sizeof(SC_HID_MOUSE_REPORT_DESC);
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/uhid/gamepad_uhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// Xbox 360
#define SC_GAMEPAD_UHID_VENDOR_ID UINT16_C(0x045e)
#define SC_GAMEPAD_UHID_PRODUCT_ID UINT16_C(0x028e)
#define SC_GAMEPAD_UHID_NAME "Microsoft X-Box 360 Pad"

static void
sc_gamepad_uhid_send_input(struct sc_gamepad_uhid *gamepad,
Expand All @@ -36,7 +37,7 @@ sc_gamepad_uhid_send_open(struct sc_gamepad_uhid *gamepad,
msg.uhid_create.id = hid_open->hid_id;
msg.uhid_create.vendor_id = SC_GAMEPAD_UHID_VENDOR_ID;
msg.uhid_create.product_id = SC_GAMEPAD_UHID_PRODUCT_ID;
msg.uhid_create.name = hid_open->name;
msg.uhid_create.name = SC_GAMEPAD_UHID_NAME;
msg.uhid_create.report_desc = hid_open->report_desc;
msg.uhid_create.report_desc_size = hid_open->report_desc_size;

Expand Down
2 changes: 1 addition & 1 deletion app/src/uhid/keyboard_uhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ sc_keyboard_uhid_init(struct sc_keyboard_uhid *kb,
msg.uhid_create.id = SC_HID_ID_KEYBOARD;
msg.uhid_create.vendor_id = 0;
msg.uhid_create.product_id = 0;
msg.uhid_create.name = hid_open.name;
msg.uhid_create.name = NULL;
msg.uhid_create.report_desc = hid_open.report_desc;
msg.uhid_create.report_desc_size = hid_open.report_desc_size;
if (!sc_controller_push_msg(controller, &msg)) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/uhid/mouse_uhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ sc_mouse_uhid_init(struct sc_mouse_uhid *mouse,
msg.uhid_create.id = SC_HID_ID_MOUSE;
msg.uhid_create.vendor_id = 0;
msg.uhid_create.product_id = 0;
msg.uhid_create.name = hid_open.name;
msg.uhid_create.name = NULL;
msg.uhid_create.report_desc = hid_open.report_desc;
msg.uhid_create.report_desc_size = hid_open.report_desc_size;
if (!sc_controller_push_msg(controller, &msg)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private static byte[] buildUhidCreate2Req(int vendorId, int productId, String na
ByteBuffer buf = ByteBuffer.allocate(280 + reportDesc.length).order(ByteOrder.nativeOrder());
buf.putInt(UHID_CREATE2);

String actualName = name.isEmpty() ? "scrcpy" : "scrcpy: " + name;
String actualName = name.isEmpty() ? "scrcpy" : name;
byte[] utf8Name = actualName.getBytes(StandardCharsets.UTF_8);
int len = StringUtils.getUtf8TruncationIndex(utf8Name, 127);
assert len <= 127;
Expand Down

0 comments on commit 7418fd0

Please sign in to comment.