Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Fix game controllers ignoring the last listed button #48934

Merged
merged 1 commit into from
Jun 3, 2021

Conversation

madmiraal
Copy link
Contributor

Fixes #47579.
Addresses godotengine/godot-demo-projects#597 (comment).

Godot is missing the last listed button on the joypad. Until #45798, this was the guide button, a.k.a. the Home button on Xbox controllers and the PS button on DualShock controllers. With #45798 (included in 3.3) this is now the touchpad button. However, it also means that the new enums for misc1, paddle1, paddle2, paddle3, paddle4, and touchpad introduced in #47598 are wrong too.

This PR increases the value for JOY_BUTTON_MAX to 23, adds the missing enum and corrects the values for the enums added in #45798. Technically this breaks compat, but, since the enums are new, no more so than #45798 itself and the Joypads Demo project was updated to support it already in godotengine/godot-demo-projects#597; so probably worth cherry-picking for 3.3.2.

Note: This was fixed in 4.0 in #38151.

@madmiraal
Copy link
Contributor Author

For reference, this will be the mapping between SDL outputs and the enum values with this PR:

SDL Primary enum Secondary enum
a JOY_BUTTON_0 = 0,  
b JOY_BUTTON_1 = 1,  
x JOY_BUTTON_2 = 2,  
y JOY_BUTTON_3 = 3,  
leftshoulder JOY_BUTTON_4 = 4, JOY_L = JOY_BUTTON_4,
rightshoulder JOY_BUTTON_5 = 5, JOY_R = JOY_BUTTON_5,
lefttrigger JOY_BUTTON_6 = 6, JOY_L2 = JOY_BUTTON_6,
righttrigger JOY_BUTTON_7 = 7, JOY_R2 = JOY_BUTTON_7,
leftstick JOY_BUTTON_8 = 8, JOY_L3 = JOY_BUTTON_8,
rightstick JOY_BUTTON_9 = 9, JOY_R3 = JOY_BUTTON_9,
back JOY_BUTTON_10 = 10, JOY_SELECT = JOY_BUTTON_10,
start JOY_BUTTON_11 = 11, JOY_START = JOY_BUTTON_11,
dpup JOY_BUTTON_12 = 12, JOY_DPAD_UP = JOY_BUTTON_12,
dpdown JOY_BUTTON_13 = 13, JOY_DPAD_DOWN = JOY_BUTTON_13,
dpleft JOY_BUTTON_14 = 14, JOY_DPAD_LEFT = JOY_BUTTON_14,
dpright JOY_BUTTON_15 = 15, JOY_DPAD_RIGHT = JOY_BUTTON_15,
guide JOY_BUTTON_16 = 16, JOY_GUIDE = JOY_BUTTON_16,
misc1 JOY_BUTTON_17 = 17, JOY_MISC1 = JOY_BUTTON_17,
paddle1 JOY_BUTTON_18 = 18, JOY_PADDLE1 = JOY_BUTTON_18,
paddle2 JOY_BUTTON_19 = 19, JOY_PADDLE2 = JOY_BUTTON_19,
paddle3 JOY_BUTTON_20 = 20, JOY_PADDLE3 = JOY_BUTTON_20,
paddle4 JOY_BUTTON_21 = 21, JOY_PADDLE4 = JOY_BUTTON_21,
touchpad JOY_BUTTON_22 = 22, JOY_TOUCHPAD = JOY_BUTTON_22,
nullptr JOY_BUTTON_MAX = 23,  

This is the current mapping:

SDL Primary enum Secondary enum
a JOY_BUTTON_0 = 0,  
b JOY_BUTTON_1 = 1,  
x JOY_BUTTON_2 = 2,  
y JOY_BUTTON_3 = 3,  
leftshoulder JOY_BUTTON_4 = 4, JOY_L = JOY_BUTTON_4,
rightshoulder JOY_BUTTON_5 = 5, JOY_R = JOY_BUTTON_5,
lefttrigger JOY_BUTTON_6 = 6, JOY_L2 = JOY_BUTTON_6,
righttrigger JOY_BUTTON_7 = 7, JOY_R2 = JOY_BUTTON_7,
leftstick JOY_BUTTON_8 = 8, JOY_L3 = JOY_BUTTON_8,
rightstick JOY_BUTTON_9 = 9, JOY_R3 = JOY_BUTTON_9,
back JOY_BUTTON_10 = 10, JOY_SELECT = JOY_BUTTON_10,
start JOY_BUTTON_11 = 11, JOY_START = JOY_BUTTON_11,
dpup JOY_BUTTON_12 = 12, JOY_DPAD_UP = JOY_BUTTON_12,
dpdown JOY_BUTTON_13 = 13, JOY_DPAD_DOWN = JOY_BUTTON_13,
dpleft JOY_BUTTON_14 = 14, JOY_DPAD_LEFT = JOY_BUTTON_14,
dpright JOY_BUTTON_15 = 15, JOY_DPAD_RIGHT = JOY_BUTTON_15,
guide JOY_BUTTON_16 = 16, JOY_MISC1 = JOY_BUTTON_16,
misc1 JOY_BUTTON_17 = 17, JOY_PADDLE1 = JOY_BUTTON_17,
paddle1 JOY_BUTTON_18 = 18, JOY_PADDLE2 = JOY_BUTTON_18,
paddle2 JOY_BUTTON_19 = 19, JOY_PADDLE3 = JOY_BUTTON_19,
paddle3 JOY_BUTTON_20 = 20, JOY_PADDLE4 = JOY_BUTTON_20,
paddle4 JOY_BUTTON_21 = 21, JOY_TOUCHPAD = JOY_BUTTON_21,
touchpad JOY_BUTTON_MAX = 22,  
nullptr    

