2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00
koreader/frontend/ui/widget/screensaverwidget.lua

117 lines
3.7 KiB
Lua
Raw Normal View History

local Device = require("device")
local Event = require("ui/event")
local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local FrameContainer = require("ui/widget/container/framecontainer")
local InputContainer = require("ui/widget/container/inputcontainer")
local UIManager = require("ui/uimanager")
local _ = require("gettext")
local Screen = Device.screen
Clarify our OOP semantics across the codebase (#9586) Basically: * Use `extend` for class definitions * Use `new` for object instantiations That includes some minor code cleanups along the way: * Updated `Widget`'s docs to make the semantics clearer. * Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283) * Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass). * Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events. * Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier. * Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references. * ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak). * Terminal: Make sure the shell is killed on plugin teardown. * InputText: Fix Home/End/Del physical keys to behave sensibly. * InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...). * OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of. * ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed! * Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
local ScreenSaverWidget = InputContainer:extend{
name = "ScreenSaver",
widget = nil,
background = nil,
}
function ScreenSaverWidget:init()
if Device:hasKeys() then
self.key_events.AnyKeyPressed = { { Device.input.group.Any } }
end
if Device:isTouchDevice() then
local range = Geom:new{
x = 0, y = 0,
w = Screen:getWidth(),
h = Screen:getHeight(),
}
self.ges_events.Tap = { GestureRange:new{ ges = "tap", range = range } }
end
self:update()
end
function ScreenSaverWidget:update()
self.height = Screen:getHeight()
self.width = Screen:getWidth()
self.region = Geom:new{
x = 0, y = 0,
w = self.width,
h = self.height,
}
self.main_frame = FrameContainer:new{
radius = 0,
bordersize = 0,
padding = 0,
margin = 0,
background = self.background,
width = self.width,
height = self.height,
self.widget,
}
Enable HW dithering in a few key places (#4541) * Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4) * FileManager and co. (where appropriate, i.e., when covers are shown) * Book Status * Reader, where appropriate: * CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone). * Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices). * ScreenSaver * ImageViewer * Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it). (The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu). * Hunted down a few redundant repaints (unneeded setDirty("all") calls), either by switching the widget to nil when only a refresh was needed, and not a repaint, or by passing the appropritate widget to setDirty. (Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard). There were also a few instances of 'em right behind a widget close. * Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog. We unfortunately do need to do it when switching tabs, because of their variable heights. * On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes! * Fix another debug guard in Kobo sysfs_light * Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not. PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
self.dithered = true
self[1] = self.main_frame
end
function ScreenSaverWidget:onShow()
UIManager:setDirty(self, function()
return "full", self.main_frame.dimen
end)
return true
end
function ScreenSaverWidget:onTap(_, ges)
if ges.pos:intersectWith(self.main_frame.dimen) then
self:onClose()
end
return true
end
function ScreenSaverWidget:onClose()
-- If we happened to shortcut a delayed close via user input, unschedule it to avoid a spurious refresh.
local Screensaver = require("ui/screensaver")
if Screensaver.delayed_close then
UIManager:unschedule(Screensaver.close_widget)
end
UIManager:close(self)
return true
end
ScreenSaverWidget.onAnyKeyPressed = ScreenSaverWidget.onClose
ScreenSaverWidget.onExitScreensaver = ScreenSaverWidget.onClose
function ScreenSaverWidget:onCloseWidget()
-- Restore to previous rotation mode, if need be.
if Device.orig_rotation_mode then
Screen:setRotationMode(Device.orig_rotation_mode)
Device.orig_rotation_mode = nil
end
-- Make it full-screen (self.main_frame.dimen might be in a different orientation, and it's already full-screen anyway...)
UIManager:setDirty(nil, function()
return "full"
end)
-- Will come after the Resume event, iff screensaver_delay is set.
-- Comes *before* it otherwise.
UIManager:broadcastEvent(Event:new("OutOfScreenSaver"))
-- NOTE: ScreenSaver itself is neither a Widget nor an instantiated object, so make sure we cleanup behind us...
local Screensaver = require("ui/screensaver")
Screensaver:cleanup()
end
function ScreenSaverWidget:onResume()
-- If we actually catch this event, it means screensaver_delay is set.
-- Tell Device about it, so that further power button presses while we're still shown send us back to suspend.
-- NOTE: This only affects devices where we handle Power events ourselves (i.e., rely on Device -> Generic's onPowerEvent),
-- and it *always* implies that Device.screen_saver_mode is true.
Device.screen_saver_lock = true
end
function ScreenSaverWidget:onSuspend()
-- Also flip this back on suspend, in case we suspend again on a delayed screensaver (e.g., via SleepCover or AutoSuspend).
Device.screen_saver_lock = false
end
return ScreenSaverWidget