u/Msnbobody

Night Mode Screensaver Patch

Night Mode Screensaver Patch

Hello everyone!

I noticed that even when Night Mode is on, KOReader shows the sleep screen without night mode applied, so transparent images end up with a bright background. I put together a small patch to fix that and figured I’d share it here. I’ve tested it on the emulator and on my Kobo Clara BW and it seems to work well.

https://preview.redd.it/kisp0z1z2h2h1.jpg?width=539&format=pjpg&auto=webp&s=fd37d50294a588d18ff64afcde1c909f419bda21

If you want to test it out,

You can download the code here:
https://pastebin.com/TrLP60gK

Or copy and paste the code below into a text editor and save it as 2-keep-nightmode.lua then add it to your koreader/patches folder.

local Screensaver = require("ui/screensaver")
local ScreenSaverWidget = require("ui/widget/screensaverwidget")
local Device = require("device")
local Screen = Device.screen

local orig_show = Screensaver.show

Screensaver.show = function(self, ...)
    if Screen.night_mode then
        local snapshot = Screen.bb:copy()
        snapshot:invertRect(0, 0, snapshot:getWidth(), snapshot:getHeight())

        local orig_init = ScreenSaverWidget.init
        ScreenSaverWidget.init = function(widget, ...)
            ScreenSaverWidget.init = orig_init
            local result = orig_init(widget, ...)
            local orig_paintTo = widget.paintTo
            widget.paintTo = function(w, bb, x, y)
                bb:blitFullFrom(snapshot)
                snapshot:free()
                snapshot = nil
                w.paintTo = orig_paintTo
                return orig_paintTo(w, bb, x, y)
            end
            return result
        end
    end
    return orig_show(self, ...)
end
reddit.com
u/Msnbobody — 17 hours ago