deal with supressed key release edge-case; add allow-inhibiting property

This commit is contained in:
sodiboo
2024-08-27 19:43:32 +02:00
committed by Ivan Molodetskikh
parent 79f22053b9
commit a7fc24bb1f
2 changed files with 44 additions and 15 deletions
+17 -1
View File
@@ -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)]
@@ -3015,6 +3016,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 +3031,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 +3055,7 @@ where
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
};
if let Some(child) = children.next() {
@@ -3078,6 +3084,7 @@ where
repeat,
cooldown,
allow_when_locked,
allow_inhibiting,
})
}
Err(e) => {
@@ -3470,7 +3477,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; }
}
@@ -3788,6 +3795,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: true,
allow_inhibiting: true,
},
Bind {
key: Key {
@@ -3798,6 +3806,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
},
Bind {
key: Key {
@@ -3808,6 +3817,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
},
Bind {
key: Key {
@@ -3818,6 +3828,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
},
Bind {
key: Key {
@@ -3828,6 +3839,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
},
Bind {
key: Key {
@@ -3838,6 +3850,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
},
Bind {
key: Key {
@@ -3850,6 +3863,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
},
Bind {
key: Key {
@@ -3860,6 +3874,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: false,
},
Bind {
key: Key {
@@ -3870,6 +3885,7 @@ mod tests {
repeat: true,
cooldown: Some(Duration::from_millis(150)),
allow_when_locked: false,
allow_inhibiting: true,
},
]),
switch_events: SwitchBinds {
+27 -14
View File
@@ -2837,29 +2837,30 @@ fn should_intercept_key(
repeat: true,
cooldown: None,
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) {
(Some(bind), true) => {
suppressed_keys.insert(key_code);
FilterResult::Intercept(Some(bind))
if is_inhibiting_shortcuts && bind.allow_inhibiting {
FilterResult::Forward
} else {
suppressed_keys.insert(key_code);
FilterResult::Intercept(Some(bind))
}
}
(_, 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);
FilterResult::Intercept(None)
}
@@ -2899,6 +2900,12 @@ fn find_bind(
repeat: true,
cooldown: None,
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,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
}]);
let comp_mod = CompositorMod::Super;
@@ -3497,6 +3505,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
},
Bind {
key: Key {
@@ -3507,6 +3516,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
},
Bind {
key: Key {
@@ -3517,6 +3527,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
},
Bind {
key: Key {
@@ -3527,6 +3538,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
},
Bind {
key: Key {
@@ -3537,6 +3549,7 @@ mod tests {
repeat: true,
cooldown: None,
allow_when_locked: false,
allow_inhibiting: true,
},
]);