internal/gamepad: bug fix: ignore a device that doesn't have an appropriate button

This commit is contained in:
Hajime Hoshi 2022-04-09 14:42:14 +09:00
parent 8522bfd0bf
commit a659c330d2
2 changed files with 24 additions and 0 deletions

View File

@ -30,6 +30,16 @@ const (
_ABS_CNT = _ABS_MAX + 1
_BTN_MISC = 0x100
_BTN_0 = 0x100
_BTN_1 = 0x101
_BTN_2 = 0x102
_BTN_3 = 0x103
_BTN_4 = 0x104
_BTN_5 = 0x105
_BTN_6 = 0x106
_BTN_7 = 0x107
_BTN_8 = 0x108
_BTN_9 = 0x109
_IOC_NONE = 0
_IOC_WRITE = 1

View File

@ -181,13 +181,27 @@ func (*nativeGamepadsImpl) openGamepad(gamepads *gamepads, path string) (err err
var axisCount int
var buttonCount int
var hatCount int
var necessaryButtonExist bool
for code := _BTN_MISC; code < _KEY_CNT; code++ {
if !isBitSet(keyBits, code) {
continue
}
n.keyMap[code-_BTN_MISC] = buttonCount
if _BTN_0 <= code && code <= _BTN_9 {
necessaryButtonExist = true
}
buttonCount++
}
// If the device doesn't have any necessary bottons, this might not be a gamepad (#2039).
// Remove this.
if !necessaryButtonExist {
n.close()
gamepads.remove(func(gamepad *Gamepad) bool {
return gamepad == gp
})
}
for code := 0; code < _ABS_CNT; code++ {
n.absMap[code] = -1
if !isBitSet(absBits, code) {