From d2d9db23b52bfa88a84944a6c97890c373f5796f Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 17 May 2019 14:23:52 +0200 Subject: [PATCH] fix: uninitialized bool --- include/modules/sni/item.hpp | 6 ++--- src/modules/sni/item.cpp | 45 ++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/include/modules/sni/item.hpp b/include/modules/sni/item.hpp index 6706e32b..c8f835bd 100644 --- a/include/modules/sni/item.hpp +++ b/include/modules/sni/item.hpp @@ -46,7 +46,7 @@ class Item : public sigc::trackable { std::string menu; DbusmenuGtkMenu* dbus_menu = nullptr; Gtk::Menu* gtk_menu = nullptr; - bool item_is_menu; + bool item_is_menu = false; private: void proxyReady(Glib::RefPtr& result); @@ -59,8 +59,8 @@ class Item : public sigc::trackable { void updateImage(); Glib::RefPtr extractPixBuf(GVariant* variant); Glib::RefPtr getIconByName(const std::string& name, int size); - static void onMenuDestroyed(Item* self); - bool makeMenu(GdkEventButton* const& ev); + static void onMenuDestroyed(Item* self, GObject* old_menu_pointer); + void makeMenu(GdkEventButton* const& ev); bool handleClick(GdkEventButton* const& /*ev*/); Glib::RefPtr proxy_; diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index cfb5fef0..106b0611 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -276,39 +276,38 @@ Glib::RefPtr Item::getIconByName(const std::string& name, int reque name.c_str(), tmp_size, Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE); } -void Item::onMenuDestroyed(Item* self) { - self->gtk_menu = nullptr; - self->dbus_menu = nullptr; +void Item::onMenuDestroyed(Item* self, GObject* old_menu_pointer) { + if (old_menu_pointer == reinterpret_cast(self->dbus_menu)) { + self->gtk_menu = nullptr; + self->dbus_menu = nullptr; + } } -bool Item::makeMenu(GdkEventButton* const& ev) { - if (gtk_menu == nullptr) { - if (!menu.empty()) { - dbus_menu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data()); - if (dbus_menu != nullptr) { - g_object_ref_sink(G_OBJECT(dbus_menu)); - g_object_weak_ref(G_OBJECT(dbus_menu), (GWeakNotify)onMenuDestroyed, this); - gtk_menu = Glib::wrap(GTK_MENU(dbus_menu)); - gtk_menu->attach_to_widget(event_box); - } +void Item::makeMenu(GdkEventButton* const& ev) { + if (gtk_menu == nullptr && !menu.empty()) { + dbus_menu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data()); + if (dbus_menu != nullptr) { + g_object_ref_sink(G_OBJECT(dbus_menu)); + g_object_weak_ref(G_OBJECT(dbus_menu), (GWeakNotify)onMenuDestroyed, this); + gtk_menu = Glib::wrap(GTK_MENU(dbus_menu)); + gtk_menu->attach_to_widget(event_box); } } - if (gtk_menu != nullptr) { -#if GTK_CHECK_VERSION(3, 22, 0) - gtk_menu->popup_at_pointer(reinterpret_cast(ev)); -#else - gtk_menu->popup(ev->button, ev->time); -#endif - return true; - } - return false; } 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) { - if (!makeMenu(ev)) { + makeMenu(ev); + if (gtk_menu != nullptr) { +#if GTK_CHECK_VERSION(3, 22, 0) + gtk_menu->popup_at_pointer(reinterpret_cast(ev)); +#else + gtk_menu->popup(ev->button, ev->time); +#endif + return true; + } else { proxy_->call("ContextMenu", parameters); return true; }