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")
|
2022-07-11 11:50:28 +00:00
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
2017-12-17 17:27:24 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local UIManager = require("ui/uimanager")
|
2022-07-11 11:50:28 +00:00
|
|
|
local util = require("util")
|
|
|
|
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-07-11 11:50:28 +00:00
|
|
|
if G_reader_settings:readSetting("screensaver_delay") == "gesture" then
|
|
|
|
self:setupGestureEvents()
|
|
|
|
end
|
|
|
|
if not self.has_exit_screensaver_gesture then
|
|
|
|
-- Exit with gesture not enabled, or no configured gesture found: allow exiting with tap
|
|
|
|
local range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
2022-10-27 00:01:51 +00:00
|
|
|
self.ges_events.Tap = { GestureRange:new{ ges = "tap", range = range } }
|
2022-07-11 11:50:28 +00:00
|
|
|
end
|
2017-12-17 17:27:24 +00:00
|
|
|
end
|
|
|
|
self:update()
|
|
|
|
end
|
|
|
|
|
2022-07-11 11:50:28 +00:00
|
|
|
function ScreenSaverWidget:setupGestureEvents()
|
|
|
|
-- The configured gesture(s) won't trigger, because this widget is at top
|
|
|
|
-- of the UI stack and will prevent ReaderUI/Filemanager from getting
|
|
|
|
-- and handling any configured gesture event.
|
|
|
|
-- We need to find all the ones configured for the "exit_screensaver" action,
|
|
|
|
-- and clone them so they are handled by this widget.
|
|
|
|
local ReaderUI = require("apps/reader/readerui")
|
|
|
|
local ui = ReaderUI:_getRunningInstance()
|
|
|
|
if not ui then
|
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
|
|
|
ui = FileManager.instance
|
|
|
|
end
|
|
|
|
if ui and ui.gestures and ui.gestures.gestures then
|
|
|
|
local multiswipe_already_met = false
|
|
|
|
for gesture, actions in pairs(ui.gestures.gestures) do
|
|
|
|
if util.stringStartsWith(gesture, "multiswipe") then
|
|
|
|
-- All multiswipes are handled by the single handler for "multiswipe"
|
|
|
|
-- We only need to clone one of them
|
|
|
|
gesture = "multiswipe"
|
|
|
|
end
|
|
|
|
if actions["exit_screensaver"] and (gesture ~= "multiswipe" or not multiswipe_already_met) then
|
|
|
|
if gesture == "multiswipe" then
|
|
|
|
multiswipe_already_met = true
|
|
|
|
end
|
|
|
|
-- Clone the gesture found in our self.ges_events
|
|
|
|
local ui_gesture = ui._zones[gesture]
|
|
|
|
if ui_gesture and ui_gesture.handler then
|
|
|
|
-- We can reuse its GestureRange object
|
|
|
|
self.ges_events[gesture] = { ui_gesture.gs_range }
|
|
|
|
-- For each of them, we need a distinct event and its handler.
|
|
|
|
-- This handler will call the original handler (created by gestures.koplugin)
|
|
|
|
-- which, after some checks (like swipe distance and direction, and multiswipe
|
|
|
|
-- directions), will emit normally the configured real ExitScreensaver event,
|
|
|
|
-- that this widget (being at top of the UI stack) will get and that
|
|
|
|
-- onExitScreensaver() will handle.
|
|
|
|
local event_name = "TriggerExitScreensaver_" .. gesture
|
|
|
|
self.ges_events[gesture].event = event_name
|
|
|
|
self["on"..event_name] = function(this, args, ev)
|
|
|
|
ui_gesture.handler(ev)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if next(self.ges_events) then -- we found a gesture configured
|
|
|
|
self.has_exit_screensaver_gesture = true
|
|
|
|
-- Override handleEvent(), so we can stop any event from propagating to widgets
|
|
|
|
-- below this one (we may get some from other multiswipe as the handler does
|
|
|
|
-- not filter the one we are insterested with, but also when multiple actions
|
|
|
|
-- are assigned to a single gesture).
|
|
|
|
self.handleEvent = function(this, event)
|
|
|
|
InputContainer.handleEvent(this, event)
|
|
|
|
return true
|
|
|
|
end
|
2022-10-24 08:46:39 +00:00
|
|
|
self.key_events = {} -- also disable exit with keys
|
2022-07-11 11:50:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ScreenSaverWidget:showWaitForGestureMessage(msg)
|
|
|
|
-- We just paint an InfoMessage on screen directly: we don't want
|
|
|
|
-- another widget that we would need to prevent catching events
|
|
|
|
local infomsg = InfoMessage:new{
|
|
|
|
text = self.has_exit_screensaver_gesture
|
|
|
|
and _("Waiting for specific gesture to exit screensaver.")
|
|
|
|
or _("No exit screensaver gesture configured. Tap to exit.")
|
|
|
|
}
|
|
|
|
infomsg:paintTo(Screen.bb, 0, 0)
|
|
|
|
infomsg:onShow() -- get the screen refreshed
|
|
|
|
infomsg:free()
|
|
|
|
end
|
|
|
|
|
2017-12-17 17:27:24 +00:00
|
|
|
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
|
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
|
|
|
UIManager:setDirty(self, function()
|
2021-07-05 02:56:14 +00:00
|
|
|
return "full", self.main_frame.dimen
|
2017-12-17 17:27:24 +00:00
|
|
|
end)
|
|
|
|
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()
|
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-11-07 16:40:45 +00:00
|
|
|
Device.screen_saver_mode = false
|
|
|
|
Device.screen_saver_lock = false
|
|
|
|
|
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...)
|
2017-12-17 17:27:24 +00:00
|
|
|
UIManager:setDirty(nil, function()
|
2022-04-02 16:21:40 +00:00
|
|
|
return "full"
|
2017-12-17 17:27:24 +00:00
|
|
|
end)
|
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"))
|
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
|