diff options
author | Kevin <[email protected]> | 2024-10-16 00:49:16 -0300 |
---|---|---|
committer | Kevin <[email protected]> | 2024-10-16 00:49:16 -0300 |
commit | 2b1e8501b46056b79d97e90c6ec94e3ad36d0ab2 (patch) | |
tree | 6486e98bd1ba523b1aeb4bd2566d1ff6e5c41798 /core/src/widget/icon.vala | |
parent | 03f2c4706faba7dac5aee71b10255eac218cbeec (diff) | |
parent | 236487001ab2a6c9c8e87e5db0ced9e5ab3ed791 (diff) |
Merge branch 'adapt-upstream-changes'
Diffstat (limited to 'core/src/widget/icon.vala')
-rw-r--r-- | core/src/widget/icon.vala | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/core/src/widget/icon.vala b/core/src/widget/icon.vala deleted file mode 100644 index 4f1c7f1..0000000 --- a/core/src/widget/icon.vala +++ /dev/null @@ -1,107 +0,0 @@ -namespace Astal { -public Gtk.IconInfo? lookup_icon(string icon) { - var theme = Gtk.IconTheme.get_default(); - return theme.lookup_icon(icon, 16, Gtk.IconLookupFlags.USE_BUILTIN); -} - -public class Icon : Gtk.Image { - private IconType type = IconType.NAMED; - private double size { get; set; default = 14; } - - public new Gdk.Pixbuf pixbuf { get; set; } - public string icon { get; set; default = ""; } - public GLib.Icon g_icon {get; set;} - - private async void display_icon() { - switch(type) { - case IconType.NAMED: - icon_name = icon; - pixel_size = (int)size; - break; - case IconType.FILE: - try { - var file = File.new_for_path(icon); - var stream = yield file.read_async(); - var pb = yield new Gdk.Pixbuf.from_stream_at_scale_async( - stream, - (int)size * scale_factor, - (int)size * scale_factor, - true, - null - ); - var cs = Gdk.cairo_surface_create_from_pixbuf(pb, 0, this.get_window()); - set_from_surface(cs); - } catch (Error err) { - printerr(err.message); - } - break; - case IconType.PIXBUF: - var pb_scaled = pixbuf.scale_simple( - (int)size * scale_factor, - (int)size * scale_factor, - Gdk.InterpType.BILINEAR - ); - if (pb_scaled != null) { - var cs = Gdk.cairo_surface_create_from_pixbuf(pb_scaled, 0, this.get_window()); - set_from_surface(cs); - } - break; - case IconType.GICON: - pixel_size = (int)size; - gicon = g_icon; - break; - - } - } - - static construct { - set_css_name("icon"); - } - - construct { - notify["icon"].connect(() => { - if(FileUtils.test(icon, GLib.FileTest.EXISTS)) - type = IconType.FILE; - else if (lookup_icon(icon) != null) - type = IconType.NAMED; - else { - type = IconType.NAMED; - warning("cannot assign %s as icon, "+ - "it is not a file nor a named icon", icon); - } - display_icon.begin(); - }); - - notify["pixbuf"].connect(() => { - type = IconType.PIXBUF; - display_icon.begin(); - }); - - notify["g-icon"].connect(() => { - type = IconType.GICON; - display_icon.begin(); - }); - - size_allocate.connect(() => { - size = get_style_context() - .get_property("font-size", Gtk.StateFlags.NORMAL).get_double(); - - display_icon.begin(); - }); - - get_style_context().changed.connect(() => { - size = get_style_context() - .get_property("font-size", Gtk.StateFlags.NORMAL).get_double(); - - display_icon.begin(); - }); - } -} - -private enum IconType { - NAMED, - FILE, - PIXBUF, - GICON, -} -} |