Lua 有没有办法在AwesomeWM上切换具有渐变效果的壁纸?

Lua 有没有办法在AwesomeWM上切换具有渐变效果的壁纸?,lua,fade,wallpaper,awesome-wm,Lua,Fade,Wallpaper,Awesome Wm,这是一个关于在很棒的Windows管理器上切换壁纸的问题 我想用淡入过渡效果平滑切换壁纸。目前,我使用gears.wallpaperAPI随机更改我的壁纸,下面是代码部分 谁能给我一点建议吗?我不想使用外部工具。当然,这是一种方法,但不是一种很好的方法 您可以使用随一起预渲染每个帧(例如,在更改墙纸之前的5秒内,每个事件循环一次,以避免延迟)。然后使用gears.wallpaperAPI将每个帧以及gears.timer设置为30hz或60hz 虽然没有那么多的工作,但它肯定不简单。当然是一种方

这是一个关于在很棒的Windows管理器上切换壁纸的问题

我想用淡入过渡效果平滑切换壁纸。目前,我使用
gears.wallpaper
API随机更改我的壁纸,下面是代码部分


谁能给我一点建议吗?我不想使用外部工具。

当然,这是一种方法,但不是一种很好的方法

您可以使用随一起预渲染每个帧(例如,在更改墙纸之前的5秒内,每个事件循环一次,以避免延迟)。然后使用
gears.wallpaper
API将每个帧以及
gears.timer
设置为30hz或60hz


虽然没有那么多的工作,但它肯定不简单。

当然是一种方式,但不是一种漂亮的方式

您可以使用随一起预渲染每个帧(例如,在更改墙纸之前的5秒内,每个事件循环一次,以避免延迟)。然后使用
gears.wallpaper
API将每个帧以及
gears.timer
设置为30hz或60hz


虽然没有那么多的工作,但它肯定不简单。

一些完全未经测试的代码可能会工作,也可能不工作,希望能为Emmanuel的建议提供更多细节:

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)
local surface=require(“齿轮表面”)
本地cairo=require(“lgi”)。cairo
本地定时器=需要(“齿轮.定时器”)
--基于0和1之间的系数“混合”两个曲面
局部函数混合曲面(第一、第二、因子)
局部结果=曲面。复制曲面(第一个)
本地cr=cairo.Context(结果)
cr:设置源曲面(秒,0,0)
cr:用α(系数)绘制
返回结果
结束
--获取当前墙纸,并使用“间隔”进行“步骤”次数的淡入淡出
--两步之间的秒数。在每一步中,墙纸都是混合的,并且
--结果被赋予“回调”。如果未设置墙纸,则回调
--使用新墙纸直接调用函数。
本地函数淡入墙纸(新的工作包、步骤、间隔、回调)
新_wp=曲面(新_wp)
local old_wp=曲面(root.wallpaper())
如果不是旧的,那么
回拨(新工作包)
返回
结束
--设置新墙纸会使返回的任何曲面无效
--通过root.wallpaper(),因此创建一个副本。
旧曲面=曲面。复制曲面(旧曲面)
本地步骤_done=0
计时器.启动\u新建(间隔,函数()
步骤完成=步骤完成+1
局部混合=混合表面(旧混合、新混合、步骤完成/步骤)
回调(混合)
混合:饰面()

返回步骤\u done一些完全未经测试的代码,这些代码可能有效,也可能无效,希望能为Emmanuel的建议提供更多细节:

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)
local surface=require(“齿轮表面”)
本地cairo=require(“lgi”)。cairo
本地定时器=需要(“齿轮.定时器”)
--基于0和1之间的系数“混合”两个曲面
局部函数混合曲面(第一、第二、因子)
局部结果=曲面。复制曲面(第一个)
本地cr=cairo.Context(结果)
cr:设置源曲面(秒,0,0)
cr:用α(系数)绘制
返回结果
结束
--获取当前墙纸,并使用“间隔”进行“步骤”次数的淡入淡出
--每一步之间的秒数。在每一步中,墙纸都是混合的
--结果被赋予“回调”。如果没有设置墙纸,则回调
--使用新墙纸直接调用函数。
本地函数淡入墙纸(新的工作包、步骤、间隔、回调)
新_wp=曲面(新_wp)
local old_wp=曲面(root.wallpaper())
如果不是旧的,那么
回拨(新工作包)
返回
结束
--设置新墙纸会使返回的任何曲面无效
--通过root.wallpaper(),因此创建一个副本。
旧曲面=曲面。复制曲面(旧曲面)
本地步骤_done=0
计时器.启动\u新建(间隔,函数()
步骤完成=步骤完成+1
局部混合=混合表面(旧混合、新混合、步骤完成/步骤)
回调(混合)
混合:饰面()
返回已完成的步骤