diff options
author | Michael Webster <miketwebster@gmail.com> | 2024-05-28 14:10:26 +0200 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2024-05-28 14:11:00 +0200 |
commit | 5a2e16b8405236a76c09de77120a03e50254c5bf (patch) | |
tree | ff949a6ea2258580cf8a359b7f2498b70d4621a9 /src/cached-image.vala | |
parent | dc19d70c2c8f6680a18f20c34b67bc70c50f680c (diff) | |
download | arctica-greeter-5a2e16b8405236a76c09de77120a03e50254c5bf.tar.gz arctica-greeter-5a2e16b8405236a76c09de77120a03e50254c5bf.tar.bz2 arctica-greeter-5a2e16b8405236a76c09de77120a03e50254c5bf.zip |
Fix hidpi rendering of session badges.
Most of the more common desktops provide a scalable icon, so they
can be rendered in hidpi.
Diffstat (limited to 'src/cached-image.vala')
-rw-r--r-- | src/cached-image.vala | 35 |
1 files changed, 18 insertions, 17 deletions
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<Gdk.Pixbuf, Cairo.Surface> 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<Gdk.Pixbuf, Cairo.Surface> (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); } } |