1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Quit on Ctrl-Q (#7985)

This adds `Ctrl-Q` as the default shortcut for closing the current egui
`Viewport`, which also means closing the entire application if you are
in the root viewport.

Can be configured by `egui::Options::quit_shortcuts`

On Mac, `cmd-Q` already triggers a quit, but not on all Linux:es.
This commit is contained in:
Emil Ernerfeldt
2026-03-18 15:24:19 +01:00
committed by GitHub
parent 265cf7ebae
commit ad510257de
2 changed files with 21 additions and 0 deletions

View File

@@ -2397,6 +2397,12 @@ impl Context {
crate::gui_zoom::zoom_with_keyboard(self);
}
for shortcut in self.options(|o| o.quit_shortcuts.clone()) {
if self.input_mut(|i| i.consume_shortcut(&shortcut)) {
self.send_viewport_cmd(ViewportCommand::Close);
}
}
#[cfg(debug_assertions)]
self.debug_painting();

View File

@@ -234,6 +234,16 @@ pub struct Options {
#[cfg_attr(feature = "serde", serde(skip))]
pub zoom_with_keyboard: bool,
/// Keyboard shortcuts to close the application.
///
/// Pressing any of these will send [`crate::ViewportCommand::Close`]
/// to the root viewport.
///
/// Defaults to `Cmd-Q` (which is Ctrl-Q on Linux/Windows, Cmd-Q on Mac).
/// Set to empty to disable.
#[cfg_attr(feature = "serde", serde(skip))]
pub quit_shortcuts: Vec<crate::KeyboardShortcut>,
/// Controls the tessellator.
pub tessellation_options: epaint::TessellationOptions,
@@ -304,6 +314,10 @@ impl Default for Options {
system_theme: None,
zoom_factor: 1.0,
zoom_with_keyboard: true,
quit_shortcuts: vec![crate::KeyboardShortcut::new(
crate::Modifiers::COMMAND,
crate::Key::Q,
)],
tessellation_options: Default::default(),
repaint_on_widget_change: false,
@@ -363,6 +377,7 @@ impl Options {
system_theme: _,
zoom_factor,
zoom_with_keyboard,
quit_shortcuts: _, // not shown in ui
tessellation_options,
repaint_on_widget_change,
max_passes,