style(detect): fix formatting

This commit is contained in:
Federico Terzi 2021-10-06 18:37:32 +02:00
parent be68a1f8ff
commit d11af8b1c2
6 changed files with 64 additions and 23 deletions

View File

@ -199,26 +199,70 @@ impl Device {
} }
} }
pub fn update_modifier_state(&mut self, modifiers_state: &ModifiersState, modifiers_map: &HashMap<String, u32>) { pub fn update_modifier_state(
&mut self,
modifiers_state: &ModifiersState,
modifiers_map: &HashMap<String, u32>,
) {
if modifiers_state.alt { if modifiers_state.alt {
self.update_key(*modifiers_map.get("alt").expect("unable to find modifiers key in map"), true); self.update_key(
*modifiers_map
.get("alt")
.expect("unable to find modifiers key in map"),
true,
);
} }
if modifiers_state.ctrl { if modifiers_state.ctrl {
self.update_key(*modifiers_map.get("ctrl").expect("unable to find modifiers key in map"), true); self.update_key(
*modifiers_map
.get("ctrl")
.expect("unable to find modifiers key in map"),
true,
);
} }
if modifiers_state.meta { if modifiers_state.meta {
self.update_key(*modifiers_map.get("meta").expect("unable to find modifiers key in map"), true); self.update_key(
*modifiers_map
.get("meta")
.expect("unable to find modifiers key in map"),
true,
);
} }
if modifiers_state.num_lock { if modifiers_state.num_lock {
self.update_key(*modifiers_map.get("num_lock").expect("unable to find modifiers key in map"), true); self.update_key(
self.update_key(*modifiers_map.get("num_lock").expect("unable to find modifiers key in map"), false); *modifiers_map
.get("num_lock")
.expect("unable to find modifiers key in map"),
true,
);
self.update_key(
*modifiers_map
.get("num_lock")
.expect("unable to find modifiers key in map"),
false,
);
} }
if modifiers_state.shift { if modifiers_state.shift {
self.update_key(*modifiers_map.get("shift").expect("unable to find modifiers key in map"), true); self.update_key(
*modifiers_map
.get("shift")
.expect("unable to find modifiers key in map"),
true,
);
} }
if modifiers_state.caps_lock { if modifiers_state.caps_lock {
self.update_key(*modifiers_map.get("caps_lock").expect("unable to find modifiers key in map"), true); self.update_key(
self.update_key(*modifiers_map.get("caps_lock").expect("unable to find modifiers key in map"), false); *modifiers_map
.get("caps_lock")
.expect("unable to find modifiers key in map"),
true,
);
self.update_key(
*modifiers_map
.get("caps_lock")
.expect("unable to find modifiers key in map"),
false,
);
} }
} }
} }

View File

@ -178,7 +178,7 @@ pub fn get_modifiers_state() -> Result<Option<super::ModifiersState>> {
redraw(&mut pool, window.surface(), dimensions).expect("Failed to draw"); redraw(&mut pool, window.surface(), dimensions).expect("Failed to draw");
} }
None => { None => {
let result_clone= result.clone(); let result_clone = result.clone();
let result_ref = result_clone.borrow(); let result_ref = result_clone.borrow();
if let Some(result) = &*result_ref { if let Some(result) = &*result_ref {
@ -191,10 +191,7 @@ pub fn get_modifiers_state() -> Result<Option<super::ModifiersState>> {
display.flush().unwrap(); display.flush().unwrap();
event_loop event_loop
.dispatch( .dispatch(Some(std::time::Duration::from_millis(10)), &mut next_action)
Some(std::time::Duration::from_millis(10)),
&mut next_action,
)
.unwrap(); .unwrap();
} }

View File

@ -22,16 +22,13 @@ use std::process::Command;
use log::error; use log::error;
pub fn get_active_layout() -> Option<String> { pub fn get_active_layout() -> Option<String> {
match Command::new("setxkbmap") match Command::new("setxkbmap").arg("-query").output() {
.arg("-query")
.output()
{
Ok(output) => { Ok(output) => {
let output_str = String::from_utf8_lossy(&output.stdout); let output_str = String::from_utf8_lossy(&output.stdout);
let layout_line = output_str.lines().find(|line| line.contains("layout:"))?; let layout_line = output_str.lines().find(|line| line.contains("layout:"))?;
let layout_raw: Vec<&str> = layout_line.split("layout:").collect(); let layout_raw: Vec<&str> = layout_line.split("layout:").collect();
Some(layout_raw.get(1)?.trim().to_string()) Some(layout_raw.get(1)?.trim().to_string())
}, }
Err(err) => { Err(err) => {
error!( error!(
"unable to retrieve current keyboard layout with 'setxkbmap': {}", "unable to retrieve current keyboard layout with 'setxkbmap': {}",

View File

@ -94,7 +94,10 @@ impl Default for SourceCreationOptions {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
pub fn get_source(options: SourceCreationOptions) -> Result<Box<dyn Source>> { pub fn get_source(options: SourceCreationOptions) -> Result<Box<dyn Source>> {
info!("using Win32Source"); info!("using Win32Source");
Ok(Box::new(win32::Win32Source::new(&options.hotkeys, options.win32_exclude_orphan_events))) Ok(Box::new(win32::Win32Source::new(
&options.hotkeys,
options.win32_exclude_orphan_events,
)))
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]