xss-dimmer: correctly handle opacity

We were using operator source which does not compose using opacity.
This commit is contained in:
Vincent Bernat 2021-12-13 18:35:46 +01:00
parent e44313b596
commit 53c5ecdfb2

View file

@ -66,19 +66,20 @@ def on_draw(widget, event, options, background, start):
cctx.restore() cctx.restore()
# Remaining time # Remaining time
cctx.set_operator(cairo.OPERATOR_OVER)
remaining = str(round(options.delay - elapsed)) remaining = str(round(options.delay - elapsed))
cctx.select_font_face(options.font, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) cctx.select_font_face(options.font, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
cctx.set_font_size(wheight // 4) cctx.set_font_size(wheight // 4)
_, _, twidth, theight, _, _ = cctx.text_extents("8" * len(remaining)) _, _, twidth, theight, _, _ = cctx.text_extents("8" * len(remaining))
text_position = wwidth // 2 - twidth // 2, wheight // 2 + theight // 2 text_position = wwidth // 2 - twidth // 2, wheight // 2 + theight // 2
cctx.move_to(*text_position) cctx.move_to(*text_position)
cctx.set_source_rgba(1, 1, 1, opacity)
cctx.show_text(remaining)
cctx.move_to(*text_position)
cctx.set_source_rgba(0, 0, 0, opacity * 2) cctx.set_source_rgba(0, 0, 0, opacity * 2)
cctx.set_line_width(4) cctx.set_line_width(4)
cctx.text_path(remaining) cctx.text_path(remaining)
cctx.stroke() cctx.stroke()
cctx.move_to(*text_position)
cctx.set_source_rgba(1, 1, 1, opacity)
cctx.show_text(remaining)
def on_refresh(window, options, start): def on_refresh(window, options, start):