From 30cd08ec5dfa1babd86e75e6c248d8baabdf6987 Mon Sep 17 00:00:00 2001 From: Nick Logozzo Date: Sun, 28 Jan 2024 15:16:52 -0500 Subject: [PATCH] Taskbar - Linux Fixes --- include/taskbar/taskbaritem.h | 1 + src/taskbar/taskbaritem.cpp | 16 +++++++++++----- tests/taskbartests.cpp | 5 +++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/taskbar/taskbaritem.h b/include/taskbar/taskbaritem.h index dad913e..79b720d 100644 --- a/include/taskbar/taskbaritem.h +++ b/include/taskbar/taskbaritem.h @@ -110,6 +110,7 @@ namespace Nickvision::Taskbar ULONG_PTR m_gdi; #elif defined(__linux__) GDBusConnection* m_connection; + std::string m_objectPath; std::string m_appUri; #endif }; diff --git a/src/taskbar/taskbaritem.cpp b/src/taskbar/taskbaritem.cpp index 0200b78..22db122 100644 --- a/src/taskbar/taskbaritem.cpp +++ b/src/taskbar/taskbaritem.cpp @@ -57,7 +57,7 @@ namespace Nickvision::Taskbar #elif defined(__linux__) if (m_connection) { - GDBusMessage* message{ g_dbus_message_new_signal("/", "com.canonical.Unity.LauncherEntry", "Update") }; + GDBusMessage* message{ g_dbus_message_new_signal(m_objectPath.c_str(), "com.canonical.Unity.LauncherEntry", "Update") }; GVariant* params[2]{ g_variant_new_string(m_appUri.c_str()), g_variant_new_dict_entry(g_variant_new_string("progress-visible"), g_variant_new_boolean(m_progressState >= ProgressState::Normal)) }; GVariant* tuple{ g_variant_new_tuple(params, 2) }; g_dbus_message_set_body(message, tuple); @@ -85,7 +85,7 @@ namespace Nickvision::Taskbar #elif defined(__linux__) if (m_connection) { - GDBusMessage* message{ g_dbus_message_new_signal("/", "com.canonical.Unity.LauncherEntry", "Update") }; + GDBusMessage* message{ g_dbus_message_new_signal(m_objectPath.c_str(), "com.canonical.Unity.LauncherEntry", "Update") }; GVariant* params[2]{ g_variant_new_string(m_appUri.c_str()), g_variant_new_dict_entry(g_variant_new_string("progress"), g_variant_new_double(m_progress)) }; GVariant* tuple{ g_variant_new_tuple(params, 2) }; g_dbus_message_set_body(message, tuple); @@ -121,7 +121,7 @@ namespace Nickvision::Taskbar #elif defined(__linux__) if (m_connection) { - GDBusMessage* message{ g_dbus_message_new_signal("/", "com.canonical.Unity.LauncherEntry", "Update") }; + GDBusMessage* message{ g_dbus_message_new_signal(m_objectPath.c_str(), "com.canonical.Unity.LauncherEntry", "Update") }; GVariant* params[2]{ g_variant_new_string(m_appUri.c_str()), g_variant_new_dict_entry(g_variant_new_string("urgent"), g_variant_new_boolean(m_urgent)) }; GVariant* tuple{ g_variant_new_tuple(params, 2) }; g_dbus_message_set_body(message, tuple); @@ -173,7 +173,7 @@ namespace Nickvision::Taskbar #elif defined(__linux__) if (m_connection) { - GDBusMessage* message{ g_dbus_message_new_signal("/", "com.canonical.Unity.LauncherEntry", "Update") }; + GDBusMessage* message{ g_dbus_message_new_signal(m_objectPath.c_str(), "com.canonical.Unity.LauncherEntry", "Update") }; GVariant* params[2]{ g_variant_new_string(m_appUri.c_str()), g_variant_new_dict_entry(g_variant_new_string("count-visible"), g_variant_new_boolean(m_countVisible)) }; GVariant* tuple{ g_variant_new_tuple(params, 2) }; g_dbus_message_set_body(message, tuple); @@ -196,7 +196,7 @@ namespace Nickvision::Taskbar #ifdef __linux__ if (m_connection) { - GDBusMessage* message{ g_dbus_message_new_signal("/", "com.canonical.Unity.LauncherEntry", "Update") }; + GDBusMessage* message{ g_dbus_message_new_signal(m_objectPath.c_str(), "com.canonical.Unity.LauncherEntry", "Update") }; GVariant* params[2]{ g_variant_new_string(m_appUri.c_str()), g_variant_new_dict_entry(g_variant_new_string("count"), g_variant_new_int64(m_count)) }; GVariant* tuple{ g_variant_new_tuple(params, 2) }; g_dbus_message_set_body(message, tuple); @@ -242,6 +242,12 @@ namespace Nickvision::Taskbar m_connection = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); //returns a singleton, no need to manage it if (m_connection) { + unsigned long hash{ 5381 }; + for(char c : desktopFile) + { + hash = (hash << 5) + hash + c; + } + m_objectPath = "/com/canonical/unity/launcherentry/" + std::to_string(hash); m_appUri = "application://" + desktopFile; return true; } diff --git a/tests/taskbartests.cpp b/tests/taskbartests.cpp index d470d0b..6c0acb8 100644 --- a/tests/taskbartests.cpp +++ b/tests/taskbartests.cpp @@ -25,6 +25,11 @@ TEST_F(TaskbarTest, ConnectWindows) ASSERT_TRUE(m_taskbar->connect(hwnd)); } } +#elif defined(__linux__) +TEST_F(TaskbarTest, ConnectLinux) +{ + ASSERT_TRUE(m_taskbar->connect("firefox.desktop")); +} #endif TEST_F(TaskbarTest, SetProgress)