diff --git a/lib/gears/surface.lua b/lib/gears/surface.lua index 24d3a000..dc61efd8 100644 --- a/lib/gears/surface.lua +++ b/lib/gears/surface.lua @@ -51,7 +51,13 @@ function surface.load_uncached_silently(_surface, default) if not pixbuf then return get_default(default), tostring(err) end - _surface = capi.awesome.pixbuf_to_surface(pixbuf._native) + _surface = capi.awesome.pixbuf_to_surface(pixbuf._native, _surface) + + -- The shims implement load_image() to return a surface directly, + -- instead of a lightuserdatum. + if cairo.Surface:is_type_of(_surface) then + return _surface + end end -- Everything else gets forced into a surface return cairo.Surface(_surface, true) diff --git a/luaa.c b/luaa.c index 29c7ec06..698773b1 100644 --- a/luaa.c +++ b/luaa.c @@ -284,6 +284,7 @@ luaA_sync(lua_State *L) /** Translate a GdkPixbuf to a cairo image surface.. * * @param pixbuf The pixbuf as a light user datum. + * @param path The pixbuf origin path * @return A cairo surface as light user datum. * @function pixbuf_to_surface */ diff --git a/tests/examples/shims/awesome.lua b/tests/examples/shims/awesome.lua index 8db8133c..990a2a22 100644 --- a/tests/examples/shims/awesome.lua +++ b/tests/examples/shims/awesome.lua @@ -1,6 +1,4 @@ local lgi = require("lgi") -local GdkPixbuf = lgi.GdkPixbuf -local Gdk = lgi.Gdk local gears_obj = require("gears.object") -- Emulate the C API classes. They differ from C API objects as connect_signal @@ -48,27 +46,10 @@ awesome.startup = true function awesome.register_xproperty() end -local init, surfaces = false, {} +awesome.load_image = lgi.cairo.ImageSurface.create_from_png -function awesome.load_image(file) - if not init then - Gdk.init{} - init = true - end - - local _, width, height = GdkPixbuf.Pixbuf.get_file_info(file) - - local pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(file, width, height) - - if not pixbuf then - return nil, "Could not load "..file - end - - local s = Gdk.cairo_surface_create_from_pixbuf( pixbuf, 1, nil ) - - table.insert(surfaces, s) - - return s._native, not s and "Could not load surface from "..file or nil, s +function awesome.pixbuf_to_surface(_, path) + return awesome.load_image(path) end -- Always show deprecated messages