wayland: use separate event queue for widgets, and code cleanup
Registry listener accepts data that lives at least as long as the
registry itself (or until program ends). However, GtkWidget is not
a suitable candidate for this, as it could be finalized any time.
A "WidgetTracker" is added for this case: it contains a "is_destroyed"
field that would be set to TRUE when corresponding GtkWidget is
destroyed, so the listener could tell if it shall continue, avoiding
derefering invalid pointer.
To avoid registry listener accessing GtkWidget that has been finalized,
a new thread with a separate event queue is created for GtkWidgets
in spice_wayland_extensions_init()
. A new function
spice_wayland_extensions_finalize()
is exposed to be called before
GtkWidget gets destroyed, to clean up the thread.
This fixes crashes in virt-manager: https://github.com/virt-manager/virt-manager/issues/501,
as registry_handle_global()
could be triggered in some cases after the initialization
(such as a new monitor is plugged in, which creates a new "wl_output" interface).
A much simpler workaround is to deref widget only when interface is zwp_relative_pointer_manager_v1
or zwp_pointer_constraints_v1
, but this does not look like a nice fix.