Added DBus pointer checks

This commit is contained in:
GamesTrap 2023-03-08 14:47:40 +01:00
parent ef4d722b76
commit 589e6b78d9
No known key found for this signature in database
GPG Key ID: 31DFD452434ECDA3
3 changed files with 88 additions and 59 deletions

View File

@ -41,77 +41,90 @@ void _glfwInitDBusPOSIX(void)
_glfw.dbus.connection = NULL;
_glfw.dbus.handle = _glfwPlatformLoadModule("libdbus-1.so.3");
if (_glfw.dbus.handle)
{
_glfw.dbus.error_init = (PFN_dbus_error_init)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_error_init");
_glfw.dbus.error_is_set = (PFN_dbus_error_is_set)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_error_is_set");
_glfw.dbus.error_free = (PFN_dbus_error_free)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_error_free");
_glfw.dbus.connection_unref = (PFN_dbus_connection_unref)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_connection_unref");
_glfw.dbus.connection_send = (PFN_dbus_connection_send)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_connection_send");
_glfw.dbus.connection_flush = (PFN_dbus_connection_flush)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_connection_flush");
_glfw.dbus.bus_request_name = (PFN_dbus_bus_request_name)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_bus_request_name");
_glfw.dbus.bus_get = (PFN_dbus_bus_get)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_bus_get");
_glfw.dbus.message_unref = (PFN_dbus_message_unref)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_unref");
_glfw.dbus.message_new_signal = (PFN_dbus_message_new_signal)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_new_signal");
_glfw.dbus.message_iter_init_append = (PFN_dbus_message_iter_init_append)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_init_append");
_glfw.dbus.message_iter_append_basic = (PFN_dbus_message_iter_append_basic)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_append_basic");
_glfw.dbus.message_iter_open_container = (PFN_dbus_message_iter_open_container)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_open_container");
_glfw.dbus.message_iter_close_container = (PFN_dbus_message_iter_close_container)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_close_container");
if (!_glfw.dbus.handle)
return;
//Initialize DBus connection
dbus_error_init(&_glfw.dbus.error);
_glfw.dbus.connection = dbus_bus_get(DBUS_BUS_SESSION, &_glfw.dbus.error);
_glfw.dbus.error_init = (PFN_dbus_error_init)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_error_init");
_glfw.dbus.error_is_set = (PFN_dbus_error_is_set)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_error_is_set");
_glfw.dbus.error_free = (PFN_dbus_error_free)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_error_free");
_glfw.dbus.connection_unref = (PFN_dbus_connection_unref)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_connection_unref");
_glfw.dbus.connection_send = (PFN_dbus_connection_send)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_connection_send");
_glfw.dbus.connection_flush = (PFN_dbus_connection_flush)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_connection_flush");
_glfw.dbus.bus_request_name = (PFN_dbus_bus_request_name)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_bus_request_name");
_glfw.dbus.bus_get = (PFN_dbus_bus_get)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_bus_get");
_glfw.dbus.message_unref = (PFN_dbus_message_unref)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_unref");
_glfw.dbus.message_new_signal = (PFN_dbus_message_new_signal)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_new_signal");
_glfw.dbus.message_iter_init_append = (PFN_dbus_message_iter_init_append)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_init_append");
_glfw.dbus.message_iter_append_basic = (PFN_dbus_message_iter_append_basic)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_append_basic");
_glfw.dbus.message_iter_open_container = (PFN_dbus_message_iter_open_container)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_open_container");
_glfw.dbus.message_iter_close_container = (PFN_dbus_message_iter_close_container)
_glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_close_container");
if (!_glfw.dbus.error_init ||
!_glfw.dbus.error_is_set ||
!_glfw.dbus.error_free ||
!_glfw.dbus.connection_unref ||
!_glfw.dbus.connection_send ||
!_glfw.dbus.connection_flush ||
!_glfw.dbus.bus_request_name ||
!_glfw.dbus.bus_get ||
!_glfw.dbus.message_unref ||
!_glfw.dbus.message_new_signal ||
!_glfw.dbus.message_iter_init_append ||
!_glfw.dbus.message_iter_append_basic ||
!_glfw.dbus.message_iter_open_container ||
!_glfw.dbus.message_iter_close_container)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"POSIX: Failed to load DBus entry points");
return;
}
//Initialize DBus connection
dbus_error_init(&_glfw.dbus.error);
_glfw.dbus.connection = dbus_bus_get(DBUS_BUS_SESSION, &_glfw.dbus.error);
//Check for errors
if(dbus_error_is_set(&_glfw.dbus.error) || !_glfw.dbus.connection)
{
if(dbus_error_is_set(&_glfw.dbus.error))
dbus_error_free(&_glfw.dbus.error);
_glfwInputError(GLFW_PLATFORM_ERROR, "Failed to connect to DBus");
dbus_connection_unref(_glfw.dbus.connection);
_glfw.dbus.connection = NULL;
}
else
{
//Request name
const int res = dbus_bus_request_name(_glfw.dbus.connection, "org.glfw", DBUS_NAME_FLAG_REPLACE_EXISTING, &_glfw.dbus.error);
//Check for errors
if(dbus_error_is_set(&_glfw.dbus.error) || !_glfw.dbus.connection)
if(dbus_error_is_set(&_glfw.dbus.error) || res != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
{
if(dbus_error_is_set(&_glfw.dbus.error))
dbus_error_free(&_glfw.dbus.error);
_glfwInputError(GLFW_PLATFORM_ERROR, "Failed to connect to DBus");
dbus_connection_unref(_glfw.dbus.connection);
_glfw.dbus.connection = NULL;
}
else
{
//Request name
const int res = dbus_bus_request_name(_glfw.dbus.connection, "org.glfw", DBUS_NAME_FLAG_REPLACE_EXISTING, &_glfw.dbus.error);
//Check for errors
if(dbus_error_is_set(&_glfw.dbus.error) || res != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
{
if(dbus_error_is_set(&_glfw.dbus.error))
dbus_error_free(&_glfw.dbus.error);
_glfwInputError(GLFW_PLATFORM_ERROR, "Failed to request DBus name");
_glfwInputError(GLFW_PLATFORM_ERROR, "Failed to request DBus name");
dbus_connection_unref(_glfw.dbus.connection);
_glfw.dbus.connection = NULL;
}
}
}
if(_glfw.dbus.connection)
{
//Window NULL is safe here because it won't get
//used inside the SetWindowTaskbarProgress function
_glfw.platform.setWindowProgressIndicator(NULL, GLFW_PROGRESS_INDICATOR_DISABLED, 0);
}
}
void _glfwTerminateDBusPOSIX(void)

View File

@ -1843,6 +1843,14 @@ GLFWbool _glfwCreateWindowWayland(_GLFWwindow* window,
return GLFW_FALSE;
}
//Reset progress state as it gets saved between application runs
if(_glfw.dbus.connection)
{
//Window NULL is safe here because it won't get
//used inside the SetWindowTaskbarProgress function
_glfwSetWindowProgressIndicatorWayland(NULL, GLFW_PROGRESS_INDICATOR_DISABLED, 0.0);
}
return GLFW_TRUE;
}

View File

@ -2040,6 +2040,14 @@ GLFWbool _glfwCreateWindowX11(_GLFWwindow* window,
}
}
//Reset progress state as it gets saved between application runs
if(_glfw.dbus.connection)
{
//Window NULL is safe here because it won't get
//used inside the SetWindowTaskbarProgress function
_glfwSetWindowProgressIndicatorX11(NULL, GLFW_PROGRESS_INDICATOR_DISABLED, 0.0);
}
XFlush(_glfw.x11.display);
return GLFW_TRUE;
}