forge
Explore
Log in

Don't you dare go Hollow

Add skip-confirmation flag to the quit action

Browse files at this commit

67182129ff3e764655cc0811ee237c3d26140b66Ivan MolodetskikhParent: d6b116d
niri-config/src/lib.rsmodified+10 -2
@@ -516,7 +516,7 @@ bitflags! {
516 // Remember to add new actions to the CLI enum too.516 // Remember to add new actions to the CLI enum too.
517 #[derive(knuffel::Decode, Debug, Clone, PartialEq)]517 #[derive(knuffel::Decode, Debug, Clone, PartialEq)]
518 pub enum Action {518 pub enum Action {
519- Quit,519+ Quit(#[knuffel(property(name = "skip-confirmation"), default)] bool),
520 #[knuffel(skip)]520 #[knuffel(skip)]
521 ChangeVt(i32),521 ChangeVt(i32),
522 Suspend,522 Suspend,
@@ -591,7 +591,7 @@ pub enum Action {
591 impl From<niri_ipc::Action> for Action {591 impl From<niri_ipc::Action> for Action {
592 fn from(value: niri_ipc::Action) -> Self {592 fn from(value: niri_ipc::Action) -> Self {
593 match value {593 match value {
594- niri_ipc::Action::Quit => Self::Quit,594+ niri_ipc::Action::Quit { skip_confirmation } => Self::Quit(skip_confirmation),
595 niri_ipc::Action::PowerOffMonitors => Self::PowerOffMonitors,595 niri_ipc::Action::PowerOffMonitors => Self::PowerOffMonitors,
596 niri_ipc::Action::Spawn { command } => Self::Spawn(command),596 niri_ipc::Action::Spawn { command } => Self::Spawn(command),
597 niri_ipc::Action::Screenshot => Self::Screenshot,597 niri_ipc::Action::Screenshot => Self::Screenshot,
@@ -936,6 +936,7 @@ mod tests {
936 Mod+Ctrl+Shift+L { move-window-to-monitor-right; }936 Mod+Ctrl+Shift+L { move-window-to-monitor-right; }
937 Mod+Comma { consume-window-into-column; }937 Mod+Comma { consume-window-into-column; }
938 Mod+1 { focus-workspace 1; }938 Mod+1 { focus-workspace 1; }
939+ Mod+Shift+E { quit skip-confirmation=true; }
939 }940 }
940 941
941 debug {942 debug {
@@ -1104,6 +1105,13 @@ mod tests {
1104 },1105 },
1105 actions: vec![Action::FocusWorkspace(1)],1106 actions: vec![Action::FocusWorkspace(1)],
1106 },1107 },
1108+ Bind {
1109+ key: Key {
1110+ keysym: Keysym::e,
1111+ modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,
1112+ },
1113+ actions: vec![Action::Quit(true)],
1114+ },
1107 ]),1115 ]),
1108 debug: DebugConfig {1116 debug: DebugConfig {
1109 render_drm_device: Some(PathBuf::from("/dev/dri/renderD129")),1117 render_drm_device: Some(PathBuf::from("/dev/dri/renderD129")),
niri-ipc/src/lib.rsmodified+5 -1
@@ -48,7 +48,11 @@ pub enum Response {
48 #[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))]48 #[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))]
49 pub enum Action {49 pub enum Action {
50 /// Exit niri.50 /// Exit niri.
51- Quit,51+ Quit {
52+ /// Skip the "Press Enter to confirm" prompt.
53+ #[cfg_attr(feature = "clap", arg(short, long))]
54+ skip_confirmation: bool,
55+ },
52 /// Power off all monitors via DPMS.56 /// Power off all monitors via DPMS.
53 PowerOffMonitors,57 PowerOffMonitors,
54 /// Spawn a command.58 /// Spawn a command.
resources/default-config.kdlmodified+4 -0
@@ -408,7 +408,11 @@ binds {
408 Ctrl+Print { screenshot-screen; }408 Ctrl+Print { screenshot-screen; }
409 Alt+Print { screenshot-window; }409 Alt+Print { screenshot-window; }
410 410
411+ // The quit action will show a confirmation dialog to avoid accidental exits.
412+ // If you want to skip the confirmation dialog, set the flag like so:
413+ // Mod+Shift+E { quit skip-confirmation=true; }
411 Mod+Shift+E { quit; }414 Mod+Shift+E { quit; }
415+
412 Mod+Shift+P { power-off-monitors; }416 Mod+Shift+P { power-off-monitors; }
413 417
414 Mod+Shift+Ctrl+T { toggle-debug-tint; }418 Mod+Shift+Ctrl+T { toggle-debug-tint; }
src/hotkey_overlay.rsmodified+19 -6
@@ -155,13 +155,26 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul
155 let binds = &config.binds.0;155 let binds = &config.binds.0;
156 156
157 // Collect actions that we want to show.157 // Collect actions that we want to show.
158- let mut actions = vec![158+ let mut actions = vec![&Action::ShowHotkeyOverlay];
159- &Action::ShowHotkeyOverlay,159+
160- &Action::Quit,160+ // Prefer Quit(false) if found, otherwise try Quit(true), and if there's neither, fall back to
161- &Action::CloseWindow,161+ // Quit(false).
162- ];162+ if binds
163+ .iter()
164+ .any(|bind| bind.actions.first() == Some(&Action::Quit(false)))
165+ {
166+ actions.push(&Action::Quit(false));
167+ } else if binds
168+ .iter()
169+ .any(|bind| bind.actions.first() == Some(&Action::Quit(true)))
170+ {
171+ actions.push(&Action::Quit(true));
172+ } else {
173+ actions.push(&Action::Quit(false));
174+ }
163 175
164 actions.extend(&[176 actions.extend(&[
177+ &Action::CloseWindow,
165 &Action::FocusColumnLeft,178 &Action::FocusColumnLeft,
166 &Action::FocusColumnRight,179 &Action::FocusColumnRight,
167 &Action::MoveColumnLeft,180 &Action::MoveColumnLeft,
@@ -365,7 +378,7 @@ fn render(config: &Config, comp_mod: CompositorMod, scale: i32) -> anyhow::Resul
365 378
366 fn action_name(action: &Action) -> String {379 fn action_name(action: &Action) -> String {
367 match action {380 match action {
368- Action::Quit => String::from("Exit niri"),381+ Action::Quit(_) => String::from("Exit niri"),
369 Action::ShowHotkeyOverlay => String::from("Show Important Hotkeys"),382 Action::ShowHotkeyOverlay => String::from("Show Important Hotkeys"),
370 Action::CloseWindow => String::from("Close Focused Window"),383 Action::CloseWindow => String::from("Close Focused Window"),
371 Action::FocusColumnLeft => String::from("Focus Column to the Left"),384 Action::FocusColumnLeft => String::from("Focus Column to the Left"),
src/input.rsmodified+12 -9
@@ -284,15 +284,18 @@ impl State {
284 }284 }
285 285
286 match action {286 match action {
287- Action::Quit => {287+ Action::Quit(skip_confirmation) => {
288- if let Some(dialog) = &mut self.niri.exit_confirm_dialog {288+ if !skip_confirmation {
289- if dialog.show() {289+ if let Some(dialog) = &mut self.niri.exit_confirm_dialog {
290- self.niri.queue_redraw_all();290+ if dialog.show() {
291+ self.niri.queue_redraw_all();
292+ }
293+ return;
291 }294 }
292- } else {
293- info!("quitting because quit bind was pressed");
294- self.niri.stop_signal.stop()
295 }295 }
296+
297+ info!("quitting as requested");
298+ self.niri.stop_signal.stop()
296 }299 }
297 Action::ChangeVt(vt) => {300 Action::ChangeVt(vt) => {
298 self.backend.change_vt(vt);301 self.backend.change_vt(vt);
@@ -1542,7 +1545,7 @@ fn should_notify_activity<I: InputBackend>(event: &InputEvent<I>) -> bool {
1542 fn allowed_when_locked(action: &Action) -> bool {1545 fn allowed_when_locked(action: &Action) -> bool {
1543 matches!(1546 matches!(
1544 action,1547 action,
1545- Action::Quit1548+ Action::Quit(_)
1546 | Action::ChangeVt(_)1549 | Action::ChangeVt(_)
1547 | Action::Suspend1550 | Action::Suspend
1548 | Action::PowerOffMonitors1551 | Action::PowerOffMonitors
@@ -1553,7 +1556,7 @@ fn allowed_when_locked(action: &Action) -> bool {
1553 fn allowed_during_screenshot(action: &Action) -> bool {1556 fn allowed_during_screenshot(action: &Action) -> bool {
1554 matches!(1557 matches!(
1555 action,1558 action,
1556- Action::Quit | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors1559+ Action::Quit(_) | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors
1557 )1560 )
1558 }1561 }
1559 1562