Skip to content

Commit

Permalink
Taskbar - Linux Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Jan 28, 2024
1 parent 9b19845 commit 30cd08e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/taskbar/taskbaritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
16 changes: 11 additions & 5 deletions src/taskbar/taskbaritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/taskbartests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 30cd08e

Please sign in to comment.