xss-dimmer/xsecurelock: handle case where background is too small

This commit is contained in:
Vincent Bernat 2021-12-13 21:20:58 +01:00
parent de2c9879bc
commit 76dfac0d99
2 changed files with 16 additions and 10 deletions

View file

@ -43,18 +43,22 @@ def on_win_realize(widget, ctx):
def on_win_draw(widget, cctx, ctx): def on_win_draw(widget, cctx, ctx):
"""Draw background image.""" """Draw background image."""
x, y = ctx.position
wwidth, wheight = widget.get_size()
scale = widget.get_scale_factor()
bg = None
if ctx.background:
bg = ctx.background.new_subpixbuf(
x * scale, y * scale, wwidth * scale, wheight * scale
)
cctx.set_operator(cairo.OPERATOR_SOURCE) cctx.set_operator(cairo.OPERATOR_SOURCE)
if not ctx.background: if not bg:
cctx.set_source_rgba(0, 0, 0, 1) cctx.set_source_rgba(0, 0, 0, 1)
cctx.paint() cctx.paint()
return return
x, y = ctx.position
wwidth, wheight = widget.get_size()
scale = widget.get_scale_factor()
bg = ctx.background.new_subpixbuf(
x * scale, y * scale, wwidth * scale, wheight * scale
)
cctx.save() cctx.save()
cctx.scale(1 / scale, 1 / scale) cctx.scale(1 / scale, 1 / scale)
Gdk.cairo_set_source_pixbuf(cctx, bg, 0, 0) Gdk.cairo_set_source_pixbuf(cctx, bg, 0, 0)

View file

@ -52,13 +52,15 @@ def on_draw(widget, event, options, background, start):
cctx = event cctx = event
# Background # Background
scale = widget.get_scale_factor()
bg = None
if background:
bg = background.new_subpixbuf(x, y, wwidth * scale, wheight * scale)
cctx.set_operator(cairo.OPERATOR_SOURCE) cctx.set_operator(cairo.OPERATOR_SOURCE)
if not background: if not bg:
cctx.set_source_rgba(0, 0, 0, opacity) cctx.set_source_rgba(0, 0, 0, opacity)
cctx.paint() cctx.paint()
else: else:
scale = widget.get_scale_factor()
bg = background.new_subpixbuf(x, y, wwidth * scale, wheight * scale)
cctx.save() cctx.save()
cctx.scale(1 / scale, 1 / scale) cctx.scale(1 / scale, 1 / scale)
Gdk.cairo_set_source_pixbuf(cctx, bg, 0, 0) Gdk.cairo_set_source_pixbuf(cctx, bg, 0, 0)