mainwindow: scale icons to sane size

If load_icon() fails, we treat the icon name as a file path and try to
load an image from the path. In case that works, we need to ensure that
the has correct size. Previously that wasn't done, which led to too
large icons.

scale_simple() doesn't do anything if the image is already the correct
size, so we can call it unconditionally.

The exception handling was a bit weird in that the exception types
didn't match the documentation of IconTheme::load_icon() and
Image::set(). I updated the exception types (Image::set() doesn't need
exception handling any more, because now it's called with a Pixbuf
rather than a file name).

Fixes: https://gitlab.freedesktop.org/pulseaudio/pavucontrol/issues/60
This commit is contained in:
Tanu Kaskinen 2019-07-27 13:53:48 +03:00
parent a6d2c8450a
commit e6caa8b87a
1 changed files with 16 additions and 10 deletions

View File

@ -283,17 +283,23 @@ static void set_icon_name_fallback(Gtk::Image *i, const char *name, Gtk::IconSiz
try { try {
pixbuf = theme->load_icon(name, width, Gtk::ICON_LOOKUP_GENERIC_FALLBACK | Gtk::ICON_LOOKUP_FORCE_SIZE); pixbuf = theme->load_icon(name, width, Gtk::ICON_LOOKUP_GENERIC_FALLBACK | Gtk::ICON_LOOKUP_FORCE_SIZE);
} catch (Glib::Error &e) {
/* Ignore errors. */
}
if (pixbuf) if (!pixbuf) {
i->set(pixbuf); try {
else pixbuf = Gdk::Pixbuf::create_from_file(name);
i->set(name); } catch (Glib::FileError &e) {
} catch (Gtk::IconThemeError &e) { /* Ignore errors. */
i->set(name); } catch (Gdk::PixbufError &e) {
} catch (Gio::Error &e) { /* Ignore errors. */
i->set(name); }
} catch (Gdk::PixbufError &e) { }
i->set(name);
if (pixbuf) {
pixbuf = pixbuf->scale_simple(width, height, Gdk::INTERP_BILINEAR);
i->set(pixbuf);
} }
} }