Merge pull request #3941 from ChaosInfinited/features/systray-custom-icons
Features/systray custom icons
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
#include "modules/sni/item.hpp"
|
||||
#include "modules/sni/icon_manager.hpp"
|
||||
|
||||
#include <gdkmm/general.h>
|
||||
#include <glibmm/main.h>
|
||||
@ -7,6 +8,7 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <filesystem>
|
||||
|
||||
#include "gdk/gdk.h"
|
||||
#include "util/format.hpp"
|
||||
@ -138,6 +140,7 @@ void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) {
|
||||
category = get_variant<std::string>(value);
|
||||
} else if (name == "Id") {
|
||||
id = get_variant<std::string>(value);
|
||||
setCustomIcon(id);
|
||||
} else if (name == "Title") {
|
||||
title = get_variant<std::string>(value);
|
||||
if (tooltip.text.empty()) {
|
||||
@ -199,6 +202,19 @@ void Item::setStatus(const Glib::ustring& value) {
|
||||
style->add_class(lower);
|
||||
}
|
||||
|
||||
void Item::setCustomIcon(const std::string& id) {
|
||||
std::string custom_icon = IconManager::instance().getIconForApp(id);
|
||||
if (!custom_icon.empty()) {
|
||||
if (std::filesystem::exists(custom_icon)) {
|
||||
Glib::RefPtr<Gdk::Pixbuf> custom_pixbuf = Gdk::Pixbuf::create_from_file(custom_icon);
|
||||
icon_name = ""; // icon_name has priority over pixmap
|
||||
icon_pixmap = custom_pixbuf;
|
||||
} else { // if file doesn't exist it's most likely an icon_name
|
||||
icon_name = custom_icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Item::getUpdatedProperties() {
|
||||
auto params = Glib::VariantContainerBase::create_tuple(
|
||||
{Glib::Variant<Glib::ustring>::create(SNI_INTERFACE_NAME)});
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "modules/sni/tray.hpp"
|
||||
#include "modules/sni/icon_manager.hpp"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
@ -20,6 +21,9 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
box_.set_spacing(config_["spacing"].asUInt());
|
||||
}
|
||||
nb_hosts_ += 1;
|
||||
if (config_["icons"].isObject()) {
|
||||
IconManager::instance().setIconsConfig(config_["icons"]);
|
||||
}
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user