SNI: Fall back to Title when ToolTip isn't set

This adds a way to filter items, which don't have a nice object path nor
a tooltip.
https://github.com/scorpion-26/gBar/issues/92#issuecomment-2089845752
This commit is contained in:
scorpion-26 2024-05-02 11:15:26 +02:00
parent b3f037db5b
commit 808d6d5989

View file

@ -11,6 +11,7 @@
#include <libdbusmenu-gtk/menu.h> #include <libdbusmenu-gtk/menu.h>
#include <cstdio> #include <cstdio>
#include <filesystem>
#include <unordered_set> #include <unordered_set>
namespace SNI namespace SNI
@ -152,10 +153,31 @@ namespace SNI
{ {
LOG("SNI: Error querying tooltip"); LOG("SNI: Error querying tooltip");
} }
LOG("SNI: Title: " << data->item.tooltip); LOG("SNI: Tooltip: " << data->item.tooltip);
g_variant_unref(tooltip); g_variant_unref(tooltip);
} }
if (data->item.tooltip.empty())
{
LOG("SNI: No tooltip found, using title as tooltip");
// No tooltip, use title as tooltip
GVariant* title = getProperty("Title");
if (title)
{
const gchar* titleStr = g_variant_get_string(title, nullptr);
if (titleStr != nullptr)
{
data->item.tooltip = titleStr;
}
else
{
LOG("SNI: Error querying title");
}
LOG("SNI: Fallback tooltip: " << data->item.tooltip);
g_variant_unref(title);
}
}
// Query menu // Query menu
GVariant* menuPath = getProperty("Menu"); GVariant* menuPath = getProperty("Menu");
if (menuPath) if (menuPath)