screensaver: improve extra flash option to fix banding (#15703)
Replace the re-flash approach (which caused banding) with a redraw approach that closes and redraws the sleep screen widget between flashes. Also make flash count and delay configurable via a spinner widget, and calculate suspend_wait_timeout dynamically based on the configured values. Fixes #15702
This commit is contained in:
1 parent
cde23b992f
commit
d67b6373aa
4 files changed
+94
-31
No files matched your search
@@ -82,8 +82,8 @@ local Device = {
|
||||
-- For Kobo, wait at least 15 seconds before calling suspend script. Otherwise, suspend might
|
||||
-- fail and the battery will be drained while we are in screensaver mode
|
||||
suspend_wait_timeout = 15,
|
||||
-- Bumped when screensaver_extra_flash is enabled, to account for ~2s of extra refresh activity
|
||||
suspend_wait_timeout_extra_flash = 17,
|
||||
-- The screensaver can opt to add additional time in case of extra anti-ghosting draws.
|
||||
screensaver_suspend_wait_timeout = nil,
|
||||
|
||||
-- hardware feature tests: (these are functions!)
|
||||
hasBattery = yes,
|
||||
@@ -390,9 +390,22 @@ function Device:getPowerDevice()
|
||||
return self.powerd
|
||||
end
|
||||
|
||||
function Device:rescheduleSuspend()
|
||||
-- Used for extra anti-ghosting redraws, to account for the time spent
|
||||
-- flashing the screen before suspend.
|
||||
-- extra_flash_count: number of corrective redraws (0 = none), delay_ms: delay between each redraw.
|
||||
function Device:getScreensaverSuspendWaitTimeout(extra_flash_count, delay_ms)
|
||||
local flash_window = (extra_flash_count and extra_flash_count > 0)
|
||||
-- 0.5s initial delay + (count-1)*delay between flashes + 0.5s for final redraw
|
||||
and (0.5 + (extra_flash_count - 1) * (delay_ms / 1000) + 0.5)
|
||||
or 0
|
||||
return self.suspend_wait_timeout + flash_window + 2 -- 2s safety margin
|
||||
end
|
||||
|
||||
-- Only used on platforms where we handle suspend ourselves.
|
||||
-- Pass an optional timeout to override the default (e.g., to account for extra screensaver flashing).
|
||||
function Device:rescheduleSuspend(timeout)
|
||||
UIManager:unschedule(self.suspend)
|
||||
UIManager:scheduleIn(self.suspend_wait_timeout, self.suspend, self)
|
||||
UIManager:scheduleIn(timeout or self.suspend_wait_timeout, self.suspend, self)
|
||||
end
|
||||
|
||||
-- Only used on platforms where we handle suspend ourselves.
|
||||
@@ -474,7 +487,8 @@ function Device:onPowerEvent(ev)
|
||||
-- Only turn off the frontlight *after* we've displayed the screensaver and dealt with Wi-Fi,
|
||||
-- to prevent that from affecting the smoothness of the frontlight ramp down.
|
||||
self.powerd:beforeSuspend()
|
||||
self:rescheduleSuspend()
|
||||
-- When self.screensaver_suspend_wait_timeout is nil the base timeout is used.
|
||||
self:rescheduleSuspend(self.screensaver_suspend_wait_timeout)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1203,11 +1203,11 @@ local function getProductId()
|
||||
end
|
||||
|
||||
-- NOTE: We overload this to make sure checkUnexpectedWakeup doesn't trip *before* the newly scheduled suspend
|
||||
function Kobo:rescheduleSuspend()
|
||||
function Kobo:rescheduleSuspend(timeout)
|
||||
UIManager:unschedule(self.suspend)
|
||||
UIManager:unschedule(self._doSuspend)
|
||||
UIManager:unschedule(self.checkUnexpectedWakeup)
|
||||
UIManager:scheduleIn(self.suspend_wait_timeout, self.suspend, self)
|
||||
UIManager:scheduleIn(timeout or self.suspend_wait_timeout, self.suspend, self)
|
||||
end
|
||||
|
||||
function Kobo:scheduleUnexpectedWakeupGuard()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
local Device = require("device")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local _ = require("gettext")
|
||||
local T = require("ffi/util").template
|
||||
local Screen = Device.screen
|
||||
|
||||
local eink_settings_table = {
|
||||
@@ -23,11 +25,40 @@ local eink_settings_table = {
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Double flash sleep screen"),
|
||||
help_text = _("Flash the sleep screen twice after it is shown to reduce ghosting. May not be needed on all devices."),
|
||||
checked_func = function() return G_reader_settings:isTrue("screensaver_extra_flash") end,
|
||||
callback = function()
|
||||
G_reader_settings:flipNilOrFalse("screensaver_extra_flash")
|
||||
text_func = function()
|
||||
local count = G_reader_settings:readSetting("screensaver_extra_flash_count", 0)
|
||||
local delay = G_reader_settings:readSetting("screensaver_extra_flash_delay", 1000)
|
||||
if count == 0 then
|
||||
return _("Sleep screen anti-ghosting redraws: off")
|
||||
end
|
||||
return T(_("Sleep screen anti-ghosting redraws: %1×, %2 ms"), count, delay)
|
||||
end,
|
||||
help_text = _("Redraw the sleep screen image a number of times after it is shown to reduce ghosting. Each redraw flashes black then redraws the cover. Set count to 0 to disable."),
|
||||
keep_menu_open = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local DoubleSpinWidget = require("ui/widget/doublespinwidget")
|
||||
local widget = DoubleSpinWidget:new{
|
||||
left_value = G_reader_settings:readSetting("screensaver_extra_flash_count", 0),
|
||||
left_min = 0,
|
||||
left_max = 4,
|
||||
left_step = 1,
|
||||
left_hold_step = 1,
|
||||
left_text = _("Redraws"),
|
||||
right_value = G_reader_settings:readSetting("screensaver_extra_flash_delay", 1000),
|
||||
right_min = 0,
|
||||
right_max = 2000,
|
||||
right_step = 50,
|
||||
right_hold_step = 250,
|
||||
right_text = _("Delay (ms)"),
|
||||
title_text = _("Sleep screen flashes"),
|
||||
ok_text = _("Set anti-ghosting redraws"),
|
||||
callback = function(left_value, right_value)
|
||||
G_reader_settings:saveSetting("screensaver_extra_flash_count", left_value)
|
||||
G_reader_settings:saveSetting("screensaver_extra_flash_delay", right_value)
|
||||
touchmenu_instance:updateItems()
|
||||
end,
|
||||
}
|
||||
UIManager:show(widget)
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
||||
+37
-19
@@ -649,6 +649,14 @@ function Screensaver:show()
|
||||
-- NOTE: Make sure InputContainer gestures are not disabled, to prevent stupid interactions with UIManager on close.
|
||||
UIManager:setIgnoreTouchInput(false)
|
||||
|
||||
-- Setup the gesture lock through an additional invisible widget, so that it works regardless of the configuration.
|
||||
if with_gesture_lock then
|
||||
self.screensaver_lock_widget = ScreenSaverLockWidget:new{
|
||||
ui = self.ui,
|
||||
orig_dimen = orig_dimen,
|
||||
}
|
||||
end
|
||||
|
||||
if widget then
|
||||
self.screensaver_widget = ScreenSaverWidget:new{
|
||||
widget = widget,
|
||||
@@ -659,27 +667,37 @@ function Screensaver:show()
|
||||
self.screensaver_widget.dithered = true
|
||||
|
||||
UIManager:show(self.screensaver_widget, "full")
|
||||
if G_reader_settings:isTrue("screensaver_extra_flash") then
|
||||
Device.suspend_wait_timeout = Device.suspend_wait_timeout_extra_flash
|
||||
local extra_flash_count = G_reader_settings:readSetting("screensaver_extra_flash_count", 0)
|
||||
if extra_flash_count > 0 then
|
||||
local screen_w2, screen_h2 = Screen:getWidth(), Screen:getHeight()
|
||||
UIManager:scheduleIn(0.5, function()
|
||||
Screen:refreshFull(0, 0, screen_w2, screen_h2)
|
||||
end)
|
||||
UIManager:scheduleIn(1.5, function()
|
||||
Screen:refreshFull(0, 0, screen_w2, screen_h2)
|
||||
end)
|
||||
local delay_ms = G_reader_settings:readSetting("screensaver_extra_flash_delay", 1000)
|
||||
Device.screensaver_suspend_wait_timeout = Device:getScreensaverSuspendWaitTimeout(extra_flash_count, delay_ms)
|
||||
for i = 1, extra_flash_count do
|
||||
local t = 0.5 + (i - 1) * (delay_ms / 1000)
|
||||
local is_last = (i == extra_flash_count)
|
||||
UIManager:scheduleIn(t, function()
|
||||
-- Paint black directly to the framebuffer and refresh, then force a full widget redraw.
|
||||
Screen.bb:fill(Blitbuffer.COLOR_BLACK)
|
||||
Screen:refreshFull(0, 0, screen_w2, screen_h2)
|
||||
UIManager:scheduleIn(0.5, function()
|
||||
UIManager:setDirty(self.screensaver_widget, "full")
|
||||
UIManager:forceRePaint()
|
||||
if is_last then
|
||||
-- It's flagged as modal, so it'll stay on top
|
||||
UIManager:show(self.screensaver_lock_widget)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
else
|
||||
-- It's flagged as modal, so it'll stay on top
|
||||
UIManager:show(self.screensaver_lock_widget)
|
||||
end
|
||||
else
|
||||
-- No screensaver widget, show lock widget immediately if needed
|
||||
if self.screensaver_lock_widget then
|
||||
UIManager:show(self.screensaver_lock_widget)
|
||||
end
|
||||
end
|
||||
|
||||
-- Setup the gesture lock through an additional invisible widget, so that it works regardless of the configuration.
|
||||
if with_gesture_lock then
|
||||
self.screensaver_lock_widget = ScreenSaverLockWidget:new{
|
||||
ui = self.ui,
|
||||
orig_dimen = orig_dimen,
|
||||
}
|
||||
|
||||
-- It's flagged as modal, so it'll stay on top
|
||||
UIManager:show(self.screensaver_lock_widget)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user