mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
deal with supressed key release edge-case; add allow-inhibiting property
This commit is contained in:
committed by
Ivan Molodetskikh
parent
79f22053b9
commit
a7fc24bb1f
+17
-1
@@ -1191,6 +1191,7 @@ pub struct Bind {
|
|||||||
pub repeat: bool,
|
pub repeat: bool,
|
||||||
pub cooldown: Option<Duration>,
|
pub cooldown: Option<Duration>,
|
||||||
pub allow_when_locked: bool,
|
pub allow_when_locked: bool,
|
||||||
|
pub allow_inhibiting: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
@@ -3015,6 +3016,7 @@ where
|
|||||||
let mut cooldown = None;
|
let mut cooldown = None;
|
||||||
let mut allow_when_locked = false;
|
let mut allow_when_locked = false;
|
||||||
let mut allow_when_locked_node = None;
|
let mut allow_when_locked_node = None;
|
||||||
|
let mut allow_inhibiting = true;
|
||||||
for (name, val) in &node.properties {
|
for (name, val) in &node.properties {
|
||||||
match &***name {
|
match &***name {
|
||||||
"repeat" => {
|
"repeat" => {
|
||||||
@@ -3029,6 +3031,9 @@ where
|
|||||||
allow_when_locked = knuffel::traits::DecodeScalar::decode(val, ctx)?;
|
allow_when_locked = knuffel::traits::DecodeScalar::decode(val, ctx)?;
|
||||||
allow_when_locked_node = Some(name);
|
allow_when_locked_node = Some(name);
|
||||||
}
|
}
|
||||||
|
"allow-inhibiting" => {
|
||||||
|
allow_inhibiting = knuffel::traits::DecodeScalar::decode(val, ctx)?;
|
||||||
|
}
|
||||||
name_str => {
|
name_str => {
|
||||||
ctx.emit_error(DecodeError::unexpected(
|
ctx.emit_error(DecodeError::unexpected(
|
||||||
name,
|
name,
|
||||||
@@ -3050,6 +3055,7 @@ where
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(child) = children.next() {
|
if let Some(child) = children.next() {
|
||||||
@@ -3078,6 +3084,7 @@ where
|
|||||||
repeat,
|
repeat,
|
||||||
cooldown,
|
cooldown,
|
||||||
allow_when_locked,
|
allow_when_locked,
|
||||||
|
allow_inhibiting,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -3470,7 +3477,7 @@ mod tests {
|
|||||||
Mod+Comma { consume-window-into-column; }
|
Mod+Comma { consume-window-into-column; }
|
||||||
Mod+1 { focus-workspace 1; }
|
Mod+1 { focus-workspace 1; }
|
||||||
Mod+Shift+1 { focus-workspace "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; }
|
Mod+WheelScrollDown cooldown-ms=150 { focus-workspace-down; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3788,6 +3795,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: true,
|
allow_when_locked: true,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
Bind {
|
Bind {
|
||||||
key: Key {
|
key: Key {
|
||||||
@@ -3798,6 +3806,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
Bind {
|
Bind {
|
||||||
key: Key {
|
key: Key {
|
||||||
@@ -3808,6 +3817,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
Bind {
|
Bind {
|
||||||
key: Key {
|
key: Key {
|
||||||
@@ -3818,6 +3828,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
Bind {
|
Bind {
|
||||||
key: Key {
|
key: Key {
|
||||||
@@ -3828,6 +3839,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
Bind {
|
Bind {
|
||||||
key: Key {
|
key: Key {
|
||||||
@@ -3838,6 +3850,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
Bind {
|
Bind {
|
||||||
key: Key {
|
key: Key {
|
||||||
@@ -3850,6 +3863,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
Bind {
|
Bind {
|
||||||
key: Key {
|
key: Key {
|
||||||
@@ -3860,6 +3874,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: false,
|
||||||
},
|
},
|
||||||
Bind {
|
Bind {
|
||||||
key: Key {
|
key: Key {
|
||||||
@@ -3870,6 +3885,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: Some(Duration::from_millis(150)),
|
cooldown: Some(Duration::from_millis(150)),
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
switch_events: SwitchBinds {
|
switch_events: SwitchBinds {
|
||||||
|
|||||||
+27
-14
@@ -2837,29 +2837,30 @@ fn should_intercept_key(
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
// The screenshot UI owns the focus anyway, so this doesn't really matter.
|
||||||
|
// But logically, nothing can inhibit its actions. Only opening it can be
|
||||||
|
// inhibited.
|
||||||
|
allow_inhibiting: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_inhibiting_shortcuts
|
|
||||||
&& !matches!(
|
|
||||||
final_bind,
|
|
||||||
Some(Bind {
|
|
||||||
action: Action::ChangeVt(_),
|
|
||||||
..
|
|
||||||
})
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return FilterResult::Forward;
|
|
||||||
}
|
|
||||||
|
|
||||||
match (final_bind, pressed) {
|
match (final_bind, pressed) {
|
||||||
(Some(bind), true) => {
|
(Some(bind), true) => {
|
||||||
suppressed_keys.insert(key_code);
|
if is_inhibiting_shortcuts && bind.allow_inhibiting {
|
||||||
FilterResult::Intercept(Some(bind))
|
FilterResult::Forward
|
||||||
|
} else {
|
||||||
|
suppressed_keys.insert(key_code);
|
||||||
|
FilterResult::Intercept(Some(bind))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(_, false) => {
|
(_, false) => {
|
||||||
|
// By this point, we know that the key was supressed on press. Even if we're inhibiting
|
||||||
|
// shortcuts, we should still suppress the release.
|
||||||
|
// But we don't need to check for shortcuts inhibition here, because
|
||||||
|
// if it was inhibited on press (forwarded to the client), it wouldn't be suppressed,
|
||||||
|
// so the release would already have been forwarded at the start of this function.
|
||||||
suppressed_keys.remove(&key_code);
|
suppressed_keys.remove(&key_code);
|
||||||
FilterResult::Intercept(None)
|
FilterResult::Intercept(None)
|
||||||
}
|
}
|
||||||
@@ -2899,6 +2900,12 @@ fn find_bind(
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
// In a worst-case scenario, the user has no way to unlock the compositor and a
|
||||||
|
// misbehaving client has a keyboard shortcuts inhibitor, "jailing" the user.
|
||||||
|
// The user must always be able to change VTs to recover from such a situation.
|
||||||
|
// It also makes no sense to inhibit the default power key handling.
|
||||||
|
// Hardcoded binds must never be inhibited.
|
||||||
|
allow_inhibiting: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3361,6 +3368,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
let comp_mod = CompositorMod::Super;
|
let comp_mod = CompositorMod::Super;
|
||||||
@@ -3497,6 +3505,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
Bind {
|
Bind {
|
||||||
key: Key {
|
key: Key {
|
||||||
@@ -3507,6 +3516,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
Bind {
|
Bind {
|
||||||
key: Key {
|
key: Key {
|
||||||
@@ -3517,6 +3527,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
Bind {
|
Bind {
|
||||||
key: Key {
|
key: Key {
|
||||||
@@ -3527,6 +3538,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
Bind {
|
Bind {
|
||||||
key: Key {
|
key: Key {
|
||||||
@@ -3537,6 +3549,7 @@ mod tests {
|
|||||||
repeat: true,
|
repeat: true,
|
||||||
cooldown: None,
|
cooldown: None,
|
||||||
allow_when_locked: false,
|
allow_when_locked: false,
|
||||||
|
allow_inhibiting: true,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user