From bdcba7a7f0b997b5ef046eea2ab6d25b5ac2aa12 Mon Sep 17 00:00:00 2001 From: Fabio Date: Tue, 17 Dec 2024 22:09:58 +0100 Subject: [PATCH 1/2] fix(linux): explicitly call gtk_init to avoid 'GTK may only be used from the main thread' --- src/platform_impl/linux/event_loop.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform_impl/linux/event_loop.rs b/src/platform_impl/linux/event_loop.rs index e39ee9f19..39bb014d3 100644 --- a/src/platform_impl/linux/event_loop.rs +++ b/src/platform_impl/linux/event_loop.rs @@ -215,6 +215,8 @@ impl EventLoop { } fn new_gtk(app_id: Option<&str>) -> Result, Box> { + // This should be done by gtk::Application::new, but does not work properly + gtk::init()?; let context = MainContext::default(); let app = gtk::Application::new(app_id, gio::ApplicationFlags::empty()); let app_ = app.clone(); From 12a0a1853a36dec6817a6206432ca677668048f4 Mon Sep 17 00:00:00 2001 From: Fabio Date: Tue, 17 Dec 2024 22:15:41 +0100 Subject: [PATCH 2/2] add change.md --- .changes/explicit_gtk_init.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changes/explicit_gtk_init.md diff --git a/.changes/explicit_gtk_init.md b/.changes/explicit_gtk_init.md new file mode 100644 index 000000000..f23ff7264 --- /dev/null +++ b/.changes/explicit_gtk_init.md @@ -0,0 +1,7 @@ +--- +"tao": patch +--- + +Explicitly call `gtk::init()` as `gtk::Application::new` does not call it reliably. +If `gtk::init()` is not called, 'GTK may only be used from the main thread' error can occur later. +`gtk::init()` checks if already initialized and does nothing if so.