Map the Bluetooth Stadia Controller (or any other controller not correctly mapped) to SDL2 correctly

Sorry if this is the wrong place to post it, but I would like to have it here for future references. I wrote the same reddit post this is taken from.

A few days ago I was struggling to get the Stadia controller working correctly with my Fedora computer.

I found a very nice post mainly focused on Ubuntu and derivatives. It was an excellent piece, but unfortunately outdated given its dependency on the xboxdrv.

Going a little bit deeper, I found out most of the inputs in Linux are handled by the SDL library, which is shipped, of course, with Fedora. The issue comes from an incorrect mapping in SDL in the first place, so we must correct that mapping for the controller to work properly.

So that’s what I did with the help of AntimicroX (in the official Fedora repos as well as a fantastic Flatpak that’ll work virtually everywhere).

  1. I followed this wonderful guide from the devs to set the mappings just as I wanted.
  2. I set the environmental variable SDL_GAMECONTROLLERCONFIG to the values I got from (1). You can do this in 2 ways:
  • (Either) Every single time you are going to use that controller, open the terminal window and type export SDL_GAMECONTROLLERCONFIG="<string>". Then, on that same terminal session, execute whatever software/game you wanted to play with the gamepad.

  • (Or) Go to $HOME/.bashrc or $HOME/.profile (you can replace $HOME by a ~) and write at the end of then file export SDL_GAMECONTROLLERCONFIG="<string>" for .bashrc or SDL_GAMECONTROLLERCONFIG="<string>" for .profile. To be honest, the .profile one didn’t work for me, but IDK if I did something wrong here.

After that, your controller will work fantastically. I have to say I’m extremely impressed by the level of flexibility of the input systems in Linux. You can tweak basically any controller to work with it, even the ones that are incorrectly mapped can be remapped. This can be useful for anyone else using weird, strange controllers or gamepads that may have some faulty buttons and you may want to still use (at the end of the day, some gamepads have more buttons that some emulators/games require).

That’s the power of Linux, my friends!

Thanks to the great guys of AntimicroX, Fedora and RedHat teams, as well as this random guy who gave me a lot of insight .

Bonus: This is the mapping I got done:

0500e9ffd11800000094000000010000635337888,Stadia96FS-f3f4,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b6,start:b7,guide:b8,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b14,righttrigger:b13,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,

With the full export key being:

export SDL_GAMECONTROLLERCONFIG="0500e9ffd11800000094000000010000635337888,Stadia96FS-f3f4,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b6,start:b7,guide:b8,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b14,righttrigger:b13,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,"

1 Like

Good as any, I think! If you want, when we have Ask Fedora merged in, we can move this to that category — but I don’t think that’s strictly necessary.

1 Like

Thank you very much Matt. I agree, once Ask and Discussion are merged, it will be easier to have these in their correct category.

Anyhow, thank you very much for the work you guys do on Fedora :slight_smile:

1 Like