mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Allow locking the gyro to the current screen mode (#6347)
* Allow locking the gyro to the current screen mode (i.e., orientation). * Tweak the "sticky rota" option to work both ways * More rotation constant usage instead of magic numbers
This commit is contained in:
@@ -657,30 +657,41 @@ function Input:handleOasisOrientationEv(ev)
|
||||
end
|
||||
|
||||
local old_rotation_mode = self.device.screen:getRotationMode()
|
||||
local old_screen_mode = self.device.screen:getScreenMode()
|
||||
if rotation_mode ~= old_rotation_mode and screen_mode == old_screen_mode then
|
||||
self.device.screen:setRotationMode(rotation_mode)
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:onRotation()
|
||||
if self.device:isGSensorLocked() then
|
||||
local old_screen_mode = self.device.screen:getScreenMode()
|
||||
if rotation_mode ~= old_rotation_mode and screen_mode == old_screen_mode then
|
||||
-- Cheaper than a full SetRotationMode event, as we don't need to re-layout anything.
|
||||
self.device.screen:setRotationMode(rotation_mode)
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:onRotation()
|
||||
end
|
||||
else
|
||||
if rotation_mode ~= old_rotation_mode then
|
||||
return Event:new("SetRotationMode", rotation_mode)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Accelerometer on the Forma, c.f., drivers/hwmon/mma8x5x.c
|
||||
function Input:handleMiscEvNTX(ev)
|
||||
local rotation_mode
|
||||
local rotation_mode, screen_mode
|
||||
if ev.code == MSC_RAW then
|
||||
if ev.value == MSC_RAW_GSENSOR_PORTRAIT_UP then
|
||||
-- i.e., UR
|
||||
rotation_mode = framebuffer.ORIENTATION_PORTRAIT
|
||||
screen_mode = 'portrait'
|
||||
elseif ev.value == MSC_RAW_GSENSOR_LANDSCAPE_RIGHT then
|
||||
-- i.e., CW
|
||||
rotation_mode = framebuffer.ORIENTATION_LANDSCAPE
|
||||
screen_mode = 'landscape'
|
||||
elseif ev.value == MSC_RAW_GSENSOR_PORTRAIT_DOWN then
|
||||
-- i.e., UD
|
||||
rotation_mode = framebuffer.ORIENTATION_PORTRAIT_ROTATED
|
||||
screen_mode = 'portrait'
|
||||
elseif ev.value == MSC_RAW_GSENSOR_LANDSCAPE_LEFT then
|
||||
-- i.e., CCW
|
||||
rotation_mode = framebuffer.ORIENTATION_LANDSCAPE_ROTATED
|
||||
screen_mode = 'landscape'
|
||||
else
|
||||
-- Discard FRONT/BACK
|
||||
return
|
||||
@@ -691,22 +702,30 @@ function Input:handleMiscEvNTX(ev)
|
||||
end
|
||||
|
||||
local old_rotation_mode = self.device.screen:getRotationMode()
|
||||
-- NOTE: See the Oasis version just above us for a variant that's locked to the current ScreenMode.
|
||||
-- Might be nice to expose the two behaviors to the user, somehow?
|
||||
if rotation_mode and rotation_mode ~= old_rotation_mode then
|
||||
return Event:new("SetRotationMode", rotation_mode)
|
||||
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
|
||||
-- Cheaper than a full SetRotationMode event, as we don't need to re-layout anything.
|
||||
self.device.screen:setRotationMode(rotation_mode)
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:onRotation()
|
||||
end
|
||||
else
|
||||
if rotation_mode and rotation_mode ~= old_rotation_mode then
|
||||
return Event:new("SetRotationMode", rotation_mode)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Allow toggling the accelerometer at runtime.
|
||||
function Input:toggleMiscEvNTX(toggle)
|
||||
if toggle and toggle == true then
|
||||
if toggle == true then
|
||||
-- Honor Gyro events
|
||||
if not self.isNTXAccelHooked then
|
||||
self.handleMiscEv = self.handleMiscEvNTX
|
||||
self.isNTXAccelHooked = true
|
||||
end
|
||||
elseif toggle and toggle == false then
|
||||
elseif toggle == false then
|
||||
-- Ignore Gyro events
|
||||
if self.isNTXAccelHooked then
|
||||
self.handleMiscEv = function() end
|
||||
|
||||
Reference in New Issue
Block a user