This was the mapping prior to #45798:

SDL Primary enum Secondary enum
a JOY_BUTTON_0 = 0,  
b JOY_BUTTON_1 = 1,  
x JOY_BUTTON_2 = 2,  
y JOY_BUTTON_3 = 3,  
leftshoulder JOY_BUTTON_4 = 4, JOY_L = JOY_BUTTON_4,
rightshoulder JOY_BUTTON_5 = 5, JOY_R = JOY_BUTTON_5,
lefttrigger JOY_BUTTON_6 = 6, JOY_L2 = JOY_BUTTON_6,
righttrigger JOY_BUTTON_7 = 7, JOY_R2 = JOY_BUTTON_7,
leftstick JOY_BUTTON_8 = 8, JOY_L3 = JOY_BUTTON_8,
rightstick JOY_BUTTON_9 = 9, JOY_R3 = JOY_BUTTON_9,
back JOY_BUTTON_10 = 10, JOY_SELECT = JOY_BUTTON_10,
start JOY_BUTTON_11 = 11, JOY_START = JOY_BUTTON_11,
dpup JOY_BUTTON_12 = 12, JOY_DPAD_UP = JOY_BUTTON_12,
dpdown JOY_BUTTON_13 = 13, JOY_DPAD_DOWN = JOY_BUTTON_13,
dpleft JOY_BUTTON_14 = 14, JOY_DPAD_LEFT = JOY_BUTTON_14,
dpright JOY_BUTTON_15 = 15, JOY_DPAD_RIGHT = JOY_BUTTON_15,
guide JOY_BUTTON_MAX = 16,  
NULL    

This is the mapping on master:

SDL enum
a JOY_BUTTON_A = 0,
b JOY_BUTTON_B = 1,
x JOY_BUTTON_X = 2,
y JOY_BUTTON_Y = 3,
back JOY_BUTTON_BACK = 4,
guide JOY_BUTTON_GUIDE = 5,
start JOY_BUTTON_START = 6,
leftstick JOY_BUTTON_LEFT_STICK = 7,
rightstick JOY_BUTTON_RIGHT_STICK = 8,
leftshoulder JOY_BUTTON_LEFT_SHOULDER = 9,
rightshoulder JOY_BUTTON_RIGHT_SHOULDER = 10,
dpup JOY_BUTTON_DPAD_UP = 11,
dpdown JOY_BUTTON_DPAD_DOWN = 12,
dpleft JOY_BUTTON_DPAD_LEFT = 13,
dpright JOY_BUTTON_DPAD_RIGHT = 14,
misc1 JOY_BUTTON_MISC1 = 15,
paddle1 JOY_BUTTON_PADDLE1 = 16,
paddle2 JOY_BUTTON_PADDLE2 = 17,
paddle3 JOY_BUTTON_PADDLE3 = 18,
paddle4 JOY_BUTTON_PADDLE4 = 19,
touchpad JOY_BUTTON_TOUCHPAD = 20,
  JOY_BUTTON_SDL_MAX = 21,
  JOY_BUTTON_MAX = 36,

core/global_constants.cpp Outdated Show resolved Hide resolved
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from my comment, seems good 👍

@akien-mga akien-mga merged commit 6aa70c6 into godotengine:3.x Jun 3, 2021
@akien-mga
Copy link
Member

Thanks!

@madmiraal madmiraal deleted the fix-47579-3.x branch June 4, 2021 08:10
@akien-mga akien-mga modified the milestones: 3.3, 3.4 Jun 7, 2021
@akien-mga
Copy link
Member

Cherry-picked for 3.3.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants