mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[FocusManager] correct cursor keys in RTL (#13362)
This commit is contained in:
@@ -51,19 +51,21 @@ end
|
||||
function ReaderPaging:onGesture() end
|
||||
|
||||
function ReaderPaging:registerKeyEvents()
|
||||
local nextKey = BD.mirroredUILayout() and "Left" or "Right"
|
||||
local prevKey = BD.mirroredUILayout() and "Right" or "Left"
|
||||
if Device:hasDPad() and Device:useDPadAsActionKeys() then
|
||||
if G_reader_settings:isTrue("left_right_keys_turn_pages") then
|
||||
self.key_events.GotoNextPage = { { { "RPgFwd", "LPgFwd", "Right", " " } }, event = "GotoViewRel", args = 1, }
|
||||
self.key_events.GotoPrevPage = { { { "RPgBack", "LPgBack", "Left" } }, event = "GotoViewRel", args = -1, }
|
||||
self.key_events.GotoNextPage = { { { "RPgFwd", "LPgFwd", nextKey, " " } }, event = "GotoViewRel", args = 1, }
|
||||
self.key_events.GotoPrevPage = { { { "RPgBack", "LPgBack", prevKey } }, event = "GotoViewRel", args = -1, }
|
||||
elseif G_reader_settings:nilOrFalse("left_right_keys_turn_pages") then
|
||||
self.key_events.GotoNextChapter = { { "Right" }, event = "GotoNextChapter", args = 1, }
|
||||
self.key_events.GotoPrevChapter = { { "Left" }, event = "GotoPrevChapter", args = -1, }
|
||||
self.key_events.GotoNextChapter = { { nextKey }, event = "GotoNextChapter", args = 1, }
|
||||
self.key_events.GotoPrevChapter = { { prevKey }, event = "GotoPrevChapter", args = -1, }
|
||||
self.key_events.GotoNextPage = { { { "RPgFwd", "LPgFwd", " " } }, event = "GotoViewRel", args = 1, }
|
||||
self.key_events.GotoPrevPage = { { { "RPgBack", "LPgBack" } }, event = "GotoViewRel", args = -1, }
|
||||
end
|
||||
elseif Device:hasKeys() then
|
||||
self.key_events.GotoNextPage = { { { "RPgFwd", "LPgFwd", not Device:hasFewKeys() and "Right" } }, event = "GotoViewRel", args = 1, }
|
||||
self.key_events.GotoPrevPage = { { { "RPgBack", "LPgBack", not Device:hasFewKeys() and "Left" } }, event = "GotoViewRel", args = -1, }
|
||||
self.key_events.GotoNextPage = { { { "RPgFwd", "LPgFwd", not Device:hasFewKeys() and nextKey } }, event = "GotoViewRel", args = 1, }
|
||||
self.key_events.GotoPrevPage = { { { "RPgBack", "LPgBack", not Device:hasFewKeys() and prevKey } }, event = "GotoViewRel", args = -1, }
|
||||
self.key_events.GotoNextPos = { { "Down" }, event = "GotoPosRel", args = 1, }
|
||||
self.key_events.GotoPrevPos = { { "Up" }, event = "GotoPosRel", args = -1, }
|
||||
end
|
||||
|
||||
@@ -116,13 +116,15 @@ end
|
||||
function ReaderRolling:onGesture() end
|
||||
|
||||
function ReaderRolling:registerKeyEvents()
|
||||
local nextKey = BD.mirroredUILayout() and "Left" or "Right"
|
||||
local prevKey = BD.mirroredUILayout() and "Right" or "Left"
|
||||
if Device:hasDPad() and Device:useDPadAsActionKeys() then
|
||||
if G_reader_settings:isTrue("left_right_keys_turn_pages") then
|
||||
self.key_events.GotoNextView = { { { "LPgFwd", "Right" } }, event = "GotoViewRel", args = 1, }
|
||||
self.key_events.GotoPrevView = { { { "LPgBack", "Left" } }, event = "GotoViewRel", args = -1, }
|
||||
self.key_events.GotoNextView = { { { "LPgFwd", nextKey } }, event = "GotoViewRel", args = 1, }
|
||||
self.key_events.GotoPrevView = { { { "LPgBack", prevKey } }, event = "GotoViewRel", args = -1, }
|
||||
elseif G_reader_settings:nilOrFalse("left_right_keys_turn_pages") then
|
||||
self.key_events.GotoNextChapter = { { "Right" }, event = "GotoNextChapter", args = 1, }
|
||||
self.key_events.GotoPrevChapter = { { "Left" }, event = "GotoPrevChapter", args = -1, }
|
||||
self.key_events.GotoNextChapter = { { nextKey }, event = "GotoNextChapter", args = 1, }
|
||||
self.key_events.GotoPrevChapter = { { prevKey }, event = "GotoPrevChapter", args = -1, }
|
||||
self.key_events.GotoNextView = { { "LPgFwd" }, event = "GotoViewRel", args = 1, }
|
||||
self.key_events.GotoPrevView = { { "LPgBack" }, event = "GotoViewRel", args = -1, }
|
||||
end
|
||||
@@ -133,8 +135,8 @@ function ReaderRolling:registerKeyEvents()
|
||||
self.key_events.MoveDown = { { "Down" }, event = "Panning", args = {0, 1}, }
|
||||
end
|
||||
if (Device:hasDPad() and not Device:useDPadAsActionKeys()) or (Device:hasKeys() and not Device:useDPadAsActionKeys()) then
|
||||
self.key_events.GotoNextView = { { { "RPgFwd", "LPgFwd", "Right" } }, event = "GotoViewRel", args = 1, }
|
||||
self.key_events.GotoPrevView = { { { "RPgBack", "LPgBack", "Left" } }, event = "GotoViewRel", args = -1, }
|
||||
self.key_events.GotoNextView = { { { "RPgFwd", "LPgFwd", nextKey } }, event = "GotoViewRel", args = 1, }
|
||||
self.key_events.GotoPrevView = { { { "RPgBack", "LPgBack", prevKey } }, event = "GotoViewRel", args = -1, }
|
||||
end
|
||||
if Device:hasKeyboard() and not Device.k3_alt_plus_key_kernel_translated then
|
||||
self.key_events.GotoFirst = { { "1" }, event = "GotoPercent", args = 0, }
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
local bit = require("bit")
|
||||
local BD = require("ui/bidi")
|
||||
local Device = require("device")
|
||||
local Event = require("ui/event")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local logger = require("logger")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local bit = require("bit")
|
||||
local logger = require("logger")
|
||||
local util = require("util")
|
||||
--[[
|
||||
Wrapper Widget that manages focus for a whole dialog
|
||||
@@ -156,6 +157,7 @@ function FocusManager:onFocusHalfMove(args)
|
||||
end
|
||||
elseif direction == "left" then
|
||||
dx = - math.floor(#row / 2)
|
||||
if BD.mirroredUILayout() then dx = -dx end
|
||||
if dx == 0 then
|
||||
dx = -1
|
||||
elseif dx + x <= 0 then
|
||||
@@ -163,12 +165,19 @@ function FocusManager:onFocusHalfMove(args)
|
||||
end
|
||||
elseif direction == "right" then
|
||||
dx = math.floor(#row / 2)
|
||||
if BD.mirroredUILayout() then dx = -dx end
|
||||
if dx == 0 then
|
||||
dx = 1
|
||||
elseif dx + x > #row then
|
||||
dx = #row - y -- last column
|
||||
dx = #row - x -- last column
|
||||
end
|
||||
end
|
||||
if dx ~= 0 and BD.mirroredUILayout() then
|
||||
-- When in RTL we mirror horizontally the elements/buttons on the screen, however we don't mirror self.layout
|
||||
-- therefore we must account for this when moving the focus. Since we're already inverting dx in the FocusMove
|
||||
-- method, we need to "unfix" our value here, before calling onFocusMove, where it will be flipped again.
|
||||
dx = -dx
|
||||
end
|
||||
return self:onFocusMove({dx, dy})
|
||||
end
|
||||
|
||||
@@ -214,6 +223,13 @@ function FocusManager:onFocusMove(args)
|
||||
end
|
||||
local dx, dy = unpack(args)
|
||||
|
||||
-- Flip horizontal direction in RTL mode
|
||||
if dx ~= 0 and BD.mirroredUILayout() then
|
||||
-- When in RTL we mirror horizontally the elements/buttons on the screen, however we don't mirror self.layout
|
||||
-- therefore we must account for this when moving the focus.
|
||||
dx = -dx
|
||||
end
|
||||
|
||||
if (dx ~= 0 and not self.movement_allowed.x)
|
||||
or (dy ~= 0 and not self.movement_allowed.y) then
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user