So I am writing a basic Gtk based text editor, and I'm trying to communicate to the user that a file they are editing on disk has changed - I have already got a basic way to submit watchers to an inotify monitoring thread - so I tried just showing a basic prompt and I got an assortment of errors from xcb
, seeming to point to cross-thread window creation causing issues.
If I had control of the main thread I would just use a pipe or what-have-you to indicate that a prompt should be created, but gtk_main
occupies the main thread.
My current idea is to use g_main_context_set_poll_func()
to redirect poll/signal handling to a user function, then send a SIGUSR
from the secondary thread to indicate that a pipe has details in it - using this instead of g_source_add_unix_fd()
since the docs say
Do not call this API on a GSource that you did not create.
(If it's actually fine to then I'll just use that and a regular pipe)
So my question is - is that the intended method to handle cross-thread communication from a secondary thread to the gtk/glib main thread (i.e. hooking into g_main_context_set_poll_func
), or is there a more formal interface for it?
If I've missed any details or context I apologise - and thanks in advance!
(In case it matters, here are some details about the versions of gtk/xcb according to pacman
)
gtk3-1:3.24.29-1
libxcb-1.14-1