Skip to content

Commit d01f19f

Browse files
committed
Fix naive joypad detection
1 parent f1498bf commit d01f19f

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

assets

Submodule assets updated 1 file

input/input.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ func floatToAnalog(v float32) int16 {
8080
return int16(v * 32767.0)
8181
}
8282

83+
// JoypadPlugged returns true if at least one joypad is plugged
84+
func JoypadPlugged() bool {
85+
for joy := glfw.Joystick(0); joy < glfw.JoystickLast; joy++ {
86+
if joy.IsGamepad() {
87+
return true
88+
}
89+
}
90+
return false
91+
}
92+
8393
// pollJoypads process joypads of all players
8494
func pollJoypads(state States, analogState AnalogStates) (States, AnalogStates) {
8595
p := 0

menu/hints.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package menu
22

33
import (
4-
"github.com/go-gl/glfw/v3.3/glfw"
4+
"github.com/libretro/ludo/input"
55
)
66

77
// Used to easily compose different hint bars based on the context.
@@ -25,7 +25,7 @@ func stackHintRight(stack *float32, icon uint32, label string, h int) {
2525
}
2626

2727
func hintIcons() (arrows, upDown, leftRight, a, b, x, y, start, slct, guide uint32) {
28-
if glfw.Joystick(0).IsGamepad() {
28+
if input.JoypadPlugged() {
2929
return menu.icons["pad-arrows"],
3030
menu.icons["pad-up-down"],
3131
menu.icons["pad-left-right"],

0 commit comments

Comments
 (0)