From 4547b2d65f7e01e16e87f877fed4505fc2883505 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Thu, 28 Feb 2019 23:49:23 +0100 Subject: [PATCH] [fix] GestureDetector: add PAN_DELAYED_INTERVAL (#4666) When multiswipes are enabled, this fixes the long-standing complaint that swiping to open the menu could unintentionally trigger some light panning. With the introduction of multiswipes, this problem has become more noticeable. --- frontend/apps/reader/modules/readerpaging.lua | 8 ++++++-- .../apps/reader/modules/readerrolling.lua | 8 ++++++-- frontend/device/gesturedetector.lua | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/frontend/apps/reader/modules/readerpaging.lua b/frontend/apps/reader/modules/readerpaging.lua index d1dc0699c..0461caa77 100644 --- a/frontend/apps/reader/modules/readerpaging.lua +++ b/frontend/apps/reader/modules/readerpaging.lua @@ -401,8 +401,12 @@ function ReaderPaging:onPan(_, ges) self.view:PanningStart(-ges.relative.x, -ges.relative.y) end elseif ges.direction == "north" or ges.direction == "south" then - self:onPanningRel(self.last_pan_relative_y - ges.relative.y) - self.last_pan_relative_y = ges.relative.y + local relative_type = "relative" + if self.ui.gesture and self.ui.gesture.multiswipes_enabled then + relative_type = "relative_delayed" + end + self:onPanningRel(self.last_pan_relative_y - ges[relative_type].y) + self.last_pan_relative_y = ges[relative_type].y end return true end diff --git a/frontend/apps/reader/modules/readerrolling.lua b/frontend/apps/reader/modules/readerrolling.lua index 9ae67f31a..90428f52e 100644 --- a/frontend/apps/reader/modules/readerrolling.lua +++ b/frontend/apps/reader/modules/readerrolling.lua @@ -421,10 +421,14 @@ end function ReaderRolling:onPan(_, ges) if self.view.view_mode == "scroll" then + local distance_type = "distance" + if self.ui.gesture and self.ui.gesture.multiswipes_enabled then + distance_type = "distance_delayed" + end if ges.direction == "north" then - self:_gotoPos(self.current_pos + ges.distance) + self:_gotoPos(self.current_pos + ges[distance_type]) elseif ges.direction == "south" then - self:_gotoPos(self.current_pos - ges.distance) + self:_gotoPos(self.current_pos - ges[distance_type]) end end return true diff --git a/frontend/device/gesturedetector.lua b/frontend/device/gesturedetector.lua index 0824118b3..243547119 100644 --- a/frontend/device/gesturedetector.lua +++ b/frontend/device/gesturedetector.lua @@ -53,6 +53,7 @@ local GestureDetector = { DOUBLE_TAP_INTERVAL = 300 * 1000, TWO_FINGER_TAP_DURATION = 300 * 1000, HOLD_INTERVAL = 500 * 1000, + PAN_DELAYED_INTERVAL = 500 * 1000, SWIPE_INTERVAL = 900 * 1000, -- pinch/spread direction table DIRECTION_TABLE = { @@ -482,6 +483,7 @@ function GestureDetector:handlePan(tev) return self:handleTwoFingerPan(tev) else local pan_direction, pan_distance = self:getPath(slot) + local tv_diff = self.last_tevs[slot].timev - self.first_tevs[slot].timev local pan_ev = { ges = "pan", @@ -490,13 +492,30 @@ function GestureDetector:handlePan(tev) x = 0, y = 0, }, + relative_delayed = { + -- default to pan 0 + x = 0, + y = 0, + }, pos = nil, direction = pan_direction, distance = pan_distance, + distance_delayed = 0, time = tev.timev, } + + -- regular pan pan_ev.relative.x = tev.x - self.first_tevs[slot].x pan_ev.relative.y = tev.y - self.first_tevs[slot].y + + -- delayed pan, used where necessary to reduce potential activation of panning + -- when swiping is intended (e.g., for the menu or for multiswipe) + if not ((tv_diff.sec == 0) and (tv_diff.usec < self.PAN_DELAYED_INTERVAL)) then + pan_ev.relative_delayed.x = tev.x - self.first_tevs[slot].x + pan_ev.relative_delayed.y = tev.y - self.first_tevs[slot].y + pan_ev.distance_delayed = pan_distance + end + pan_ev.pos = Geom:new{ x = self.last_tevs[slot].x, y = self.last_tevs[slot].y,