PolyMeilex / rfd

Rusty File Dialog
MIT License
526 stars 60 forks source link

Run all GTK dialogs on one thread #152

Closed valadaptive closed 9 months ago

valadaptive commented 9 months ago

When investigating #150 more deeply, I noticed that the GTK documentation seems to indicate that all GTK functions must only be called on the thread that called gtk_init(). The existing code does ensure that only one thread accesses GTK at a time, but the documentation seems to suggest that once a thread calls gtk_init, all calls to GTK must go through that thread:

"GTK+, however, is not thread safe. You should only use GTK+ and GDK from the thread gtk_init() and gtk_main() were called on. This is usually referred to as the "main thread"."

To facilitate that, this PR changes the GTK dialog code to spin up a thread and initialize GTK on it, keeping it alive for the lifetime of the program. It's a bit unfortunate that we have to keep it around forever, but the GTK documentation seems to indicate that once you call gtk_init on a thread, you're stuck with that thread.