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 ++++++++++++++++++----------------- src/greeter-list.vala | 4 ++++ src/prompt-box.vala | 2 +- src/session-list.vala | 5 ++++- 4 files changed, 27 insertions(+), 19 deletions(-) (limited to 'src') 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); } } diff --git a/src/greeter-list.vala b/src/greeter-list.vala index 2ed347b..8158f9d 100644 --- a/src/greeter-list.vala +++ b/src/greeter-list.vala @@ -24,6 +24,8 @@ */ private const int MAX_FIELD_SIZE = 200; +public int _scale_factor = 1; + private int get_grid_offset (int size) { @@ -173,6 +175,8 @@ public abstract class GreeterList : FadableBox can_focus = false; visible_window = false; + _scale_factor = get_scale_factor (); + fixed = new Gtk.Fixed (); fixed.show (); add (fixed); diff --git a/src/prompt-box.vala b/src/prompt-box.vala index 267dab8..601464e 100644 --- a/src/prompt-box.vala +++ b/src/prompt-box.vala @@ -394,7 +394,7 @@ public class PromptBox : FadableBox if (option_button == null) return; - option_image.pixbuf = image; + option_image.set_pixbuf (image); if (tooltip == null) option_image.set_tooltip_text(""); diff --git a/src/session-list.vala b/src/session-list.vala index 047b86e..eef234b 100644 --- a/src/session-list.vala +++ b/src/session-list.vala @@ -79,6 +79,8 @@ public class SessionList : GreeterList private SessionPrompt prompt; + private const int BADGE_SIZE = 22; + public SessionList (Background bg, MenuBar mb, string? session, string? default_session) { Object (background: bg, menubar: mb, session: session, default_session: default_session); @@ -227,7 +229,8 @@ public class SessionList : GreeterList { try { - pixbuf = new Gdk.Pixbuf.from_file (Path.build_filename (Config.PKGDATADIR, name, null)); + pixbuf = new Gdk.Pixbuf.from_file_at_size (Path.build_filename (Config.PKGDATADIR, name, null), + BADGE_SIZE * _scale_factor, BADGE_SIZE * _scale_factor); badges.insert (name, pixbuf); } catch (Error e) -- cgit v1.2.3