Perform action on Window close

Is there a way to send a message or trigger a callback when closing a window? This would be useful to cleanup state in a multi-window application when, for example, popping up a modal.

(Yes, I know that window decorations can be disabled, but unfortunately that doesn’t help if the window is closed with a keybinding, e.g. Mod+Shift+Q or Alt-F4)

There is a subscription for close_events. close_events in iced::window - Rust

Convert the output Id with .map on the Subscription<Id> to your Message to get a Subscription<YourMessage>.

1 Like

Ohh, of course, I should have checked that first. Thanks!