mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
implement keyboard-shortcuts-inhibit and wlr-virtual-pointer (#630)
* stub keyboard-shortcuts-inhibit and virtual-pointer impls * implement keyboard-shortcuts-inhibit * implement virtual-pointer * deal with supressed key release edge-case; add allow-inhibiting property * add toggle-keyboard-shortcuts-inhibit bind * add InputBackend extensions; use Device::output() for absolute pos events * add a `State` parameter to the backend exts and better document future intent * Add some tests for is_inhibiting_shortcuts --------- Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
This commit is contained in:
+48
-1
@@ -1191,6 +1191,7 @@ pub struct Bind {
|
||||
pub repeat: bool,
|
||||
pub cooldown: Option<Duration>,
|
||||
pub allow_when_locked: bool,
|
||||
pub allow_inhibiting: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
||||
@@ -1278,6 +1279,7 @@ pub enum Action {
|
||||
id: u64,
|
||||
write_to_disk: bool,
|
||||
},
|
||||
ToggleKeyboardShortcutsInhibit,
|
||||
CloseWindow,
|
||||
#[knuffel(skip)]
|
||||
CloseWindowById(u64),
|
||||
@@ -3015,6 +3017,7 @@ where
|
||||
let mut cooldown = None;
|
||||
let mut allow_when_locked = false;
|
||||
let mut allow_when_locked_node = None;
|
||||
let mut allow_inhibiting = true;
|
||||
for (name, val) in &node.properties {
|
||||
match &***name {
|
||||
"repeat" => {
|
||||
@@ -3029,6 +3032,9 @@ where
|
||||
allow_when_locked = knuffel::traits::DecodeScalar::decode(val, ctx)?;
|
||||
allow_when_locked_node = Some(name);
|
||||
}
|
||||
"allow-inhibiting" => {
|
||||
allow_inhibiting = knuffel::traits::DecodeScalar::decode(val, ctx)?;
|
||||
}
|
||||
name_str => {
|
||||
ctx.emit_error(DecodeError::unexpected(
|
||||
name,
|
||||
@@ -3050,6 +3056,7 @@ where
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: true,
|
||||
};
|
||||
|
||||
if let Some(child) = children.next() {
|
||||
@@ -3072,12 +3079,19 @@ 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,
|
||||
repeat,
|
||||
cooldown,
|
||||
allow_when_locked,
|
||||
allow_inhibiting,
|
||||
})
|
||||
}
|
||||
Err(e) => {
|
||||
@@ -3463,6 +3477,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; }
|
||||
@@ -3470,7 +3486,7 @@ mod tests {
|
||||
Mod+Comma { consume-window-into-column; }
|
||||
Mod+1 { focus-workspace 1; }
|
||||
Mod+Shift+1 { focus-workspace "workspace-1"; }
|
||||
Mod+Shift+E { quit skip-confirmation=true; }
|
||||
Mod+Shift+E allow-inhibiting=false { quit skip-confirmation=true; }
|
||||
Mod+WheelScrollDown cooldown-ms=150 { focus-workspace-down; }
|
||||
}
|
||||
|
||||
@@ -3779,6 +3795,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),
|
||||
@@ -3788,6 +3826,7 @@ mod tests {
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: true,
|
||||
allow_inhibiting: true,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
@@ -3798,6 +3837,7 @@ mod tests {
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: true,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
@@ -3808,6 +3848,7 @@ mod tests {
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: true,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
@@ -3818,6 +3859,7 @@ mod tests {
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: true,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
@@ -3828,6 +3870,7 @@ mod tests {
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: true,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
@@ -3838,6 +3881,7 @@ mod tests {
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: true,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
@@ -3850,6 +3894,7 @@ mod tests {
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: true,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
@@ -3860,6 +3905,7 @@ mod tests {
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: false,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
@@ -3870,6 +3916,7 @@ mod tests {
|
||||
repeat: true,
|
||||
cooldown: Some(Duration::from_millis(150)),
|
||||
allow_when_locked: false,
|
||||
allow_inhibiting: true,
|
||||
},
|
||||
]),
|
||||
switch_events: SwitchBinds {
|
||||
|
||||
Reference in New Issue
Block a user