From dee65a799944f1a62e6ebece9ae4c923fa77c5dd Mon Sep 17 00:00:00 2001 From: chrox Date: Fri, 1 Jul 2016 23:47:29 +0800 Subject: [PATCH] add inactive touch zones around buttons on Kindle Voyage This should fix #1801. --- frontend/device/input.lua | 15 +++++++++++++++ frontend/device/kindle/device.lua | 29 +++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/frontend/device/input.lua b/frontend/device/input.lua index 0a8ae532e..dc429194c 100644 --- a/frontend/device/input.lua +++ b/frontend/device/input.lua @@ -159,10 +159,22 @@ function Input:registerEventAdjustHook(hook, hook_params) end end +function Input:registerGestureAdjustHook(hook, hook_params) + local old = self.gestureAdjustHook + self.gestureAdjustHook = function(this, ges) + old(this, ges) + hook(this, ges, hook_params) + end +end + function Input:eventAdjustHook(ev) -- do nothing by default end +function Input:gestureAdjustHook(ges) + -- do nothing by default +end + -- catalogue of predefined hooks: function Input:adjustTouchSwitchXY(ev) if ev.type == EV_ABS then @@ -363,6 +375,7 @@ function Input:handleTouchEv(ev) self.MTSlots = {} if touch_ges then --DEBUG("ges", touch_ges) + self:gestureAdjustHook(touch_ges) return Event:new("Gesture", self.gesture_detector:adjustGesCoordinate(touch_ges) ) @@ -427,6 +440,7 @@ function Input:handleTouchEvPhoenix(ev) local touch_ges = self.gesture_detector:feedEvent(self.MTSlots) self.MTSlots = {} if touch_ges then + self:gestureAdjustHook(touch_ges) return Event:new("Gesture", self.gesture_detector:adjustGesCoordinate(touch_ges) ) @@ -495,6 +509,7 @@ function Input:waitEvent(timeout_us) -- Do we really need to clear all setTimeout after -- decided a gesture? FIXME self.timer_callbacks = {} + self:gestureAdjustHook(touch_ges) return Event:new("Gesture", self.gesture_detector:adjustGesCoordinate(touch_ges) ) diff --git a/frontend/device/kindle/device.lua b/frontend/device/kindle/device.lua index 36e084125..40824a8dd 100644 --- a/frontend/device/kindle/device.lua +++ b/frontend/device/kindle/device.lua @@ -234,6 +234,35 @@ function KindleVoyage:init() [109] = "LPgFwd", }, } + -- touch gestures fall into these cold spots defined by (x, y, r) + -- will be rewritten to 'none' ges thus being ignored + -- x, y is the absolute position disregard of screen mode, r is spot radius + self.cold_spots = { + { + x = 1080 + 50, y = 485, r = 80 + }, + { + x = 1080 + 70, y = 910, r = 120 + }, + { + x = -50, y = 485, r = 80 + }, + { + x = -70, y = 910, r = 120 + }, + } + + self.input:registerGestureAdjustHook(function(_, ges) + if ges then + local pos = ges.pos + for _, spot in ipairs(self.cold_spots) do + if (spot.x - pos.x) * (spot.x - pos.x) + + (spot.y - pos.y) * (spot.y - pos.y) < spot.r * spot.r then + ges.ges = "none" + end + end + end + end) Kindle.init(self)