mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
emulate Power button with F2 on emulator
This commit is contained in:
@@ -2,14 +2,14 @@ local CenterContainer = require("ui/widget/container/centercontainer")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local Screensaver = require("ui/screensaver")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Menu = require("ui/widget/menu")
|
||||
local Screen = require("ui/screen")
|
||||
local _ = require("gettext")
|
||||
local Font = require("ui/font")
|
||||
local UIToolbox = require("ui/uitoolbox")
|
||||
local util = require("ffi/util")
|
||||
local Font = require("ui/font")
|
||||
local _ = require("gettext")
|
||||
|
||||
local calibre = "metadata.calibre"
|
||||
local koreaderfile = "temp/metadata.koreader"
|
||||
@@ -472,7 +472,7 @@ function Search:onMenuHold(item)
|
||||
item.notchecked = false
|
||||
end
|
||||
local thumbwidth = math.min(240, Screen:getWidth()/3)
|
||||
UIManager:show(InfoMessage:new{text = item.info,image = UIToolbox:getPicture(item.path), image_width = thumbwidth,image_height = thumbwidth/2*3})
|
||||
UIManager:show(InfoMessage:new{text = item.info,image = Screensaver:getCoverPicture(item.path), image_width = thumbwidth,image_height = thumbwidth/2*3})
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,6 +6,7 @@ local BasePowerD = require("ui/device/basepowerd")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local Screen = require("ui/device/screen")
|
||||
local util = require("ffi/util")
|
||||
local DEBUG = require("dbg")
|
||||
local ffi = require("ffi")
|
||||
|
||||
local Device = {
|
||||
@@ -201,26 +202,54 @@ function Device:outofScreenSaver()
|
||||
self.screen_saver_mode = false
|
||||
end
|
||||
|
||||
function Device:prepareSuspend() -- currently only used for kobo devices
|
||||
function Device:onPowerEvent(ev)
|
||||
local Screensaver = require("ui/screensaver")
|
||||
local UIManager = require("ui/uimanager")
|
||||
if (ev == "Power" or ev == "Suspend") and not self.screen_saver_mode then
|
||||
DEBUG("Suspending...")
|
||||
Screensaver:show()
|
||||
self:prepareSuspend()
|
||||
UIManager:scheduleIn(2, function() self:Suspend() end)
|
||||
elseif (ev == "Power" or ev == "Resume") and self.screen_saver_mode then
|
||||
DEBUG("Resuming...")
|
||||
self:Resume()
|
||||
Screensaver:close()
|
||||
end
|
||||
end
|
||||
|
||||
function Device:prepareSuspend()
|
||||
local powerd = self:getPowerDevice()
|
||||
if powerd ~= nil then
|
||||
if powerd.fl ~= nil then
|
||||
-- in no case should the frontlight be turned on in suspend mode
|
||||
powerd.fl:sleep()
|
||||
end
|
||||
self.screen:refresh(0)
|
||||
self.screen_saver_mode = true
|
||||
end
|
||||
|
||||
function Device:Suspend() -- currently only used for kobo devices
|
||||
os.execute("./suspend.sh")
|
||||
function Device:Suspend()
|
||||
if self:isKobo() then
|
||||
os.execute("./suspend.sh")
|
||||
end
|
||||
end
|
||||
|
||||
function Device:Resume() -- currently only used for kobo devices
|
||||
os.execute("echo 0 > /sys/power/state-extended")
|
||||
function Device:Resume()
|
||||
if self:isKobo() then
|
||||
os.execute("echo 0 > /sys/power/state-extended")
|
||||
end
|
||||
self.screen:refresh(1)
|
||||
local powerd = self:getPowerDevice()
|
||||
if powerd ~= nil then
|
||||
if powerd.fl ~= nil then
|
||||
powerd.fl:restore()
|
||||
end
|
||||
-- FIXME: this conflicts with powerd.fl:restore
|
||||
--[[
|
||||
if KOBO_LIGHT_ON_START and tonumber(KOBO_LIGHT_ON_START) > -1 then
|
||||
if powerd then
|
||||
powerd:setIntensity(math.max(math.min(KOBO_LIGHT_ON_START,100),0))
|
||||
end
|
||||
end
|
||||
--]]
|
||||
self.screen_saver_mode = false
|
||||
end
|
||||
|
||||
|
||||
@@ -205,6 +205,7 @@ function Input:initKeyMap()
|
||||
[64] = "Alt", -- left alt
|
||||
[65] = " ", -- Spacebar
|
||||
[67] = "Menu", -- F[1]
|
||||
[68] = "Power", -- F[2]
|
||||
[72] = "LPgBack", -- F[6]
|
||||
[73] = "LPgFwd", -- F[7]
|
||||
[95] = "VPlus", -- F[11]
|
||||
@@ -237,6 +238,7 @@ function Input:initKeyMap()
|
||||
[226] = "Alt", -- left alt
|
||||
[44] = " ", -- Spacebar
|
||||
[58] = "Menu", -- F[1]
|
||||
[59] = "Power", -- F[2]
|
||||
[63] = "LPgBack", -- F[6]
|
||||
[64] = "LPgFwd", -- F[7]
|
||||
[68] = "VPlus", -- F[11]
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Screen = require("ui/screen")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
|
||||
local UIToolbox = InputContainer:new{
|
||||
local Screensaver = {
|
||||
}
|
||||
|
||||
function UIToolbox:getPicture(file)
|
||||
|
||||
function Screensaver:getCoverPicture(file)
|
||||
local contentopf
|
||||
local contentpath
|
||||
local epub_folder = "temp/epub"
|
||||
@@ -69,13 +71,13 @@ function UIToolbox:getPicture(file)
|
||||
end
|
||||
return check_extension(cover)
|
||||
end
|
||||
|
||||
|
||||
local function checkoldfile(cover)
|
||||
if io.open(cover) then
|
||||
return cover
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local cover
|
||||
|
||||
local oldfile = "temp/" .. file:gsub("/","#") .. "."
|
||||
@@ -104,13 +106,13 @@ function UIToolbox:getPicture(file)
|
||||
contentpath = ""
|
||||
end
|
||||
pcall(os.execute("unzip \"" .. file .. "\" \"" .. contentopf .. "\" -oq -d " .. epub_folder)) -- read content.opf
|
||||
|
||||
|
||||
cover = try_content_opf("^%s*<meta name=\"cover\"","content=",true) -- Make Room
|
||||
if not cover then cover = try_content_opf('id="cover',"item href=",false) end -- Kishon
|
||||
if not cover then cover = try_content_opf("cover","href=",true) end
|
||||
if not cover then cover = try_content_opf("cover","=",true) end
|
||||
if not cover then cover = try_content_opf("cover","=",false) end
|
||||
|
||||
|
||||
if not cover then guess("jpg") end
|
||||
if not cover then guess("jpeg") end
|
||||
if not cover then guess("png") end
|
||||
@@ -129,10 +131,10 @@ function UIToolbox:getPicture(file)
|
||||
return cover
|
||||
end
|
||||
|
||||
function UIToolbox:getRandomPicture(dir)
|
||||
function Screensaver:getRandomPicture(dir)
|
||||
local pics = {}
|
||||
local i = 0
|
||||
math.randomseed( os.time() )
|
||||
math.randomseed(os.time())
|
||||
for entry in lfs.dir(dir) do
|
||||
if lfs.attributes(dir .. entry, "mode") == "file" then
|
||||
local extension = string.lower(string.match(entry, ".+%.([^.]+)") or "")
|
||||
@@ -145,4 +147,45 @@ function UIToolbox:getRandomPicture(dir)
|
||||
return pics[math.random(i)]
|
||||
end
|
||||
|
||||
return UIToolbox
|
||||
function Screensaver:show()
|
||||
DEBUG("show screensaver")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local ImageWidget = require("ui/widget/imagewidget")
|
||||
local file = nil
|
||||
-- first check book cover image
|
||||
if KOBO_SCREEN_SAVER_LAST_BOOK then
|
||||
file = self:getCoverPicture(G_reader_settings:readSetting("lastfile"))
|
||||
-- then screensaver image
|
||||
elseif type(KOBO_SCREEN_SAVER) == "string" then
|
||||
file = KOBO_SCREEN_SAVER
|
||||
if lfs.attributes(file, "mode") == "directory" then
|
||||
if string.sub(file,string.len(file)) ~= "/" then
|
||||
file = file .. "/"
|
||||
end
|
||||
local dummy = self:getRandomPicture(file)
|
||||
if dummy then file = file .. dummy end
|
||||
end
|
||||
end
|
||||
if file and lfs.attributes(file, "mode") == "file" then
|
||||
self.suspend_msg = ImageWidget:new{
|
||||
file = file,
|
||||
width = Screen:getWidth(),
|
||||
height = Screen:getHeight(),
|
||||
}
|
||||
end
|
||||
-- fallback to suspended message
|
||||
if not self.suspend_msg then
|
||||
self.suspend_msg = InfoMessage:new{ text = _("Suspended") }
|
||||
end
|
||||
UIManager:show(self.suspend_msg)
|
||||
end
|
||||
|
||||
function Screensaver:close()
|
||||
DEBUG("close screensaver")
|
||||
if self.suspend_msg then
|
||||
UIManager:close(self.suspend_msg)
|
||||
self.suspend_msg = nil
|
||||
end
|
||||
end
|
||||
|
||||
return Screensaver
|
||||
@@ -2,11 +2,9 @@ local Device = require("ui/device")
|
||||
local Screen = require("ui/screen")
|
||||
local Input = require("ui/input")
|
||||
local Event = require("ui/event")
|
||||
local util = require("ffi/util")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
local util = require("ffi/util")
|
||||
local ImageWidget = require("ui/widget/imagewidget")
|
||||
local UIToolbox = require("ui/uitoolbox")
|
||||
|
||||
-- initialize output module, this must be initialized before Input
|
||||
Screen:init()
|
||||
@@ -57,7 +55,6 @@ local UIManager = {
|
||||
_execution_stack = {},
|
||||
_dirty = {},
|
||||
_zeromqs = {},
|
||||
suspend_msg = nil
|
||||
}
|
||||
|
||||
function UIManager:init()
|
||||
@@ -67,68 +64,20 @@ function UIManager:init()
|
||||
end,
|
||||
SaveState = function()
|
||||
self:sendEvent(Event:new("FlushSettings"))
|
||||
end
|
||||
end,
|
||||
Power = function(input_event)
|
||||
Device:onPowerEvent(input_event)
|
||||
end,
|
||||
}
|
||||
if Device:isKobo() then
|
||||
-- lazy create suspend_msg to avoid dependence loop
|
||||
|
||||
function kobo_power(input_event)
|
||||
|
||||
if (input_event == "Power" or input_event == "Suspend")
|
||||
and not Device.screen_saver_mode then
|
||||
if not UIManager.suspend_msg then
|
||||
|
||||
local file
|
||||
if KOBO_SCREEN_SAVER_LAST_BOOK then
|
||||
file = UIToolbox:getPicture(G_reader_settings:readSetting("lastfile"))
|
||||
end
|
||||
|
||||
if type(KOBO_SCREEN_SAVER) == "string" or file then
|
||||
if not file then
|
||||
file = KOBO_SCREEN_SAVER
|
||||
if lfs.attributes(file, "mode") == "directory" then
|
||||
if string.sub(file,string.len(file)) ~= "/" then
|
||||
file = file .. "/"
|
||||
end
|
||||
local dummy = UIToolbox:getRandomPicture(file)
|
||||
if dummy then file = file .. dummy end
|
||||
end
|
||||
end
|
||||
if lfs.attributes(file, "mode") == "file" then
|
||||
UIManager.suspend_msg = ImageWidget:new{
|
||||
file = file,
|
||||
width = Screen:getWidth(),
|
||||
height = Screen:getHeight(),
|
||||
}
|
||||
end
|
||||
end
|
||||
if not UIManager.suspend_msg then
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
UIManager.suspend_msg = InfoMessage:new{ text = _("Suspended") }
|
||||
end
|
||||
end
|
||||
if KOBO_LIGHT_OFF_ON_SUSPEND then Device:getPowerDevice():setIntensity(0) end
|
||||
self:show(UIManager.suspend_msg)
|
||||
self:sendEvent(Event:new("FlushSettings"))
|
||||
Device:prepareSuspend()
|
||||
self:scheduleIn(2, function() Device:Suspend() end)
|
||||
elseif (input_event == "Power" or input_event == "Resume")
|
||||
and Device.screen_saver_mode then
|
||||
Device:Resume()
|
||||
self:sendEvent(Event:new("Resume"))
|
||||
if UIManager.suspend_msg then
|
||||
self:close(UIManager.suspend_msg)
|
||||
UIManager.suspend_msg = nil
|
||||
end
|
||||
if KOBO_LIGHT_ON_START and tonumber(KOBO_LIGHT_ON_START) > -1 then
|
||||
Device:getPowerDevice():setIntensity( math.max( math.min(KOBO_LIGHT_ON_START,100) ,0) )
|
||||
end
|
||||
end
|
||||
self.event_handlers["Suspend"] = function(input_event)
|
||||
self:sendEvent(Event:new("FlushSettings"))
|
||||
Device:onPowerEvent(input_event)
|
||||
end
|
||||
self.event_handlers["Resume"] = function(input_event)
|
||||
Device:onPowerEvent(input_event)
|
||||
self:sendEvent(Event:new("Resume"))
|
||||
end
|
||||
|
||||
self.event_handlers["Power"] = kobo_power
|
||||
self.event_handlers["Suspend"] = kobo_power
|
||||
self.event_handlers["Resume"] = kobo_power
|
||||
self.event_handlers["Light"] = function()
|
||||
Device:getPowerDevice():toggleFrontlight()
|
||||
end
|
||||
@@ -152,6 +101,7 @@ function UIManager:init()
|
||||
end
|
||||
self.event_handlers["OutOfSS"] = function()
|
||||
Device:outofScreenSaver()
|
||||
self:sendEvent(Event:new("Resume"))
|
||||
end
|
||||
self.event_handlers["Charging"] = function()
|
||||
Device:usbPlugIn()
|
||||
|
||||
Reference in New Issue
Block a user