Skip to content

Commit

Permalink
add toggle-keyboard-shortcuts-inhibit bind
Browse files Browse the repository at this point in the history
  • Loading branch information
sodiboo committed Oct 6, 2024
1 parent d4396ed commit 234b6b5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
31 changes: 31 additions & 0 deletions niri-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ pub enum Action {
ScreenshotWindow,
#[knuffel(skip)]
ScreenshotWindowById(u64),
ToggleKeyboardShortcutsInhibit,
CloseWindow,
#[knuffel(skip)]
CloseWindowById(u64),
Expand Down Expand Up @@ -2664,6 +2665,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 {
key,
action,
Expand Down Expand Up @@ -3009,6 +3016,8 @@ mod tests {
}
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+Q { close-window; }
Mod+Shift+H { focus-monitor-left; }
Expand Down Expand Up @@ -3259,6 +3268,28 @@ mod tests {
},
],
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 {
key: Key {
trigger: Trigger::Keysym(Keysym::t),
Expand Down
10 changes: 10 additions & 0 deletions resources/default-config.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,16 @@ binds {
Ctrl+Print { screenshot-screen; }
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+Shift+Escape allow-inhibiting=false { toggle-keyboard-shortcuts-inhibit; }

// The quit action will show a confirmation dialog to avoid accidental exits.
Mod+Shift+E { quit; }

Expand Down
13 changes: 13 additions & 0 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,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 => {
if let Some(mapped) = self.niri.layout.focus() {
mapped.toplevel().send_close();
Expand Down

0 comments on commit 234b6b5

Please sign in to comment.