From 5a2e16b8405236a76c09de77120a03e50254c5bf Mon Sep 17 00:00:00 2001 From: Michael Webster Date: Tue, 28 May 2024 14:10:26 +0200 Subject: Fix hidpi rendering of session badges. Most of the more common desktops provide a scalable icon, so they can be rendered in hidpi. --- src/cached-image.vala | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/cached-image.vala') diff --git a/src/cached-image.vala b/src/cached-image.vala index 56157a3..3dfc5b8 100644 --- a/src/cached-image.vala +++ b/src/cached-image.vala @@ -21,7 +21,7 @@ public class CachedImage : Gtk.Image { private static HashTable surface_table; - public static Cairo.Surface? get_cached_surface (Cairo.Context c, Gdk.Pixbuf pixbuf) + public static Cairo.Surface? get_cached_surface (Gdk.Pixbuf pixbuf) { if (surface_table == null) surface_table = new HashTable (direct_hash, direct_equal); @@ -29,31 +29,32 @@ public class CachedImage : Gtk.Image var surface = surface_table.lookup (pixbuf); if (surface == null) { - surface = new Cairo.Surface.similar (c.get_target (), Cairo.Content.COLOR_ALPHA, pixbuf.width, pixbuf.height); - var new_c = new Cairo.Context (surface); - Gdk.cairo_set_source_pixbuf (new_c, pixbuf, 0, 0); - new_c.paint (); + surface = Gdk.cairo_surface_create_from_pixbuf (pixbuf, _scale_factor, null); surface_table.insert (pixbuf, surface); } return surface; } + private void update_image(Gdk.Pixbuf? pixbuf) + { + if (pixbuf != null) + { + surface = get_cached_surface (pixbuf); + } + else + { + surface = null; + pixbuf = null; + } + } + public CachedImage (Gdk.Pixbuf? pixbuf) { - Object (pixbuf: pixbuf); + update_image (pixbuf); } - public override bool draw (Cairo.Context c) + public void set_pixbuf(Gdk.Pixbuf? pixbuf) { - if (pixbuf != null) - { - var cached_surface = get_cached_surface (c, pixbuf); - if (cached_surface != null) - { - c.set_source_surface (cached_surface, 0, 0); - c.paint (); - } - } - return false; + update_image (pixbuf); } } -- cgit v1.2.3