Upstream hajimehoshi/ebiten state of the touched files before 39aa8ab4c0
This commit is contained in:
1 parent
6545add45f
commit
3462b6821c
1 file changed
+16
-14
@@ -65,27 +65,26 @@ func (g *nativeGamepadsImpl) init(gamepads *gamepads) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Another program of the same user can exhaust the inotify limits (#3304). That only costs
|
inotify, err := unix.InotifyInit1(unix.IN_NONBLOCK | unix.IN_CLOEXEC)
|
||||||
// hotplug detection, so it is not fatal here, and GLFW ignores the same errors.
|
if err != nil {
|
||||||
if inotify, err := unix.InotifyInit1(unix.IN_NONBLOCK | unix.IN_CLOEXEC); err == nil {
|
return fmt.Errorf("gamepad: InotifyInit1 failed: %w", err)
|
||||||
|
}
|
||||||
g.inotifyPlus1 = inotify + 1
|
g.inotifyPlus1 = inotify + 1
|
||||||
|
|
||||||
// Register for IN_ATTRIB to get notified when udev is done.
|
|
||||||
// This works well in practice but the true way is libudev.
|
|
||||||
if watch, err := unix.InotifyAddWatch(g.inotifyPlus1-1, dirName, unix.IN_CREATE|unix.IN_ATTRIB|unix.IN_DELETE); err == nil {
|
|
||||||
g.watch = watch
|
|
||||||
} else {
|
|
||||||
_ = unix.Close(g.inotifyPlus1 - 1)
|
|
||||||
g.inotifyPlus1 = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil && g.inotifyPlus1 != 0 {
|
if err != nil {
|
||||||
_ = unix.Close(g.inotifyPlus1 - 1)
|
_ = unix.Close(g.inotifyPlus1 - 1)
|
||||||
g.inotifyPlus1 = 0
|
g.inotifyPlus1 = 0
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Register for IN_ATTRIB to get notified when udev is done.
|
||||||
|
// This works well in practice but the true way is libudev.
|
||||||
|
watch, err := unix.InotifyAddWatch(g.inotifyPlus1-1, dirName, unix.IN_CREATE|unix.IN_ATTRIB|unix.IN_DELETE)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("gamepad: InotifyAddWatch failed: %w", err)
|
||||||
|
}
|
||||||
|
g.watch = watch
|
||||||
|
|
||||||
ents, err := os.ReadDir(dirName)
|
ents, err := os.ReadDir(dirName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("gamepad: ReadDir(%s) failed: %w", dirName, err)
|
return fmt.Errorf("gamepad: ReadDir(%s) failed: %w", dirName, err)
|
||||||
@@ -441,6 +440,9 @@ func (g *nativeGamepadImpl) pollAbsState() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *nativeGamepadImpl) handleAbsEvent(code int, value int32) {
|
func (g *nativeGamepadImpl) handleAbsEvent(code int, value int32) {
|
||||||
|
if code < 0 || code >= len(g.absMap) {
|
||||||
|
return
|
||||||
|
}
|
||||||
index := g.absMap[code]
|
index := g.absMap[code]
|
||||||
if index < 0 {
|
if index < 0 {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in new issue
Block a user