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 | |
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')
-rw-r--r-- | src/cached-image.vala | 35 | ||||
-rw-r--r-- | src/greeter-list.vala | 4 | ||||
-rw-r--r-- | src/prompt-box.vala | 2 | ||||
-rw-r--r-- | src/session-list.vala | 5 |
4 files changed, 27 insertions, 19 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); } } 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) |