Add skip-confirmation flag to the quit action

This commit is contained in:
Ivan Molodetskikh
2024-02-12 07:53:06 +04:00
parent d6b116d229
commit 67182129ff
5 changed files with 50 additions and 18 deletions
+10 -2
View File
@@ -516,7 +516,7 @@ bitflags! {
// Remember to add new actions to the CLI enum too. // Remember to add new actions to the CLI enum too.
#[derive(knuffel::Decode, Debug, Clone, PartialEq)] #[derive(knuffel::Decode, Debug, Clone, PartialEq)]
pub enum Action { pub enum Action {
Quit, Quit(#[knuffel(property(name = "skip-confirmation"), default)] bool),
#[knuffel(skip)] #[knuffel(skip)]
ChangeVt(i32), ChangeVt(i32),
Suspend, Suspend,
@@ -591,7 +591,7 @@ pub enum Action {
impl From<niri_ipc::Action> for Action { impl From<niri_ipc::Action> for Action {
fn from(value: niri_ipc::Action) -> Self { fn from(value: niri_ipc::Action) -> Self {
match value { match value {
niri_ipc::Action::Quit => Self::Quit, niri_ipc::Action::Quit { skip_confirmation } => Self::Quit(skip_confirmation),
niri_ipc::Action::PowerOffMonitors => Self::PowerOffMonitors, niri_ipc::Action::PowerOffMonitors => Self::PowerOffMonitors,
niri_ipc::Action::Spawn { command } => Self::Spawn(command), niri_ipc::Action::Spawn { command } => Self::Spawn(command),
niri_ipc::Action::Screenshot => Self::Screenshot, niri_ipc::Action::Screenshot => Self::Screenshot,
@@ -936,6 +936,7 @@ mod tests {
Mod+Ctrl+Shift+L { move-window-to-monitor-right; } Mod+Ctrl+Shift+L { move-window-to-monitor-right; }
Mod+Comma { consume-window-into-column; } Mod+Comma { consume-window-into-column; }
Mod+1 { focus-workspace 1; } Mod+1 { focus-workspace 1; }
Mod+Shift+E { quit skip-confirmation=true; }
} }
debug { debug {
@@ -1104,6 +1105,13 @@ mod tests {
}, },
actions: vec![Action::FocusWorkspace(1)], actions: vec![Action::FocusWorkspace(1)],
}, },
Bind {
key: Key {
keysym: Keysym::e,
modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,
},
actions: vec![Action::Quit(true)],
},
]), ]),
debug: DebugConfig { debug: DebugConfig {
render_drm_device: Some(PathBuf::from("/dev/dri/renderD129")), render_drm_device: Some(PathBuf::from("/dev/dri/renderD129")),
+5 -1
View File
@@ -48,7 +48,11 @@ pub enum Response {
#[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))] #[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))]
pub enum Action { pub enum Action {
/// Exit niri. /// Exit niri.
Quit, Quit {
/// Skip the "Press Enter to confirm" prompt.
#[cfg_attr(feature = "clap", arg(short, long))]
skip_confirmation: bool,
},
/// Power off all monitors via DPMS. /// Power off all monitors via DPMS.
PowerOffMonitors, PowerOffMonitors,
/// Spawn a command. /// Spawn a command.
+4
View File
@@ -408,7 +408,11 @@ binds {
Ctrl+Print { screenshot-screen; } Ctrl+Print { screenshot-screen; }
Alt+Print { screenshot-window; } Alt+Print { screenshot-window; }
// The quit action will show a confirmation dialog to avoid accidental exits.
// If you want to skip the confirmation dialog, set the flag like so:
// Mod+Shift+E { quit skip-confirmation=true; }
Mod+Shift+E { quit; } Mod+Shift+E { quit; }
Mod+Shift+P { power-off-monitors; } Mod+Shift+P { power-off-monitors; }
Mod+Shift+Ctrl+T { toggle-debug-tint; } Mod+Shift+Ctrl+T { toggle-debug-tint; }
+19 -6
View File
@@ -155,13 +155,26 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul
let binds = &config.binds.0; let binds = &config.binds.0;
// Collect actions that we want to show. // Collect actions that we want to show.
let mut actions = vec![ let mut actions = vec![&Action::ShowHotkeyOverlay];
&Action::ShowHotkeyOverlay,
&Action::Quit, // Prefer Quit(false) if found, otherwise try Quit(true), and if there's neither, fall back to
&Action::CloseWindow, // Quit(false).
]; if binds
.iter()
.any(|bind| bind.actions.first() == Some(&Action::Quit(false)))
{
actions.push(&Action::Quit(false));
} else if binds
.iter()
.any(|bind| bind.actions.first() == Some(&Action::Quit(true)))
{
actions.push(&Action::Quit(true));
} else {
actions.push(&Action::Quit(false));
}
actions.extend(&[ actions.extend(&[
&Action::CloseWindow,
&Action::FocusColumnLeft, &Action::FocusColumnLeft,
&Action::FocusColumnRight, &Action::FocusColumnRight,
&Action::MoveColumnLeft, &Action::MoveColumnLeft,
@@ -365,7 +378,7 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul
fn action_name(action: &Action) -> String { fn action_name(action: &Action) -> String {
match action { match action {
Action::Quit => String::from("Exit niri"), Action::Quit(_) => String::from("Exit niri"),
Action::ShowHotkeyOverlay => String::from("Show Important Hotkeys"), Action::ShowHotkeyOverlay => String::from("Show Important Hotkeys"),
Action::CloseWindow => String::from("Close Focused Window"), Action::CloseWindow => String::from("Close Focused Window"),
Action::FocusColumnLeft => String::from("Focus Column to the Left"), Action::FocusColumnLeft => String::from("Focus Column to the Left"),
+9 -6
View File
@@ -284,16 +284,19 @@ impl State {
} }
match action { match action {
Action::Quit => { Action::Quit(skip_confirmation) => {
if !skip_confirmation {
if let Some(dialog) = &mut self.niri.exit_confirm_dialog { if let Some(dialog) = &mut self.niri.exit_confirm_dialog {
if dialog.show() { if dialog.show() {
self.niri.queue_redraw_all(); self.niri.queue_redraw_all();
} }
} else { return;
info!("quitting because quit bind was pressed");
self.niri.stop_signal.stop()
} }
} }
info!("quitting as requested");
self.niri.stop_signal.stop()
}
Action::ChangeVt(vt) => { Action::ChangeVt(vt) => {
self.backend.change_vt(vt); self.backend.change_vt(vt);
// Changing VT may not deliver the key releases, so clear the state. // Changing VT may not deliver the key releases, so clear the state.
@@ -1542,7 +1545,7 @@ fn should_notify_activity<I: InputBackend>(event: &InputEvent<I>) -> bool {
fn allowed_when_locked(action: &Action) -> bool { fn allowed_when_locked(action: &Action) -> bool {
matches!( matches!(
action, action,
Action::Quit Action::Quit(_)
| Action::ChangeVt(_) | Action::ChangeVt(_)
| Action::Suspend | Action::Suspend
| Action::PowerOffMonitors | Action::PowerOffMonitors
@@ -1553,7 +1556,7 @@ fn allowed_when_locked(action: &Action) -> bool {
fn allowed_during_screenshot(action: &Action) -> bool { fn allowed_during_screenshot(action: &Action) -> bool {
matches!( matches!(
action, action,
Action::Quit | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors Action::Quit(_) | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors
) )
} }