internal/gamepad: bug fix: a wireless Xbox controller didn't work correctly on macOS

The button and hat values must be adjusted by their minimum values.
See also GLFW's implementation.

Closes #266
This commit is contained in:
Hajime Hoshi 2022-09-12 01:55:03 +09:00
parent 89598df520
commit 7d6ee39c15

View File

@ -380,7 +380,7 @@ func (g *nativeGamepadImpl) update(gamepads *gamepads) error {
} }
for i, b := range g.buttons { for i, b := range g.buttons {
g.buttonValues[i] = g.elementValue(&b) > 0 g.buttonValues[i] = (g.elementValue(&b) - b.minimum) > 0
} }
hatStates := []int{ hatStates := []int{
@ -394,7 +394,7 @@ func (g *nativeGamepadImpl) update(gamepads *gamepads) error {
hatLeftUp, hatLeftUp,
} }
for i, h := range g.hats { for i, h := range g.hats {
if state := g.elementValue(&h); state < 0 || state >= len(hatStates) { if state := g.elementValue(&h) - h.minimum; state < 0 || state >= len(hatStates) {
g.hatValues[i] = hatCentered g.hatValues[i] = hatCentered
} else { } else {
g.hatValues[i] = hatStates[state] g.hatValues[i] = hatStates[state]