From 39cf17c30f8fbedf5462dd85368c4d683fed3120 Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Wed, 26 Jul 2023 13:28:50 +0200 Subject: [PATCH] SNI: Use our object path for ItemPropertyChanged ItemPropertyChanged is called multiple times per actual icon change. senderName is the same, objectPath is the same, but our registered name for the callback differs. We can't use the provided name for item searching, since that *can* differ from the one we registered with (Looking at you, Discord. Discord registers with org.kde.StatusNotifierItem-*, but calls back with :*.*) Since then the object path will sometimes be wrong for the name, we just use the one from the icon we originally registered with. This causes multiple icons to reload though Potential fix for https://github.com/scorpion-26/gBar/issues/26 --- src/SNI.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/SNI.cpp b/src/SNI.cpp index 2c91225..c1cf16a 100644 --- a/src/SNI.cpp +++ b/src/SNI.cpp @@ -279,16 +279,20 @@ namespace SNI } } - static void ItemPropertyChanged(GDBusConnection*, const char*, const char* object, const char*, const char*, GVariant*, void* name) + static void ItemPropertyChanged(GDBusConnection*, const char* senderName, const char* object, const char*, const char*, GVariant*, void* name) { std::string nameStr = (const char*)name; - LOG("SNI: Reloading " << (const char*)name << " " << object); + LOG("SNI: Reloading " << (const char*)name << " " << object << " (Sender: " << senderName << ")"); // We don't care about *what* changed, just remove and reload auto it = std::find_if(items.begin(), items.end(), [&](const Item& item) { return item.name == nameStr; }); + // We can't trust the object path given to us, since ItemPropertyChanged is called multiple times with the same name, but with different + // object paths. + std::string itemObjectPath = it->object; + LOG("SNI: Actual object path: " << itemObjectPath) if (it != items.end()) { items.erase(it); @@ -297,7 +301,7 @@ namespace SNI { LOG("SNI: Coudn't remove item " << nameStr << " when reloading"); } - clientsToQuery[nameStr] = {nameStr, std::string(object)}; + clientsToQuery[nameStr] = {nameStr, itemObjectPath}; } static TimerResult UpdateWidgets(Box&)