From cdb347aaca5f129748de0f39af31c828cdc768f6 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Mon, 20 May 2019 04:57:41 -0700 Subject: [PATCH 1/4] Add --log-level command line option --- src/client.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/client.cpp b/src/client.cpp index efdcee6c..114b0d28 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -243,10 +243,14 @@ int waybar::Client::main(int argc, char *argv[]) { std::string config; std::string style; std::string bar_id; + std::string log_level; auto cli = clara::detail::Help(show_help) | clara::detail::Opt(show_version)["-v"]["--version"]("Show version") | clara::detail::Opt(config, "config")["-c"]["--config"]("Config path") | clara::detail::Opt(style, "style")["-s"]["--style"]("Style path") | + clara::detail::Opt( + log_level, + "trace|debug|info|warning|error|critical|off")["-l"]["--log-level"]("Log level") | clara::detail::Opt(bar_id, "id")["-b"]["--bar"]("Bar id"); auto res = cli.parse(clara::detail::Args(argc, argv)); if (!res) { @@ -261,6 +265,9 @@ int waybar::Client::main(int argc, char *argv[]) { std::cout << "Waybar v" << VERSION << std::endl; return 0; } + if (!log_level.empty()) { + spdlog::set_level(spdlog::level::from_str(log_level)); + } setupConfigs(config, style); setupConfig(); setupCss(); From 316a9be656d090455efae6134fd74786a045ae30 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Mon, 20 May 2019 05:35:05 -0700 Subject: [PATCH 2/4] refactor(tray): Use spdlog for SNI::Item error messages --- src/modules/sni/item.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index f763758a..72630573 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -54,15 +54,10 @@ void Item::proxyReady(Glib::RefPtr& result) { // this->event_box.set_tooltip_text(this->title); } catch (const Glib::Error& err) { - g_error("Failed to create DBus Proxy for %s %s: %s", - bus_name.c_str(), - object_path.c_str(), - err.what().c_str()); + spdlog::error( + "Failed to create DBus Proxy for {} {}: {}", bus_name, object_path, err.what().raw()); } catch (const std::exception& err) { - g_error("Failed to create DBus Proxy for %s %s: %s", - bus_name.c_str(), - object_path.c_str(), - err.what()); + spdlog::error("Failed to create DBus Proxy for {} {}: {}", bus_name, object_path, err.what()); } } @@ -140,9 +135,9 @@ void Item::processUpdatedProperties(Glib::RefPtr& _result) { this->updateImage(); // this->event_box.set_tooltip_text(this->title); } catch (const Glib::Error& err) { - g_warning("Failed to update properties: %s", err.what().c_str()); + spdlog::warn("Failed to update properties: {}", err.what().raw()); } catch (const std::exception& err) { - g_warning("Failed to update properties: %s", err.what()); + spdlog::warn("Failed to update properties: {}", err.what()); } } From afd291a566f3735e7706e04f85b267cd9f7c0eb4 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Mon, 20 May 2019 05:55:13 -0700 Subject: [PATCH 3/4] fix(tray): Fix glib assertion when old property value is missing xembedsniproxy sets WindowId as 'i' instead of 'u' and DBus::Proxy ignores incorrectly typed value. --- src/modules/sni/item.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index 72630573..9dc463d0 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -126,7 +126,7 @@ void Item::processUpdatedProperties(Glib::RefPtr& _result) { for (const auto& [name, value] : properties) { Glib::VariantBase old_value; proxy_->get_cached_property(old_value, name); - if (!value.equal(old_value)) { + if (!old_value || !value.equal(old_value)) { proxy_->set_cached_property(name, value); setProperty(name, const_cast(value)); } From 50bfe78aed8ea2a90eded038646d887e5481fe18 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Mon, 20 May 2019 08:00:07 -0700 Subject: [PATCH 4/4] refactor(tray): improve error handling and add debug logs --- src/modules/sni/item.cpp | 118 ++++++++++++++++++++++++++------------- 1 file changed, 80 insertions(+), 38 deletions(-) diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index 9dc463d0..8149c350 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -1,6 +1,32 @@ -#include "modules/sni/item.hpp" #include #include +#include "modules/sni/item.hpp" + +template <> +struct fmt::formatter : formatter { + template + auto format(const Glib::ustring& value, FormatContext& ctx) { + return formatter::format(value, ctx); + } +}; + +template <> +struct fmt::formatter : formatter { + bool is_printable(const Glib::VariantBase& value) { + auto type = value.get_type_string(); + /* Print only primitive (single character excluding 'v') and short complex types */ + return (type.length() == 1 && islower(type[0]) && type[0] != 'v') || value.get_size() <= 32; + } + + template + auto format(const Glib::VariantBase& value, FormatContext& ctx) { + if (is_printable(value)) { + return formatter::format(value.print(), ctx); + } else { + return formatter::format(value.get_type_string(), ctx); + } + } +}; namespace waybar::modules::SNI { @@ -54,8 +80,7 @@ void Item::proxyReady(Glib::RefPtr& result) { // this->event_box.set_tooltip_text(this->title); } catch (const Glib::Error& err) { - spdlog::error( - "Failed to create DBus Proxy for {} {}: {}", bus_name, object_path, err.what().raw()); + spdlog::error("Failed to create DBus Proxy for {} {}: {}", bus_name, object_path, err.what()); } catch (const std::exception& err) { spdlog::error("Failed to create DBus Proxy for {} {}: {}", bus_name, object_path, err.what()); } @@ -67,41 +92,57 @@ T get_variant(Glib::VariantBase& value) { } void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) { - if (name == "Category") { - category = get_variant(value); - } else if (name == "Id") { - id = get_variant(value); - } else if (name == "Title") { - title = get_variant(value); - } else if (name == "Status") { - status = get_variant(value); - } else if (name == "WindowId") { - window_id = get_variant(value); - } else if (name == "IconName") { - icon_name = get_variant(value); - } else if (name == "IconPixmap") { - icon_pixmap = this->extractPixBuf(value.gobj()); - } else if (name == "OverlayIconName") { - overlay_icon_name = get_variant(value); - } else if (name == "OverlayIconPixmap") { - // TODO: overlay_icon_pixmap - } else if (name == "AttentionIconName") { - attention_icon_name = get_variant(value); - } else if (name == "AttentionIconPixmap") { - // TODO: attention_icon_pixmap - } else if (name == "AttentionMovieName") { - attention_movie_name = get_variant(value); - } else if (name == "ToolTip") { - // TODO: tooltip - } else if (name == "IconThemePath") { - icon_theme_path = get_variant(value); - if (!icon_theme_path.empty()) { - icon_theme->set_search_path({icon_theme_path}); + try { + spdlog::trace("Set tray item property: {}.{} = {}", id.empty() ? bus_name : id, name, value); + + if (name == "Category") { + category = get_variant(value); + } else if (name == "Id") { + id = get_variant(value); + } else if (name == "Title") { + title = get_variant(value); + } else if (name == "Status") { + status = get_variant(value); + } else if (name == "WindowId") { + window_id = get_variant(value); + } else if (name == "IconName") { + icon_name = get_variant(value); + } else if (name == "IconPixmap") { + icon_pixmap = this->extractPixBuf(value.gobj()); + } else if (name == "OverlayIconName") { + overlay_icon_name = get_variant(value); + } else if (name == "OverlayIconPixmap") { + // TODO: overlay_icon_pixmap + } else if (name == "AttentionIconName") { + attention_icon_name = get_variant(value); + } else if (name == "AttentionIconPixmap") { + // TODO: attention_icon_pixmap + } else if (name == "AttentionMovieName") { + attention_movie_name = get_variant(value); + } else if (name == "ToolTip") { + // TODO: tooltip + } else if (name == "IconThemePath") { + icon_theme_path = get_variant(value); + if (!icon_theme_path.empty()) { + icon_theme->set_search_path({icon_theme_path}); + } + } else if (name == "Menu") { + menu = get_variant(value); + } else if (name == "ItemIsMenu") { + item_is_menu = get_variant(value); } - } else if (name == "Menu") { - menu = get_variant(value); - } else if (name == "ItemIsMenu") { - item_is_menu = get_variant(value); + } catch (const Glib::Error& err) { + spdlog::warn("Failed to set tray item property: {}.{}, value = {}, err = {}", + id.empty() ? bus_name : id, + name, + value, + err.what()); + } catch (const std::exception& err) { + spdlog::warn("Failed to set tray item property: {}.{}, value = {}, err = {}", + id.empty() ? bus_name : id, + name, + value, + err.what()); } } @@ -135,7 +176,7 @@ void Item::processUpdatedProperties(Glib::RefPtr& _result) { this->updateImage(); // this->event_box.set_tooltip_text(this->title); } catch (const Glib::Error& err) { - spdlog::warn("Failed to update properties: {}", err.what().raw()); + spdlog::warn("Failed to update properties: {}", err.what()); } catch (const std::exception& err) { spdlog::warn("Failed to update properties: {}", err.what()); } @@ -143,6 +184,7 @@ void Item::processUpdatedProperties(Glib::RefPtr& _result) { void Item::onSignal(const Glib::ustring& sender_name, const Glib::ustring& signal_name, const Glib::VariantContainerBase& arguments) { + spdlog::trace("Tray item '{}' got signal {}", id, signal_name); if (!update_pending_ && signal_name.compare(0, 3, "New") == 0) { /* Debounce signals and schedule update of all properties. * Based on behavior of Plasma dataengine for StatusNotifierItem.