aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--niri-config/src/lib.rs12
-rw-r--r--niri-ipc/src/lib.rs6
-rw-r--r--resources/default-config.kdl4
-rw-r--r--src/hotkey_overlay.rs25
-rw-r--r--src/input.rs21
5 files changed, 50 insertions, 18 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs
index e39fd4af..1b4a999c 100644
--- a/niri-config/src/lib.rs
+++ b/niri-config/src/lib.rs
@@ -516,7 +516,7 @@ bitflags! {
// Remember to add new actions to the CLI enum too.
#[derive(knuffel::Decode, Debug, Clone, PartialEq)]
pub enum Action {
- Quit,
+ Quit(#[knuffel(property(name = "skip-confirmation"), default)] bool),
#[knuffel(skip)]
ChangeVt(i32),
Suspend,
@@ -591,7 +591,7 @@ pub enum Action {
impl From<niri_ipc::Action> for Action {
fn from(value: niri_ipc::Action) -> Self {
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::Spawn { command } => Self::Spawn(command),
niri_ipc::Action::Screenshot => Self::Screenshot,
@@ -936,6 +936,7 @@ mod tests {
Mod+Ctrl+Shift+L { move-window-to-monitor-right; }
Mod+Comma { consume-window-into-column; }
Mod+1 { focus-workspace 1; }
+ Mod+Shift+E { quit skip-confirmation=true; }
}
debug {
@@ -1104,6 +1105,13 @@ mod tests {
},
actions: vec![Action::FocusWorkspace(1)],
},
+ Bind {
+ key: Key {
+ keysym: Keysym::e,
+ modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,
+ },
+ actions: vec![Action::Quit(true)],
+ },
]),
debug: DebugConfig {
render_drm_device: Some(PathBuf::from("/dev/dri/renderD129")),
diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs
index 622435f4..b26eb3cc 100644
--- a/niri-ipc/src/lib.rs
+++ b/niri-ipc/src/lib.rs
@@ -48,7 +48,11 @@ pub enum Response {
#[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))]
pub enum Action {
/// 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.
PowerOffMonitors,
/// Spawn a command.
diff --git a/resources/default-config.kdl b/resources/default-config.kdl
index 2cee1c62..3eceeecf 100644
--- a/resources/default-config.kdl
+++ b/resources/default-config.kdl
@@ -408,7 +408,11 @@ binds {
Ctrl+Print { screenshot-screen; }
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+P { power-off-monitors; }
Mod+Shift+Ctrl+T { toggle-debug-tint; }
diff --git a/src/hotkey_overlay.rs b/src/hotkey_overlay.rs
index 15a46706..bfb263f4 100644
--- a/src/hotkey_overlay.rs
+++ b/src/hotkey_overlay.rs
@@ -155,13 +155,26 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul
let binds = &config.binds.0;
// Collect actions that we want to show.
- let mut actions = vec![
- &Action::ShowHotkeyOverlay,
- &Action::Quit,
- &Action::CloseWindow,
- ];
+ let mut actions = vec![&Action::ShowHotkeyOverlay];
+
+ // Prefer Quit(false) if found, otherwise try Quit(true), and if there's neither, fall back to
+ // 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(&[
+ &Action::CloseWindow,
&Action::FocusColumnLeft,
&Action::FocusColumnRight,
&Action::MoveColumnLeft,
@@ -365,7 +378,7 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul
fn action_name(action: &Action) -> String {
match action {
- Action::Quit => String::from("Exit niri"),
+ Action::Quit(_) => String::from("Exit niri"),
Action::ShowHotkeyOverlay => String::from("Show Important Hotkeys"),
Action::CloseWindow => String::from("Close Focused Window"),
Action::FocusColumnLeft => String::from("Focus Column to the Left"),
diff --git a/src/input.rs b/src/input.rs
index e941c57c..6c49ecdd 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -284,15 +284,18 @@ impl State {
}
match action {
- Action::Quit => {
- if let Some(dialog) = &mut self.niri.exit_confirm_dialog {
- if dialog.show() {
- self.niri.queue_redraw_all();
+ Action::Quit(skip_confirmation) => {
+ if !skip_confirmation {
+ if let Some(dialog) = &mut self.niri.exit_confirm_dialog {
+ if dialog.show() {
+ self.niri.queue_redraw_all();
+ }
+ return;
}
- } else {
- info!("quitting because quit bind was pressed");
- self.niri.stop_signal.stop()
}
+
+ info!("quitting as requested");
+ self.niri.stop_signal.stop()
}
Action::ChangeVt(vt) => {
self.backend.change_vt(vt);
@@ -1542,7 +1545,7 @@ fn should_notify_activity<I: InputBackend>(event: &InputEvent<I>) -> bool {
fn allowed_when_locked(action: &Action) -> bool {
matches!(
action,
- Action::Quit
+ Action::Quit(_)
| Action::ChangeVt(_)
| Action::Suspend
| Action::PowerOffMonitors
@@ -1553,7 +1556,7 @@ fn allowed_when_locked(action: &Action) -> bool {
fn allowed_during_screenshot(action: &Action) -> bool {
matches!(
action,
- Action::Quit | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors
+ Action::Quit(_) | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors
)
}