From 01ad3d96d828d2aed852b719358c3efb8e5cc8d8 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Sat, 24 Aug 2019 08:20:32 -0700 Subject: [PATCH] fix(tray): pre-create dbusmenu for tray items It seems that dbusmenu is not ready to display menu immediately and needs some time to sync data via DBus. Fixes LIBDBUSMENU-GLIB-CRITICAL: dbusmenu_menuitem_send_about_to_show: assertion 'DBUSMENU_IS_MENUITEM(mi)' failed. Also fixes initial render of the menu with layer shell popups support patch. --- include/modules/sni/item.hpp | 2 +- src/modules/sni/item.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/modules/sni/item.hpp b/include/modules/sni/item.hpp index a6180db..fc04673 100644 --- a/include/modules/sni/item.hpp +++ b/include/modules/sni/item.hpp @@ -65,7 +65,7 @@ class Item : public sigc::trackable { Glib::RefPtr extractPixBuf(GVariant* variant); Glib::RefPtr getIconByName(const std::string& name, int size); static void onMenuDestroyed(Item* self, GObject* old_menu_pointer); - void makeMenu(GdkEventButton* const& ev); + void makeMenu(); bool handleClick(GdkEventButton* const& /*ev*/); Glib::RefPtr proxy_; diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index 51f9789..bcc66e2 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -128,6 +128,7 @@ void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) { } } else if (name == "Menu") { menu = get_variant(value); + makeMenu(); } else if (name == "ItemIsMenu") { item_is_menu = get_variant(value); } @@ -319,7 +320,7 @@ void Item::onMenuDestroyed(Item* self, GObject* old_menu_pointer) { } } -void Item::makeMenu(GdkEventButton* const& ev) { +void Item::makeMenu() { if (gtk_menu == nullptr && !menu.empty()) { dbus_menu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data()); if (dbus_menu != nullptr) { @@ -335,7 +336,7 @@ bool Item::handleClick(GdkEventButton* const& ev) { auto parameters = Glib::VariantContainerBase::create_tuple( {Glib::Variant::create(ev->x), Glib::Variant::create(ev->y)}); if ((ev->button == 1 && item_is_menu) || ev->button == 3) { - makeMenu(ev); + makeMenu(); if (gtk_menu != nullptr) { #if GTK_CHECK_VERSION(3, 22, 0) gtk_menu->popup_at_pointer(reinterpret_cast(ev));