Merge pull request #4102 from edwin0cheng/style-sym
Use load_symbolic for gtk icon to support styling in tray icon
This commit is contained in:
@ -10,5 +10,7 @@ class DefaultGtkIconThemeWrapper {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static bool has_icon(const std::string&);
|
static bool has_icon(const std::string&);
|
||||||
static Glib::RefPtr<Gdk::Pixbuf> load_icon(const char*, int, Gtk::IconLookupFlags);
|
static Glib::RefPtr<Gdk::Pixbuf> load_icon(
|
||||||
|
const char*, int, Gtk::IconLookupFlags,
|
||||||
|
Glib::RefPtr<Gtk::StyleContext> style = Glib::RefPtr<Gtk::StyleContext>());
|
||||||
};
|
};
|
||||||
|
@ -388,14 +388,17 @@ Glib::RefPtr<Gdk::Pixbuf> Item::getIconPixbuf() {
|
|||||||
Glib::RefPtr<Gdk::Pixbuf> Item::getIconByName(const std::string& name, int request_size) {
|
Glib::RefPtr<Gdk::Pixbuf> Item::getIconByName(const std::string& name, int request_size) {
|
||||||
icon_theme->rescan_if_needed();
|
icon_theme->rescan_if_needed();
|
||||||
|
|
||||||
if (!icon_theme_path.empty() &&
|
if (!icon_theme_path.empty()) {
|
||||||
icon_theme->lookup_icon(name.c_str(), request_size,
|
auto icon_info = icon_theme->lookup_icon(name.c_str(), request_size,
|
||||||
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE)) {
|
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
||||||
return icon_theme->load_icon(name.c_str(), request_size,
|
if (icon_info) {
|
||||||
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
bool is_sym = false;
|
||||||
|
return icon_info.load_symbolic(event_box.get_style_context(), is_sym);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return DefaultGtkIconThemeWrapper::load_icon(name.c_str(), request_size,
|
return DefaultGtkIconThemeWrapper::load_icon(name.c_str(), request_size,
|
||||||
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE,
|
||||||
|
event_box.get_style_context());
|
||||||
}
|
}
|
||||||
|
|
||||||
double Item::getScaledIconSize() {
|
double Item::getScaledIconSize() {
|
||||||
|
@ -15,11 +15,20 @@ bool DefaultGtkIconThemeWrapper::has_icon(const std::string& value) {
|
|||||||
return Gtk::IconTheme::get_default()->has_icon(value);
|
return Gtk::IconTheme::get_default()->has_icon(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::RefPtr<Gdk::Pixbuf> DefaultGtkIconThemeWrapper::load_icon(const char* name, int tmp_size,
|
Glib::RefPtr<Gdk::Pixbuf> DefaultGtkIconThemeWrapper::load_icon(
|
||||||
Gtk::IconLookupFlags flags) {
|
const char* name, int tmp_size, Gtk::IconLookupFlags flags,
|
||||||
|
Glib::RefPtr<Gtk::StyleContext> style) {
|
||||||
const std::lock_guard<std::mutex> lock(default_theme_mutex);
|
const std::lock_guard<std::mutex> lock(default_theme_mutex);
|
||||||
|
|
||||||
auto default_theme = Gtk::IconTheme::get_default();
|
auto default_theme = Gtk::IconTheme::get_default();
|
||||||
default_theme->rescan_if_needed();
|
default_theme->rescan_if_needed();
|
||||||
return default_theme->load_icon(name, tmp_size, flags);
|
|
||||||
|
auto icon_info = default_theme->lookup_icon(name, tmp_size, flags);
|
||||||
|
|
||||||
|
if (style.get() == nullptr) {
|
||||||
|
return icon_info.load_icon();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_sym = false;
|
||||||
|
return icon_info.load_symbolic(style, is_sym);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user