mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Support auto-detection of input devices via fbink_input (#11807)
* Kobo: Drop a bunch of if ladder crap and switch to auto-detection of input devices via fbink_input * Kindle: Drop an even larger bundle of crap to do the same ;p. (re: #11392) * ExternalKeyboard: Switch to fbink_input to whitelist keyboards instead of the manual parsing of caps via its FindKeyboard class * Input: Extended open/close wrappers to handle logging & tracking of dupe open/close calls.
This commit is contained in:
@@ -195,6 +195,10 @@ local Input = {
|
||||
setClipboardText = function(text)
|
||||
_internal_clipboard_text = text or ""
|
||||
end,
|
||||
|
||||
-- open'ed input devices hashmap (key: path, value: fd number)
|
||||
-- Must be a class member, both because Input is a singleton and that state is process-wide anyway.
|
||||
opened_devices = {},
|
||||
}
|
||||
|
||||
function Input:new(o)
|
||||
@@ -295,14 +299,74 @@ function Input:disableRotationMap()
|
||||
end
|
||||
|
||||
--[[--
|
||||
Wrapper for FFI input open.
|
||||
Wrapper for our Lua/C input module's open.
|
||||
|
||||
Note that we adhere to the "." syntax here for compatibility.
|
||||
|
||||
@todo Clean up separation FFI/this.
|
||||
The `name` argument is optional, and used for logging purposes only.
|
||||
--]]
|
||||
function Input.open(device, is_emu_events)
|
||||
return input.open(device, is_emu_events and 1 or 0)
|
||||
function Input.open(path, name)
|
||||
-- Make sure we don't open the same device twice.
|
||||
if not Input.opened_devices[path] then
|
||||
local fd = input.open(path)
|
||||
if fd then
|
||||
Input.opened_devices[path] = fd
|
||||
if name then
|
||||
logger.dbg("Opened fd", fd, "for input device", name, "@", path)
|
||||
else
|
||||
logger.dbg("Opened fd", fd, "for input device @", path)
|
||||
end
|
||||
end
|
||||
-- No need to log failures, input will have raised an error already,
|
||||
-- and we want to make those fatal, so we don't protect this call.
|
||||
return fd
|
||||
end
|
||||
end
|
||||
|
||||
--[[--
|
||||
Wrapper for our Lua/C input module's close.
|
||||
|
||||
Note that we adhere to the "." syntax here for compatibility.
|
||||
--]]
|
||||
function Input.close(path)
|
||||
-- Make sure we actually know about this device
|
||||
local fd = Input.opened_devices[path]
|
||||
if fd then
|
||||
local ok, err = input.close(fd)
|
||||
if ok or err == C.ENODEV then
|
||||
-- Either the call succeeded,
|
||||
-- or the backend had already caught an ENODEV in waitForInput and closed the fd internally.
|
||||
-- (Because the EvdevInputRemove Event comes from an UsbDevicePlugOut uevent forwarded as an... *input* EV_KEY event ;)).
|
||||
-- Regardless, that device is gone, so clear its spot in the hashmap.
|
||||
Input.opened_devices[path] = nil
|
||||
end
|
||||
else
|
||||
logger.warn("Tried to close an unknown input device @", path)
|
||||
end
|
||||
end
|
||||
|
||||
--[[--
|
||||
Wrapper for our Lua/C input module's closeAll.
|
||||
|
||||
Note that we adhere to the "." syntax here for compatibility.
|
||||
--]]
|
||||
function Input.teardown()
|
||||
input.closeAll()
|
||||
Input.opened_devices = {}
|
||||
end
|
||||
|
||||
-- Wrappers for the custom FFI implementations with no concept of paths or fd
|
||||
if input.is_ffi then
|
||||
-- Pass args as-is. None of 'em actually *take* arguments, but some may be invoked as methods...
|
||||
function Input.open(...)
|
||||
return input.open(...)
|
||||
end
|
||||
function Input.close(...)
|
||||
return input.close(...)
|
||||
end
|
||||
function Input.teardown(...)
|
||||
return input.closeAll(...)
|
||||
end
|
||||
end
|
||||
|
||||
--[[--
|
||||
|
||||
Reference in New Issue
Block a user