Wayland: Use Wayland to wait for libdecor to init

Much of libdecor is initialized only after certain events have been
received from the compositor and some parts of libdecor 0.1 are unsafe
to use until this delayed initialization has completed.

Since libdecor does not provide an API to query if or be notified when
this has happened, GLFW processed events until its newly created
libdecor frame had created its XDG shell objects.

This commit switches to using a generic Wayland sync point created just
after libdecor (and presumably its plugin) has set up its delayed
initialization, instead of relying on the more specific implementation
detail mentioned above.

It also makes this wait mandatory before the first libdecor frame is
created instead of a pre-condition for certain libdecor frame calls,
hopefully removing even more dependence on implementation details.
This commit is contained in:
Camilla Löwy
2023-11-30 02:43:48 +01:00
parent 23ea072c41
commit 9fdc425931
3 changed files with 35 additions and 9 deletions
+29 -3
View File
@@ -40,6 +40,7 @@
#include <sys/timerfd.h>
#include <unistd.h>
#include <time.h>
#include <assert.h>
#include "wayland-client-protocol.h"
#include "wayland-xdg-shell-client-protocol.h"
@@ -216,6 +217,22 @@ static const struct libdecor_interface libdecorInterface =
libdecorHandleError
};
static void libdecorReadyCallback(void* userData,
struct wl_callback* callback,
uint32_t time)
{
_glfw.wl.libdecor.ready = GLFW_TRUE;
assert(_glfw.wl.libdecor.callback == callback);
wl_callback_destroy(_glfw.wl.libdecor.callback);
_glfw.wl.libdecor.callback = NULL;
}
static const struct wl_callback_listener libdecorReadyListener =
{
libdecorReadyCallback
};
// Create key code translation tables
//
static void createKeyTables(void)
@@ -775,10 +792,17 @@ int _glfwInitWayland(void)
if (_glfw.wl.libdecor.handle)
{
_glfw.wl.libdecor.context = libdecor_new(_glfw.wl.display, &libdecorInterface);
// Allow libdecor to receive its globals before proceeding
if (_glfw.wl.libdecor.context)
libdecor_dispatch(_glfw.wl.libdecor.context, 1);
{
// Perform an initial dispatch and flush to get the init started
libdecor_dispatch(_glfw.wl.libdecor.context, 0);
// Create sync point to "know" when libdecor is ready for use
_glfw.wl.libdecor.callback = wl_display_sync(_glfw.wl.display);
wl_callback_add_listener(_glfw.wl.libdecor.callback,
&libdecorReadyListener,
NULL);
}
}
#ifdef WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION
@@ -822,6 +846,8 @@ void _glfwTerminateWayland(void)
_glfwTerminateEGL();
_glfwTerminateOSMesa();
if (_glfw.wl.libdecor.callback)
wl_callback_destroy(_glfw.wl.libdecor.callback);
if (_glfw.wl.libdecor.context)
libdecor_unref(_glfw.wl.libdecor.context);