Add key_repeat support to Kindle NT (#13328)
Some checks are pending
macos / macOS 13 x86-64 🔨15.2 🎯10.15 (push) Waiting to run
macos / macOS 14 ARM64 🔨15.4 🎯11.0 (push) Waiting to run

closes #12745
This commit is contained in:
David
2025-03-15 22:31:30 +00:00
committed by GitHub
parent 5a92aa2b51
commit 135453776a
4 changed files with 51 additions and 12 deletions

View File

@@ -773,28 +773,31 @@ function Input:handleKeyBoardEv(ev)
if ev.value == KEY_PRESS then
return Event:new("KeyPress", key)
elseif ev.value == KEY_REPEAT then
-- NOTE: We only care about repeat events from the pageturn buttons...
-- NOTE: We only care about repeat events from the page-turn buttons and cursor keys...
-- And we *definitely* don't want to flood the Event queue with useless SleepCover repeats!
if keycode == "LPgBack"
or keycode == "RPgBack"
or keycode == "LPgFwd"
or keycode == "RPgFwd" then
if keycode == "Up" or keycode == "Down" or keycode == "Left" or keycode == "Right"
or keycode == "RPgBack" or keycode == "RPgFwd" or keycode == "LPgBack" or keycode == "LPgFwd" then
--- @fixme Crappy event staggering!
--
-- The Forma & co repeats every 80ms after a 400ms delay, and 500ms roughly corresponds to a flashing update,
-- so stuff is usually in sync when you release the key.
-- Obvious downside is that this ends up slower than just mashing the key.
--
-- A better approach would be an onKeyRelease handler that flushes the Event queue...
self.repeat_count = self.repeat_count + 1
if self.repeat_count == 1 then
local rep_period = self.device.key_repeat and self.device.key_repeat[C.REP_PERIOD] or 80
local now = time.now()
if not self.last_repeat_time then
self.last_repeat_time = now
return Event:new("KeyRepeat", key)
elseif self.repeat_count >= 6 then
self.repeat_count = 0
else
local time_diff = time.to_ms(now - self.last_repeat_time)
if time_diff >= rep_period then
self.last_repeat_time = now
return Event:new("KeyRepeat", key)
end
end
end
elseif ev.value == KEY_RELEASE then
self.repeat_count = 0
self.last_repeat_time = nil
return Event:new("KeyRelease", key)
end
end

View File

@@ -543,6 +543,29 @@ function Kindle:otaModel()
return model, "ota"
end
function Kindle:toggleKeyRepeat(toggle)
if toggle == true then
self.key_repeat[C.REP_DELAY] = 400
self.key_repeat[C.REP_PERIOD] = 120
-- We can't easily clear existing hooks, but we can overwrite the eventAdjustHook
-- with the default empty implementation to effectively remove previous hooks
local Input = require("device/input")
self.input.eventAdjustHook = Input.eventAdjustHook
else
self.key_repeat[C.REP_DELAY] = 0
self.key_repeat[C.REP_PERIOD] = 0
-- Register an event hook that filters out KEY_REPEAT events
self.input:registerEventAdjustHook(function(this, ev)
if ev.type == C.EV_KEY and ev.value == 2 then -- KEY_REPEAT = 2
ev.value = -1 -- Set to an invalid value that will be ignored
end
end)
end
return true
end
function Kindle:init()
-- Check if the device supports deep sleep/quick boot
if lfs.attributes("/sys/devices/platform/falconblk/uevent", "mode") == "file" then
@@ -586,6 +609,18 @@ function Kindle:init()
end
end
if self:hasDPad() then
self.canKeyRepeat = yes
self.key_repeat = ffi.new("unsigned int[?]", C.REP_CNT)
if G_reader_settings:isTrue("input_no_key_repeat") then
self.key_repeat[C.REP_DELAY] = 0
self.key_repeat[C.REP_PERIOD] = 0
else
self.key_repeat[C.REP_DELAY] = 400
self.key_repeat[C.REP_PERIOD] = 120
end
end
Generic.init(self)
end

View File

@@ -62,7 +62,7 @@ if Device:hasDPad() and Device:useDPadAsActionKeys() then
end
if Device:canKeyRepeat() then
table.insert(PhysicalButtons.sub_item_table, {
table.insert(PhysicalButtons.sub_item_table, 1, {
text = _("Disable key repeat"),
help_text = _("Useful if you don't like the behavior or if your device has faulty switches"),
checked_func = function()

View File

@@ -525,5 +525,6 @@ function FocusManager:onKeyPress(key)
end
return InputContainer.onKeyPress(self, key)
end
FocusManager.onKeyRepeat = FocusManager.onKeyPress
return FocusManager