mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Reader: Do less work on same-orientation non-gyro rotations (#11297)
Namely, don't recompute layouts, as they do not change. (The gyro codepaths were already doing something similar.) * Keep ConfigDialog, FileManagerMenu & ReaderMenu open on rotation. (In practice, only ConfigDialog is affected, as *Menu doesn't handle the rotation event.) * Plugged an instance leak in the aforementioned Menu classes. * Unify behavior & code with the gyro codepaths.
This commit is contained in:
@@ -984,39 +984,37 @@ end
|
||||
--- (Translation should be done via registerEventAdjustHook in Device implementations).
|
||||
--- This needs to be called *via handleGyroEv* in a handleMiscEv implementation (c.f., Kobo, Kindle or PocketBook).
|
||||
function Input:handleMiscGyroEv(ev)
|
||||
local rotation_mode, screen_mode
|
||||
local rotation
|
||||
if ev.value == C.DEVICE_ROTATED_UPRIGHT then
|
||||
-- i.e., UR
|
||||
rotation_mode = framebuffer.DEVICE_ROTATED_UPRIGHT
|
||||
screen_mode = "portrait"
|
||||
rotation = framebuffer.DEVICE_ROTATED_UPRIGHT
|
||||
elseif ev.value == C.DEVICE_ROTATED_CLOCKWISE then
|
||||
-- i.e., CW
|
||||
rotation_mode = framebuffer.DEVICE_ROTATED_CLOCKWISE
|
||||
screen_mode = "landscape"
|
||||
rotation = framebuffer.DEVICE_ROTATED_CLOCKWISE
|
||||
elseif ev.value == C.DEVICE_ROTATED_UPSIDE_DOWN then
|
||||
-- i.e., UD
|
||||
rotation_mode = framebuffer.DEVICE_ROTATED_UPSIDE_DOWN
|
||||
screen_mode = "portrait"
|
||||
rotation = framebuffer.DEVICE_ROTATED_UPSIDE_DOWN
|
||||
elseif ev.value == C.DEVICE_ROTATED_COUNTER_CLOCKWISE then
|
||||
-- i.e., CCW
|
||||
rotation_mode = framebuffer.DEVICE_ROTATED_COUNTER_CLOCKWISE
|
||||
screen_mode = "landscape"
|
||||
rotation = framebuffer.DEVICE_ROTATED_COUNTER_CLOCKWISE
|
||||
else
|
||||
-- Discard FRONT/BACK
|
||||
return
|
||||
end
|
||||
|
||||
local old_rotation_mode = self.device.screen:getRotationMode()
|
||||
local old_rotation = self.device.screen:getRotationMode()
|
||||
if self.device:isGSensorLocked() then
|
||||
local old_screen_mode = self.device.screen:getScreenMode()
|
||||
if rotation_mode and rotation_mode ~= old_rotation_mode and screen_mode == old_screen_mode then
|
||||
local matching_orientation = bit.band(rotation, 1) == bit.band(old_rotation, 1)
|
||||
if rotation and rotation ~= old_rotation and matching_orientation then
|
||||
-- Cheaper than a full SetRotationMode event, as we don't need to re-layout anything.
|
||||
self.device.screen:setRotationMode(rotation_mode)
|
||||
self.device.screen:setRotationMode(rotation)
|
||||
UIManager:onRotation()
|
||||
end
|
||||
else
|
||||
if rotation_mode and rotation_mode ~= old_rotation_mode then
|
||||
return Event:new("SetRotationMode", rotation_mode)
|
||||
if rotation and rotation ~= old_rotation then
|
||||
-- NOTE: We do *NOT* send a broadcast manually, and instead rely on the main loop's sendEvent:
|
||||
-- this ensures that only widgets that actually know how to handle a rotation will do so ;).
|
||||
return Event:new("SetRotationMode", rotation)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user