mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-17 07:47:41 +01:00
gears.surface: Also apply default when called with "nil"
Before this, calling one of the loading functions with a nil argument always made it return the default 0x0 surface. With this change, the passed-in default value is now properly applied. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
62495daa66
commit
a2c1106401
1 changed files with 10 additions and 10 deletions
|
@ -20,8 +20,11 @@ end
|
|||
local surface = { mt = {} }
|
||||
local surface_cache = setmetatable({}, { __mode = 'v' })
|
||||
|
||||
local function get_empty_surface()
|
||||
return cairo.ImageSurface(cairo.Format.ARGB32, 0, 0)
|
||||
local function get_default(arg)
|
||||
if type(arg) == 'nil' then
|
||||
return cairo.ImageSurface(cairo.Format.ARGB32, 0, 0)
|
||||
end
|
||||
return arg
|
||||
end
|
||||
|
||||
--- Try to convert the argument into an lgi cairo surface.
|
||||
|
@ -33,9 +36,9 @@ end
|
|||
-- @return An error message, or nil on success
|
||||
function surface.load_uncached_silently(_surface, default)
|
||||
local file
|
||||
-- On nil, return an empty surface
|
||||
-- On nil, return some sane default
|
||||
if not _surface then
|
||||
return get_empty_surface()
|
||||
return get_default(default)
|
||||
end
|
||||
-- Remove from cache if it was cached
|
||||
surface_cache[_surface] = nil
|
||||
|
@ -49,10 +52,7 @@ function surface.load_uncached_silently(_surface, default)
|
|||
file = _surface
|
||||
_surface, err = capi.awesome.load_image(file)
|
||||
if not _surface then
|
||||
if type(default) == 'nil' then
|
||||
default = get_empty_surface()
|
||||
end
|
||||
return default, err
|
||||
return get_default(default), err
|
||||
end
|
||||
end
|
||||
-- Everything else gets forced into a surface
|
||||
|
@ -85,14 +85,14 @@ end
|
|||
|
||||
local function do_load_and_handle_errors(_surface, func)
|
||||
if type(_surface) == 'nil' then
|
||||
return get_empty_surface()
|
||||
return get_default()
|
||||
end
|
||||
local result, err = func(_surface, false)
|
||||
if result then
|
||||
return result
|
||||
end
|
||||
gdebug.print_error("Failed to load '" .. tostring(_surface) .. "': " .. tostring(err))
|
||||
return get_empty_surface()
|
||||
return get_default()
|
||||
end
|
||||
|
||||
--- Try to convert the argument into an lgi cairo surface.
|
||||
|
|
Loading…
Reference in a new issue