mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Add skip-confirmation flag to the quit action
This commit is contained in:
+10
-2
@@ -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")),
|
||||
|
||||
+5
-1
@@ -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.
|
||||
|
||||
@@ -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; }
|
||||
|
||||
+19
-6
@@ -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"),
|
||||
|
||||
+12
-9
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user