Hi, I’m trying to integrate a Swift app I’ve built for both macOS and Linux with a GMainLoop. On Linux my app uses a native Wayland window rendering via EGL for UI, and I have a frame timer (driven by the display timer externally) which updates the window. The application’s event loop is driven by libdispatch, calling dispatch_main() to start the event loop.
I’d now like to implement the UI in HTML/JS using WebKit WPE, which relies on GLib and processes its events.signals and runs its internal WebProcess on Linux via a GMainLoop. I’m having some difficulty integrating this with libdispatch.
Some users have attempted to manually poll for Glib events using an X socket (https://mail.gnome.org/archives/gtk-list/2016-April/msg00049.html) however this won’t work as Wayland doesn’t have this concept.
Alternatively there is an option to use internal dispatch API to drive libdispatch from a GMainLoop (https://stackoverflow.com/questions/10291972/integrating-a-custom-run-loop-with-libdispatch) however this doesn’t seem quite robust to me.
My third option is to iterate either the GMainLoop or libdispatch run loop from my display callback and driving the application from the other, however as the rest of the application doesn’t depend on GLib and also needs to run on macOS (where WebKit is also driven by libdispatch/CFRunLoop) I’d prefer not to do this. I’d also rather have the ability to have the app run headless.
Would love any comments or advice about the best approach. Also, is there any way to listen on a single fd for GLib events? I could just create a libdispatch dispatch source watching the fd in that case.