mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
mod: move slider event handling to global command module
Since this event must be handled in all UIs, it is better to register it on command object construction.
This commit is contained in:
19
commands.lua
19
commands.lua
@@ -162,5 +162,24 @@ function Commands:new(obj)
|
||||
end
|
||||
setmetatable(obj.map, mt)
|
||||
|
||||
obj:add(KEY_INTO_SCREEN_SAVER, nil, "slider",
|
||||
"toggle screen saver",
|
||||
function()
|
||||
Screen:saveCurrentBB()
|
||||
Screen.kpv_rotation_mode = Screen.cur_rotation_mode
|
||||
fb:setOrientation(Screen.native_rotation_mode)
|
||||
--os.execute("killall -cont cvm")
|
||||
end
|
||||
)
|
||||
obj:add(KEY_OUTOF_SCREEN_SAVER, nil, "slider",
|
||||
"toggle screen saver",
|
||||
function()
|
||||
os.execute("sleep 3")
|
||||
--os.execute("killall -stop cvm")
|
||||
fb:setOrientation(Screen.kpv_rotation_mode)
|
||||
Screen:resotreFromSavedBB()
|
||||
fb:refresh(0)
|
||||
end
|
||||
)
|
||||
return obj
|
||||
end
|
||||
|
||||
26
screen.lua
26
screen.lua
@@ -44,6 +44,8 @@ Screen = {
|
||||
-- these two variabls are used to help switching from framework to reader
|
||||
native_rotation_mode = nil,
|
||||
kpv_rotation_mode = nil,
|
||||
|
||||
saved_bb = nil,
|
||||
}
|
||||
|
||||
-- @orien: 1 for clockwise rotate, -1 for anti-clockwise
|
||||
@@ -74,3 +76,27 @@ function Screen:updateRotationMode()
|
||||
end
|
||||
end
|
||||
|
||||
function Screen:saveCurrentBB()
|
||||
if not self.saved_bb then
|
||||
self.saved_bb = Blitbuffer.new(width, height)
|
||||
end
|
||||
if self.saved_bb:getWidth() ~= width then
|
||||
self.saved_bb:free()
|
||||
self.saved_bb = Blitbuffer.new(width, height)
|
||||
end
|
||||
self.saved_bb:blitFullFrom(fb.bb)
|
||||
end
|
||||
|
||||
function Screen:resotreFromSavedBB()
|
||||
self:restoreFromBB(self.saved_bb)
|
||||
end
|
||||
|
||||
function Screen:getCurrentScreenBB()
|
||||
local bb = Blitbuffer.new(width, height)
|
||||
bb:blitFullFrom(fb.bb)
|
||||
return bb
|
||||
end
|
||||
|
||||
function Screen:restoreFromBB(bb)
|
||||
fb.bb:blitFullFrom(bb)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user