add toggle-keyboard-shortcuts-inhibit bind

This commit is contained in:
sodiboo
2024-09-07 21:26:00 +02:00
committed by Ivan Molodetskikh
parent a7fc24bb1f
commit ef8d5274b8
3 changed files with 55 additions and 0 deletions
+31
View File
@@ -1279,6 +1279,7 @@ pub enum Action {
id: u64, id: u64,
write_to_disk: bool, write_to_disk: bool,
}, },
ToggleKeyboardShortcutsInhibit,
CloseWindow, CloseWindow,
#[knuffel(skip)] #[knuffel(skip)]
CloseWindowById(u64), CloseWindowById(u64),
@@ -3078,6 +3079,12 @@ where
} }
} }
// The toggle-inhibit action must always be uninhibitable.
// Otherwise, it would be impossible to trigger it.
if matches!(action, Action::ToggleKeyboardShortcutsInhibit) {
allow_inhibiting = false;
}
Ok(Self { Ok(Self {
key, key,
action, action,
@@ -3470,6 +3477,8 @@ mod tests {
} }
binds { binds {
Mod+Escape { toggle-keyboard-shortcuts-inhibit; }
Mod+Shift+Escape allow-inhibiting=true { toggle-keyboard-shortcuts-inhibit; }
Mod+T allow-when-locked=true { spawn "alacritty"; } Mod+T allow-when-locked=true { spawn "alacritty"; }
Mod+Q { close-window; } Mod+Q { close-window; }
Mod+Shift+H { focus-monitor-left; } Mod+Shift+H { focus-monitor-left; }
@@ -3786,6 +3795,28 @@ mod tests {
}, },
], ],
binds: Binds(vec![ binds: Binds(vec![
Bind {
key: Key {
trigger: Trigger::Keysym(Keysym::Escape),
modifiers: Modifiers::COMPOSITOR,
},
action: Action::ToggleKeyboardShortcutsInhibit,
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: false,
},
Bind {
key: Key {
trigger: Trigger::Keysym(Keysym::Escape),
modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,
},
action: Action::ToggleKeyboardShortcutsInhibit,
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: false,
},
Bind { Bind {
key: Key { key: Key {
trigger: Trigger::Keysym(Keysym::t), trigger: Trigger::Keysym(Keysym::t),
+10
View File
@@ -536,6 +536,16 @@ binds {
Ctrl+Print { screenshot-screen; } Ctrl+Print { screenshot-screen; }
Alt+Print { screenshot-window; } Alt+Print { screenshot-window; }
// Applications such as remote-desktop clients and software KVM switches may
// request that niri stops processing the keyboard shortcuts defined here
// so they may, for example, forward the key presses as-is to a remote machine.
// It's a good idea to bind an escape hatch to toggle the inhibitor,
// so a buggy application can't hold your session hostage.
//
// The allow-inhibiting=false property can be applied to other binds as well,
// which ensures niri always processes them, even when an inhibitor is active.
Mod+Escape allow-inhibiting=false { toggle-keyboard-shortcuts-inhibit; }
// The quit action will show a confirmation dialog to avoid accidental exits. // The quit action will show a confirmation dialog to avoid accidental exits.
Mod+Shift+E { quit; } Mod+Shift+E { quit; }
Ctrl+Alt+Delete { quit; } Ctrl+Alt+Delete { quit; }
+14
View File
@@ -626,6 +626,19 @@ impl State {
}); });
} }
} }
Action::ToggleKeyboardShortcutsInhibit => {
if let Some(inhibitor) = self.niri.keyboard_focus.surface().and_then(|surface| {
self.niri
.keyboard_shortcuts_inhibiting_surfaces
.get(surface)
}) {
if inhibitor.is_active() {
inhibitor.inactivate();
} else {
inhibitor.activate();
}
}
}
Action::CloseWindow => { Action::CloseWindow => {
if let Some(mapped) = self.niri.layout.focus() { if let Some(mapped) = self.niri.layout.focus() {
mapped.toplevel().send_close(); mapped.toplevel().send_close();
@@ -3071,6 +3084,7 @@ fn allowed_when_locked(action: &Action) -> bool {
| Action::PowerOffMonitors | Action::PowerOffMonitors
| Action::PowerOnMonitors | Action::PowerOnMonitors
| Action::SwitchLayout(_) | Action::SwitchLayout(_)
| Action::ToggleKeyboardShortcutsInhibit
) )
} }