diff --git a/src/posix_dbus.c b/src/posix_dbus.c index 0306323f..701eac5e 100644 --- a/src/posix_dbus.c +++ b/src/posix_dbus.c @@ -30,6 +30,10 @@ #include "internal.h" +#include +#include +#include + void _glfwInitDBusPOSIX(void) { //Initialize DBus library functions @@ -124,3 +128,92 @@ void _glfwTerminateDBusPOSIX(void) _glfw.dbus.handle = NULL; } } + +void _glfwUpdateTaskbarProgressDBusPOSIX(dbus_bool_t progressVisible, double progressValue) +{ + if(!_glfw.dbus.handle || !_glfw.dbus.connection) + return; + + //Signal signature: + //signal com.canonical.Unity.LauncherEntry.Update (in s app_uri, in a{sv} properties) + + struct DBusMessageIter args; + memset(&args, 0, sizeof(args)); + + //Get name of the running executable + char exeName[PATH_MAX]; + memset(exeName, 0, sizeof(char) * PATH_MAX); + if(readlink("/proc/self/exe", exeName, PATH_MAX) == -1) + { + _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to get name of the running executable"); + return; + } + char* exeNameEnd = strchr(exeName, '\0'); + char* lastFound = strrchr(exeName, '/'); + if(!lastFound || !exeNameEnd) + { + _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to get name of the running executable"); + return; + } + unsigned int exeNameLength = (exeNameEnd - lastFound) - 1; + + //Create our final desktop file uri + unsigned int desktopFileLength = strlen("application://") + exeNameLength + strlen(".desktop") + 1; + char desktopFile[desktopFileLength]; + memset(desktopFile, 0, sizeof(char) * desktopFileLength); + strcpy(desktopFile, "application://"); + memcpy(desktopFile + strlen("application://"), lastFound + 1, exeNameLength); + strcpy(desktopFile + strlen("application://") + (exeNameLength), ".desktop"); + desktopFile[desktopFileLength - 1] = '\0'; + + DBusMessage* msg = dbus_message_new_signal("/org/glfw", "com.canonical.Unity.LauncherEntry", "Update"); + if(!msg) + { + _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to create new DBus message"); + return; + } + + dbus_message_iter_init_append(msg, &args); + + //Setup app_uri parameter + const char* desktopFileStr = desktopFile; + dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &desktopFileStr); + + //Set properties parameter + struct DBusMessageIter sub1, sub2, sub3; + memset(&sub1, 0, sizeof(sub1)); + memset(&sub2, 0, sizeof(sub2)); + memset(&sub3, 0, sizeof(sub3)); + + dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, "{sv}", &sub1); + + //Set progress visible property + dbus_message_iter_open_container(&sub1, DBUS_TYPE_DICT_ENTRY, NULL, &sub2); + const char* progressVisibleStr = "progress-visible"; + dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &progressVisibleStr); + dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, "b", &sub3); + dbus_message_iter_append_basic(&sub3, DBUS_TYPE_BOOLEAN, &progressVisible); + dbus_message_iter_close_container(&sub2, &sub3); + dbus_message_iter_close_container(&sub1, &sub2); + + //Set progress value property + dbus_message_iter_open_container(&sub1, DBUS_TYPE_DICT_ENTRY, NULL, &sub2); + const char* progressValueStr = "progress"; + dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &progressValueStr); + dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, "d", &sub3); + dbus_message_iter_append_basic(&sub3, DBUS_TYPE_DOUBLE, &progressValue); + dbus_message_iter_close_container(&sub2, &sub3); + dbus_message_iter_close_container(&sub1, &sub2); + + dbus_message_iter_close_container(&args, &sub1); + + //Finally send the signal + unsigned int serial = 0; + if(!dbus_connection_send(_glfw.dbus.connection, msg, &serial)) + _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to send DBus message"); + else + dbus_connection_flush(_glfw.dbus.connection); + + //Free the message + dbus_message_unref(msg); +} diff --git a/src/posix_dbus.h b/src/posix_dbus.h index 58cc13ee..82d81bbb 100644 --- a/src/posix_dbus.h +++ b/src/posix_dbus.h @@ -129,3 +129,4 @@ typedef struct _GLFWDBusPOSIX void _glfwInitDBusPOSIX(void); void _glfwTerminateDBusPOSIX(void); +void _glfwUpdateTaskbarProgressDBusPOSIX(dbus_bool_t progressVisible, double progressValue); diff --git a/src/wl_window.c b/src/wl_window.c index c25058aa..97232140 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1902,96 +1902,12 @@ void _glfwSetWindowIconWayland(_GLFWwindow* window, "Wayland: The platform does not support setting the window icon"); } -void _glfwSetWindowTaskbarProgress(_GLFWwindow* window, const int progressState, int completed) +void _glfwSetWindowTaskbarProgress(_GLFWwindow* /*window*/, const int progressState, int completed) { - if(!_glfw.dbus.handle || !_glfw.dbus.connection) - return; - - //Signal signature: - //signal com.canonical.Unity.LauncherEntry.Update (in s app_uri, in a{sv} properties) - const dbus_bool_t progressVisible = (taskbarState != GLFW_TASKBAR_PROGRESS_NOPROGRESS); const double progressValue = (double)completed / 100.0; - struct DBusMessageIter args; - memset(&args, 0, sizeof(args)); - - //Get name of the running executable - char exeName[PATH_MAX]; - memset(exeName, 0, sizeof(char) * PATH_MAX); - if(readlink("/proc/self/exe", exeName, PATH_MAX) == -1) - { - _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to get name of the running executable"); - return; - } - char* exeNameEnd = strchr(exeName, '\0'); - char* lastFound = strrchr(exeName, '/'); - if(!lastFound || !exeNameEnd) - { - _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to get name of the running executable"); - return; - } - unsigned int exeNameLength = (exeNameEnd - lastFound) - 1; - - //Create our final desktop file uri - unsigned int desktopFileLength = strlen("application://") + exeNameLength + strlen(".desktop") + 1; - char desktopFile[desktopFileLength]; - memset(desktopFile, 0, sizeof(char) * desktopFileLength); - strcpy(desktopFile, "application://"); - memcpy(desktopFile + strlen("application://"), lastFound + 1, exeNameLength); - strcpy(desktopFile + strlen("application://") + (exeNameLength), ".desktop"); - desktopFile[desktopFileLength - 1] = '\0'; - - DBusMessage* msg = dbus_message_new_signal("/org/glfw", "com.canonical.Unity.LauncherEntry", "Update"); - if(!msg) - { - _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to create new DBus message"); - return; - } - - dbus_message_iter_init_append(msg, &args); - - //Setup app_uri parameter - const char* desktopFileStr = desktopFile; - dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &desktopFileStr); - - //Set properties parameter - struct DBusMessageIter sub1, sub2, sub3; - memset(&sub1, 0, sizeof(sub1)); - memset(&sub2, 0, sizeof(sub2)); - memset(&sub3, 0, sizeof(sub3)); - - dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, "{sv}", &sub1); - - //Set progress visible property - dbus_message_iter_open_container(&sub1, DBUS_TYPE_DICT_ENTRY, NULL, &sub2); - const char* progressVisibleStr = "progress-visible"; - dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &progressVisibleStr); - dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, "b", &sub3); - dbus_message_iter_append_basic(&sub3, DBUS_TYPE_BOOLEAN, &progressVisible); - dbus_message_iter_close_container(&sub2, &sub3); - dbus_message_iter_close_container(&sub1, &sub2); - - //Set progress value property - dbus_message_iter_open_container(&sub1, DBUS_TYPE_DICT_ENTRY, NULL, &sub2); - const char* progressValueStr = "progress"; - dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &progressValueStr); - dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, "d", &sub3); - dbus_message_iter_append_basic(&sub3, DBUS_TYPE_DOUBLE, &progressValue); - dbus_message_iter_close_container(&sub2, &sub3); - dbus_message_iter_close_container(&sub1, &sub2); - - dbus_message_iter_close_container(&args, &sub1); - - //Finally send the signal - unsigned int serial = 0; - if(!dbus_connection_send(_glfw.dbus.connection, msg, &serial)) - _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to send DBus message"); - else - dbus_connection_flush(_glfw.dbus.connection); - - //Free the message - dbus_message_unref(msg); + _glfwUpdateTaskbarProgressDBusPOSIX(progressVisible, progressValue); } void _glfwGetWindowPosWayland(_GLFWwindow* window, int* xpos, int* ypos) diff --git a/src/x11_window.c b/src/x11_window.c index 41f51f9c..0a5e8dfc 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2154,94 +2154,10 @@ void _glfwSetWindowIconX11(_GLFWwindow* window, int count, const GLFWimage* imag void _glfwSetWindowTaskbarProgressX11(_GLFWwindow* /*window*/, const int taskbarState, int completed) { - if(!_glfw.dbus.handle || !_glfw.dbus.connection) - return; - - //Signal signature: - //signal com.canonical.Unity.LauncherEntry.Update (in s app_uri, in a{sv} properties) - const dbus_bool_t progressVisible = (taskbarState != GLFW_TASKBAR_PROGRESS_NOPROGRESS); const double progressValue = (double)completed / 100.0; - struct DBusMessageIter args; - memset(&args, 0, sizeof(args)); - - //Get name of the running executable - char exeName[PATH_MAX]; - memset(exeName, 0, sizeof(char) * PATH_MAX); - if(readlink("/proc/self/exe", exeName, PATH_MAX) == -1) - { - _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to get name of the running executable"); - return; - } - char* exeNameEnd = strchr(exeName, '\0'); - char* lastFound = strrchr(exeName, '/'); - if(!lastFound || !exeNameEnd) - { - _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to get name of the running executable"); - return; - } - unsigned int exeNameLength = (exeNameEnd - lastFound) - 1; - - //Create our final desktop file uri - unsigned int desktopFileLength = strlen("application://") + exeNameLength + strlen(".desktop") + 1; - char desktopFile[desktopFileLength]; - memset(desktopFile, 0, sizeof(char) * desktopFileLength); - strcpy(desktopFile, "application://"); - memcpy(desktopFile + strlen("application://"), lastFound + 1, exeNameLength); - strcpy(desktopFile + strlen("application://") + (exeNameLength), ".desktop"); - desktopFile[desktopFileLength - 1] = '\0'; - - DBusMessage* msg = dbus_message_new_signal("/org/glfw", "com.canonical.Unity.LauncherEntry", "Update"); - if(!msg) - { - _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to create new DBus message"); - return; - } - - dbus_message_iter_init_append(msg, &args); - - //Setup app_uri parameter - const char* desktopFileStr = desktopFile; - dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &desktopFileStr); - - //Set properties parameter - struct DBusMessageIter sub1, sub2, sub3; - memset(&sub1, 0, sizeof(sub1)); - memset(&sub2, 0, sizeof(sub2)); - memset(&sub3, 0, sizeof(sub3)); - - dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, "{sv}", &sub1); - - //Set progress visible property - dbus_message_iter_open_container(&sub1, DBUS_TYPE_DICT_ENTRY, NULL, &sub2); - const char* progressVisibleStr = "progress-visible"; - dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &progressVisibleStr); - dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, "b", &sub3); - dbus_message_iter_append_basic(&sub3, DBUS_TYPE_BOOLEAN, &progressVisible); - dbus_message_iter_close_container(&sub2, &sub3); - dbus_message_iter_close_container(&sub1, &sub2); - - //Set progress value property - dbus_message_iter_open_container(&sub1, DBUS_TYPE_DICT_ENTRY, NULL, &sub2); - const char* progressValueStr = "progress"; - dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &progressValueStr); - dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, "d", &sub3); - dbus_message_iter_append_basic(&sub3, DBUS_TYPE_DOUBLE, &progressValue); - dbus_message_iter_close_container(&sub2, &sub3); - dbus_message_iter_close_container(&sub1, &sub2); - - dbus_message_iter_close_container(&args, &sub1); - - //Finally send the signal - unsigned int serial = 0; - if(!dbus_connection_send(_glfw.dbus.connection, msg, &serial)) - _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to send DBus message"); - else - dbus_connection_flush(_glfw.dbus.connection); - - //Free the message - dbus_message_unref(msg); + _glfwUpdateTaskbarProgressDBusPOSIX(progressVisible, progressValue); } void _glfwGetWindowPosX11(_GLFWwindow* window, int* xpos, int* ypos)