Some completely untested code that might or might not work that hopefully provides some more details to Emmanuel's suggestion:
local surface = require("gears.surface")
local cairo = require("lgi").cairo
local timer = require("gears.timer")
-- "Mix" two surface based on a factor between 0 and 1
local function mix_surfaces(first, second, factor)
local result = surface.duplicate_surface(first)
local cr = cairo.Context(result)
cr:set_source_surface(second, 0, 0)
cr:paint_with_alpha(factor)
return result
end
-- Get the current wallpaper and do a fade 'steps' times with 'interval'
-- seconds between steps. At each step, the wallpapers are mixed and the
-- result is given to 'callback'. If no wallpaper is set, the callback
-- function is directly called with the new wallpaper.
local function fade_to_wallpaper(new_wp, steps, interval, callback)
new_wp = surface(new_wp)
local old_wp = surface(root.wallpaper())
if not old_wp then
callback(new_wp)
return
end
-- Setting a new wallpaper invalidates any surface returned
-- by root.wallpaper(), so create a copy.
old_wp = surface.duplicate_surface(old_wp)
local steps_done = 0
timer.start_new(interval, function()
steps_done = steps_done + 1
local mix = mix_surface(old_wp, new_wp, steps_done / steps)
callback(mix)
mix:finish()
return steps_done <= steps
end)
end
-- Example how to use:
-- Fade to the given file for 4 seconds with 30 "frames per second".
fade_to_wallpaper("path/to/file.png", 120, 1/30, function(surf)
gears.wallpaper.maximized(surf)
end)
Note that this does not "pre-render" the frames, as suggested by Emmanuel. However, the actual mixing is done on a surface which was created via create_similar() from a create_similar() from the old wallpaper. As such, this is not a cairo image surface, but a cairo XCB surface and the mixing is done on the X11 server and not in awesome. That might or might not help to speed things up...