From e6caa8b87a9b463ea0db85deb77bac3d960ff1f1 Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Sat, 27 Jul 2019 13:53:48 +0300 Subject: [PATCH] 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 --- src/mainwindow.cc | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 6fa3480..4b1cb8a 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -283,17 +283,23 @@ static void set_icon_name_fallback(Gtk::Image *i, const char *name, Gtk::IconSiz try { pixbuf = theme->load_icon(name, width, Gtk::ICON_LOOKUP_GENERIC_FALLBACK | Gtk::ICON_LOOKUP_FORCE_SIZE); + } catch (Glib::Error &e) { + /* Ignore errors. */ + } - if (pixbuf) - i->set(pixbuf); - else - i->set(name); - } catch (Gtk::IconThemeError &e) { - i->set(name); - } catch (Gio::Error &e) { - i->set(name); - } catch (Gdk::PixbufError &e) { - i->set(name); + if (!pixbuf) { + try { + pixbuf = Gdk::Pixbuf::create_from_file(name); + } catch (Glib::FileError &e) { + /* Ignore errors. */ + } catch (Gdk::PixbufError &e) { + /* Ignore errors. */ + } + } + + if (pixbuf) { + pixbuf = pixbuf->scale_simple(width, height, Gdk::INTERP_BILINEAR); + i->set(pixbuf); } }