My program processes Wayland events in a GTK main loop. It does this by adding a GSource for the Wayland display fd using g_source_add_unix_fd(source, wl_display_get_fd(display), G_IO_IN | G_IO_ERR | G_IO_HUP);
Here is the full code for the GSources: https://github.com/sardemff7/libgwater/blob/master/wayland/libgwater-wayland.c
My program connects to Wayland events and runs them through the program’s event handler.
At one point it opens a modal GtkWindow in a nested GTK mainloop by calling gtk_main()
. When it calls gtk_main_quit()
and returns to the outer loop, it stops handling the Wayland events (not intended). It seems that the GMainLoop freezes.
void clientCycleEventFilter ()
{
do_stuff();
gtk_main_quit ();
}
void ClientCycle ()
{
passdata.window = myWindowCreate ();
eventFilterPush (display_info->xfilter, clientCycleEventFilter, &passdata);
GWaterWaylandSource *source = g_water_wayland_source_new_for_display (NULL, screen_info->display_info->wayland_display);
gtk_main ();
eventFilterPop (display_info->xfilter);
}
int main ()
{
wayland_display = wl_display_connect (NULL);
gtk_init (&argc, &argv);
registry = wl_display_get_registry (wayland_display);
wl_registry_add_listener (registry, ®istry_listener, myStruct);
/*This binds to Wayland interfaces, which then feeds events
to the event filter*/
wl_display_roundtrip (wayland_display);
wl_display_roundtrip (wayland_display);
source = g_water_wayland_source_new_for_display (NULL, wayland_display);
gtk_main ();
}
(I seemed to have to add the GSource a second time when entering my nested loop)
Here is the rest of the code: https://github.com/adlocode/xfwm4/blob/wayland/src/cycle.c#L557
How can I resolve this?