Fixed indentation because Builder messed it up somehow

This commit is contained in:
cyber-sushi 2024-05-31 08:36:37 +02:00
parent eba63a4470
commit a0110e1fea
3 changed files with 204 additions and 204 deletions

View file

@ -14,8 +14,8 @@ pub async fn get_active_window(environment: &Environment, config: &Vec<Config>)
let query = Command::new("hyprctl").args(["activewindow", "-j"]).output().unwrap(); let query = Command::new("hyprctl").args(["activewindow", "-j"]).output().unwrap();
if let Ok(reply) = serde_json::from_str::<serde_json::Value>(std::str::from_utf8(query.stdout.as_slice()).unwrap()) { if let Ok(reply) = serde_json::from_str::<serde_json::Value>(std::str::from_utf8(query.stdout.as_slice()).unwrap()) {
let active_window = Client::Class(reply["class"].to_string().replace("\"", "")); let active_window = Client::Class(reply["class"].to_string().replace("\"", ""));
if let Some(_) = config.iter().find(|&x| x.associations.client == active_window) { if let Some(_) = config.iter().find(|&x| x.associations.client == active_window) {
active_window active_window
} else { } else {
Client::Default Client::Default
} }
@ -41,44 +41,44 @@ pub async fn get_active_window(environment: &Environment, config: &Vec<Config>)
} }
}, },
"KDE" => { "KDE" => {
let (user, running_as_root) = let (user, running_as_root) =
if let Ok(sudo_user) = environment.sudo_user.clone() { if let Ok(sudo_user) = environment.sudo_user.clone() {
(Option::Some(sudo_user), true) (Option::Some(sudo_user), true)
} }
else if let Ok(user) = environment.user.clone() { else if let Ok(user) = environment.user.clone() {
(Option::Some(user), false) (Option::Some(user), false)
} }
else { else {
(Option::None, false) (Option::None, false)
}; };
let active_window = { let active_window = {
if let Some(user) = user { if let Some(user) = user {
if running_as_root { if running_as_root {
let output = Command::new("runuser") let output = Command::new("runuser")
.arg(user) .arg(user)
.arg("-c") .arg("-c")
.arg("kdotool getactivewindow getwindowclassname") .arg("kdotool getactivewindow getwindowclassname")
.output() .output()
.unwrap(); .unwrap();
Client::Class(std::str::from_utf8(output.stdout.as_slice()).unwrap().trim().to_string()) Client::Class(std::str::from_utf8(output.stdout.as_slice()).unwrap().trim().to_string())
} else { } else {
let output = Command::new("sh") let output = Command::new("sh")
.arg("-c") .arg("-c")
.arg(format!("systemd-run --user --scope -M {}@ kdotool getactivewindow getwindowclassname", user)) .arg(format!("systemd-run --user --scope -M {}@ kdotool getactivewindow getwindowclassname", user))
.stderr(Stdio::null()) .stderr(Stdio::null())
.output() .output()
.unwrap(); .unwrap();
Client::Class(std::str::from_utf8(output.stdout.as_slice()).unwrap().trim().to_string()) Client::Class(std::str::from_utf8(output.stdout.as_slice()).unwrap().trim().to_string())
} }
} else { } else {
Client::Default Client::Default
} }
}; };
if let Some(_) = config.iter().find(|&x| x.associations.client == active_window) { if let Some(_) = config.iter().find(|&x| x.associations.client == active_window) {
active_window active_window
} else { } else {
Client::Default Client::Default
} }
}, },
"x11" => { "x11" => {
let connection = x11rb::connect(None).unwrap().0; let connection = x11rb::connect(None).unwrap().0;

View file

@ -102,7 +102,7 @@ impl EventReader {
.settings.get("LAYOUT_SWITCHER").unwrap_or(&"BTN_0".to_string())).expect("LAYOUT_SWITCHER is not a valid Key."); .settings.get("LAYOUT_SWITCHER").unwrap_or(&"BTN_0".to_string())).expect("LAYOUT_SWITCHER is not a valid Key.");
let notify_layout_switch: bool = config.iter().find(|&x| x.associations == Associations::default()).unwrap() let notify_layout_switch: bool = config.iter().find(|&x| x.associations == Associations::default()).unwrap()
.settings.get("NOTIFY_LAYOUT_SWITCH").unwrap_or(&"false".to_string()).parse().expect("NOTIFY_LAYOUT_SWITCH can only be true or false."); .settings.get("NOTIFY_LAYOUT_SWITCH").unwrap_or(&"false".to_string()).parse().expect("NOTIFY_LAYOUT_SWITCH can only be true or false.");
let settings = Settings { let settings = Settings {
lstick, lstick,
@ -143,14 +143,14 @@ impl EventReader {
let (mut dpad_values, mut lstick_values, mut rstick_values, mut triggers_values, mut abs_wheel_position) = ((0, 0), (0, 0), (0, 0), (0, 0), 0); let (mut dpad_values, mut lstick_values, mut rstick_values, mut triggers_values, mut abs_wheel_position) = ((0, 0), (0, 0), (0, 0), (0, 0), 0);
let switcher: Key = self.settings.layout_switcher; let switcher: Key = self.settings.layout_switcher;
let mut stream = self.stream.lock().await; let mut stream = self.stream.lock().await;
let mut max_abs_wheel = 0; let mut max_abs_wheel = 0;
if let Ok(abs_state) = stream.device().get_abs_state() { if let Ok(abs_state) = stream.device().get_abs_state() {
for state in abs_state { for state in abs_state {
if state.maximum > max_abs_wheel { if state.maximum > max_abs_wheel {
max_abs_wheel = state.maximum; max_abs_wheel = state.maximum;
} }
}; };
} }
while let Some(Ok(event)) = stream.next().await { while let Some(Ok(event)) = stream.next().await {
match (event.event_type(), RelativeAxisType(event.code()), AbsoluteAxisType(event.code())) { match (event.event_type(), RelativeAxisType(event.code()), AbsoluteAxisType(event.code())) {
(EventType::KEY, _, _) => { (EventType::KEY, _, _) => {
@ -174,12 +174,12 @@ impl EventReader {
(_, _, AbsoluteAxisType::ABS_HAT0X) => { (_, _, AbsoluteAxisType::ABS_HAT0X) => {
match event.value() { match event.value() {
-1 => { -1 => {
self.convert_event(event, Event::Axis(Axis::BTN_DPAD_LEFT), 1, false).await; self.convert_event(event, Event::Axis(Axis::BTN_DPAD_LEFT), 1, false).await;
dpad_values.0 = -1; dpad_values.0 = -1;
}, },
1 => { 1 => {
self.convert_event(event, Event::Axis(Axis::BTN_DPAD_RIGHT), 1, false).await; self.convert_event(event, Event::Axis(Axis::BTN_DPAD_RIGHT), 1, false).await;
dpad_values.0 = 1; dpad_values.0 = 1;
}, },
0 => { 0 => {
match dpad_values.0 { match dpad_values.0 {
@ -195,12 +195,12 @@ impl EventReader {
(_, _, AbsoluteAxisType::ABS_HAT0Y) => { (_, _, AbsoluteAxisType::ABS_HAT0Y) => {
match event.value() { match event.value() {
-1 => { -1 => {
self.convert_event(event, Event::Axis(Axis::BTN_DPAD_UP), 1, false).await; self.convert_event(event, Event::Axis(Axis::BTN_DPAD_UP), 1, false).await;
dpad_values.1 = -1; dpad_values.1 = -1;
}, },
1 => { 1 => {
self.convert_event(event, Event::Axis(Axis::BTN_DPAD_DOWN), 1, false).await; self.convert_event(event, Event::Axis(Axis::BTN_DPAD_DOWN), 1, false).await;
dpad_values.1 = 1; dpad_values.1 = 1;
}, },
0 => { 0 => {
match dpad_values.1 { match dpad_values.1 {
@ -363,20 +363,20 @@ impl EventReader {
} }
}, },
(EventType::ABSOLUTE, _, AbsoluteAxisType::ABS_WHEEL) => { (EventType::ABSOLUTE, _, AbsoluteAxisType::ABS_WHEEL) => {
let value = event.value(); let value = event.value();
if value != 0 && abs_wheel_position != 0 { if value != 0 && abs_wheel_position != 0 {
let gap = value - abs_wheel_position; let gap = value - abs_wheel_position;
if gap < -max_abs_wheel/2 { if gap < -max_abs_wheel/2 {
self.convert_event(event, Event::Axis(Axis::ABS_WHEEL_CW), 1, true).await; self.convert_event(event, Event::Axis(Axis::ABS_WHEEL_CW), 1, true).await;
} else if gap > max_abs_wheel/2 { } else if gap > max_abs_wheel/2 {
self.convert_event(event, Event::Axis(Axis::ABS_WHEEL_CCW), 1, true).await; self.convert_event(event, Event::Axis(Axis::ABS_WHEEL_CCW), 1, true).await;
} else if value > abs_wheel_position { } else if value > abs_wheel_position {
self.convert_event(event, Event::Axis(Axis::ABS_WHEEL_CW), 1, true).await; self.convert_event(event, Event::Axis(Axis::ABS_WHEEL_CW), 1, true).await;
} else if value < abs_wheel_position { } else if value < abs_wheel_position {
self.convert_event(event, Event::Axis(Axis::ABS_WHEEL_CCW), 1, true).await; self.convert_event(event, Event::Axis(Axis::ABS_WHEEL_CCW), 1, true).await;
} }
} }
abs_wheel_position = value; abs_wheel_position = value;
}, },
(EventType::ABSOLUTE, _, AbsoluteAxisType::ABS_MISC) => { (EventType::ABSOLUTE, _, AbsoluteAxisType::ABS_MISC) => {
if event.value() == 0 { abs_wheel_position = 0 }; if event.value() == 0 { abs_wheel_position = 0 };
@ -392,7 +392,7 @@ impl EventReader {
async fn convert_event(&self, default_event: InputEvent, event: Event, value: i32, send_zero: bool) { async fn convert_event(&self, default_event: InputEvent, event: Event, value: i32, send_zero: bool) {
if value == 1 { if value == 1 {
self.update_config().await; self.update_config().await;
}; };
let config = self.current_config.lock().await; let config = self.current_config.lock().await;
let modifiers = self.modifiers.lock().await.clone(); let modifiers = self.modifiers.lock().await.clone();
@ -408,11 +408,11 @@ impl EventReader {
} }
} }
if let Some(map) = config.bindings.commands.get(&event) { if let Some(map) = config.bindings.commands.get(&event) {
if let Some(command_list) = map.get(&modifiers) { if let Some(command_list) = map.get(&modifiers) {
if value == 1 { self.spawn_subprocess(command_list).await }; if value == 1 { self.spawn_subprocess(command_list).await };
return return
} }
} }
if let Some(event_list) = map.get(&Vec::new()) { if let Some(event_list) = map.get(&Vec::new()) {
self.emit_event(event_list, value, &modifiers, &config, true, false, send_zero).await; self.emit_event(event_list, value, &modifiers, &config, true, false, send_zero).await;
return return
@ -463,8 +463,8 @@ impl EventReader {
let virtual_event: InputEvent = InputEvent::new_now(EventType::KEY, key.code(), value); let virtual_event: InputEvent = InputEvent::new_now(EventType::KEY, key.code(), value);
virt_dev.keys.emit(&[virtual_event]).unwrap(); virt_dev.keys.emit(&[virtual_event]).unwrap();
if send_zero { if send_zero {
let virtual_event: InputEvent = InputEvent::new_now(EventType::KEY, key.code(), 0); let virtual_event: InputEvent = InputEvent::new_now(EventType::KEY, key.code(), 0);
virt_dev.keys.emit(&[virtual_event]).unwrap(); virt_dev.keys.emit(&[virtual_event]).unwrap();
} }
*modifier_was_activated = true; *modifier_was_activated = true;
} }
@ -536,36 +536,36 @@ impl EventReader {
for command in command_list { for command in command_list {
if running_as_root { if running_as_root {
match fork() { match fork() {
Ok(Fork::Child) => { Ok(Fork::Child) => {
match fork() { match fork() {
Ok(Fork::Child) => { Ok(Fork::Child) => {
setsid().unwrap(); setsid().unwrap();
Command::new("runuser") Command::new("runuser")
.args([user, "-c", command]) .args([user, "-c", command])
.stdin(Stdio::null()) .stdin(Stdio::null())
.stdout(Stdio::null()) .stdout(Stdio::null())
.stderr(Stdio::null()) .stderr(Stdio::null())
.spawn() .spawn()
.unwrap(); .unwrap();
std::process::exit(0); std::process::exit(0);
} }
Ok(Fork::Parent(_)) => std::process::exit(0), Ok(Fork::Parent(_)) => std::process::exit(0),
Err(_) => std::process::exit(1), Err(_) => std::process::exit(1),
} }
} }
Ok(Fork::Parent(_)) => (), Ok(Fork::Parent(_)) => (),
Err(_) => std::process::exit(1), Err(_) => std::process::exit(1),
} }
} else { } else {
Command::new("sh") Command::new("sh")
.arg("-c") .arg("-c")
.arg(format!("systemd-run --user -M {}@ {}", user, command)) .arg(format!("systemd-run --user -M {}@ {}", user, command))
.stdin(Stdio::null()) .stdin(Stdio::null())
.stdout(Stdio::null()) .stdout(Stdio::null())
.stderr(Stdio::null()) .stderr(Stdio::null())
.spawn() .spawn()
.unwrap(); .unwrap();
} }
} }
} }
} }
@ -607,42 +607,42 @@ impl EventReader {
released_keys released_keys
} }
async fn change_active_layout(&self) { async fn change_active_layout(&self) {
let mut active_layout = self.active_layout.lock().await; let mut active_layout = self.active_layout.lock().await;
let active_window = get_active_window(&self.environment, &self.config).await; let active_window = get_active_window(&self.environment, &self.config).await;
loop { loop {
if *active_layout == 3 { *active_layout = 0 } if *active_layout == 3 { *active_layout = 0 }
else { *active_layout += 1 }; else { *active_layout += 1 };
if let Some(_) = self.config.iter().find(|&x| x.associations.layout == *active_layout && x.associations.client == active_window) { if let Some(_) = self.config.iter().find(|&x| x.associations.layout == *active_layout && x.associations.client == active_window) {
break break
}; };
} }
if self.settings.notify_layout_switch { if self.settings.notify_layout_switch {
let notify = vec![String::from(format!("notify-send -t 500 'Makima' 'Switching to layout {}'", *active_layout))]; let notify = vec![String::from(format!("notify-send -t 500 'Makima' 'Switching to layout {}'", *active_layout))];
self.spawn_subprocess(&notify).await; self.spawn_subprocess(&notify).await;
} }
} }
fn update_config(&self) -> Pin<Box<dyn Future<Output = ()> + Send + '_>> { fn update_config(&self) -> Pin<Box<dyn Future<Output = ()> + Send + '_>> {
Box::pin(async move { Box::pin(async move {
let active_layout = self.active_layout.lock().await.clone(); let active_layout = self.active_layout.lock().await.clone();
let active_window = get_active_window(&self.environment, &self.config).await; let active_window = get_active_window(&self.environment, &self.config).await;
let associations = Associations { let associations = Associations {
client: active_window, client: active_window,
layout: active_layout, layout: active_layout,
}; };
match self.config.iter().find(|&x| x.associations == associations) { match self.config.iter().find(|&x| x.associations == associations) {
Some(config) => { Some(config) => {
let mut current_config = self.current_config.lock().await; let mut current_config = self.current_config.lock().await;
*current_config = config.clone(); *current_config = config.clone();
}, },
None => { None => {
self.change_active_layout().await; self.change_active_layout().await;
self.update_config().await; self.update_config().await;
}, },
}; };
}) })
} }
pub async fn cursor_loop(&self) { pub async fn cursor_loop(&self) {
let (cursor, sensitivity, activation_modifiers) = if self.settings.lstick.function.as_str() == "cursor" { let (cursor, sensitivity, activation_modifiers) = if self.settings.lstick.function.as_str() == "cursor" {
@ -665,9 +665,9 @@ impl EventReader {
if stick_position[0] != 0 || stick_position[1] != 0 { if stick_position[0] != 0 || stick_position[1] != 0 {
let modifiers = self.modifiers.lock().await; let modifiers = self.modifiers.lock().await;
if activation_modifiers.len() == 0 || activation_modifiers == *modifiers { if activation_modifiers.len() == 0 || activation_modifiers == *modifiers {
let (x_coord, y_coord) = let (x_coord, y_coord) =
if self.settings.invert_cursor_axis { (-stick_position[0], -stick_position[1]) } if self.settings.invert_cursor_axis { (-stick_position[0], -stick_position[1]) }
else { (stick_position[0], stick_position[1]) }; else { (stick_position[0], stick_position[1]) };
let virtual_event_x: InputEvent = InputEvent::new_now(EventType::RELATIVE, 0, x_coord); let virtual_event_x: InputEvent = InputEvent::new_now(EventType::RELATIVE, 0, x_coord);
let virtual_event_y: InputEvent = InputEvent::new_now(EventType::RELATIVE, 1, y_coord); let virtual_event_y: InputEvent = InputEvent::new_now(EventType::RELATIVE, 1, y_coord);
let mut virt_dev = self.virt_dev.lock().await; let mut virt_dev = self.virt_dev.lock().await;
@ -704,9 +704,9 @@ impl EventReader {
if stick_position[0] != 0 || stick_position[1] != 0 { if stick_position[0] != 0 || stick_position[1] != 0 {
let modifiers = self.modifiers.lock().await; let modifiers = self.modifiers.lock().await;
if activation_modifiers.len() == 0 || activation_modifiers == *modifiers { if activation_modifiers.len() == 0 || activation_modifiers == *modifiers {
let (x_coord, y_coord) = let (x_coord, y_coord) =
if self.settings.invert_scroll_axis { (-stick_position[0], -stick_position[1]) } if self.settings.invert_scroll_axis { (-stick_position[0], -stick_position[1]) }
else { (stick_position[0], stick_position[1]) }; else { (stick_position[0], stick_position[1]) };
let virtual_event_x: InputEvent = InputEvent::new_now(EventType::RELATIVE, 12, x_coord); let virtual_event_x: InputEvent = InputEvent::new_now(EventType::RELATIVE, 12, x_coord);
let virtual_event_y: InputEvent = InputEvent::new_now(EventType::RELATIVE, 11, y_coord); let virtual_event_y: InputEvent = InputEvent::new_now(EventType::RELATIVE, 11, y_coord);
let mut virt_dev = self.virt_dev.lock().await; let mut virt_dev = self.virt_dev.lock().await;

View file

@ -10,7 +10,7 @@ use crate::event_reader::EventReader;
#[derive(Debug, Default, Eq, PartialEq, Hash, Clone)] #[derive(Debug, Default, Eq, PartialEq, Hash, Clone)]
pub enum Client { pub enum Client {
#[default] #[default]
Default, Default,
Class(String), Class(String),
} }
@ -80,28 +80,28 @@ pub fn launch_tasks(config_files: &Vec<Config>, tasks: &mut Vec<JoinHandle<()>>,
let associated_device_name = split_config_name[0]; let associated_device_name = split_config_name[0];
if associated_device_name == device.1.name().unwrap().replace("/", "") { if associated_device_name == device.1.name().unwrap().replace("/", "") {
let (window_class, layout) = match split_config_name.len() { let (window_class, layout) = match split_config_name.len() {
1 => (Client::Default, 0), 1 => (Client::Default, 0),
2 => { 2 => {
if let Ok(layout) = split_config_name[1].parse::<u16>() { if let Ok(layout) = split_config_name[1].parse::<u16>() {
(Client::Default, layout) (Client::Default, layout)
} else { } else {
(Client::Class(split_config_name[1].to_string()), 0) (Client::Class(split_config_name[1].to_string()), 0)
} }
}, },
3 => { 3 => {
if let Ok(layout) = split_config_name[1].parse::<u16>() { if let Ok(layout) = split_config_name[1].parse::<u16>() {
(Client::Class(split_config_name[2].to_string()), layout) (Client::Class(split_config_name[2].to_string()), layout)
} else if let Ok(layout) = split_config_name[2].parse::<u16>() { } else if let Ok(layout) = split_config_name[2].parse::<u16>() {
(Client::Class(split_config_name[1].to_string()), layout) (Client::Class(split_config_name[1].to_string()), layout)
} else { } else {
println!("Warning: unable to parse layout number in {}, treating it as default.", config.name); println!("Warning: unable to parse layout number in {}, treating it as default.", config.name);
(Client::Default, 0) (Client::Default, 0)
} }
}, },
_ => { _ => {
println!("Warning: too many arguments in config file name {}, treating it as default.", config.name); println!("Warning: too many arguments in config file name {}, treating it as default.", config.name);
(Client::Default, 0) (Client::Default, 0)
}, },
}; };
config.associations.client = window_class; config.associations.client = window_class;
config.associations.layout = layout; config.associations.layout = layout;
@ -147,20 +147,20 @@ fn set_environment() -> Environment {
let uid = Command::new("sh").arg("-c").arg("id -u").output().unwrap(); let uid = Command::new("sh").arg("-c").arg("id -u").output().unwrap();
let uid_number = std::str::from_utf8(uid.stdout.as_slice()).unwrap().trim(); let uid_number = std::str::from_utf8(uid.stdout.as_slice()).unwrap().trim();
if uid_number != "0" { if uid_number != "0" {
let bus_address = format!("unix:path=/run/user/{}/bus", uid_number); let bus_address = format!("unix:path=/run/user/{}/bus", uid_number);
env::set_var("DBUS_SESSION_BUS_ADDRESS", bus_address); env::set_var("DBUS_SESSION_BUS_ADDRESS", bus_address);
let command = Command::new("sh").arg("-c").arg("systemctl --user show-environment").output().unwrap(); let command = Command::new("sh").arg("-c").arg("systemctl --user show-environment").output().unwrap();
let vars = std::str::from_utf8(command.stdout.as_slice()).unwrap().split("\n").collect::<Vec<&str>>(); let vars = std::str::from_utf8(command.stdout.as_slice()).unwrap().split("\n").collect::<Vec<&str>>();
for var in vars { for var in vars {
if let Some((variable, value)) = var.split_once("=") { if let Some((variable, value)) = var.split_once("=") {
if let Err(env::VarError::NotPresent) = env::var(variable) { if let Err(env::VarError::NotPresent) = env::var(variable) {
env::set_var(variable, value); env::set_var(variable, value);
} }
} }
} }
} else { } else {
println!("Warning: unable to inherit user environment.\n\ println!("Warning: unable to inherit user environment.\n\
Launch Makima with 'sudo -E makima' or make sure that your systemd unit is running with the 'User=<username>' parameter.\n"); Launch Makima with 'sudo -E makima' or make sure that your systemd unit is running with the 'User=<username>' parameter.\n");
} }
}, },
}; };
@ -172,18 +172,18 @@ fn set_environment() -> Environment {
let (x11, wayland) = (String::from("x11"), String::from("wayland")); let (x11, wayland) = (String::from("x11"), String::from("wayland"));
let server: Server = match (env::var("XDG_SESSION_TYPE"), env::var("XDG_CURRENT_DESKTOP")) { let server: Server = match (env::var("XDG_SESSION_TYPE"), env::var("XDG_CURRENT_DESKTOP")) {
(Ok(session), Ok(desktop)) if session == wayland && supported_compositors.contains(&desktop) => { (Ok(session), Ok(desktop)) if session == wayland && supported_compositors.contains(&desktop) => {
let server = 'a: { let server = 'a: {
if desktop == String::from("KDE") { if desktop == String::from("KDE") {
if let Err(_) = Command::new("kdotool").output() { if let Err(_) = Command::new("kdotool").output() {
println!("Running on KDE but kdotool doesn't seem to be installed.\n\ println!("Running on KDE but kdotool doesn't seem to be installed.\n\
Won't be able to change bindings according to the active window.\n"); Won't be able to change bindings according to the active window.\n");
break 'a Server::Unsupported; break 'a Server::Unsupported;
} }
} }
println!("Running on {}, per application bindings enabled.", desktop); println!("Running on {}, per application bindings enabled.", desktop);
Server::Connected(desktop) Server::Connected(desktop)
}; };
server server
}, },
(Ok(session), Ok(desktop)) if session == wayland => { (Ok(session), Ok(desktop)) if session == wayland => {
println!("Warning: unsupported compositor: {}, won't be able to change bindings according to the active window.\n\ println!("Warning: unsupported compositor: {}, won't be able to change bindings according to the active window.\n\
@ -217,14 +217,14 @@ fn set_environment() -> Environment {
pub fn get_event_stream(path: &Path, config: Vec<Config>) -> EventStream { pub fn get_event_stream(path: &Path, config: Vec<Config>) -> EventStream {
let mut device: Device = Device::open(path).expect("Couldn't open device path."); let mut device: Device = Device::open(path).expect("Couldn't open device path.");
match config.iter().find(|&x| x.associations == Associations::default()).unwrap().settings.get("GRAB_DEVICE") { match config.iter().find(|&x| x.associations == Associations::default()).unwrap().settings.get("GRAB_DEVICE") {
Some(value) => { Some(value) => {
if value == &true.to_string() { if value == &true.to_string() {
device.grab().expect("Unable to grab device. Is another instance of Makima running?") device.grab().expect("Unable to grab device. Is another instance of Makima running?")
} }
} }
None => device.grab().expect("Unable to grab device. Is another instance of Makima running?") None => device.grab().expect("Unable to grab device. Is another instance of Makima running?")
} }
let stream: EventStream = device.into_event_stream().unwrap(); let stream: EventStream = device.into_event_stream().unwrap();
return stream return stream
} }