From 1a2e93c59451eda761926b6c503aa0132295f46c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 12 Sep 2022 01:55:03 +0900 Subject: [PATCH] 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 --- internal/gamepad/gamepad_darwin.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/gamepad/gamepad_darwin.go b/internal/gamepad/gamepad_darwin.go index c930da2c3..e8344af38 100644 --- a/internal/gamepad/gamepad_darwin.go +++ b/internal/gamepad/gamepad_darwin.go @@ -380,7 +380,7 @@ func (g *nativeGamepadImpl) update(gamepads *gamepads) error { } for i, b := range g.buttons { - g.buttonValues[i] = g.elementValue(&b) > 0 + g.buttonValues[i] = (g.elementValue(&b) - b.minimum) > 0 } hatStates := []int{ @@ -394,7 +394,7 @@ func (g *nativeGamepadImpl) update(gamepads *gamepads) error { hatLeftUp, } 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 } else { g.hatValues[i] = hatStates[state]