mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Initial hotpluggable keyboard handling (#9540)
* Added a new plugin external-keyboard. It listens to USB events. When keyboard is plugged in or plugged out, it updates device and input configuration accordingly. * Added new fake events UsbDevicePlugIn and UsbDevicePlugOut that are emitted when a device is connected to a book reader that plays the role of USB host. The usage of the existing events UsbPlugIn and UsbPlugOut has not changed - they are used when a reader is connected to a host. The koreader-base has a related PR for those events. * Did a small refactoring of initialization for the modules FocusManager and InputText. They check device keyboard capabilities on their when the module is first loaded and store it. Some of the initialization code has been extracted into functions, so that we can re-initialize them when keyboard is (dis)connected. * Initial implementation centered around text input, and tested with USB keyboards on devices with OTG support. * Said OTG shenanigans are so far supported on devices with debugfs & the chipidea driver, or sunxi devices.
This commit is contained in:
@@ -72,9 +72,7 @@ function InputText:initEventListener() end
|
||||
function InputText:onFocus() end
|
||||
function InputText:onUnfocus() end
|
||||
|
||||
-- only use PhysicalKeyboard if the device does not have touch screen
|
||||
if Device:isTouchDevice() or Device:hasDPad() then
|
||||
Keyboard = require("ui/widget/virtualkeyboard")
|
||||
local function initTouchEvents()
|
||||
if Device:isTouchDevice() then
|
||||
function InputText:initEventListener()
|
||||
self.ges_events = {
|
||||
@@ -284,6 +282,9 @@ if Device:isTouchDevice() or Device:hasDPad() then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function initDPadEvents()
|
||||
if Device:hasDPad() then
|
||||
function InputText:onFocus()
|
||||
-- Event called by the focusmanager
|
||||
@@ -302,10 +303,23 @@ if Device:isTouchDevice() or Device:hasDPad() then
|
||||
return true
|
||||
end
|
||||
end
|
||||
else
|
||||
Keyboard = require("ui/widget/physicalkeyboard")
|
||||
end
|
||||
|
||||
-- only use PhysicalKeyboard if the device does not support touch input
|
||||
function InputText.initInputEvents()
|
||||
FocusManagerInstance = nil
|
||||
|
||||
if Device:isTouchDevice() or Device:hasDPad() then
|
||||
Keyboard = require("ui/widget/virtualkeyboard")
|
||||
initTouchEvents()
|
||||
initDPadEvents()
|
||||
else
|
||||
Keyboard = require("ui/widget/physicalkeyboard")
|
||||
end
|
||||
end
|
||||
|
||||
InputText.initInputEvents()
|
||||
|
||||
function InputText:checkTextEditability()
|
||||
-- The split of the 'text' string to a table of utf8 chars may not be
|
||||
-- reversible to the same string, if 'text' comes from a binary file
|
||||
|
||||
Reference in New Issue
Block a user