2019-12-06 21:55:39 +00:00
|
|
|
local BD = require("ui/bidi")
|
2019-02-17 20:38:02 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
local DataStorage = require("datastorage")
|
2018-09-29 21:15:57 +00:00
|
|
|
local Device = require("device")
|
2020-07-17 03:03:23 +00:00
|
|
|
local Dispatcher = require("dispatcher")
|
2020-08-05 22:13:26 +00:00
|
|
|
local Event = require("ui/event")
|
2020-07-17 03:03:23 +00:00
|
|
|
local FFIUtil = require("ffi/util")
|
2019-02-22 19:59:32 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2021-11-29 03:56:21 +00:00
|
|
|
local GestureDetector = require("device/gesturedetector")
|
2019-02-22 19:59:32 +00:00
|
|
|
local GestureRange = require("ui/gesturerange")
|
2019-02-24 11:29:49 +00:00
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
2022-11-02 22:20:56 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2019-02-22 19:59:32 +00:00
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
2020-07-17 03:03:23 +00:00
|
|
|
local LuaSettings = require("luasettings")
|
2018-09-29 21:15:57 +00:00
|
|
|
local Screen = require("device").screen
|
2021-11-29 03:56:21 +00:00
|
|
|
local SpinWidget = require("ui/widget/spinwidget")
|
2018-09-29 21:15:57 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2022-09-27 23:10:50 +00:00
|
|
|
local lfs = require("libs/libkoreader-lfs")
|
|
|
|
local logger = require("logger")
|
2020-07-17 03:03:23 +00:00
|
|
|
local util = require("util")
|
2020-09-15 18:39:32 +00:00
|
|
|
local T = FFIUtil.template
|
2022-05-05 19:00:22 +00:00
|
|
|
local time = require("ui/time")
|
2018-09-29 21:15:57 +00:00
|
|
|
local _ = require("gettext")
|
2022-05-23 22:25:50 +00:00
|
|
|
local C_ = _.pgettext
|
2018-09-29 21:15:57 +00:00
|
|
|
|
2020-07-15 22:24:31 +00:00
|
|
|
if not Device:isTouchDevice() then
|
|
|
|
return { disabled = true, }
|
|
|
|
end
|
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local Gestures = WidgetContainer:extend{
|
2020-07-15 22:24:31 +00:00
|
|
|
name = "gestures",
|
2020-07-17 03:03:23 +00:00
|
|
|
settings_data = nil,
|
2020-07-15 22:24:31 +00:00
|
|
|
gestures = nil,
|
2020-07-17 03:03:23 +00:00
|
|
|
defaults = nil,
|
|
|
|
custom_multiswipes = nil,
|
2020-08-04 22:19:28 +00:00
|
|
|
updated = false,
|
2020-07-15 22:24:31 +00:00
|
|
|
}
|
2020-07-17 03:03:23 +00:00
|
|
|
local gestures_path = FFIUtil.joinPath(DataStorage:getSettingsDir(), "gestures.lua")
|
|
|
|
|
|
|
|
local gestures_list = {
|
|
|
|
tap_top_left_corner = _("Top left"),
|
|
|
|
tap_top_right_corner = _("Top right"),
|
|
|
|
tap_left_bottom_corner = _("Bottom left"),
|
|
|
|
tap_right_bottom_corner = _("Bottom right"),
|
|
|
|
hold_top_left_corner = _("Top left"),
|
|
|
|
hold_top_right_corner = _("Top right"),
|
|
|
|
hold_bottom_left_corner = _("Bottom left"),
|
|
|
|
hold_bottom_right_corner = _("Bottom right"),
|
|
|
|
one_finger_swipe_left_edge_down = _("Left edge down"),
|
|
|
|
one_finger_swipe_left_edge_up = _("Left edge up"),
|
|
|
|
one_finger_swipe_right_edge_down = _("Right edge down"),
|
|
|
|
one_finger_swipe_right_edge_up = _("Right edge up"),
|
|
|
|
one_finger_swipe_top_edge_right = _("Top edge right"),
|
|
|
|
one_finger_swipe_top_edge_left = _("Top edge left"),
|
|
|
|
one_finger_swipe_bottom_edge_right = _("Bottom edge right"),
|
|
|
|
one_finger_swipe_bottom_edge_left = _("Bottom edge left"),
|
|
|
|
double_tap_left_side = _("Left side"),
|
|
|
|
double_tap_right_side = _("Right side"),
|
|
|
|
double_tap_top_left_corner = _("Top left"),
|
|
|
|
double_tap_top_right_corner = _("Top right"),
|
|
|
|
double_tap_bottom_left_corner = _("Bottom left"),
|
|
|
|
double_tap_bottom_right_corner = _("Bottom right"),
|
|
|
|
two_finger_tap_top_left_corner = _("Top left"),
|
|
|
|
two_finger_tap_top_right_corner = _("Top right"),
|
|
|
|
two_finger_tap_bottom_left_corner = _("Bottom left"),
|
|
|
|
two_finger_tap_bottom_right_corner = _("Bottom right"),
|
|
|
|
short_diagonal_swipe = _("Short diagonal swipe"),
|
|
|
|
two_finger_swipe_east = "⇒",
|
|
|
|
two_finger_swipe_west = "⇐",
|
|
|
|
two_finger_swipe_south = "⇓",
|
|
|
|
two_finger_swipe_north = "⇑",
|
|
|
|
two_finger_swipe_northeast = "⇗",
|
|
|
|
two_finger_swipe_northwest = "⇖",
|
|
|
|
two_finger_swipe_southeast = "⇘",
|
|
|
|
two_finger_swipe_southwest = "⇙",
|
|
|
|
spread_gesture = _("Spread"),
|
|
|
|
pinch_gesture = _("Pinch"),
|
2022-09-04 00:38:27 +00:00
|
|
|
rotate_cw = _("Rotate ⤸ 90°"),
|
|
|
|
rotate_ccw = _("Rotate ⤹ 90°"),
|
2020-07-17 03:03:23 +00:00
|
|
|
multiswipe = "", -- otherwise registerGesture() won't pick up on multiswipes
|
|
|
|
multiswipe_west_east = "⬅ ➡",
|
|
|
|
multiswipe_east_west = "➡ ⬅",
|
|
|
|
multiswipe_north_east = "⬆ ➡",
|
|
|
|
multiswipe_north_west = "⬆ ⬅",
|
|
|
|
multiswipe_north_south = "⬆ ⬇",
|
|
|
|
multiswipe_east_north = "➡ ⬆",
|
|
|
|
multiswipe_west_north = "⬅ ⬆",
|
|
|
|
multiswipe_east_south = "➡ ⬇",
|
|
|
|
multiswipe_south_north = "⬇ ⬆",
|
|
|
|
multiswipe_south_east = "⬇ ➡",
|
|
|
|
multiswipe_south_west = "⬇ ⬅",
|
|
|
|
multiswipe_west_south = "⬅ ⬇",
|
|
|
|
multiswipe_north_south_north = "⬆ ⬇ ⬆",
|
|
|
|
multiswipe_south_north_south = "⬇ ⬆ ⬇",
|
|
|
|
multiswipe_west_east_west = "⬅ ➡ ⬅",
|
|
|
|
multiswipe_east_west_east = "➡ ⬅ ➡",
|
|
|
|
multiswipe_south_west_north = "⬇ ⬅ ⬆",
|
|
|
|
multiswipe_north_east_south = "⬆ ➡ ⬇",
|
|
|
|
multiswipe_north_west_south = "⬆ ⬅ ⬇",
|
|
|
|
multiswipe_west_south_east = "⬅ ⬇ ➡",
|
|
|
|
multiswipe_west_north_east = "⬅ ⬆ ➡",
|
|
|
|
multiswipe_east_south_west = "➡ ⬇ ⬅",
|
|
|
|
multiswipe_east_north_west = "➡ ⬆ ⬅",
|
|
|
|
multiswipe_south_east_north = "⬇ ➡ ⬆",
|
|
|
|
multiswipe_east_north_west_east = "➡ ⬆ ⬅ ➡",
|
|
|
|
multiswipe_south_east_north_south = "⬇ ➡ ⬆ ⬇",
|
|
|
|
multiswipe_east_south_west_north = "➡ ⬇ ⬅ ⬆",
|
|
|
|
multiswipe_west_south_east_north = "⬅ ⬇ ➡ ⬆",
|
|
|
|
multiswipe_south_east_north_west = "⬇ ➡ ⬆ ⬅",
|
|
|
|
multiswipe_south_west_north_east = "⬇ ⬅ ⬆ ➡",
|
|
|
|
multiswipe_southeast_northeast = "⬊ ⬈",
|
|
|
|
multiswipe_northeast_southeast = "⬈ ⬊",
|
|
|
|
multiswipe_northwest_southwest_northwest = "⬉ ⬋ ⬉",
|
|
|
|
multiswipe_southeast_southwest_northwest = "⬊ ⬋ ⬉",
|
|
|
|
multiswipe_southeast_northeast_northwest = "⬊ ⬈ ⬉",
|
2019-02-24 16:07:42 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 15:11:47 +00:00
|
|
|
local multiswipes_info_text = _([[
|
|
|
|
Multiswipes allow you to perform complex gestures built up out of multiple swipe directions, never losing touch with the screen.
|
2019-03-02 13:38:40 +00:00
|
|
|
|
|
|
|
These advanced gestures consist of either straight swipes or diagonal swipes. To ensure accuracy, they can't be mixed.]])
|
2019-02-17 20:38:02 +00:00
|
|
|
|
2023-07-03 04:58:51 +00:00
|
|
|
-- If the gesture contains "toggle_touch_input" or "touch_input_on" actions, or is set "Always active" manually,
|
2022-11-02 22:20:56 +00:00
|
|
|
-- mark it "always active" to make sure that InputContainer won't block it after the IgnoreTouchInput Event.
|
|
|
|
function Gestures:isGestureAlwaysActive(ges, multiswipe_directions)
|
|
|
|
-- Handle multiswipes properly
|
|
|
|
-- NOTE: This is a bit clunky, as ges comes from the list of registered touch zones,
|
|
|
|
-- while multiswipe_directions comes from the actual input event.
|
|
|
|
-- Alas, all our multiswipe gestures are handled by a single "multiswipe" zone.
|
|
|
|
if self.multiswipes_enabled then
|
|
|
|
if ges == "multiswipe" and multiswipe_directions then
|
|
|
|
ges = "multiswipe_" .. self:safeMultiswipeName(multiswipe_directions)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-03 04:58:51 +00:00
|
|
|
local gest = self.gestures[ges]
|
|
|
|
return gest and (gest.toggle_touch_input or gest.touch_input_on or (gest.settings and gest.settings.always_active))
|
2022-11-02 22:20:56 +00:00
|
|
|
end
|
|
|
|
|
2020-07-15 22:24:31 +00:00
|
|
|
function Gestures:init()
|
2020-07-17 03:03:23 +00:00
|
|
|
local defaults_path = FFIUtil.joinPath(self.path, "defaults.lua")
|
|
|
|
if not lfs.attributes(gestures_path, "mode") then
|
|
|
|
FFIUtil.copyFile(defaults_path, gestures_path)
|
|
|
|
end
|
2021-03-06 21:44:18 +00:00
|
|
|
self.ignore_hold_corners = G_reader_settings:isTrue("ignore_hold_corners")
|
|
|
|
self.multiswipes_enabled = G_reader_settings:isTrue("multiswipes_enabled")
|
2018-09-29 21:15:57 +00:00
|
|
|
self.is_docless = self.ui == nil or self.ui.document == nil
|
|
|
|
self.ges_mode = self.is_docless and "gesture_fm" or "gesture_reader"
|
2020-07-17 03:03:23 +00:00
|
|
|
self.defaults = LuaSettings:open(defaults_path).data[self.ges_mode]
|
|
|
|
if not self.settings_data then
|
|
|
|
self.settings_data = LuaSettings:open(gestures_path)
|
|
|
|
end
|
|
|
|
self.gestures = self.settings_data.data[self.ges_mode]
|
|
|
|
self.custom_multiswipes = self.settings_data.data["custom_multiswipes"]
|
|
|
|
if G_reader_settings:has("gesture_fm") or G_reader_settings:has("gesture_reader") then
|
|
|
|
-- Migrate old gestures
|
|
|
|
local Migration = require("migration")
|
|
|
|
Migration:migrateGestures(self)
|
|
|
|
end
|
2019-12-06 21:55:39 +00:00
|
|
|
|
|
|
|
-- Some of these defaults need to be reversed in RTL mirrored UI,
|
|
|
|
-- and as we set them in the saved gestures, we need to reset them
|
|
|
|
-- to the defaults in case of UI language's direction change.
|
|
|
|
local mirrored_if_rtl = {
|
|
|
|
tap_top_left_corner = "tap_top_right_corner",
|
|
|
|
tap_right_bottom_corner = "tap_left_bottom_corner",
|
2020-06-28 13:41:24 +00:00
|
|
|
double_tap_left_side = "double_tap_right_side",
|
2019-12-06 21:55:39 +00:00
|
|
|
}
|
2020-07-17 03:03:23 +00:00
|
|
|
|
2019-12-06 21:55:39 +00:00
|
|
|
local is_rtl = BD.mirroredUILayout()
|
|
|
|
if is_rtl then
|
|
|
|
for k, v in pairs(mirrored_if_rtl) do
|
2020-07-17 03:03:23 +00:00
|
|
|
self.defaults[k], self.defaults[v] = self.defaults[v], self.defaults[k]
|
2019-12-06 21:55:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
-- We remember the last UI direction gestures were made on. If it changes,
|
|
|
|
-- reset the mirrored_if_rtl ones to the default for the new direction.
|
|
|
|
local ges_dir_setting = self.ges_mode.."ui_lang_direction_rtl"
|
|
|
|
local prev_lang_dir_rtl = G_reader_settings:isTrue(ges_dir_setting)
|
|
|
|
if (is_rtl and not prev_lang_dir_rtl) or (not is_rtl and prev_lang_dir_rtl) then
|
|
|
|
local reset = false
|
|
|
|
for k, v in pairs(mirrored_if_rtl) do
|
|
|
|
-- We only replace them if they are still the other direction's default.
|
|
|
|
-- If not, the user has changed them: let him deal with setting new ones if needed.
|
2020-07-17 03:03:23 +00:00
|
|
|
if util.tableEquals(self.gestures[k], self.defaults[v]) then
|
|
|
|
self.gestures[k] = self.defaults[k]
|
2019-12-06 21:55:39 +00:00
|
|
|
reset = true
|
|
|
|
end
|
2020-07-17 03:03:23 +00:00
|
|
|
if util.tableEquals(self.gestures[v], self.defaults[k]) then
|
|
|
|
self.gestures[v] = self.defaults[v]
|
2019-12-06 21:55:39 +00:00
|
|
|
reset = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if reset then
|
2020-08-04 22:19:28 +00:00
|
|
|
self.updated = true
|
2019-12-06 21:55:39 +00:00
|
|
|
logger.info("UI language direction changed: resetting some gestures to direction default")
|
|
|
|
end
|
|
|
|
G_reader_settings:flipNilOrFalse(ges_dir_setting)
|
|
|
|
end
|
|
|
|
|
2018-09-29 21:15:57 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2020-09-22 00:05:02 +00:00
|
|
|
Dispatcher:init()
|
2018-09-29 21:15:57 +00:00
|
|
|
self:initGesture()
|
2022-11-02 22:20:56 +00:00
|
|
|
-- Overload InputContainer's stub to allow it to recognize "always active" gestures
|
|
|
|
InputContainer.isGestureAlwaysActive = function(this, ges, multiswipe_directions) return self:isGestureAlwaysActive(ges, multiswipe_directions) end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Gestures:onCloseWidget()
|
|
|
|
-- Restore the stub implementation on teardown, to avoid pinning a stale instance of ourselves
|
|
|
|
InputContainer.isGestureAlwaysActive = InputContainer._isGestureAlwaysActive
|
2018-09-29 21:15:57 +00:00
|
|
|
end
|
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
function Gestures:gestureTitleFunc(ges)
|
|
|
|
local title = gestures_list[ges] or self:friendlyMultiswipeName(ges)
|
2022-09-19 02:22:41 +00:00
|
|
|
return T(_("%1 (%2)"), title, Dispatcher:menuTextFunc(self.gestures[ges]))
|
2020-07-17 03:03:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Gestures:genMenu(ges)
|
|
|
|
local sub_items = {}
|
|
|
|
if gestures_list[ges] ~= nil then
|
|
|
|
table.insert(sub_items, {
|
2022-09-19 02:22:41 +00:00
|
|
|
text = T(_("%1 (default)"), Dispatcher:menuTextFunc(self.defaults[ges])),
|
2020-07-17 03:03:23 +00:00
|
|
|
keep_menu_open = true,
|
|
|
|
separator = true,
|
|
|
|
checked_func = function()
|
|
|
|
return util.tableEquals(self.gestures[ges], self.defaults[ges])
|
|
|
|
end,
|
|
|
|
callback = function()
|
|
|
|
self.gestures[ges] = util.tableDeepCopy(self.defaults[ges])
|
2020-08-04 22:19:28 +00:00
|
|
|
self.updated = true
|
2020-07-17 03:03:23 +00:00
|
|
|
end,
|
|
|
|
})
|
2018-09-29 21:15:57 +00:00
|
|
|
end
|
2020-07-17 03:03:23 +00:00
|
|
|
table.insert(sub_items, {
|
|
|
|
text = _("Pass through"),
|
|
|
|
keep_menu_open = true,
|
|
|
|
checked_func = function()
|
|
|
|
return self.gestures[ges] == nil
|
|
|
|
end,
|
|
|
|
callback = function()
|
|
|
|
self.gestures[ges] = nil
|
2020-08-04 22:19:28 +00:00
|
|
|
self.updated = true
|
2020-07-17 03:03:23 +00:00
|
|
|
end,
|
|
|
|
})
|
2020-08-04 22:19:28 +00:00
|
|
|
Dispatcher:addSubMenu(self, sub_items, self.gestures, ges)
|
2023-07-08 05:17:42 +00:00
|
|
|
table.insert(sub_items, {
|
|
|
|
text = _("Anchor QuickMenu to gesture position"),
|
|
|
|
checked_func = function()
|
|
|
|
return self.gestures[ges] ~= nil
|
|
|
|
and self.gestures[ges].settings ~= nil
|
|
|
|
and self.gestures[ges].settings.anchor_quickmenu
|
|
|
|
end,
|
|
|
|
callback = function()
|
|
|
|
if self.gestures[ges] then
|
|
|
|
if self.gestures[ges].settings then
|
|
|
|
if self.gestures[ges].settings.anchor_quickmenu then
|
|
|
|
self.gestures[ges].settings.anchor_quickmenu = nil
|
|
|
|
if next(self.gestures[ges].settings) == nil then
|
|
|
|
self.gestures[ges].settings = nil
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.gestures[ges].settings.anchor_quickmenu = true
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.gestures[ges].settings = {["anchor_quickmenu"] = true}
|
|
|
|
end
|
|
|
|
self.updated = true
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
table.insert(sub_items, {
|
|
|
|
text = _("Always active"),
|
|
|
|
checked_func = function()
|
|
|
|
return self.gestures[ges] ~= nil
|
|
|
|
and self.gestures[ges].settings ~= nil
|
|
|
|
and self.gestures[ges].settings.always_active
|
|
|
|
end,
|
|
|
|
callback = function()
|
|
|
|
if self.gestures[ges] then
|
|
|
|
if self.gestures[ges].settings then
|
|
|
|
if self.gestures[ges].settings.always_active then
|
|
|
|
self.gestures[ges].settings.always_active = nil
|
|
|
|
if next(self.gestures[ges].settings) == nil then
|
|
|
|
self.gestures[ges].settings = nil
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.gestures[ges].settings.always_active = true
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.gestures[ges].settings = {["always_active"] = true}
|
|
|
|
end
|
|
|
|
self.updated = true
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
2020-07-17 03:03:23 +00:00
|
|
|
return sub_items
|
2018-09-29 21:15:57 +00:00
|
|
|
end
|
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
function Gestures:genSubItem(ges, separator, hold_callback)
|
2022-02-19 09:45:10 +00:00
|
|
|
local reader_only = {tap_top_left_corner=true, tap_top_right_corner=true,}
|
2020-07-17 03:03:23 +00:00
|
|
|
local enabled_func
|
|
|
|
if reader_only[ges] then
|
|
|
|
enabled_func = function() return self.ges_mode == "gesture_reader" end
|
|
|
|
end
|
2019-02-24 11:29:49 +00:00
|
|
|
return {
|
2020-07-17 03:03:23 +00:00
|
|
|
text_func = function() return self:gestureTitleFunc(ges) end,
|
|
|
|
enabled_func = enabled_func,
|
2021-09-10 20:14:07 +00:00
|
|
|
sub_item_table_func = function() return self:genMenu(ges) end,
|
2020-07-17 03:03:23 +00:00
|
|
|
separator = separator,
|
|
|
|
hold_callback = hold_callback,
|
2021-11-23 17:52:40 +00:00
|
|
|
menu_item_id = ges,
|
2022-12-18 00:25:41 +00:00
|
|
|
ignored_by_menu_search = true, -- This item is not strictly duplicated, but its subitems are.
|
|
|
|
-- Ignoring it speeds up search.
|
2019-02-24 11:29:49 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
function Gestures:genSubItemTable(gestures)
|
|
|
|
local sub_item_table = {}
|
|
|
|
for _, item in ipairs(gestures) do
|
|
|
|
table.insert(sub_item_table, self:genSubItem(item))
|
2019-04-07 17:00:15 +00:00
|
|
|
end
|
2020-07-17 03:03:23 +00:00
|
|
|
return sub_item_table
|
|
|
|
end
|
|
|
|
|
|
|
|
function Gestures:genMultiswipeMenu()
|
|
|
|
local sub_item_table = {}
|
|
|
|
-- { multiswipe name, separator }
|
|
|
|
local multiswipe_list = {
|
|
|
|
{"multiswipe_west_east",},
|
|
|
|
{"multiswipe_east_west",},
|
|
|
|
{"multiswipe_north_south",},
|
|
|
|
{"multiswipe_south_north", true},
|
|
|
|
{"multiswipe_north_west",},
|
|
|
|
{"multiswipe_north_east",},
|
|
|
|
{"multiswipe_south_west",},
|
|
|
|
{"multiswipe_south_east",},
|
|
|
|
{"multiswipe_east_north",},
|
|
|
|
{"multiswipe_west_north",},
|
|
|
|
{"multiswipe_east_south",},
|
|
|
|
{"multiswipe_west_south", true},
|
|
|
|
{"multiswipe_north_south_north",},
|
|
|
|
{"multiswipe_south_north_south",},
|
|
|
|
{"multiswipe_west_east_west",},
|
|
|
|
{"multiswipe_east_west_east", true},
|
|
|
|
{"multiswipe_south_west_north",},
|
|
|
|
{"multiswipe_north_east_south",},
|
|
|
|
{"multiswipe_north_west_south",},
|
|
|
|
{"multiswipe_west_south_east",},
|
|
|
|
{"multiswipe_west_north_east",},
|
|
|
|
{"multiswipe_east_south_west",},
|
|
|
|
{"multiswipe_east_north_west",},
|
|
|
|
{"multiswipe_south_east_north", true},
|
|
|
|
{"multiswipe_east_north_west_east",},
|
|
|
|
{"multiswipe_south_east_north_south", true},
|
|
|
|
{"multiswipe_east_south_west_north",},
|
|
|
|
{"multiswipe_west_south_east_north",},
|
|
|
|
{"multiswipe_south_east_north_west",},
|
|
|
|
{"multiswipe_south_west_north_east", true},
|
|
|
|
{"multiswipe_southeast_northeast",},
|
|
|
|
{"multiswipe_northeast_southeast",},
|
|
|
|
{"multiswipe_northwest_southwest_northwest",},
|
|
|
|
{"multiswipe_southeast_southwest_northwest",},
|
|
|
|
{"multiswipe_southeast_northeast_northwest",},
|
2019-08-18 17:36:11 +00:00
|
|
|
}
|
2020-07-17 03:03:23 +00:00
|
|
|
for _, item in ipairs(multiswipe_list) do
|
|
|
|
table.insert(sub_item_table, self:genSubItem(item[1], item[2]))
|
|
|
|
end
|
|
|
|
return sub_item_table
|
|
|
|
end
|
|
|
|
|
|
|
|
local multiswipe_to_arrow = {
|
|
|
|
east = "➡",
|
|
|
|
west = "⬅",
|
|
|
|
north = "⬆",
|
|
|
|
south = "⬇",
|
|
|
|
northeast = "⬈",
|
|
|
|
northwest = "⬉",
|
|
|
|
southeast = "⬊",
|
|
|
|
southwest = "⬋",
|
|
|
|
}
|
|
|
|
function Gestures:friendlyMultiswipeName(multiswipe)
|
|
|
|
return multiswipe:gsub("multiswipe", ""):gsub("_", " "):gsub("%S+", multiswipe_to_arrow)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Gestures:safeMultiswipeName(multiswipe)
|
|
|
|
return multiswipe:gsub(" ", "_")
|
|
|
|
end
|
|
|
|
|
|
|
|
function Gestures:multiswipeRecorder(touchmenu_instance)
|
|
|
|
local multiswipe_recorder
|
|
|
|
multiswipe_recorder = InputDialog:new{
|
|
|
|
title = _("Multiswipe recorder"),
|
|
|
|
input_hint = _("Make a multiswipe gesture"),
|
|
|
|
buttons = {
|
2019-04-07 17:00:15 +00:00
|
|
|
{
|
2020-07-17 03:03:23 +00:00
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
2022-03-04 20:20:00 +00:00
|
|
|
id = "close",
|
2020-07-17 03:03:23 +00:00
|
|
|
callback = function()
|
|
|
|
UIManager:close(multiswipe_recorder)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Save"),
|
|
|
|
is_enter_default = true,
|
|
|
|
callback = function()
|
|
|
|
local recorded_multiswipe = multiswipe_recorder._raw_multiswipe
|
|
|
|
if not recorded_multiswipe then return end
|
|
|
|
logger.dbg("Multiswipe recorder detected:", recorded_multiswipe)
|
|
|
|
|
|
|
|
if gestures_list[recorded_multiswipe] ~= nil then
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("Recorded multiswipe already exists."),
|
|
|
|
show_icon = false,
|
|
|
|
timeout = 5,
|
|
|
|
})
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
self.custom_multiswipes[recorded_multiswipe] = true
|
2020-08-04 22:19:28 +00:00
|
|
|
self.updated = true
|
2020-07-17 03:03:23 +00:00
|
|
|
--touchmenu_instance.item_table = self:genMultiswipeMenu()
|
|
|
|
-- We need to update touchmenu_instance.item_table in-place for the upper
|
|
|
|
-- menu to have it updated too
|
|
|
|
local item_table = touchmenu_instance.item_table
|
|
|
|
while #item_table > 0 do
|
|
|
|
table.remove(item_table, #item_table)
|
|
|
|
end
|
|
|
|
for __, v in ipairs(self:genCustomMultiswipeSubmenu()) do
|
|
|
|
table.insert(item_table, v)
|
|
|
|
end
|
|
|
|
touchmenu_instance:updateItems()
|
|
|
|
UIManager:close(multiswipe_recorder)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
}
|
2019-04-07 17:00:15 +00:00
|
|
|
},
|
|
|
|
}
|
2020-07-17 03:03:23 +00:00
|
|
|
|
|
|
|
multiswipe_recorder.ges_events.Multiswipe = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "multiswipe",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
2020-06-28 13:41:24 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2019-02-24 11:29:49 +00:00
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
function multiswipe_recorder:onMultiswipe(arg, ges)
|
|
|
|
multiswipe_recorder._raw_multiswipe = "multiswipe_" .. Gestures:safeMultiswipeName(ges.multiswipe_directions)
|
|
|
|
multiswipe_recorder:setInputText(Gestures:friendlyMultiswipeName(ges.multiswipe_directions))
|
|
|
|
end
|
2019-02-24 11:29:49 +00:00
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
UIManager:show(multiswipe_recorder)
|
|
|
|
end
|
2019-02-22 19:59:32 +00:00
|
|
|
|
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
function Gestures:genCustomMultiswipeSubmenu()
|
|
|
|
local submenu = {
|
|
|
|
{
|
|
|
|
text = _("Multiswipe recorder"),
|
|
|
|
keep_menu_open = true,
|
|
|
|
callback = function(touchmenu_instance)
|
|
|
|
self:multiswipeRecorder(touchmenu_instance)
|
|
|
|
end,
|
|
|
|
help_text = _("The number of possible multiswipe gestures is theoretically infinite. With the multiswipe recorder you can easily record your own."),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for item in FFIUtil.orderedPairs(self.custom_multiswipes) do
|
|
|
|
local hold_callback = function(touchmenu_instance)
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
text = T(_("Remove custom multiswipe %1?"), self:friendlyMultiswipeName(item)),
|
|
|
|
ok_text = _("Remove"),
|
|
|
|
ok_callback = function()
|
|
|
|
-- remove from list of custom multiswipes
|
|
|
|
self.custom_multiswipes[item] = nil
|
|
|
|
-- remove any settings for the muliswipe
|
|
|
|
self.settings_data.data["gesture_fm"][item] = nil
|
|
|
|
self.settings_data.data["gesture_reader"][item] = nil
|
2020-08-04 22:19:28 +00:00
|
|
|
self.updated = true
|
2020-07-17 03:03:23 +00:00
|
|
|
|
|
|
|
--touchmenu_instance.item_table = self:genMultiswipeMenu()
|
|
|
|
-- We need to update touchmenu_instance.item_table in-place for the upper
|
|
|
|
-- menu to have it updated too
|
|
|
|
local item_table = touchmenu_instance.item_table
|
|
|
|
while #item_table > 0 do
|
|
|
|
table.remove(item_table, #item_table)
|
2019-02-22 19:59:32 +00:00
|
|
|
end
|
2020-07-17 03:03:23 +00:00
|
|
|
for __, v in ipairs(self:genCustomMultiswipeSubmenu()) do
|
|
|
|
table.insert(item_table, v)
|
|
|
|
end
|
|
|
|
touchmenu_instance:updateItems()
|
2019-02-22 19:59:32 +00:00
|
|
|
end,
|
2020-07-17 03:03:23 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
table.insert(submenu, self:genSubItem(item, nil, hold_callback))
|
|
|
|
end
|
|
|
|
return submenu
|
|
|
|
end
|
|
|
|
|
|
|
|
function Gestures:addIntervals(menu_items)
|
2019-07-24 12:31:20 +00:00
|
|
|
menu_items.gesture_intervals = {
|
|
|
|
text = _("Gesture intervals"),
|
|
|
|
sub_item_table = {
|
2020-08-05 22:13:26 +00:00
|
|
|
{
|
|
|
|
text = _("Text selection rate"),
|
2020-10-18 13:57:40 +00:00
|
|
|
keep_menu_open = true,
|
2020-08-05 22:13:26 +00:00
|
|
|
callback = function()
|
2021-11-29 03:56:21 +00:00
|
|
|
local default_value = Screen.low_pan_rate and 5.0 or 30.0
|
|
|
|
local current_value = G_reader_settings:readSetting("hold_pan_rate", default_value)
|
2020-08-05 22:13:26 +00:00
|
|
|
local items = SpinWidget:new{
|
2020-10-18 13:57:40 +00:00
|
|
|
title_text = _("Text selection rate"),
|
2021-11-29 03:56:21 +00:00
|
|
|
info_text = _([[
|
2020-08-05 22:13:26 +00:00
|
|
|
The rate is how often screen will be refreshed per second while selecting text.
|
2021-11-29 03:56:21 +00:00
|
|
|
Higher values mean faster screen updates, but also use more CPU.]]),
|
2020-10-18 13:57:40 +00:00
|
|
|
width = math.floor(Screen:getWidth() * 0.75),
|
2020-08-05 22:13:26 +00:00
|
|
|
value = current_value,
|
|
|
|
value_min = 1.0,
|
|
|
|
value_max = 60.0,
|
|
|
|
value_step = 1,
|
|
|
|
value_hold_step = 15,
|
2022-05-23 22:25:50 +00:00
|
|
|
unit = C_("Frequency", "Hz"),
|
2020-08-05 22:13:26 +00:00
|
|
|
ok_text = _("Set rate"),
|
2021-11-29 03:56:21 +00:00
|
|
|
default_value = default_value,
|
2020-08-05 22:13:26 +00:00
|
|
|
callback = function(spin)
|
|
|
|
G_reader_settings:saveSetting("hold_pan_rate", spin.value)
|
|
|
|
UIManager:broadcastEvent(Event:new("UpdateHoldPanRate"))
|
|
|
|
end
|
|
|
|
}
|
|
|
|
UIManager:show(items)
|
|
|
|
end,
|
|
|
|
separator = true,
|
|
|
|
},
|
2020-10-18 13:57:40 +00:00
|
|
|
{
|
|
|
|
text = _("Tap interval"),
|
|
|
|
keep_menu_open = true,
|
|
|
|
callback = function()
|
|
|
|
local items = SpinWidget:new{
|
|
|
|
title_text = _("Tap interval"),
|
2021-11-29 03:56:21 +00:00
|
|
|
info_text = _([[
|
2020-10-18 13:57:40 +00:00
|
|
|
Any other taps made within this interval after a first tap will be considered accidental and ignored.
|
|
|
|
|
2021-11-29 03:56:21 +00:00
|
|
|
The interval value is in milliseconds and can range from 0 (0 seconds) to 2000 (2 seconds).]]),
|
2020-10-18 13:57:40 +00:00
|
|
|
width = math.floor(Screen:getWidth() * 0.75),
|
2022-05-05 19:00:22 +00:00
|
|
|
value = time.to_ms(GestureDetector.ges_tap_interval),
|
2020-10-18 13:57:40 +00:00
|
|
|
value_min = 0,
|
|
|
|
value_max = 2000,
|
|
|
|
value_step = 50,
|
|
|
|
value_hold_step = 200,
|
2022-05-23 22:25:50 +00:00
|
|
|
unit = C_("Time", "ms"),
|
2020-10-18 13:57:40 +00:00
|
|
|
ok_text = _("Set interval"),
|
2022-05-05 19:00:22 +00:00
|
|
|
default_value = GestureDetector.TAP_INTERVAL_MS,
|
2020-10-18 13:57:40 +00:00
|
|
|
callback = function(spin)
|
2022-05-05 19:00:22 +00:00
|
|
|
G_reader_settings:saveSetting("ges_tap_interval_ms", spin.value)
|
|
|
|
GestureDetector.ges_tap_interval = time.ms(spin.value)
|
2020-10-18 13:57:40 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
UIManager:show(items)
|
|
|
|
end,
|
|
|
|
},
|
2020-10-28 21:47:42 +00:00
|
|
|
{
|
|
|
|
text = _("Tap interval on keyboard"),
|
|
|
|
keep_menu_open = true,
|
|
|
|
callback = function()
|
|
|
|
local items = SpinWidget:new{
|
|
|
|
title_text = _("Tap interval on keyboard"),
|
|
|
|
info_text = _([[
|
|
|
|
Any other taps made within this interval after a first tap will be considered accidental and ignored.
|
|
|
|
|
2021-11-29 03:56:21 +00:00
|
|
|
The interval value is in milliseconds and can range from 0 (0 seconds) to 2000 (2 seconds).]]),
|
2020-10-28 21:47:42 +00:00
|
|
|
width = math.floor(Screen:getWidth() * 0.75),
|
2022-05-05 19:00:22 +00:00
|
|
|
value = time.to_ms(G_reader_settings:readSetting("ges_tap_interval_on_keyboard_ms", 0)),
|
2020-10-28 21:47:42 +00:00
|
|
|
value_min = 0,
|
|
|
|
value_max = 2000,
|
|
|
|
value_step = 50,
|
|
|
|
value_hold_step = 200,
|
2022-05-23 22:25:50 +00:00
|
|
|
unit = C_("Time", "ms"),
|
2020-10-28 21:47:42 +00:00
|
|
|
ok_text = _("Set interval"),
|
|
|
|
default_value = 0,
|
|
|
|
callback = function(spin)
|
2022-05-05 19:00:22 +00:00
|
|
|
G_reader_settings:saveSetting("ges_tap_interval_on_keyboard_ms", spin.value)
|
2020-10-28 21:47:42 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
UIManager:show(items)
|
|
|
|
end,
|
|
|
|
},
|
2019-07-24 12:31:20 +00:00
|
|
|
{
|
|
|
|
text = _("Double tap interval"),
|
2020-10-18 13:57:40 +00:00
|
|
|
keep_menu_open = true,
|
2019-07-24 12:31:20 +00:00
|
|
|
callback = function()
|
|
|
|
local items = SpinWidget:new{
|
2020-10-18 13:57:40 +00:00
|
|
|
title_text = _("Double tap interval"),
|
2021-11-29 03:56:21 +00:00
|
|
|
info_text = _([[
|
2020-10-18 13:57:40 +00:00
|
|
|
When double tap is enabled, this sets the time to wait for the second tap. A single tap will take at least this long to be detected.
|
|
|
|
|
2021-11-29 03:56:21 +00:00
|
|
|
The interval value is in milliseconds and can range from 100 (0.1 seconds) to 2000 (2 seconds).]]),
|
2020-10-18 13:57:40 +00:00
|
|
|
width = math.floor(Screen:getWidth() * 0.75),
|
2022-05-05 19:00:22 +00:00
|
|
|
value = time.to_ms(GestureDetector.ges_double_tap_interval),
|
2019-07-24 12:31:20 +00:00
|
|
|
value_min = 100,
|
|
|
|
value_max = 2000,
|
|
|
|
value_step = 100,
|
|
|
|
value_hold_step = 500,
|
2022-05-23 22:25:50 +00:00
|
|
|
unit = C_("Time", "ms"),
|
2019-07-24 12:31:20 +00:00
|
|
|
ok_text = _("Set interval"),
|
2022-05-05 19:00:22 +00:00
|
|
|
default_value = GestureDetector.DOUBLE_TAP_INTERVAL_MS,
|
2019-07-24 12:31:20 +00:00
|
|
|
callback = function(spin)
|
2022-05-05 19:00:22 +00:00
|
|
|
G_reader_settings:saveSetting("ges_double_tap_interval_ms", spin.value)
|
|
|
|
GestureDetector.ges_double_tap_interval = time.ms(spin.value)
|
2019-07-24 12:31:20 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
UIManager:show(items)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Two finger tap duration"),
|
2020-10-18 13:57:40 +00:00
|
|
|
keep_menu_open = true,
|
2019-07-24 12:31:20 +00:00
|
|
|
callback = function()
|
|
|
|
local items = SpinWidget:new{
|
2020-10-18 13:57:40 +00:00
|
|
|
title_text = _("Two finger tap duration"),
|
2021-11-29 03:56:21 +00:00
|
|
|
info_text = _([[
|
2020-10-18 13:57:40 +00:00
|
|
|
This sets the allowed duration of any of the two fingers touch/release for the combined event to be considered a two finger tap.
|
|
|
|
|
2021-11-29 03:56:21 +00:00
|
|
|
The duration value is in milliseconds and can range from 100 (0.1 seconds) to 2000 (2 seconds).]]),
|
2020-10-18 13:57:40 +00:00
|
|
|
width = math.floor(Screen:getWidth() * 0.75),
|
2022-05-05 19:00:22 +00:00
|
|
|
value = time.to_ms(GestureDetector.ges_two_finger_tap_duration),
|
2019-07-24 12:31:20 +00:00
|
|
|
value_min = 100,
|
|
|
|
value_max = 2000,
|
|
|
|
value_step = 100,
|
|
|
|
value_hold_step = 500,
|
2022-05-23 22:25:50 +00:00
|
|
|
unit = C_("Time", "ms"),
|
2019-07-24 12:31:20 +00:00
|
|
|
ok_text = _("Set duration"),
|
2022-05-05 19:00:22 +00:00
|
|
|
default_value = GestureDetector.TWO_FINGER_TAP_DURATION_MS,
|
2019-07-24 12:31:20 +00:00
|
|
|
callback = function(spin)
|
2022-05-05 19:00:22 +00:00
|
|
|
G_reader_settings:saveSetting("ges_two_finger_tap_duration_ms", spin.value)
|
|
|
|
GestureDetector.ges_two_finger_tap_duration = time.ms(spin.value)
|
2019-07-24 12:31:20 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
UIManager:show(items)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
2021-09-06 15:08:48 +00:00
|
|
|
text = _("Long-press interval"),
|
2020-10-18 13:57:40 +00:00
|
|
|
keep_menu_open = true,
|
2019-07-24 12:31:20 +00:00
|
|
|
callback = function()
|
|
|
|
local items = SpinWidget:new{
|
2021-09-06 15:08:48 +00:00
|
|
|
title_text = _("Long-press interval"),
|
2021-11-29 03:56:21 +00:00
|
|
|
info_text = _([[
|
2021-09-06 15:08:48 +00:00
|
|
|
If a touch is not released in this interval, it is considered a long-press. On document text, single word selection will then be triggered.
|
2020-10-18 13:57:40 +00:00
|
|
|
|
2021-11-29 03:56:21 +00:00
|
|
|
The interval value is in milliseconds and can range from 100 (0.1 seconds) to 2000 (2 seconds).]]),
|
2020-10-18 13:57:40 +00:00
|
|
|
width = math.floor(Screen:getWidth() * 0.75),
|
2022-05-05 19:00:22 +00:00
|
|
|
value = time.to_ms(GestureDetector.ges_hold_interval),
|
2019-07-24 12:31:20 +00:00
|
|
|
value_min = 100,
|
|
|
|
value_max = 2000,
|
|
|
|
value_step = 100,
|
|
|
|
value_hold_step = 500,
|
2022-05-23 22:25:50 +00:00
|
|
|
unit = C_("Time", "ms"),
|
2019-07-24 12:31:20 +00:00
|
|
|
ok_text = _("Set interval"),
|
2022-05-05 19:00:22 +00:00
|
|
|
default_value = GestureDetector.HOLD_INTERVAL_MS,
|
2019-07-24 12:31:20 +00:00
|
|
|
callback = function(spin)
|
2022-05-05 19:00:22 +00:00
|
|
|
G_reader_settings:saveSetting("ges_hold_interval_ms", spin.value)
|
|
|
|
GestureDetector.ges_hold_interval = time.ms(spin.value)
|
2019-07-24 12:31:20 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
UIManager:show(items)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Swipe interval"),
|
2020-10-18 13:57:40 +00:00
|
|
|
keep_menu_open = true,
|
2019-07-24 12:31:20 +00:00
|
|
|
callback = function()
|
|
|
|
local items = SpinWidget:new{
|
2020-10-18 13:57:40 +00:00
|
|
|
title_text = _("Swipe interval"),
|
2021-11-29 03:56:21 +00:00
|
|
|
info_text = _([[
|
2020-10-18 13:57:40 +00:00
|
|
|
This sets the maximum delay between the start and the end of a swipe for it to be considered a swipe. Above this interval, it's considered panning.
|
|
|
|
|
2021-11-29 03:56:21 +00:00
|
|
|
The interval value is in milliseconds and can range from 100 (0.1 seconds) to 2000 (2 seconds).]]),
|
2020-10-18 13:57:40 +00:00
|
|
|
width = math.floor(Screen:getWidth() * 0.75),
|
2022-05-05 19:00:22 +00:00
|
|
|
value = time.to_ms(GestureDetector.ges_swipe_interval),
|
2019-07-24 12:31:20 +00:00
|
|
|
value_min = 100,
|
|
|
|
value_max = 2000,
|
|
|
|
value_step = 100,
|
2022-05-23 22:25:50 +00:00
|
|
|
unit = C_("Time", "ms"),
|
2019-07-24 12:31:20 +00:00
|
|
|
value_hold_step = 500,
|
|
|
|
ok_text = _("Set interval"),
|
2022-05-05 19:00:22 +00:00
|
|
|
default_value = GestureDetector.SWIPE_INTERVAL_MS,
|
2019-07-24 12:31:20 +00:00
|
|
|
callback = function(spin)
|
2022-05-05 19:00:22 +00:00
|
|
|
G_reader_settings:saveSetting("ges_swipe_interval_ms", spin.value)
|
|
|
|
GestureDetector.ges_swipe_interval = time.ms(spin.value)
|
2019-07-24 12:31:20 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
UIManager:show(items)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-07-17 03:03:23 +00:00
|
|
|
end
|
2019-03-30 12:06:15 +00:00
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
function Gestures:addToMainMenu(menu_items)
|
|
|
|
menu_items.gesture_manager = {
|
|
|
|
text = _("Gesture manager"),
|
|
|
|
sub_item_table = {
|
|
|
|
{
|
|
|
|
text = _("Turn on multiswipes"),
|
|
|
|
checked_func = function() return self.multiswipes_enabled end,
|
|
|
|
callback = function()
|
2021-03-06 21:44:18 +00:00
|
|
|
G_reader_settings:toggle("multiswipes_enabled")
|
2020-07-17 03:03:23 +00:00
|
|
|
self.multiswipes_enabled = G_reader_settings:isTrue("multiswipes_enabled")
|
|
|
|
end,
|
|
|
|
help_text = multiswipes_info_text,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Multiswipes"),
|
|
|
|
sub_item_table = self:genMultiswipeMenu(),
|
|
|
|
enabled_func = function() return self.multiswipes_enabled end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Custom multiswipes"),
|
|
|
|
sub_item_table = self:genCustomMultiswipeSubmenu(),
|
|
|
|
enabled_func = function() return self.multiswipes_enabled end,
|
|
|
|
separator = true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Tap corner"),
|
|
|
|
sub_item_table = self:genSubItemTable({"tap_top_left_corner", "tap_top_right_corner", "tap_left_bottom_corner", "tap_right_bottom_corner"}),
|
|
|
|
},
|
|
|
|
{
|
2021-09-06 15:08:48 +00:00
|
|
|
text = _("Long-press on corner"),
|
2020-07-17 03:03:23 +00:00
|
|
|
sub_item_table = self:genSubItemTable({"hold_top_left_corner", "hold_top_right_corner", "hold_bottom_left_corner", "hold_bottom_right_corner"}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("One-finger swipe"),
|
2021-04-27 18:56:15 +00:00
|
|
|
sub_item_table = self:genSubItemTable({"short_diagonal_swipe", "one_finger_swipe_left_edge_down", "one_finger_swipe_left_edge_up", "one_finger_swipe_right_edge_down", "one_finger_swipe_right_edge_up", "one_finger_swipe_top_edge_right", "one_finger_swipe_top_edge_left", "one_finger_swipe_bottom_edge_right", "one_finger_swipe_bottom_edge_left"}),
|
2020-07-17 03:03:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Double tap"),
|
|
|
|
enabled_func = function()
|
|
|
|
return self.ges_mode == "gesture_reader" and self.ui.disable_double_tap ~= true
|
|
|
|
end,
|
|
|
|
sub_item_table = self:genSubItemTable({"double_tap_left_side", "double_tap_right_side", "double_tap_top_left_corner", "double_tap_top_right_corner", "double_tap_bottom_left_corner", "double_tap_bottom_right_corner"}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2019-03-30 12:06:15 +00:00
|
|
|
|
2019-03-19 19:18:38 +00:00
|
|
|
if Device:hasMultitouch() then
|
2020-07-17 03:03:23 +00:00
|
|
|
table.insert(menu_items.gesture_manager.sub_item_table, {
|
2019-04-07 17:00:15 +00:00
|
|
|
text = _("Two-finger tap corner"),
|
2020-07-17 03:03:23 +00:00
|
|
|
sub_item_table = self:genSubItemTable({"two_finger_tap_top_left_corner", "two_finger_tap_top_right_corner", "two_finger_tap_bottom_left_corner", "two_finger_tap_bottom_right_corner"}),
|
|
|
|
})
|
2019-03-19 19:18:38 +00:00
|
|
|
table.insert(menu_items.gesture_manager.sub_item_table, {
|
2019-04-07 17:00:15 +00:00
|
|
|
text = _("Two-finger swipe"),
|
2020-07-17 03:03:23 +00:00
|
|
|
sub_item_table = self:genSubItemTable({"two_finger_swipe_east", "two_finger_swipe_west", "two_finger_swipe_south", "two_finger_swipe_north", "two_finger_swipe_northeast", "two_finger_swipe_northwest", "two_finger_swipe_southeast", "two_finger_swipe_southwest"}),
|
2019-03-19 19:18:38 +00:00
|
|
|
})
|
2019-08-07 18:18:36 +00:00
|
|
|
table.insert(menu_items.gesture_manager.sub_item_table, {
|
|
|
|
text = _("Spread and pinch"),
|
2020-07-17 03:03:23 +00:00
|
|
|
sub_item_table = self:genSubItemTable({"spread_gesture", "pinch_gesture"}),
|
2019-08-07 18:18:36 +00:00
|
|
|
})
|
2022-09-04 00:38:27 +00:00
|
|
|
table.insert(menu_items.gesture_manager.sub_item_table, {
|
|
|
|
text = _("Rotation"),
|
|
|
|
sub_item_table = self:genSubItemTable({"rotate_cw", "rotate_ccw"}),
|
|
|
|
})
|
2019-03-19 19:18:38 +00:00
|
|
|
end
|
2019-02-24 14:12:01 +00:00
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
self:addIntervals(menu_items)
|
2018-09-29 21:15:57 +00:00
|
|
|
end
|
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
function Gestures:initGesture()
|
|
|
|
for ges, _ in pairs(gestures_list) do
|
|
|
|
self:setupGesture(ges)
|
2019-02-17 20:38:02 +00:00
|
|
|
end
|
2018-09-29 21:15:57 +00:00
|
|
|
end
|
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
function Gestures:setupGesture(ges)
|
2018-09-29 21:15:57 +00:00
|
|
|
local ges_type
|
|
|
|
local zone
|
|
|
|
local overrides
|
|
|
|
local direction, distance
|
2019-03-19 19:18:38 +00:00
|
|
|
|
|
|
|
local zone_fullscreen = {
|
2019-08-05 19:24:58 +00:00
|
|
|
ratio_x = 0, ratio_y = 0,
|
2019-03-19 19:18:38 +00:00
|
|
|
ratio_w = 1, ratio_h = 1,
|
|
|
|
}
|
|
|
|
|
2019-08-01 17:08:09 +00:00
|
|
|
local zone_left_edge = {
|
2019-08-05 19:24:58 +00:00
|
|
|
ratio_x = 0, ratio_y = 0,
|
|
|
|
ratio_w = 1/8, ratio_h = 1,
|
2019-08-01 17:08:09 +00:00
|
|
|
}
|
|
|
|
local zone_right_edge = {
|
2019-08-05 19:24:58 +00:00
|
|
|
ratio_x = 7/8, ratio_y = 0,
|
|
|
|
ratio_w = 1/8, ratio_h = 1,
|
2019-08-01 17:08:09 +00:00
|
|
|
}
|
2019-08-04 17:59:20 +00:00
|
|
|
local zone_top_edge = {
|
2019-08-05 19:24:58 +00:00
|
|
|
ratio_x = 0, ratio_y = 0,
|
|
|
|
ratio_w = 1, ratio_h = 1/8,
|
2019-08-04 17:59:20 +00:00
|
|
|
}
|
|
|
|
local zone_bottom_edge = {
|
2019-08-05 19:24:58 +00:00
|
|
|
ratio_x = 0, ratio_y = 7/8,
|
|
|
|
ratio_w = 1, ratio_h = 1/8,
|
2019-08-04 17:59:20 +00:00
|
|
|
}
|
2019-08-01 17:08:09 +00:00
|
|
|
|
2022-09-27 23:10:50 +00:00
|
|
|
local dtap_zone_top_left = G_defaults:readSetting("DTAP_ZONE_TOP_LEFT")
|
2019-04-07 17:00:15 +00:00
|
|
|
local zone_top_left_corner = {
|
|
|
|
ratio_x = dtap_zone_top_left.x,
|
|
|
|
ratio_y = dtap_zone_top_left.y,
|
|
|
|
ratio_w = dtap_zone_top_left.w,
|
|
|
|
ratio_h = dtap_zone_top_left.h,
|
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
local dtap_zone_top_right = G_defaults:readSetting("DTAP_ZONE_TOP_RIGHT")
|
2019-04-07 17:00:15 +00:00
|
|
|
local zone_top_right_corner = {
|
|
|
|
ratio_x = dtap_zone_top_right.x,
|
|
|
|
ratio_y = dtap_zone_top_right.y,
|
|
|
|
ratio_w = dtap_zone_top_right.w,
|
|
|
|
ratio_h = dtap_zone_top_right.h,
|
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
local dtap_zone_bottom_left = G_defaults:readSetting("DTAP_ZONE_BOTTOM_LEFT")
|
2019-04-07 17:00:15 +00:00
|
|
|
local zone_bottom_left_corner = {
|
2022-09-27 23:10:50 +00:00
|
|
|
ratio_x = dtap_zone_bottom_left.x,
|
|
|
|
ratio_y = dtap_zone_bottom_left.y,
|
|
|
|
ratio_w = dtap_zone_bottom_left.w,
|
|
|
|
ratio_h = dtap_zone_bottom_left.h,
|
2019-04-07 17:00:15 +00:00
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
local dtap_zone_bottom_right = G_defaults:readSetting("DTAP_ZONE_BOTTOM_RIGHT")
|
2019-04-07 17:00:15 +00:00
|
|
|
local zone_bottom_right_corner = {
|
2022-09-27 23:10:50 +00:00
|
|
|
ratio_x = dtap_zone_bottom_right.x,
|
|
|
|
ratio_y = dtap_zone_bottom_right.y,
|
|
|
|
ratio_w = dtap_zone_bottom_right.w,
|
|
|
|
ratio_h = dtap_zone_bottom_right.h,
|
2019-04-07 17:00:15 +00:00
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
-- NOTE: The defaults are effectively mapped to G_defaults:readSetting("DTAP_ZONE_BACKWARD") & G_defaults:readSetting("DTAP_ZONE_FORWARD")
|
|
|
|
local ddouble_tap_zone_prev_chapter = G_defaults:readSetting("DDOUBLE_TAP_ZONE_PREV_CHAPTER")
|
2020-06-28 13:41:24 +00:00
|
|
|
local zone_left = {
|
2022-09-27 23:10:50 +00:00
|
|
|
ratio_x = ddouble_tap_zone_prev_chapter.x,
|
|
|
|
ratio_y = ddouble_tap_zone_prev_chapter.y,
|
|
|
|
ratio_w = ddouble_tap_zone_prev_chapter.w,
|
|
|
|
ratio_h = ddouble_tap_zone_prev_chapter.h,
|
2020-06-28 13:41:24 +00:00
|
|
|
}
|
2022-09-27 23:10:50 +00:00
|
|
|
local ddouble_tap_zone_next_chapter = G_defaults:readSetting("DDOUBLE_TAP_ZONE_NEXT_CHAPTER")
|
2020-06-28 13:41:24 +00:00
|
|
|
local zone_right = {
|
2022-09-27 23:10:50 +00:00
|
|
|
ratio_x = ddouble_tap_zone_next_chapter.x,
|
|
|
|
ratio_y = ddouble_tap_zone_next_chapter.y,
|
|
|
|
ratio_w = ddouble_tap_zone_next_chapter.w,
|
|
|
|
ratio_h = ddouble_tap_zone_next_chapter.h,
|
2020-06-28 13:41:24 +00:00
|
|
|
}
|
2019-04-07 17:00:15 +00:00
|
|
|
|
|
|
|
local overrides_tap_corner
|
2021-05-20 03:39:18 +00:00
|
|
|
local overrides_double_tap_corner
|
2019-04-07 17:00:15 +00:00
|
|
|
local overrides_hold_corner
|
2019-08-04 17:59:20 +00:00
|
|
|
local overrides_vertical_edge, overrides_horizontal_edge
|
2019-08-01 17:08:09 +00:00
|
|
|
local overrides_pan, overrides_pan_release
|
|
|
|
local overrides_swipe_pan, overrides_swipe_pan_release
|
2019-04-07 17:00:15 +00:00
|
|
|
if self.is_docless then
|
|
|
|
overrides_tap_corner = {
|
2020-12-03 16:33:54 +00:00
|
|
|
"filemanager_ext_tap",
|
2019-04-07 17:00:15 +00:00
|
|
|
"filemanager_tap",
|
|
|
|
}
|
2019-08-04 17:59:20 +00:00
|
|
|
overrides_horizontal_edge = {
|
2020-12-03 16:33:54 +00:00
|
|
|
"filemanager_ext_swipe",
|
2019-08-04 17:59:20 +00:00
|
|
|
"filemanager_swipe",
|
|
|
|
}
|
2019-04-07 17:00:15 +00:00
|
|
|
else
|
|
|
|
overrides_tap_corner = {
|
|
|
|
"readerfooter_tap",
|
2020-12-03 16:33:54 +00:00
|
|
|
"readerconfigmenu_ext_tap",
|
|
|
|
"readerconfigmenu_tap",
|
|
|
|
"readermenu_ext_tap",
|
|
|
|
"readermenu_tap",
|
|
|
|
"tap_forward",
|
|
|
|
"tap_backward",
|
2019-04-07 17:00:15 +00:00
|
|
|
}
|
2021-05-20 03:39:18 +00:00
|
|
|
overrides_double_tap_corner = {
|
|
|
|
"double_tap_left_side",
|
|
|
|
"double_tap_right_side",
|
|
|
|
}
|
2019-04-07 17:00:15 +00:00
|
|
|
overrides_hold_corner = {
|
2020-01-24 19:05:21 +00:00
|
|
|
-- As hold corners are "ignored" by default, and we have
|
|
|
|
-- a "Ignore hold on corners" menu item and gesture, let
|
|
|
|
-- them have priority over word lookup and text selection.
|
|
|
|
"readerhighlight_hold",
|
2019-04-07 17:00:15 +00:00
|
|
|
"readerfooter_hold",
|
|
|
|
}
|
2019-08-01 17:08:09 +00:00
|
|
|
overrides_vertical_edge = {
|
2020-12-03 16:33:54 +00:00
|
|
|
"readerconfigmenu_ext_swipe",
|
|
|
|
"readerconfigmenu_swipe",
|
|
|
|
"readermenu_ext_swipe",
|
|
|
|
"readermenu_swipe",
|
2019-08-01 17:08:09 +00:00
|
|
|
"paging_swipe",
|
|
|
|
"rolling_swipe",
|
2019-08-08 13:19:09 +00:00
|
|
|
}
|
|
|
|
overrides_horizontal_edge = {
|
|
|
|
"swipe_link",
|
2020-12-03 16:33:54 +00:00
|
|
|
"readerconfigmenu_ext_swipe",
|
|
|
|
"readerconfigmenu_swipe",
|
|
|
|
"readermenu_ext_swipe",
|
|
|
|
"readermenu_swipe",
|
2019-08-08 13:19:09 +00:00
|
|
|
"paging_swipe",
|
|
|
|
"rolling_swipe",
|
2019-08-01 17:08:09 +00:00
|
|
|
}
|
|
|
|
overrides_pan = {
|
|
|
|
"paging_swipe",
|
|
|
|
"rolling_swipe",
|
|
|
|
}
|
|
|
|
overrides_pan_release = {
|
|
|
|
"paging_pan_release",
|
|
|
|
}
|
2019-04-07 17:00:15 +00:00
|
|
|
end
|
|
|
|
|
2019-02-17 20:38:02 +00:00
|
|
|
if ges == "multiswipe" then
|
|
|
|
ges_type = "multiswipe"
|
2019-03-19 19:18:38 +00:00
|
|
|
zone = zone_fullscreen
|
2019-02-17 20:38:02 +00:00
|
|
|
direction = {
|
|
|
|
northeast = true, northwest = true,
|
|
|
|
southeast = true, southwest = true,
|
|
|
|
east = true, west = true,
|
|
|
|
north = true, south = true,
|
|
|
|
}
|
2019-04-07 17:00:15 +00:00
|
|
|
elseif ges == "tap_top_left_corner" then
|
|
|
|
ges_type = "tap"
|
|
|
|
zone = zone_top_left_corner
|
|
|
|
overrides = overrides_tap_corner
|
|
|
|
elseif ges == "tap_top_right_corner" then
|
|
|
|
ges_type = "tap"
|
|
|
|
zone = zone_top_right_corner
|
|
|
|
overrides = overrides_tap_corner
|
2019-02-17 20:38:02 +00:00
|
|
|
elseif ges == "tap_right_bottom_corner" then
|
2018-09-29 21:15:57 +00:00
|
|
|
ges_type = "tap"
|
2019-04-07 17:00:15 +00:00
|
|
|
zone = zone_bottom_right_corner
|
|
|
|
overrides = overrides_tap_corner
|
2018-09-29 21:15:57 +00:00
|
|
|
elseif ges == "tap_left_bottom_corner" then
|
|
|
|
ges_type = "tap"
|
2019-04-07 17:00:15 +00:00
|
|
|
zone = zone_bottom_left_corner
|
|
|
|
overrides = overrides_tap_corner
|
2020-06-28 13:41:24 +00:00
|
|
|
elseif ges == "double_tap_left_side" then
|
|
|
|
ges_type = "double_tap"
|
|
|
|
zone = zone_left
|
|
|
|
elseif ges == "double_tap_right_side" then
|
|
|
|
ges_type = "double_tap"
|
|
|
|
zone = zone_right
|
|
|
|
elseif ges == "double_tap_top_left_corner" then
|
|
|
|
ges_type = "double_tap"
|
|
|
|
zone = zone_top_left_corner
|
2021-05-20 03:39:18 +00:00
|
|
|
overrides = overrides_double_tap_corner
|
2020-06-28 13:41:24 +00:00
|
|
|
elseif ges == "double_tap_top_right_corner" then
|
|
|
|
ges_type = "double_tap"
|
|
|
|
zone = zone_top_right_corner
|
2021-05-20 03:39:18 +00:00
|
|
|
overrides = overrides_double_tap_corner
|
2020-06-28 13:41:24 +00:00
|
|
|
elseif ges == "double_tap_bottom_right_corner" then
|
|
|
|
ges_type = "double_tap"
|
|
|
|
zone = zone_bottom_right_corner
|
2021-05-20 03:39:18 +00:00
|
|
|
overrides = overrides_double_tap_corner
|
2020-06-28 13:41:24 +00:00
|
|
|
elseif ges == "double_tap_bottom_left_corner" then
|
|
|
|
ges_type = "double_tap"
|
|
|
|
zone = zone_bottom_left_corner
|
2021-05-20 03:39:18 +00:00
|
|
|
overrides = overrides_double_tap_corner
|
2019-04-07 17:00:15 +00:00
|
|
|
elseif ges == "hold_top_left_corner" then
|
|
|
|
ges_type = "hold"
|
|
|
|
zone = zone_top_left_corner
|
|
|
|
overrides = overrides_hold_corner
|
|
|
|
elseif ges == "hold_top_right_corner" then
|
|
|
|
ges_type = "hold"
|
|
|
|
zone = zone_top_right_corner
|
|
|
|
overrides = overrides_hold_corner
|
|
|
|
elseif ges == "hold_bottom_right_corner" then
|
|
|
|
ges_type = "hold"
|
|
|
|
zone = zone_bottom_right_corner
|
|
|
|
overrides = overrides_hold_corner
|
|
|
|
elseif ges == "hold_bottom_left_corner" then
|
|
|
|
ges_type = "hold"
|
|
|
|
zone = zone_bottom_left_corner
|
|
|
|
overrides = overrides_hold_corner
|
2019-08-01 17:08:09 +00:00
|
|
|
elseif ges == "one_finger_swipe_left_edge_down" then
|
|
|
|
ges_type = "swipe"
|
|
|
|
zone = zone_left_edge
|
|
|
|
direction = {south = true}
|
|
|
|
overrides = overrides_vertical_edge
|
|
|
|
overrides_swipe_pan = overrides_pan
|
|
|
|
overrides_swipe_pan_release = overrides_pan_release
|
|
|
|
elseif ges == "one_finger_swipe_left_edge_up" then
|
|
|
|
ges_type = "swipe"
|
|
|
|
zone = zone_left_edge
|
|
|
|
direction = {north = true}
|
|
|
|
overrides = overrides_vertical_edge
|
|
|
|
overrides_swipe_pan = overrides_pan
|
|
|
|
overrides_swipe_pan_release = overrides_pan_release
|
|
|
|
elseif ges == "one_finger_swipe_right_edge_down" then
|
|
|
|
ges_type = "swipe"
|
|
|
|
zone = zone_right_edge
|
|
|
|
direction = {south = true}
|
|
|
|
overrides = overrides_vertical_edge
|
|
|
|
overrides_swipe_pan = overrides_pan
|
|
|
|
overrides_swipe_pan_release = overrides_pan_release
|
|
|
|
elseif ges == "one_finger_swipe_right_edge_up" then
|
|
|
|
ges_type = "swipe"
|
|
|
|
zone = zone_right_edge
|
|
|
|
direction = {north = true}
|
|
|
|
overrides = overrides_vertical_edge
|
|
|
|
overrides_swipe_pan = overrides_pan
|
|
|
|
overrides_swipe_pan_release = overrides_pan_release
|
2019-08-04 17:59:20 +00:00
|
|
|
elseif ges == "one_finger_swipe_top_edge_right" then
|
|
|
|
ges_type = "swipe"
|
|
|
|
zone = zone_top_edge
|
|
|
|
direction = {east = true}
|
|
|
|
overrides = overrides_horizontal_edge
|
|
|
|
overrides_swipe_pan = overrides_pan
|
|
|
|
overrides_swipe_pan_release = overrides_pan_release
|
|
|
|
elseif ges == "one_finger_swipe_top_edge_left" then
|
|
|
|
ges_type = "swipe"
|
|
|
|
zone = zone_top_edge
|
|
|
|
direction = {west = true}
|
|
|
|
overrides = overrides_horizontal_edge
|
|
|
|
overrides_swipe_pan = overrides_pan
|
|
|
|
overrides_swipe_pan_release = overrides_pan_release
|
|
|
|
elseif ges == "one_finger_swipe_bottom_edge_right" then
|
|
|
|
ges_type = "swipe"
|
|
|
|
zone = zone_bottom_edge
|
|
|
|
direction = {east = true}
|
|
|
|
overrides = overrides_horizontal_edge
|
|
|
|
overrides_swipe_pan = overrides_pan
|
|
|
|
overrides_swipe_pan_release = overrides_pan_release
|
|
|
|
elseif ges == "one_finger_swipe_bottom_edge_left" then
|
|
|
|
ges_type = "swipe"
|
|
|
|
zone = zone_bottom_edge
|
|
|
|
direction = {west = true}
|
|
|
|
overrides = overrides_horizontal_edge
|
|
|
|
overrides_swipe_pan = overrides_pan
|
|
|
|
overrides_swipe_pan_release = overrides_pan_release
|
2019-04-07 17:00:15 +00:00
|
|
|
elseif ges == "two_finger_tap_top_left_corner" then
|
|
|
|
ges_type = "two_finger_tap"
|
|
|
|
zone = zone_top_left_corner
|
|
|
|
elseif ges == "two_finger_tap_top_right_corner" then
|
|
|
|
ges_type = "two_finger_tap"
|
|
|
|
zone = zone_top_right_corner
|
|
|
|
elseif ges == "two_finger_tap_bottom_right_corner" then
|
|
|
|
ges_type = "two_finger_tap"
|
|
|
|
zone = zone_bottom_right_corner
|
|
|
|
elseif ges == "two_finger_tap_bottom_left_corner" then
|
|
|
|
ges_type = "two_finger_tap"
|
|
|
|
zone = zone_bottom_left_corner
|
2019-03-19 19:18:38 +00:00
|
|
|
elseif ges == "two_finger_swipe_west" then
|
|
|
|
ges_type = "two_finger_swipe"
|
|
|
|
zone = zone_fullscreen
|
|
|
|
direction = {west = true}
|
|
|
|
elseif ges == "two_finger_swipe_east" then
|
|
|
|
ges_type = "two_finger_swipe"
|
|
|
|
zone = zone_fullscreen
|
|
|
|
direction = {east = true}
|
2019-08-06 17:54:09 +00:00
|
|
|
elseif ges == "two_finger_swipe_south" then
|
|
|
|
ges_type = "two_finger_swipe"
|
|
|
|
zone = zone_fullscreen
|
|
|
|
direction = {south = true}
|
|
|
|
elseif ges == "two_finger_swipe_north" then
|
|
|
|
ges_type = "two_finger_swipe"
|
|
|
|
zone = zone_fullscreen
|
|
|
|
direction = {north = true}
|
2019-03-29 10:28:24 +00:00
|
|
|
elseif ges == "two_finger_swipe_northwest" then
|
|
|
|
ges_type = "two_finger_swipe"
|
|
|
|
zone = zone_fullscreen
|
|
|
|
direction = {northwest = true}
|
|
|
|
elseif ges == "two_finger_swipe_northeast" then
|
|
|
|
ges_type = "two_finger_swipe"
|
|
|
|
zone = zone_fullscreen
|
|
|
|
direction = {northeast = true}
|
|
|
|
elseif ges == "two_finger_swipe_southwest" then
|
|
|
|
ges_type = "two_finger_swipe"
|
|
|
|
zone = zone_fullscreen
|
|
|
|
direction = {southwest = true}
|
|
|
|
elseif ges == "two_finger_swipe_southeast" then
|
|
|
|
ges_type = "two_finger_swipe"
|
|
|
|
zone = zone_fullscreen
|
|
|
|
direction = {southeast = true}
|
2018-09-29 21:15:57 +00:00
|
|
|
elseif ges == "short_diagonal_swipe" then
|
|
|
|
ges_type = "swipe"
|
|
|
|
zone = {
|
|
|
|
ratio_x = 0.0, ratio_y = 0,
|
|
|
|
ratio_w = 1, ratio_h = 1,
|
|
|
|
}
|
|
|
|
direction = {northeast = true, northwest = true, southeast = true, southwest = true}
|
|
|
|
distance = "short"
|
|
|
|
if self.is_docless then
|
2019-03-30 20:05:44 +00:00
|
|
|
overrides = {
|
2020-12-03 16:33:54 +00:00
|
|
|
"filemanager_ext_tap",
|
2019-03-30 20:05:44 +00:00
|
|
|
"filemanager_tap",
|
2020-12-03 16:33:54 +00:00
|
|
|
"filemanager_ext_swipe",
|
|
|
|
"filemanager_swipe",
|
2019-03-30 20:05:44 +00:00
|
|
|
}
|
2018-09-29 21:15:57 +00:00
|
|
|
else
|
2019-03-30 20:05:44 +00:00
|
|
|
overrides = {
|
|
|
|
"paging_swipe",
|
2020-12-03 16:33:54 +00:00
|
|
|
"rolling_swipe",
|
2019-03-30 20:05:44 +00:00
|
|
|
}
|
2018-09-29 21:15:57 +00:00
|
|
|
end
|
2019-08-07 18:18:36 +00:00
|
|
|
elseif ges == "spread_gesture" then
|
|
|
|
ges_type = "spread"
|
|
|
|
zone = zone_fullscreen
|
|
|
|
elseif ges == "pinch_gesture" then
|
|
|
|
ges_type = "pinch"
|
|
|
|
zone = zone_fullscreen
|
2022-09-04 00:38:27 +00:00
|
|
|
elseif ges == "rotate_cw" then
|
|
|
|
ges_type = "rotate"
|
|
|
|
zone = zone_fullscreen
|
|
|
|
direction = {cw = true}
|
|
|
|
elseif ges == "rotate_ccw" then
|
|
|
|
ges_type = "rotate"
|
|
|
|
zone = zone_fullscreen
|
|
|
|
direction = {ccw = true}
|
2018-09-29 21:15:57 +00:00
|
|
|
else return
|
|
|
|
end
|
2020-07-17 03:03:23 +00:00
|
|
|
self:registerGesture(ges, ges_type, zone, overrides, direction, distance)
|
2019-08-01 17:08:09 +00:00
|
|
|
-- make dummy zone to disable panning and panning_release when gesture is swipe
|
|
|
|
if ges_type == "swipe" and ges ~= "short_diagonal_swipe" then
|
|
|
|
local pan_gesture = ges.."_pan"
|
|
|
|
local pan_release_gesture = ges.."_pan_release"
|
2020-07-17 03:03:23 +00:00
|
|
|
self:registerGesture(pan_gesture, "pan", zone, overrides_swipe_pan, direction, distance)
|
|
|
|
self:registerGesture(pan_release_gesture, "pan_release", zone, overrides_swipe_pan_release, direction, distance)
|
2019-08-01 17:08:09 +00:00
|
|
|
end
|
2018-09-29 21:15:57 +00:00
|
|
|
end
|
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
function Gestures:registerGesture(ges, ges_type, zone, overrides, direction, distance)
|
2018-09-29 21:15:57 +00:00
|
|
|
self.ui:registerTouchZones({
|
|
|
|
{
|
|
|
|
id = ges,
|
|
|
|
ges = ges_type,
|
|
|
|
screen_zone = zone,
|
|
|
|
handler = function(gest)
|
|
|
|
if distance == "short" and gest.distance > Screen:scaleBySize(300) then return end
|
|
|
|
if direction and not direction[gest.direction] then return end
|
2019-02-17 20:38:02 +00:00
|
|
|
|
|
|
|
if ges == "multiswipe" then
|
2020-07-15 22:24:31 +00:00
|
|
|
return self:multiswipeAction(gest.multiswipe_directions, gest)
|
2019-02-17 20:38:02 +00:00
|
|
|
end
|
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
return self:gestureAction(ges, gest)
|
2018-09-29 21:15:57 +00:00
|
|
|
end,
|
|
|
|
overrides = overrides,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2020-07-15 22:24:31 +00:00
|
|
|
function Gestures:gestureAction(action, ges)
|
2020-07-17 03:03:23 +00:00
|
|
|
if G_reader_settings:isTrue("gestures_migrated") then
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("Gestures have been upgraded. You may now set more than one action per gesture."),
|
|
|
|
show_icon = false,
|
|
|
|
})
|
|
|
|
G_reader_settings:delSetting("gestures_migrated")
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
local action_list = self.gestures[action]
|
|
|
|
if action_list == nil
|
2020-05-05 16:50:16 +00:00
|
|
|
or (ges.ges == "hold" and self.ignore_hold_corners) then
|
2019-04-07 17:00:15 +00:00
|
|
|
return
|
2020-07-17 03:03:23 +00:00
|
|
|
else
|
2021-05-19 20:57:54 +00:00
|
|
|
self.ui:handleEvent(Event:new("HandledAsSwipe"))
|
2023-07-08 05:17:42 +00:00
|
|
|
ges.anchor_quickmenu = action_list.settings and action_list.settings.anchor_quickmenu
|
2021-07-23 11:27:12 +00:00
|
|
|
Dispatcher:execute(action_list, ges)
|
2018-09-29 21:15:57 +00:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2020-07-15 22:24:31 +00:00
|
|
|
function Gestures:multiswipeAction(multiswipe_directions, ges)
|
|
|
|
if self.multiswipes_enabled == nil then
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
text = _("You have just performed your first multiswipe gesture.") .."\n\n".. multiswipes_info_text,
|
|
|
|
ok_text = _("Turn on"),
|
|
|
|
ok_callback = function()
|
2021-03-06 21:44:18 +00:00
|
|
|
G_reader_settings:makeTrue("multiswipes_enabled")
|
2020-07-15 22:24:31 +00:00
|
|
|
self.multiswipes_enabled = true
|
|
|
|
end,
|
|
|
|
cancel_text = _("Turn off"),
|
|
|
|
cancel_callback = function()
|
2021-03-06 21:44:18 +00:00
|
|
|
G_reader_settings:makeFalse("multiswipes_enabled")
|
2020-07-15 22:24:31 +00:00
|
|
|
self.multiswipes_enabled = false
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
return
|
|
|
|
else
|
|
|
|
if not self.multiswipes_enabled then return end
|
|
|
|
local multiswipe_gesture_name = "multiswipe_"..self:safeMultiswipeName(multiswipe_directions)
|
2020-07-17 03:03:23 +00:00
|
|
|
return self:gestureAction(multiswipe_gesture_name, ges)
|
2019-02-17 20:38:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-15 22:24:31 +00:00
|
|
|
function Gestures:onIgnoreHoldCorners(ignore_hold_corners)
|
2019-09-19 14:51:47 +00:00
|
|
|
if ignore_hold_corners == nil then
|
|
|
|
G_reader_settings:flipNilOrFalse("ignore_hold_corners")
|
|
|
|
else
|
|
|
|
G_reader_settings:saveSetting("ignore_hold_corners", ignore_hold_corners)
|
|
|
|
end
|
|
|
|
self.ignore_hold_corners = G_reader_settings:isTrue("ignore_hold_corners")
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2020-07-17 03:03:23 +00:00
|
|
|
function Gestures:onFlushSettings()
|
2020-08-04 22:19:28 +00:00
|
|
|
if self.settings_data and self.updated then
|
2020-07-17 03:03:23 +00:00
|
|
|
self.settings_data:flush()
|
2020-08-04 22:19:28 +00:00
|
|
|
self.updated = false
|
2020-07-17 03:03:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-15 22:24:31 +00:00
|
|
|
return Gestures
|