widget: Fix saving a widget to a file.
Previously, if `beautiful.fg_normal` wasn't black, it would not render correctly.
This commit is contained in:
parent
91fe314e0b
commit
18468d32dd
|
@ -62,7 +62,10 @@ local allowed_deps = {
|
|||
naughty = true,
|
||||
},
|
||||
-- TODO: Get rid of these
|
||||
["gears.surface"] = { ["wibox.hierarchy"] = true },
|
||||
["gears.surface"] = {
|
||||
["wibox.hierarchy"] = true,
|
||||
beautiful = true,
|
||||
},
|
||||
}
|
||||
|
||||
-- Turn "foo.bar.baz" into "foo.bar". Returns nil if there is nothing more to
|
||||
|
|
|
@ -9,7 +9,7 @@ local type = type
|
|||
local capi = { awesome = awesome }
|
||||
local cairo = require("lgi").cairo
|
||||
local GdkPixbuf = require("lgi").GdkPixbuf
|
||||
local color = nil
|
||||
local color, beautiful = nil, nil
|
||||
local gdebug = require("gears.debug")
|
||||
local hierarchy = require("wibox.hierarchy")
|
||||
|
||||
|
@ -232,7 +232,7 @@ end
|
|||
--- Create an SVG file with this widget content.
|
||||
-- This is dynamic, so the SVG will be updated along with the widget content.
|
||||
-- because of this, the painting may happen hover multiple event loop cycles.
|
||||
-- @deprecated draw_to_svg_file
|
||||
-- @deprecated widget_to_svg
|
||||
-- @tparam widget widget A widget
|
||||
-- @tparam string path The output file path
|
||||
-- @tparam number width The surface width
|
||||
|
@ -243,17 +243,22 @@ end
|
|||
-- @see wibox.widget.draw_to_image_surface
|
||||
function surface.widget_to_svg(widget, path, width, height)
|
||||
gdebug.deprecate("Use wibox.widget.draw_to_svg_file instead of "..
|
||||
"gears.surface.render_to_svg", {deprecated_in=5})
|
||||
"gears.surface.widget_to_svg", {deprecated_in=5})
|
||||
local img = cairo.SvgSurface.create(path, width, height)
|
||||
local cr = cairo.Context(img)
|
||||
|
||||
-- Bad dependecy, but this is deprecated.
|
||||
beautiful = beautiful or require("beautiful")
|
||||
color = color or require("gears.color")
|
||||
cr:set_source(color(beautiful.fg_normal))
|
||||
|
||||
return img, run_in_hierarchy(widget, cr, width, height)
|
||||
end
|
||||
|
||||
--- Create a cairo surface with this widget content.
|
||||
-- This is dynamic, so the SVG will be updated along with the widget content.
|
||||
-- because of this, the painting may happen hover multiple event loop cycles.
|
||||
-- @deprecated draw_to_image_surface
|
||||
-- @deprecated widget_to_surface
|
||||
-- @tparam widget widget A widget
|
||||
-- @tparam number width The surface width
|
||||
-- @tparam number height The surface height
|
||||
|
@ -268,6 +273,11 @@ function surface.widget_to_surface(widget, width, height, format)
|
|||
local img = cairo.ImageSurface(format or cairo.Format.ARGB32, width, height)
|
||||
local cr = cairo.Context(img)
|
||||
|
||||
-- Bad dependecy, but this is deprecated.
|
||||
color = color or require("gears.color")
|
||||
beautiful = beautiful or require("beautiful")
|
||||
cr:set_source(color(beautiful.fg_normal))
|
||||
|
||||
return img, run_in_hierarchy(widget, cr, width, height)
|
||||
end
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
local cairo = require("lgi").cairo
|
||||
local hierarchy = require("wibox.hierarchy")
|
||||
local gcolor = require("gears.color")
|
||||
local beautiful = nil
|
||||
|
||||
local widget = {
|
||||
base = require("wibox.widget.base");
|
||||
|
@ -55,6 +57,10 @@ end
|
|||
function widget.draw_to_svg_file(wdg, path, width, height, context)
|
||||
local img = cairo.SvgSurface.create(path, width, height)
|
||||
local cr = cairo.Context(img)
|
||||
|
||||
beautiful = beautiful or require("beautiful")
|
||||
cr:set_source(gcolor(beautiful.fg_normal))
|
||||
|
||||
widget.draw_to_cairo_context(wdg, cr, width, height, context)
|
||||
img:finish()
|
||||
end
|
||||
|
@ -70,6 +76,10 @@ end
|
|||
function widget.draw_to_image_surface(wdg, width, height, format, context)
|
||||
local img = cairo.ImageSurface(format or cairo.Format.ARGB32, width, height)
|
||||
local cr = cairo.Context(img)
|
||||
|
||||
beautiful = beautiful or require("beautiful")
|
||||
cr:set_source(gcolor(beautiful.fg_normal))
|
||||
|
||||
widget.draw_to_cairo_context(wdg, cr, width, height, context)
|
||||
return img
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue