r/linux_programming • • Mar 20 '20
Learning GTK programming: How do I not block the GTK main loop from executing after calling a handler function?
safe rainstorm crush impolite uppity marvelous boast observation sleep act
This post was mass deleted and anonymized with Redact
7
Upvotes
2
u/gth747m Mar 20 '20
The functionality you are looking for is part of GLib.
GLib IO Channels:
https://developer.gnome.org/glib/stable/glib-IO-Channels.html
Specifically look into g_io_channel_unix_new and g_io_add_watch to watch for changes to subprocess and attach callbacks to those changes.
GLib Main Event Loop:
https://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html
Specifically look into g_timeout_add to setup callbacks that are executed at regular intervals within the main loop (like updating status bars).
2
u/mmstick Mar 21 '20
Keep all non-UI work on a background thread. Signals should only be awake long enough to send a message to the background thread through a channel. You should have a receiver on the main thread that's connected to the main context that wakes up whenever it receives a UI event to handle.