Skip to content

Commit d805a69

Browse files
NiLuJeFrenzie
authored andcommitted
Open input device outside of the readdir loop to workaround a bug in the
input backend
1 parent 84e942a commit d805a69

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

frontend/device/kindle/device.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,25 +1240,27 @@ function KindlePaperWhite5:init()
12401240
self.input.open(self.touch_dev)
12411241
else
12421242
-- Walk /sys/class/input and pick up any evdev input device with EV_ABS capabilities
1243+
-- NOTE: Run self.input.open *outside* of the loop, as the backend code assumes fd numbers are opened in increasing order...
1244+
local devices = {}
12431245
for evdev in lfs.dir("/sys/class/input/") do
12441246
if evdev:match("event.*") then
12451247
local abs_cap = "/sys/class/input/" .. evdev .. "/device/capabilities/abs"
12461248
local f = io.open(abs_cap, "r")
12471249
if f then
12481250
local bitmap_str = f:read("l")
1251+
f:close()
12491252
if bitmap_str ~= "0" then
12501253
logger.info("Potential input device found at", evdev, "because of ABS caps:", bitmap_str)
1251-
-- Allow multiple matches, but only remember the first as touch_dev
1252-
local touch = "/dev/input/" .. evdev
1253-
self.input.open(touch)
1254-
if not self.touch_dev then
1255-
self.touch_dev = touch
1256-
end
1254+
table.insert(devices, "/dev/input/" .. evdev)
12571255
end
1258-
f:close()
12591256
end
12601257
end
12611258
end
1259+
for _, touch in ipairs(devices) do
1260+
-- There should only be one match on the PW5 anyway...
1261+
self.touch_dev = touch
1262+
self.input.open(touch)
1263+
end
12621264
end
12631265
self.input.open("fake_events")
12641266
end

0 commit comments

Comments
 (0)