Skip to content

Commit 8466af2

Browse files
authored
[UX] Gesture manager: corner gestures (koreader#4878)
Adds configuration to the top corners as well as the additional gestures hold and two-finger tap. Deprecates `DTAP_ZONE_FLIPPING` and `DTAP_ZONE_BOOKMARK`. Fixes koreader#4877.
1 parent 22db71c commit 8466af2

File tree

8 files changed

+217
-103
lines changed

8 files changed

+217
-103
lines changed

.luacheckrc

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ read_globals = {
3737
"DTAP_ZONE_BACKWARD",
3838
"DTAP_ZONE_BOOKMARK",
3939
"DTAP_ZONE_FLIPPING",
40+
"DTAP_ZONE_TOP_LEFT",
41+
"DTAP_ZONE_TOP_RIGHT",
42+
"DTAP_ZONE_BOTTOM_LEFT",
43+
"DTAP_ZONE_BOTTOM_RIGHT",
4044
"DDOUBLE_TAP_ZONE_NEXT_CHAPTER",
4145
"DDOUBLE_TAP_ZONE_PREV_CHAPTER",
4246
"DCHANGE_WEST_SWIPE_TO_EAST",

defaults.lua

+10-6
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,21 @@ DOVERLAPPIXELS = 30
6464
FOLLOW_LINK_TIMEOUT = 0.5
6565

6666
-- customizable tap zones(rectangles)
67-
-- x: x coordinate of top left corner in proportion of screen width
68-
-- y: y coordinate of top left corner in proportion of screen height
69-
-- w: width of tap zone in proportion of screen width
70-
-- h: height of tap zone in proportion of screen height
67+
-- x: x coordinate of top left corner in proportion to screen width
68+
-- y: y coordinate of top left corner in proportion to screen height
69+
-- w: tap zone width in proportion to screen width
70+
-- h: tap zone height in proportion to screen height
7171
DTAP_ZONE_MENU = {x = 1/8, y = 0, w = 3/4, h = 1/8}
7272
DTAP_ZONE_CONFIG = {x = 1/8, y = 7/8, w = 3/4, h = 1/8}
7373
DTAP_ZONE_MINIBAR = {x = 0, y = 31/32, w = 1, h = 1/32}
7474
DTAP_ZONE_FORWARD = {x = 1/4, y = 0, w = 3/4, h = 1}
7575
DTAP_ZONE_BACKWARD = {x = 0, y = 0, w = 1/4, h = 1}
76-
DTAP_ZONE_BOOKMARK = {x = 7/8, y = 0, w = 1/8, h = 1/8}
77-
DTAP_ZONE_FLIPPING = {x = 0, y = 0, w = 1/8, h = 1/8}
76+
-- DTAP_ZONE_BOOKMARK = {x = 7/8, y = 0, w = 1/8, h = 1/8} -- deprecated
77+
-- DTAP_ZONE_FLIPPING = {x = 0, y = 0, w = 1/8, h = 1/8} -- deprecated
78+
DTAP_ZONE_TOP_LEFT = {x = 0, y = 0, w = 1/8, h = 1/8}
79+
DTAP_ZONE_TOP_RIGHT = {x = 7/8, y = 0, w = 1/8, h = 1/8}
80+
DTAP_ZONE_BOTTOM_LEFT = {x = 0, y = 7/8, w = 1/8, h = 1/8}
81+
DTAP_ZONE_BOTTOM_RIGHT = {x = 7/8, y = 7/8, w = 1/8, h = 1/8}
7882
DDOUBLE_TAP_ZONE_NEXT_CHAPTER = {x = 6/8, y = 0, w = 2/8, h = 2/8}
7983
DDOUBLE_TAP_ZONE_PREV_CHAPTER = {x = 0, y = 0, w = 2/8, h = 2/8}
8084

frontend/apps/filemanager/filemanager.lua

+6-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function FileManager:init()
8888
padding_left = Size.padding.large,
8989
padding_right = Size.padding.large,
9090
padding_bottom = 0,
91-
callback = function() self:tapPlus() end,
91+
callback = nil, -- top right corner callback handled by gesture manager
9292
}
9393

9494
self.path_text = TextWidget:new{
@@ -404,6 +404,11 @@ function FileChooser:onBack()
404404
end
405405
end
406406

407+
function FileManager:onShowPlusMenu()
408+
self:tapPlus()
409+
return true
410+
end
411+
407412
function FileManager:tapPlus()
408413
local buttons = {
409414
{

frontend/apps/reader/modules/readerdogear.lua

+1-24
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
local Device = require("device")
2-
local Event = require("ui/event")
32
local Geom = require("ui/geometry")
4-
local GestureRange = require("ui/gesturerange")
53
local ImageWidget = require("ui/widget/imagewidget")
64
local InputContainer = require("ui/widget/container/inputcontainer")
75
local RightContainer = require("ui/widget/container/rightcontainer")
8-
local Screen = require("device").screen
6+
local Screen = Device.screen
97

108
local ReaderDogear = InputContainer:new{}
119

@@ -70,30 +68,9 @@ end
7068
function ReaderDogear:resetLayout()
7169
local new_screen_width = Screen:getWidth()
7270
if new_screen_width == self._last_screen_width then return end
73-
local new_screen_height = Screen:getHeight()
7471
self._last_screen_width = new_screen_width
7572

7673
self[1].dimen.w = new_screen_width
77-
if Device:isTouchDevice() then
78-
self.ges_events = {
79-
Tap = {
80-
GestureRange:new{
81-
ges = "tap",
82-
range = Geom:new{
83-
x = new_screen_width*DTAP_ZONE_BOOKMARK.x,
84-
y = new_screen_height*DTAP_ZONE_BOOKMARK.y,
85-
w = new_screen_width*DTAP_ZONE_BOOKMARK.w,
86-
h = new_screen_height*DTAP_ZONE_BOOKMARK.h
87-
}
88-
}
89-
}
90-
}
91-
end
92-
end
93-
94-
function ReaderDogear:onTap()
95-
self.ui:handleEvent(Event:new("ToggleBookmark"))
96-
return true
9774
end
9875

9976
function ReaderDogear:onSetDogearVisibility(visible)
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
local Geom = require("ui/geometry")
2+
local ImageWidget = require("ui/widget/imagewidget")
13
local InputContainer = require("ui/widget/container/inputcontainer")
24
local LeftContainer = require("ui/widget/container/leftcontainer")
3-
local ImageWidget = require("ui/widget/imagewidget")
4-
local GestureRange = require("ui/gesturerange")
5-
local Device = require("device")
6-
local Geom = require("ui/geometry")
75
local Screen = require("device").screen
8-
local Event = require("ui/event")
96

107
local ReaderFlipping = InputContainer:new{
118
orig_reflow_mode = 0,
@@ -25,36 +22,9 @@ end
2522
function ReaderFlipping:resetLayout()
2623
local new_screen_width = Screen:getWidth()
2724
if new_screen_width == self._last_screen_width then return end
28-
local new_screen_height = Screen:getHeight()
2925
self._last_screen_width = new_screen_width
3026

3127
self[1].dimen.w = new_screen_width
32-
if Device:isTouchDevice() then
33-
self.ges_events = {
34-
Tap = {
35-
GestureRange:new{
36-
ges = "tap",
37-
range = Geom:new{
38-
x = new_screen_width*DTAP_ZONE_FLIPPING.x,
39-
y = new_screen_height*DTAP_ZONE_FLIPPING.y,
40-
w = new_screen_width*DTAP_ZONE_FLIPPING.w,
41-
h = new_screen_height*DTAP_ZONE_FLIPPING.h
42-
}
43-
}
44-
}
45-
}
46-
end
47-
end
48-
49-
function ReaderFlipping:onTap()
50-
if not self.ui.document.info.has_pages then
51-
-- ReaderRolling has no support (yet) for onTogglePageFlipping,
52-
-- so don't make that top left tap area unusable (and allow
53-
-- taping on links there)
54-
return false
55-
end
56-
self.ui:handleEvent(Event:new("TogglePageFlipping"))
57-
return true
5828
end
5929

6030
return ReaderFlipping

0 commit comments

Comments
 (0)