From b0a2d82d8f5fd41b61b97a6eaa06d62f232b400e Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 23 May 2021 23:11:09 -0700 Subject: [PATCH] compat: Do not require to pass pattern._native to the wallpaper. It makes the shims impossible to implement without a double free, a memory leak or a crash. Using `capi` should not require to destroy the LGI wrappers. Another example, not fixed in this commit, are the client shapes. --- lib/awful/_compat.lua | 22 ++++++++++++++++++++++ lib/gears/wallpaper.lua | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/awful/_compat.lua b/lib/awful/_compat.lua index c25714f0e..496b090bc 100644 --- a/lib/awful/_compat.lua +++ b/lib/awful/_compat.lua @@ -58,6 +58,28 @@ do assert(root.object == root_object) end +--- The old wallpaper only took native surfaces. +-- +-- This was a problem for the test backend. The new function takes both +-- native surfaces and LGI-ified Cairo surfaces. +function root.wallpaper(pattern) + if not pattern then return root._wallpaper() end + + -- Checking for type will either potentially `error()` or always + -- return `userdata`. This check will error() when the surface is + -- already native. + local err = pcall(function() return pattern._native end) + + -- The presence of `root._write_string` means the test backend is + -- used. Avoid passing the native surface. + if err and not root._write_string then + return root._wallpaper(pattern._native) + else + return root._wallpaper(pattern) + end +end + + -- root.bottons() used to be a capi function. However this proved confusing -- as rc.lua used `awful.button` and `root.buttons()` used capi.button. There -- was a little documented hack to "flatten" awful.button into a pair of diff --git a/lib/gears/wallpaper.lua b/lib/gears/wallpaper.lua index 8b3f796a9..b65cdf85e 100644 --- a/lib/gears/wallpaper.lua +++ b/lib/gears/wallpaper.lua @@ -121,7 +121,7 @@ function wallpaper.set(pattern) if not cairo.Pattern:is_type_of(pattern) then error("wallpaper.set() called with an invalid argument") end - root.wallpaper(pattern._native) + root.wallpaper(pattern) end --- Set a centered wallpaper.