libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.79k stars 1.82k forks source link

Share button on Xbox Series Controller is sent as "private button" instead of MISC #5101

Closed selimrecep closed 11 months ago

selimrecep commented 2 years ago

Hi, I was testing out the library, found out that the controller's share button event is fired as "SDL_JOYBUTTONDOWN/SDL_JOYBUTTONUP, button=11" instead of "SDL_CONTROLLER_BUTTON_MISC1". I am not sure if HIDP is available on Windows but for some reason the controller isnt even recognized as XINPUT, at least by the program, because 14th char of the GUID is 'r' which means raw input according to the library, even though it is visible as XINPUT on device manager, I couldnt go in deep that why it is being read as 'raw input' instead of 'xinput'. But I'd like to provide information as much I can :) And yes, firmware of the controller is up to date.

Windows 10 Pro 21H1 Xbox Wireless Controller (9th gen, Xbox Series S|X Controller)

a1rsh commented 2 years ago

I hope you can solve your problem mate

slouken commented 2 years ago

Interesting. I'm running Windows 11, and when I press that button on my controller, Windows takes a screenshot of my game.

selimrecep commented 2 years ago

It is probably because it is included in Windows 11 as a feature but they didn't include it in Windows 10 unfortunately... https://www.neowin.net/news/you-can-now-use-the-xbox-share-button-feature-on-windows-11-pcs-too/

slouken commented 2 years ago

Feel free to use controllermap to map all the buttons on the controller and post the config here, and I'll include it in the next SDL release.

selimrecep commented 2 years ago

And I just realised it is just not about share button... Since the library somehow accepts my controller as RAWInput, it doesnt allow me to haptic, I thought maybe HIDPInput wasnt available on Windows, but I cant even use it through XInput interface, I got a bit in deep and realised 14th character of GUID is actually 'r' which means it is a raw input, but still couldn't find out how is GUID being generated... Some screenshots from device manager. resim resim resim I believe bluetooth one refers to wireless connection where as others relate to USB connection to the connector... Or one of them could be a common interface.

selimrecep commented 2 years ago

Thank you, I think I can do that(mapping) but I think I still have a rawinput issue(which is the main issue, I believe), I am on it so I can find out if it is really seens as raw input instead of xinput by the library. Or maybe I should create another issue for that

slouken commented 2 years ago

SDL uses a hybrid solution to allow more than 4 Xbox controllers, and it looks at raw input, XInput, and WGI to achieve this.

selimrecep commented 2 years ago

I see, but is there a way to at least vibrate(via HapticEffect(s)) the controller over a RawInput device? Because I couldnt achieve it with the minimal code I found on docs. (I added some lines though, because I didnt want to open a new window, besides everything looks normal except I cant use haptic effects, like I can read values from the controller.), and I can see that SDL_NumHaptics() is equal to 0 too, while debugging.


    SDL_Haptic* haptic;

    SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
    if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
        SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER);

    haptic = SDL_HapticOpen(0);
    if (haptic == NULL)
        return -1;

    // Initialize simple rumble
    if (SDL_HapticRumbleInit(haptic) != 0)
        return -1;

    // Play effect at 50% strength for 2 seconds
    if (SDL_HapticRumblePlay(haptic, 0.5, 2000) != 0)
        return -1;
slouken commented 2 years ago

No, you should use SDL_GameControllerRumble()

selimrecep commented 2 years ago

Thanks but SDL_GameControllerRumble(gGameController, 6000, 6000, 5000) didn't seem to work either even it returns 0

Edit: I also found out in SDL_rawinputjoystick.c, that since neither ctx->xinput_correlated or ctx->wgi_correlated is 1, the function doesnt do anything except returning 0.

slouken commented 2 years ago

Make sure you press a button on the controller before trying to rumble. That's how they get correlated.

selimrecep commented 2 years ago

Thank you, that was the thing I missed, after pressing any button it got correlated and successfully rumbled. Today or tomorrow I will use controllermap and post here to give additional information about share button's mapping on my controller