From 9c4e246038a30a405957b3f537c8c1c27d4a872b Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 7 Jun 2020 23:35:43 +0200 Subject: [PATCH] Ensure feature-parity in ScreenSaver handling on Kindle (#6240) * Ensure feature-parity in ScreenSaver handling on Kindle We were missing the fancy extra white flash and landscape handling that most every other eInk device gets ;). Fix #5724 * Minor SO tweaks The "swipe to unlock" ad screen was possibly managing to seep through on slow devices. * Less convoluted and more consistent logic Thanks, @yparitcher ;). --- frontend/device/kindle/device.lua | 60 ++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/frontend/device/kindle/device.lua b/frontend/device/kindle/device.lua index 85d31dc9f..ccf247783 100644 --- a/frontend/device/kindle/device.lua +++ b/frontend/device/kindle/device.lua @@ -161,15 +161,42 @@ function Kindle:usbPlugIn() end function Kindle:intoScreenSaver() - local Screensaver = require("ui/screensaver") - if self:supportsScreensaver() then - -- NOTE: Meaning this is not a SO device ;) - if self.screen_saver_mode == false then + if self.screen_saver_mode == false then + if self:supportsScreensaver() then + -- NOTE: Meaning this is not a SO device ;) + local Screensaver = require("ui/screensaver") + -- NOTE: Pilefered from Device:onPowerEvent @ frontend/device/generic/device.lua + -- Mostly always suspend in Portrait/Inverted Portrait mode... + -- ... except when we just show an InfoMessage or when the screensaver + -- is disabled, as it plays badly with Landscape mode (c.f., #4098 and #5290) + local screensaver_type = G_reader_settings:readSetting("screensaver_type") + if screensaver_type ~= "message" and screensaver_type ~= "disable" then + self.orig_rotation_mode = self.screen:getRotationMode() + -- Leave Portrait & Inverted Portrait alone, that works just fine. + if bit.band(self.orig_rotation_mode, 1) == 1 then + -- i.e., only switch to Portrait if we're currently in *any* Landscape orientation (odd number) + self.screen:setRotationMode(0) + else + self.orig_rotation_mode = nil + end + + -- On eInk, if we're using a screensaver mode that shows an image, + -- flash the screen to white first, to eliminate ghosting. + if self:hasEinkScreen() and + screensaver_type == "cover" or screensaver_type == "random_image" or + screensaver_type == "image_file" then + if not G_reader_settings:isTrue("screensaver_no_background") then + self.screen:clear() + end + self.screen:refreshFull() + end + else + -- nil it, in case user switched ScreenSaver modes during our lifetime. + self.orig_rotation_mode = nil + end Screensaver:show() - end - else - -- Let the native system handle screensavers on SO devices... - if self.screen_saver_mode == false then + else + -- Let the native system handle screensavers on SO devices... if os.getenv("AWESOME_STOPPED") == "yes" then os.execute("killall -cont awesome") end @@ -181,19 +208,26 @@ end function Kindle:outofScreenSaver() if self.screen_saver_mode == true then - local Screensaver = require("ui/screensaver") if self:supportsScreensaver() then + local Screensaver = require("ui/screensaver") + -- Restore to previous rotation mode, if need be. + if self.orig_rotation_mode then + self.screen:setRotationMode(self.orig_rotation_mode) + end Screensaver:close() + -- And redraw everything in case the framework managed to screw us over... + local UIManager = require("ui/uimanager") + UIManager:nextTick(function() UIManager:setDirty("all", "full") end) else -- Stop awesome again if need be... if os.getenv("AWESOME_STOPPED") == "yes" then os.execute("killall -stop awesome") end + local UIManager = require("ui/uimanager") + -- NOTE: We redraw after a slightly longer delay to take care of the potentially dynamic ad screen... + -- This is obviously brittle as all hell. Tested on a slow-ass PW1. + UIManager:scheduleIn(1.5, function() UIManager:setDirty("all", "full") end) end - local UIManager = require("ui/uimanager") - -- NOTE: If we *really* wanted to avoid the framework seeping through, we could use tickAfterNext instead, - -- at the cost of an extra flashing update... - UIManager:nextTick(function() UIManager:setDirty("all", "full") end) end self.powerd:afterResume() self.screen_saver_mode = false