Skip to content

Commit

Permalink
gtk-utils: set icon changes (#244)
Browse files Browse the repository at this point in the history
* gtk-utils: set_image_icon use both theme and filesystem
gtk-utils: set_image_icon stores at double necessary scale to allow unblurred scaling

* uncrustify

* gtk-util: choose 'image-missing' fallback if possible
  • Loading branch information
trigg authored Apr 26, 2024
1 parent dffc9d8 commit 6028fd0
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/util/gtk-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,36 @@ void set_image_icon(Gtk::Image& image, std::string icon_name, int size,
{
int scale = ((options.user_scale == -1) ?
image.get_scale_factor() : options.user_scale);

/* Create surface above necessary scale to allow zoom effects */
scale = scale * 2;
int scaled_size = size * scale;

if (!icon_theme->lookup_icon(icon_name, scaled_size))
Glib::RefPtr<Gdk::Pixbuf> pbuff = {};
/* Get from theme if possible */
if (icon_theme->lookup_icon(icon_name, scaled_size))
{
std::cerr << "Failed to load icon \"" << icon_name << "\"" << std::endl;
return;
pbuff = icon_theme->load_icon(icon_name, scaled_size, Gtk::ICON_LOOKUP_FORCE_SIZE)
->scale_simple(scaled_size, scaled_size, Gdk::INTERP_BILINEAR);
}

auto pbuff = icon_theme->load_icon(icon_name, scaled_size, Gtk::ICON_LOOKUP_FORCE_SIZE)
->scale_simple(scaled_size, scaled_size, Gdk::INTERP_BILINEAR);
/* Get from filesystem if necessary */
if (!pbuff)
{
pbuff = load_icon_pixbuf_safe(icon_name, scaled_size);
}

if (!pbuff)
{
if (icon_theme->lookup_icon("image-missing", scaled_size))
{
pbuff = icon_theme->load_icon("image-missing", scaled_size, Gtk::ICON_LOOKUP_FORCE_SIZE)
->scale_simple(scaled_size, scaled_size, Gdk::INTERP_BILINEAR);
} else
{
return;
}
}

if (options.invert)
{
Expand Down

0 comments on commit 6028fd0

Please sign in to comment.