Skip to content

Commit

Permalink
Bugfix/various gamepad issues (#243)
Browse files Browse the repository at this point in the history
* fix nintendo switch pro controller

* readded joystickadded/joystickremoved callbacks
call joystickadded on load for all connected gamepads

* move joysticks callbacks out of love.load check
  • Loading branch information
christphe authored Dec 19, 2024
1 parent 15e5ecb commit 80e8b73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions source/modules/love/scripts/callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ function love.createhandlers()
return love.gamepadaxis(joystick, axis, value)
end
end,
-- joystickadded = function(joystick)
-- if love.joystickadded then
-- return love.joystickadded(joystick)
-- end
-- end,
-- joystickremoved = function(joystick)
-- if love.joystickremoved then
-- return love.joystickremoved(joystick)
-- end
-- end,
joystickadded = function(joystick)
if love.joystickadded then
return love.joystickadded(joystick)
end
end,
joystickremoved = function(joystick)
if love.joystickremoved then
return love.joystickremoved(joystick)
end
end,
focus = function(focused)
if love.focus then
return love.focus(focused)
Expand Down Expand Up @@ -227,6 +227,12 @@ function love.run()
love.load(love.parsedGameArguments, love.rawGameArguments)
end

-- https://love2d.org/wiki/love.joystickadded
-- This callback is also triggered after love.load for every Joystick which was already connected when the game started up.
for _, j in ipairs(love.joystick.getJoysticks()) do
love.handlers.joystickadded(j)
end

if love.timer then
love.timer.step()
end
Expand Down
2 changes: 1 addition & 1 deletion source/utilities/guid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static constexpr love::guid::GamepadInfo gamepadInfo[] =
{ 12, 8, 0, "Nintendo 3DS", "{B58A259A-13AA-46E0-BDCB-31898EDAB24E}", false, false }, // GAMEPAD_TYPE_NINTENDO_3DS
{ 12, 12, 0, "New Nintendo 3DS", "{7BC9702D-7D81-4EBB-AD4F-8C94076588D5}", true, true }, // GAMEPAD_TYPE_NEW_NINTENDO_3DS
{ 14, 6, 0, "Nintendo Switch", "{6EBE242C-820F-46E1-9A66-DC8200686D51}", true, true }, // GAMEPAD_TYPE_NINTENDO_SWITCH_HANDHELD
{ 14, 6, 0, "Nintendo Switch Pro Controller", "{42ECF5C5-AFA5-4EDE-B1A2-4E9C2287559A}", true, false }, // GAMEPAD_TYPE_NINTENDO_SWITCH_PRO
{ 14, 6, 0, "Nintendo Switch Pro Controller", "{42ECF5C5-AFA5-4EDE-B1A2-4E9C2287559A}", true, true }, // GAMEPAD_TYPE_NINTENDO_SWITCH_PRO
{ 7, 12, 0, "Joy-Con L", "{660EBC7E-3953-4B74-8406-AD5992FCC5C7}", true, false }, // GAMEPAD_TYPE_JOYCON_LEFT
{ 7, 12, 0, "Joy-Con R", "{AD770831-A7E4-41A8-8DD0-FD48323E0043}", false, true }, // GAMEPAD_TYPE_JOYCON_RIGHT
{ 14, 18, 0, "Joy-Con Pair", "{701B198B-9AD9-4730-8EEB-EBECF707B9DF}", true, true }, // GAMEPAD_TYPE_JOYCON_PAIR
Expand Down

0 comments on commit 80e8b73

Please sign in to comment.