How to close AlertDialog with Escape key?

I’m trying to assign EventControllerKey to the AlertDialog,
but it does not react (even for any key press):

alert_dialog.add_controller({
    let c = gtk::EventControllerKey::builder().build();
    c.connect_key_pressed({
        let alert_dialog = alert_dialog.clone();
        move |_, k, _, _| {
            alert_dialog.close(); // on k == code
            gtk::glib::Propagation::Stop
        }
    });
    c
});

It already does that by default. Chances are the code above breaks it.

1 Like

Hm, thanks for reply, maybe that’s really my bug somewhere…

Is this actual for Adw v1.5?

Alert dialogs (AdwDialog in general) have had this since day 1

1 Like

I remembered that I had assigned the Escape key to parent window accels, so this modification is blocking the dialog close event.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.