mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 06:14:35 +00:00
Added caching of desktop file path
This commit is contained in:
parent
d7cc6477ae
commit
e3bcb1e384
116
src/posix_dbus.c
116
src/posix_dbus.c
@ -125,37 +125,13 @@ void _glfwInitDBusPOSIX(void)
|
|||||||
_glfw.dbus.connection = NULL;
|
_glfw.dbus.connection = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_glfwCacheDesktopFilePathPOSIX();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwTerminateDBusPOSIX(void)
|
void _glfwCacheDesktopFilePathPOSIX(void)
|
||||||
{
|
{
|
||||||
if (_glfw.dbus.connection)
|
//Cache path of .desktop file
|
||||||
{
|
|
||||||
dbus_connection_unref(_glfw.dbus.connection);
|
|
||||||
_glfw.dbus.connection = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_glfw.dbus.handle)
|
|
||||||
{
|
|
||||||
_glfwPlatformFreeModule(_glfw.dbus.handle);
|
|
||||||
_glfw.dbus.handle = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _glfwUpdateTaskbarProgressDBusPOSIX(dbus_bool_t progressVisible, double progressValue)
|
|
||||||
{
|
|
||||||
if(!_glfw.dbus.handle || !_glfw.dbus.connection)
|
|
||||||
{
|
|
||||||
_glfwInputError(GLFW_FEATURE_UNAVAILABLE, "POSIX: No DBus connection open to set taskbar progress");
|
|
||||||
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
|
//Get name of the running executable
|
||||||
char exeName[PATH_MAX];
|
char exeName[PATH_MAX];
|
||||||
memset(exeName, 0, sizeof(char) * PATH_MAX);
|
memset(exeName, 0, sizeof(char) * PATH_MAX);
|
||||||
@ -175,12 +151,50 @@ void _glfwUpdateTaskbarProgressDBusPOSIX(dbus_bool_t progressVisible, double pro
|
|||||||
|
|
||||||
//Create our final desktop file uri
|
//Create our final desktop file uri
|
||||||
unsigned int desktopFileLength = strlen("application://") + exeNameLength + strlen(".desktop") + 1;
|
unsigned int desktopFileLength = strlen("application://") + exeNameLength + strlen(".desktop") + 1;
|
||||||
char desktopFile[desktopFileLength];
|
_glfw.dbus.desktopFilePath = _glfw_calloc(desktopFileLength, sizeof(char));
|
||||||
memset(desktopFile, 0, sizeof(char) * desktopFileLength);
|
if(!_glfw.dbus.desktopFilePath)
|
||||||
strcpy(desktopFile, "application://");
|
{
|
||||||
memcpy(desktopFile + strlen("application://"), lastFound + 1, exeNameLength);
|
_glfwInputError(GLFW_OUT_OF_MEMORY, "Failed to allocate memory for .desktop file path");
|
||||||
strcpy(desktopFile + strlen("application://") + (exeNameLength), ".desktop");
|
return;
|
||||||
desktopFile[desktopFileLength - 1] = '\0';
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memset(_glfw.dbus.desktopFilePath, 0, sizeof(char) * desktopFileLength);
|
||||||
|
strcpy(_glfw.dbus.desktopFilePath, "application://");
|
||||||
|
memcpy(_glfw.dbus.desktopFilePath + strlen("application://"), lastFound + 1, exeNameLength);
|
||||||
|
strcpy(_glfw.dbus.desktopFilePath + strlen("application://") + (exeNameLength), ".desktop");
|
||||||
|
_glfw.dbus.desktopFilePath[desktopFileLength - 1] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _glfwTerminateDBusPOSIX(void)
|
||||||
|
{
|
||||||
|
if(_glfw.dbus.desktopFilePath)
|
||||||
|
_glfw_free(_glfw.dbus.desktopFilePath);
|
||||||
|
|
||||||
|
if (_glfw.dbus.connection)
|
||||||
|
{
|
||||||
|
dbus_connection_unref(_glfw.dbus.connection);
|
||||||
|
_glfw.dbus.connection = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_glfw.dbus.handle)
|
||||||
|
{
|
||||||
|
_glfwPlatformFreeModule(_glfw.dbus.handle);
|
||||||
|
_glfw.dbus.handle = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _glfwUpdateTaskbarProgressDBusPOSIX(dbus_bool_t progressVisible, double progressValue)
|
||||||
|
{
|
||||||
|
if(!_glfw.dbus.handle || !_glfw.dbus.connection || !_glfw.dbus.desktopFilePath)
|
||||||
|
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));
|
||||||
|
|
||||||
DBusMessage* msg = dbus_message_new_signal("/org/glfw", "com.canonical.Unity.LauncherEntry", "Update");
|
DBusMessage* msg = dbus_message_new_signal("/org/glfw", "com.canonical.Unity.LauncherEntry", "Update");
|
||||||
if(!msg)
|
if(!msg)
|
||||||
@ -192,8 +206,7 @@ void _glfwUpdateTaskbarProgressDBusPOSIX(dbus_bool_t progressVisible, double pro
|
|||||||
dbus_message_iter_init_append(msg, &args);
|
dbus_message_iter_init_append(msg, &args);
|
||||||
|
|
||||||
//Setup app_uri parameter
|
//Setup app_uri parameter
|
||||||
const char* desktopFileStr = desktopFile;
|
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &_glfw.dbus.desktopFilePath);
|
||||||
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &desktopFileStr);
|
|
||||||
|
|
||||||
//Set properties parameter
|
//Set properties parameter
|
||||||
struct DBusMessageIter sub1, sub2, sub3;
|
struct DBusMessageIter sub1, sub2, sub3;
|
||||||
@ -236,7 +249,7 @@ void _glfwUpdateTaskbarProgressDBusPOSIX(dbus_bool_t progressVisible, double pro
|
|||||||
|
|
||||||
void _glfwUpdateBadgeDBusPOSIX(dbus_bool_t badgeVisible, int badgeCount)
|
void _glfwUpdateBadgeDBusPOSIX(dbus_bool_t badgeVisible, int badgeCount)
|
||||||
{
|
{
|
||||||
if(!_glfw.dbus.handle || !_glfw.dbus.connection)
|
if(!_glfw.dbus.handle || !_glfw.dbus.connection || !_glfw.dbus.desktopFilePath)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
long long badgeCountLL = badgeCount;
|
long long badgeCountLL = badgeCount;
|
||||||
@ -247,32 +260,6 @@ void _glfwUpdateBadgeDBusPOSIX(dbus_bool_t badgeVisible, int badgeCount)
|
|||||||
struct DBusMessageIter args;
|
struct DBusMessageIter args;
|
||||||
memset(&args, 0, sizeof(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");
|
DBusMessage* msg = dbus_message_new_signal("/org/glfw", "com.canonical.Unity.LauncherEntry", "Update");
|
||||||
if(!msg)
|
if(!msg)
|
||||||
{
|
{
|
||||||
@ -283,8 +270,7 @@ void _glfwUpdateBadgeDBusPOSIX(dbus_bool_t badgeVisible, int badgeCount)
|
|||||||
dbus_message_iter_init_append(msg, &args);
|
dbus_message_iter_init_append(msg, &args);
|
||||||
|
|
||||||
//Setup app_uri parameter
|
//Setup app_uri parameter
|
||||||
const char* desktopFileStr = desktopFile;
|
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &_glfw.dbus.desktopFilePath);
|
||||||
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &desktopFileStr);
|
|
||||||
|
|
||||||
//Set properties parameter
|
//Set properties parameter
|
||||||
struct DBusMessageIter sub1, sub2, sub3;
|
struct DBusMessageIter sub1, sub2, sub3;
|
||||||
|
@ -125,9 +125,12 @@ typedef struct _GLFWDBusPOSIX
|
|||||||
|
|
||||||
DBusConnection* connection;
|
DBusConnection* connection;
|
||||||
struct DBusError error;
|
struct DBusError error;
|
||||||
|
|
||||||
|
char* desktopFilePath;
|
||||||
} _GLFWDBusPOSIX;
|
} _GLFWDBusPOSIX;
|
||||||
|
|
||||||
void _glfwInitDBusPOSIX(void);
|
void _glfwInitDBusPOSIX(void);
|
||||||
|
void _glfwCacheDesktopFilePathPOSIX(void);
|
||||||
void _glfwTerminateDBusPOSIX(void);
|
void _glfwTerminateDBusPOSIX(void);
|
||||||
void _glfwUpdateTaskbarProgressDBusPOSIX(dbus_bool_t progressVisible, double progressValue);
|
void _glfwUpdateTaskbarProgressDBusPOSIX(dbus_bool_t progressVisible, double progressValue);
|
||||||
void _glfwUpdateBadgeDBusPOSIX(dbus_bool_t badgeVisible, int badgeCount);
|
void _glfwUpdateBadgeDBusPOSIX(dbus_bool_t badgeVisible, int badgeCount);
|
||||||
|
Loading…
Reference in New Issue
Block a user