Format Rust code using rustfmt

This commit is contained in:
github-actions[bot] 2024-12-25 18:17:53 +00:00 committed by GitHub
parent b1a3061b20
commit 44b5c155db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 84 additions and 30 deletions

View file

@ -392,54 +392,90 @@ fn parse_raw_config(raw_config: RawConfig) -> (Bindings, HashMap<String, String>
} }
if let Ok(event) = Axis::from_str(event) { if let Ok(event) = Axis::from_str(event) {
if !bindings.movements.contains_key(&Event::Axis(event)) { if !bindings.movements.contains_key(&Event::Axis(event)) {
bindings bindings.movements.insert(
.movements Event::Axis(event),
.insert(Event::Axis(event), HashMap::from([(modifiers, Relative::from_str(output.as_str()).expect("Invalid movement in [movements]."))])); HashMap::from([(
modifiers,
Relative::from_str(output.as_str())
.expect("Invalid movement in [movements]."),
)]),
);
} else { } else {
bindings bindings
.movements .movements
.get_mut(&Event::Axis(event)) .get_mut(&Event::Axis(event))
.unwrap() .unwrap()
.insert(modifiers, Relative::from_str(output.as_str()).expect("Invalid movement in [movements].")); .insert(
modifiers,
Relative::from_str(output.as_str())
.expect("Invalid movement in [movements]."),
);
} }
} else if let Ok(event) = Key::from_str(event) { } else if let Ok(event) = Key::from_str(event) {
if !bindings.movements.contains_key(&Event::Key(event)) { if !bindings.movements.contains_key(&Event::Key(event)) {
bindings bindings.movements.insert(
.movements Event::Key(event),
.insert(Event::Key(event), HashMap::from([(modifiers, Relative::from_str(output.as_str()).expect("Invalid movement in [movements]."))])); HashMap::from([(
modifiers,
Relative::from_str(output.as_str())
.expect("Invalid movement in [movements]."),
)]),
);
} else { } else {
bindings bindings
.movements .movements
.get_mut(&Event::Key(event)) .get_mut(&Event::Key(event))
.unwrap() .unwrap()
.insert(modifiers, Relative::from_str(output.as_str()).expect("Invalid movement in [movements].")); .insert(
modifiers,
Relative::from_str(output.as_str())
.expect("Invalid movement in [movements]."),
);
} }
} }
} else { } else {
let modifiers: Vec<Event> = Vec::new(); let modifiers: Vec<Event> = Vec::new();
if let Ok(event) = Axis::from_str(input.as_str()) { if let Ok(event) = Axis::from_str(input.as_str()) {
if !bindings.movements.contains_key(&Event::Axis(event)) { if !bindings.movements.contains_key(&Event::Axis(event)) {
bindings bindings.movements.insert(
.movements Event::Axis(event),
.insert(Event::Axis(event), HashMap::from([(modifiers, Relative::from_str(output.as_str()).expect("Invalid movement in [movements]."))])); HashMap::from([(
modifiers,
Relative::from_str(output.as_str())
.expect("Invalid movement in [movements]."),
)]),
);
} else { } else {
bindings bindings
.movements .movements
.get_mut(&Event::Axis(event)) .get_mut(&Event::Axis(event))
.unwrap() .unwrap()
.insert(modifiers, Relative::from_str(output.as_str()).expect("Invalid movement in [movements].")); .insert(
modifiers,
Relative::from_str(output.as_str())
.expect("Invalid movement in [movements]."),
);
} }
} else if let Ok(event) = Key::from_str(input.as_str()) { } else if let Ok(event) = Key::from_str(input.as_str()) {
if !bindings.movements.contains_key(&Event::Key(event)) { if !bindings.movements.contains_key(&Event::Key(event)) {
bindings bindings.movements.insert(
.movements Event::Key(event),
.insert(Event::Key(event), HashMap::from([(modifiers, Relative::from_str(output.as_str()).expect("Invalid movement in [movements]."))])); HashMap::from([(
modifiers,
Relative::from_str(output.as_str())
.expect("Invalid movement in [movements]."),
)]),
);
} else { } else {
bindings bindings
.movements .movements
.get_mut(&Event::Key(event)) .get_mut(&Event::Key(event))
.unwrap() .unwrap()
.insert(modifiers, Relative::from_str(output.as_str()).expect("Invalid movement in [movements].")); .insert(
modifiers,
Relative::from_str(output.as_str())
.expect("Invalid movement in [movements]."),
);
} }
} }
} }

View file

