【问题标题】:Is there a way to switch the wallpapers with a fade transition effect on AwesomeWM?有没有办法在 AwesomeWM 上切换具有淡入淡出过渡效果的壁纸?
【发布时间】:2018-01-22 09:36:31
【问题描述】:

这是一个关于在 Awesome Windows Manager 上切换壁纸的问题。

我想用淡入过渡效果平滑地切换我的壁纸。目前我使用gears.wallpaper API随机更换壁纸,这里是https://p.ume.ink/t/cbbM的部分代码。

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

【问题讨论】:

    标签: lua fade wallpaper awesome-wm


    【解决方案1】:

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

    您可以使用LGI CairoCairo composition operators 来预渲染每一帧(比如说,在更改壁纸之前每个事件循环一个超过 5 秒以避免延迟)。然后使用gears.wallpaper API 设置每个帧以及设置为 30hz 或 60hz 的gears.timer

    虽然没有那么多工作,但绝对不简单。

    【讨论】:

      【解决方案2】:

      一些完全未经测试的代码可能有效也可能无效,希望能为 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)
      

      请注意,这不会像 Emmanuel 所建议的那样“预渲染”帧。然而,实际的混合是在一个表面上完成的,该表面是通过旧墙纸中的 create_similar() 中的 create_similar() 创建的。因此,这不是一个 cairo 图像表面,而是一个 cairo XCB 表面,并且混合是在 X11 服务器上完成的,而不是很棒。这可能会也可能不会有助于加快速度...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-03-29
        • 1970-01-01
        • 2021-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-17
        • 1970-01-01
        相关资源
        最近更新 更多