InputContainer/FocusManager: Simplify key_events clearing on unplug

Thanks to @poire-z for the idea, it's indeed much nicer this way ;).
This commit is contained in:
NiLuJe
2022-11-01 23:22:07 +01:00
parent d585cd5d86
commit 925fd647dc
19 changed files with 66 additions and 141 deletions

View File

@@ -41,7 +41,7 @@ local ReaderPaging = InputContainer:extend{
}
function ReaderPaging:init()
self:registerKeyEvents(true)
self:registerKeyEvents()
self.pan_interval = time.s(1 / self.pan_rate)
self.number_of_pages = self.ui.document.info.number_of_pages
@@ -51,7 +51,7 @@ end
function ReaderPaging:onGesture() end
function ReaderPaging:registerKeyEvents(init)
function ReaderPaging:registerKeyEvents()
if Device:hasKeys() then
self.key_events.GotoNextPage = {
{ { "RPgFwd", "LPgFwd", not Device:hasFewKeys() and "Right" } },
@@ -73,11 +73,6 @@ function ReaderPaging:registerKeyEvents(init)
event = "GotoPosRel",
args = -1,
}
elseif not init then
self.key_events.GotoNextPage = nil
self.key_events.GotoPrevPage = nil
self.key_events.GotoNextPos = nil
self.key_events.GotoPrevPos = nil
end
if Device:hasKeyboard() then
self.key_events.GotoFirst = {
@@ -130,22 +125,10 @@ function ReaderPaging:registerKeyEvents(init)
event = "GotoPercent",
args = 100,
}
elseif not init then
self.key_events.GotoFirst = nil
self.key_events.Goto11 = nil
self.key_events.Goto22 = nil
self.key_events.Goto33 = nil
self.key_events.Goto44 = nil
self.key_events.Goto55 = nil
self.key_events.Goto66 = nil
self.key_events.Goto77 = nil
self.key_events.Goto88 = nil
self.key_events.GotoLast = nil
end
end
ReaderPaging.onPhysicalKeyboardConnected = ReaderPaging.registerKeyEvents
ReaderPaging.onPhysicalKeyboardDisconnected = ReaderPaging.registerKeyEvents
function ReaderPaging:onReaderReady()
self:setupTouchZones()