Skip to content

Replace gtk3 with gtk4#319

Open
zhao-gang wants to merge 5 commits into
PolyMeilex:masterfrom
zhao-gang:replace-gtk3-with-gtk4
Open

Replace gtk3 with gtk4#319
zhao-gang wants to merge 5 commits into
PolyMeilex:masterfrom
zhao-gang:replace-gtk3-with-gtk4

Conversation

@zhao-gang
Copy link
Copy Markdown
Contributor

Fixed #227

@PolyMeilex
Copy link
Copy Markdown
Owner

PolyMeilex commented Apr 13, 2026

GTK does not support multithreading, so those changes seem to be untested, and will most likely simply panic on threading assertions at runtime.

@zhao-gang
Copy link
Copy Markdown
Contributor Author

Hi @PolyMeilex , how to test GTK4 with multithreading ? I run examples with GTK4 feature and they seemed okay.

@PolyMeilex
Copy link
Copy Markdown
Owner

My guess is that simply opening the async dialog more than once during the same process lifetime should do the trick, and cause the process to blow up in one way or another. So either open 2 dialogs, or open one and the next one once the first one is done.

@zhao-gang
Copy link
Copy Markdown
Contributor Author

zhao-gang commented Apr 18, 2026

Modified async example to open 2 dialogs in sequence and it's working. Added my testing code.

Yes it crashed with GTK. I'll try to fix the async code.

fn main() {
    // Spawn dialog on main thread
    let task1 = rfd::AsyncFileDialog::new().pick_file();
    let task2 = rfd::AsyncFileDialog::new().pick_file();

    // Await somewhere else
    execute(async {
        let file = task1.await;

        if let Some(file) = file {
            // If you are on native platform you can just get the path
            #[cfg(not(target_arch = "wasm32"))]
            println!("{:?}", file.path());

            // If you care about wasm support you just read() the file
            file.read().await;
        }

        let file = task2.await;

        if let Some(file) = file {
            // If you are on native platform you can just get the path
            #[cfg(not(target_arch = "wasm32"))]
            println!("{:?}", file.path());

            // If you care about wasm support you just read() the file
            file.read().await;
        }
    });

    std::thread::park();
}

use std::future::Future;

#[cfg(not(target_arch = "wasm32"))]
fn execute<F: Future<Output = ()> + Send + 'static>(f: F) {
    // this is stupid... use any executor of your choice instead
    std::thread::spawn(move || futures::executor::block_on(f));
}
#[cfg(target_arch = "wasm32")]
fn execute<F: Future<Output = ()> + 'static>(f: F) {
    wasm_bindgen_futures::spawn_local(f);
}

@zhao-gang zhao-gang force-pushed the replace-gtk3-with-gtk4 branch 2 times, most recently from e3a89e9 to 4f47bd2 Compare May 1, 2026 08:04
@zhao-gang
Copy link
Copy Markdown
Contributor Author

Hi @PolyMeilex , I think the GTK multithreading issue is fixed. And updated async test to check this.

zhao-gang added 5 commits May 17, 2026 19:48
Fixed following message:

Gtk-Message: 15:22:02.779: GtkDialog mapped without a transient parent. This is discouraged.
Now the async test can check API in multithreading.
@PolyMeilex PolyMeilex force-pushed the replace-gtk3-with-gtk4 branch from 4f47bd2 to 1e9c03f Compare May 17, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gtk-rs GTK3 bindings - no longer maintained

2 participants