Skip to main content

teksilo_core/window/
quit_source.rs

1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! Where a quit comes from: [`QuitSource`].
5
6/// Where a quit request came from, read by a close guard or the
7/// application's [`on_quit_requested`] guard through
8/// [`EventContext::quit_source`](crate::widget::EventContext::quit_source).
9///
10/// A guard that asks the user before closing can skip its dialog when the
11/// user is not there to answer: for [`SessionEnd`](Self::SessionEnd) and
12/// [`Signal`](Self::Signal) it saves directly and lets the close go ahead,
13/// as AppKit and Qt applications do when the session is ending.
14///
15/// [`on_quit_requested`]: https://docs.rs/teksilo/latest/teksilo/struct.TeksiloAppBuilder.html#method.on_quit_requested
16#[non_exhaustive]
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18pub enum QuitSource {
19    /// The application asked: `ctx.quit()`, `ctx.quit_forced()`, or the App
20    /// menu's Quit row.
21    Application,
22    /// The user quit from outside the application's own controls: macOS's
23    /// Dock menu Quit, AppleScript's `quit`, or another `terminate:`; on
24    /// Windows, `taskkill` without `/F` reaching the event loop's hidden
25    /// window while a window of the application is open. A guarded quit: a
26    /// guard can ask, and refuse.
27    UserQuit,
28    /// The session ends (log out, restart, shut down). On macOS a guarded
29    /// quit (AppKit waits for the answer, and a refusal cancels the
30    /// logout); on Windows every guard is asked once and cannot refuse,
31    /// since the session ends whatever the application answers.
32    SessionEnd,
33    /// A termination signal on Unix (`SIGTERM`, `SIGHUP`), heard while the
34    /// event loop runs; on Windows, `taskkill` without `/F` while no window
35    /// of the application is open, or the console it runs in closing.
36    /// Nobody is there to answer: every guard is asked once and cannot
37    /// refuse.
38    Signal,
39}