2017-12-17 17:27:24 +00:00
|
|
|
local Device = require("device")
|
2021-02-23 23:36:05 +00:00
|
|
|
local Event = require("ui/event")
|
2017-12-17 17:27:24 +00:00
|
|
|
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")
|
2022-07-11 11:50:28 +00:00
|
|
|
local _ = require("gettext")
|
2017-12-17 17:27:24 +00:00
|
|
|
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{
|
2022-06-12 17:16:46 +00:00
|
|
|
name = "ScreenSaver",
|
2017-12-17 17:27:24 +00:00
|
|
|
widget = nil,
|
|
|
|
background = nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
function ScreenSaverWidget:init()
|
|
|
|
if Device:hasKeys() then
|
2022-10-27 00:01:51 +00:00
|
|
|
self.key_events.AnyKeyPressed = { { Device.input.group.Any } }
|
2017-12-17 17:27:24 +00:00
|
|
|
end
|
|
|
|
if Device:isTouchDevice() then
|
2022-12-28 20:02:57 +00:00
|
|
|
local range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
self.ges_events.Tap = { GestureRange:new{ ges = "tap", range = range } }
|
2017-12-17 17:27:24 +00:00
|
|
|
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
|
2017-12-17 17:27:24 +00:00
|
|
|
self[1] = self.main_frame
|
|
|
|
end
|
|
|
|
|
|
|
|
function ScreenSaverWidget:onShow()
|
|
|
|
UIManager:setDirty(self, function()
|
2024-07-27 23:19:40 +00:00
|
|
|
return "full", self.main_frame.dimen
|
2017-12-17 17:27:24 +00:00
|
|
|
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()
|
2022-04-02 16:21:40 +00:00
|
|
|
-- 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
|
|
|
|
|
2021-07-05 02:56:14 +00:00
|
|
|
UIManager:close(self)
|
2017-12-17 17:27:24 +00:00
|
|
|
return true
|
|
|
|
end
|
2022-10-23 20:25:08 +00:00
|
|
|
ScreenSaverWidget.onAnyKeyPressed = ScreenSaverWidget.onClose
|
|
|
|
ScreenSaverWidget.onExitScreensaver = ScreenSaverWidget.onClose
|
2017-12-17 17:27:24 +00:00
|
|
|
|
|
|
|
function ScreenSaverWidget:onCloseWidget()
|
2022-04-02 16:21:40 +00:00
|
|
|
-- 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...)
|
2024-01-20 19:20:35 +00:00
|
|
|
UIManager:setDirty(nil, "full")
|
2021-07-05 02:56:14 +00:00
|
|
|
|
|
|
|
-- Will come after the Resume event, iff screensaver_delay is set.
|
|
|
|
-- Comes *before* it otherwise.
|
|
|
|
UIManager:broadcastEvent(Event:new("OutOfScreenSaver"))
|
2022-12-28 22:46:13 +00:00
|
|
|
|
|
|
|
-- 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()
|
2017-12-17 17:27:24 +00:00
|
|
|
end
|
|
|
|
|
2022-11-07 16:40:45 +00:00
|
|
|
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
|
|
|
|
|
2017-12-17 17:27:24 +00:00
|
|
|
return ScreenSaverWidget
|