Format Rust sources at 100 columns
This commit is contained in:
1 parent
4661f595f8
commit
610478f8c7
336 files changed
+23497
-7892
No files matched your search
@@ -26,7 +26,9 @@ struct Registration {
|
||||
|
||||
impl Registration {
|
||||
fn timestamp(&self) -> u64 {
|
||||
self.latest.0.saturating_add(self.latest.1.elapsed().as_millis() as u64)
|
||||
self.latest
|
||||
.0
|
||||
.saturating_add(self.latest.1.elapsed().as_millis() as u64)
|
||||
}
|
||||
|
||||
fn release_all(&mut self) {
|
||||
@@ -53,7 +55,11 @@ impl PortalShortcuts {
|
||||
return Err("Shortcut limit reached".into());
|
||||
}
|
||||
let keymap = crate::config::physical_keymap(input).map_err(|error| error.to_string())?;
|
||||
if self.0.get(&owner).is_some_and(|registration| registration.closed) {
|
||||
if self
|
||||
.0
|
||||
.get(&owner)
|
||||
.is_some_and(|registration| registration.closed)
|
||||
{
|
||||
return Err("Shortcut session has ended".into());
|
||||
}
|
||||
let mut parsed: Vec<(Shortcut, Binding)> = Vec::new();
|
||||
@@ -62,11 +68,17 @@ impl PortalShortcuts {
|
||||
.trigger
|
||||
.split('+')
|
||||
.any(|part| part.trim().eq_ignore_ascii_case("num"));
|
||||
if shortcut.id.is_empty() || shortcut.id.len() > 256 || shortcut.id.chars().any(char::is_control) {
|
||||
if shortcut.id.is_empty()
|
||||
|| shortcut.id.len() > 256
|
||||
|| shortcut.id.chars().any(char::is_control)
|
||||
{
|
||||
return Err("Invalid shortcut identifier".into());
|
||||
}
|
||||
let binding = Binding::portal_trigger(&shortcut.trigger).map_err(|error| error.to_string())?;
|
||||
if configured.iter().any(|other| binding.conflicts(other, &keymap))
|
||||
let binding =
|
||||
Binding::portal_trigger(&shortcut.trigger).map_err(|error| error.to_string())?;
|
||||
if configured
|
||||
.iter()
|
||||
.any(|other| binding.conflicts(other, &keymap))
|
||||
|| parsed
|
||||
.iter()
|
||||
.any(|(other, key)| other.id == shortcut.id || binding.conflicts(key, &keymap))
|
||||
@@ -106,9 +118,9 @@ impl PortalShortcuts {
|
||||
return;
|
||||
};
|
||||
for registration in self.0.values_mut() {
|
||||
registration
|
||||
.shortcuts
|
||||
.retain(|(_, binding)| !configured.iter().any(|key| binding.conflicts(key, &keymap)));
|
||||
registration.shortcuts.retain(|(_, binding)| {
|
||||
!configured.iter().any(|key| binding.conflicts(key, &keymap))
|
||||
});
|
||||
let active_ids = registration
|
||||
.shortcuts
|
||||
.iter()
|
||||
@@ -144,7 +156,13 @@ impl PortalShortcuts {
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn press(&mut self, key: Keycode, symbols: &[u32], modifiers: &ModifiersState, timestamp: u64) -> bool {
|
||||
pub(crate) fn press(
|
||||
&mut self,
|
||||
key: Keycode,
|
||||
symbols: &[u32],
|
||||
modifiers: &ModifiersState,
|
||||
timestamp: u64,
|
||||
) -> bool {
|
||||
for registration in self.0.values_mut() {
|
||||
let Some((shortcut, _)) = registration.shortcuts.iter().find(|(shortcut, binding)| {
|
||||
(!shortcut.num_required || modifiers.num_lock)
|
||||
@@ -225,7 +243,10 @@ mod tests {
|
||||
.register(1, vec![shortcut("one", "Super+q")], &configured, &input)
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(shortcuts.poll(1, false)["shortcuts"][0]["trigger"], "Ctrl+Alt+a");
|
||||
assert_eq!(
|
||||
shortcuts.poll(1, false)["shortcuts"][0]["trigger"],
|
||||
"Ctrl+Alt+a"
|
||||
);
|
||||
shortcuts.remove(1);
|
||||
assert_eq!(shortcuts.poll(1, false)["closed"], true);
|
||||
shortcuts
|
||||
@@ -274,7 +295,12 @@ mod tests {
|
||||
.register(1, vec![shortcut("one", "Ctrl+Alt+a")], &[], &input)
|
||||
.unwrap();
|
||||
shortcuts.reconcile(&[Binding::portal_trigger("Ctrl+Alt+a").unwrap()], &input);
|
||||
assert!(shortcuts.poll(1, false)["shortcuts"].as_array().unwrap().is_empty());
|
||||
assert!(
|
||||
shortcuts.poll(1, false)["shortcuts"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
);
|
||||
assert!(Binding::portal_trigger("Ctrl+Alt+Escape").is_err());
|
||||
assert!(Binding::portal_trigger("Ctrl+Alt+F3").is_err());
|
||||
}
|
||||
@@ -305,9 +331,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn physical_conflicts_include_secondary_layouts_and_num_modifier_is_honored() {
|
||||
let config =
|
||||
crate::config::Config::parse_source("binding keys=\"Ctrl+AD01\" match=\"physical\" action=\"none\"\n")
|
||||
.unwrap();
|
||||
let config = crate::config::Config::parse_source(
|
||||
"binding keys=\"Ctrl+AD01\" match=\"physical\" action=\"none\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
let mut input = config.input_settings().unwrap();
|
||||
input.xkb_layout = "us,fr".into();
|
||||
let configured = config.bindings(&input).unwrap();
|
||||
|
||||
Reference in new issue
Block a user