Widget opacity: draw with alpha only if transparent
This commit is contained in:
parent
03663fe778
commit
d2407c3de1
|
@ -59,10 +59,17 @@ local function do_redraw(self)
|
||||||
self._widget_geometries = {}
|
self._widget_geometries = {}
|
||||||
if self.widget and self.widget.visible then
|
if self.widget and self.widget.visible then
|
||||||
cr:set_source(self.foreground_color)
|
cr:set_source(self.foreground_color)
|
||||||
cr:push_group()
|
|
||||||
|
if self.widget.opacity ~= 1 then
|
||||||
|
cr:push_group()
|
||||||
|
end
|
||||||
self.widget:draw(self.widget_arg, cr, width, height)
|
self.widget:draw(self.widget_arg, cr, width, height)
|
||||||
cr:pop_group_to_source()
|
if self.widget.opacity ~= 1 then
|
||||||
cr:paint_with_alpha(self.widget.opacity)
|
cr:pop_group_to_source()
|
||||||
|
cr.operator = cairo.Operator.OVER
|
||||||
|
cr:paint_with_alpha(self.widget.opacity)
|
||||||
|
end
|
||||||
|
|
||||||
self:widget_at(self.widget, 0, 0, width, height)
|
self:widget_at(self.widget, 0, 0, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ local pcall = pcall
|
||||||
local print = print
|
local print = print
|
||||||
local min = math.min
|
local min = math.min
|
||||||
local max = math.max
|
local max = math.max
|
||||||
|
local cairo = require("lgi").cairo
|
||||||
|
|
||||||
local base = {}
|
local base = {}
|
||||||
|
|
||||||
|
@ -66,14 +67,19 @@ function base.draw_widget(wibox, cr, widget, x, y, width, height)
|
||||||
cr:rectangle(0, 0, width, height)
|
cr:rectangle(0, 0, width, height)
|
||||||
cr:clip()
|
cr:clip()
|
||||||
|
|
||||||
cr:push_group()
|
if widget.opacity ~= 1 then
|
||||||
|
cr:push_group()
|
||||||
|
end
|
||||||
-- Let the widget draw itself
|
-- Let the widget draw itself
|
||||||
local success, msg = pcall(widget.draw, widget, wibox, cr, width, height)
|
local success, msg = pcall(widget.draw, widget, wibox, cr, width, height)
|
||||||
|
if widget.opacity ~= 1 then
|
||||||
|
cr:pop_group_to_source()
|
||||||
|
cr.operator = cairo.Operator.OVER
|
||||||
|
cr:paint_with_alpha(widget.opacity)
|
||||||
|
end
|
||||||
if not success then
|
if not success then
|
||||||
print("Error while drawing widget: " .. msg)
|
print("Error while drawing widget: " .. msg)
|
||||||
end
|
end
|
||||||
cr:pop_group_to_source()
|
|
||||||
cr:paint_with_alpha(widget.opacity)
|
|
||||||
|
|
||||||
-- Register the widget for input handling
|
-- Register the widget for input handling
|
||||||
wibox:widget_at(widget, base.rect_to_device_geometry(cr, 0, 0, width, height))
|
wibox:widget_at(widget, base.rect_to_device_geometry(cr, 0, 0, width, height))
|
||||||
|
|
Loading…
Reference in New Issue