@ -1,5 +1,5 @@
use crate::active_client::*; use crate::active_client::*;
use crate::config::{parse_modifiers, Associations, Axis, Event, Relative, Cursor, Scroll}; use crate::config::{parse_modifiers, Associations, Axis, Cursor, Event, Relative, Scroll};
use crate::udev_monitor::Environment; use crate::udev_monitor::Environment;
use crate::virtual_devices::VirtualDevices; use crate::virtual_devices::VirtualDevices;
use crate::Config; use crate::Config;
@ -328,7 +328,13 @@ impl EventReader {
.unwrap() .unwrap()
.name .name
); );
tokio::join!(self.event_loop(), self.cursor_loop(), self.scroll_loop(), self.key_cursor_loop(), self.key_scroll_loop()); tokio::join!(
self.event_loop(),
self.cursor_loop(),
self.scroll_loop(),
self.key_cursor_loop(),
self.key_scroll_loop()
);
} }
pub async fn event_loop(&self) { pub async fn event_loop(&self) {
@ -1448,7 +1454,7 @@ impl EventReader {
pub async fn key_cursor_loop(&self) { pub async fn key_cursor_loop(&self) {
let (speed, acceleration, mut current_speed) = ( let (speed, acceleration, mut current_speed) = (
if self.settings.cursor.speed == 0 { if self.settings.cursor.speed == 0 {
return return;
} else { } else {
self.settings.cursor.speed self.settings.cursor.speed
}, },
@ -1457,7 +1463,7 @@ impl EventReader {
} else { } else {
self.settings.cursor.acceleration.abs() self.settings.cursor.acceleration.abs()
}, },
self.settings.cursor.speed as f32 self.settings.cursor.speed as f32,
); );
while *self.device_is_connected.lock().await { while *self.device_is_connected.lock().await {
{ {
@ -1471,14 +1477,20 @@ impl EventReader {
} }
if cursor_movement.0 != 0 { if cursor_movement.0 != 0 {
let mut virt_dev = self.virt_dev.lock().await; let mut virt_dev = self.virt_dev.lock().await;
let virtual_event_x: InputEvent = let virtual_event_x: InputEvent = InputEvent::new_now(
InputEvent::new_now(EventType::RELATIVE, 0, cursor_movement.0 * current_speed as i32); EventType::RELATIVE,
0,
cursor_movement.0 * current_speed as i32,
);
virt_dev.axis.emit(&[virtual_event_x]).unwrap(); virt_dev.axis.emit(&[virtual_event_x]).unwrap();
} }
if cursor_movement.1 != 0 { if cursor_movement.1 != 0 {
let mut virt_dev = self.virt_dev.lock().await; let mut virt_dev = self.virt_dev.lock().await;
let virtual_event_y: InputEvent = let virtual_event_y: InputEvent = InputEvent::new_now(
InputEvent::new_now(EventType::RELATIVE, 1, cursor_movement.1 * current_speed as i32); EventType::RELATIVE,
1,
cursor_movement.1 * current_speed as i32,
);
virt_dev.axis.emit(&[virtual_event_y]).unwrap(); virt_dev.axis.emit(&[virtual_event_y]).unwrap();
} }
} }
@ -1490,7 +1502,7 @@ impl EventReader {
pub async fn key_scroll_loop(&self) { pub async fn key_scroll_loop(&self) {
let (speed, acceleration, mut current_speed) = ( let (speed, acceleration, mut current_speed) = (
if self.settings.scroll.speed == 0 { if self.settings.scroll.speed == 0 {
return return;
} else { } else {
self.settings.scroll.speed self.settings.scroll.speed
}, },
@ -1499,7 +1511,7 @@ impl EventReader {
} else { } else {
self.settings.scroll.acceleration.abs() self.settings.scroll.acceleration.abs()
}, },
self.settings.scroll.speed as f32 self.settings.scroll.speed as f32,
); );
while *self.device_is_connected.lock().await { while *self.device_is_connected.lock().await {
{ {
@ -1513,13 +1525,19 @@ impl EventReader {
} }
let mut virt_dev = self.virt_dev.lock().await; let mut virt_dev = self.virt_dev.lock().await;
if scroll_movement.0 != 0 { if scroll_movement.0 != 0 {
let virtual_event_x: InputEvent = let virtual_event_x: InputEvent = InputEvent::new_now(
InputEvent::new_now(EventType::RELATIVE, 12, scroll_movement.0 * current_speed as i32); EventType::RELATIVE,
12,
scroll_movement.0 * current_speed as i32,
);
virt_dev.axis.emit(&[virtual_event_x]).unwrap(); virt_dev.axis.emit(&[virtual_event_x]).unwrap();
} }
if scroll_movement.1 != 0 { if scroll_movement.1 != 0 {
let virtual_event_y: InputEvent = let virtual_event_y: InputEvent = InputEvent::new_now(
InputEvent::new_now(EventType::RELATIVE, 11, scroll_movement.1 * current_speed as i32); EventType::RELATIVE,
11,
scroll_movement.1 * current_speed as i32,
);
virt_dev.axis.emit(&[virtual_event_y]).unwrap(); virt_dev.axis.emit(&[virtual_event_y]).unwrap();
} }
} }