From 81b255cb857388589b8bf450cd4550d87cce8fec Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Fri, 11 Jan 2019 16:39:00 +0100 Subject: [PATCH] Better-than-nothing key repeat handling. Mainly aimed at the Forma. Still fairly terrible, as these things goes ;p. --- frontend/device/input.lua | 23 +++++++++++++++++++ .../ui/widget/container/inputcontainer.lua | 14 +++++++++++ 2 files changed, 37 insertions(+) diff --git a/frontend/device/input.lua b/frontend/device/input.lua index 5d130ec00..f0857f253 100755 --- a/frontend/device/input.lua +++ b/frontend/device/input.lua @@ -134,6 +134,9 @@ local Input = { Shift = false, }, + -- repeat state: + repeat_count = 0, + -- touch state: cur_slot = 0, MTSlots = {}, @@ -388,7 +391,27 @@ function Input:handleKeyBoardEv(ev) if ev.value == EVENT_VALUE_KEY_PRESS then return Event:new("KeyPress", key) + elseif ev.value == EVENT_VALUE_KEY_REPEAT then + -- NOTE: We only care about repeat events from the pageturn buttons... + -- 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 + -- FIXME: Crappy event staggering! + -- The Forma 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. + -- FIXME: 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 + return Event:new("KeyRepeat", key) + elseif self.repeat_count >= 6 then + self.repeat_count = 0 + end + end elseif ev.value == EVENT_VALUE_KEY_RELEASE then + self.repeat_count = 0 return Event:new("KeyRelease", key) end end diff --git a/frontend/ui/widget/container/inputcontainer.lua b/frontend/ui/widget/container/inputcontainer.lua index af499474a..781eda39e 100644 --- a/frontend/ui/widget/container/inputcontainer.lua +++ b/frontend/ui/widget/container/inputcontainer.lua @@ -228,6 +228,20 @@ function InputContainer:onKeyPress(key) end end +-- NOTE: Currently a verbatim copy of onKeyPress ;). +function InputContainer:onKeyRepeat(key) + for name, seq in pairs(self.key_events) do + if not seq.is_inactive then + for _, oneseq in ipairs(seq) do + if key:match(oneseq) then + local eventname = seq.event or name + return self:handleEvent(Event:new(eventname, seq.args, key)) + end + end + end + end +end + function InputContainer:onGesture(ev) for _, tzone in ipairs(self._ordered_touch_zones) do if tzone.gs_range:match(ev) and tzone.handler(ev) then