diff --git a/Cargo.lock b/Cargo.lock index d124fad..413afc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -536,7 +536,7 @@ dependencies = [ [[package]] name = "swkb" -version = "0.2.0" +version = "0.2.1" dependencies = [ "async-std", "failure", diff --git a/Cargo.toml b/Cargo.toml index 34f9673..1703987 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swkb" -version = "0.2.1" +version = "0.2.2" authors = ["Alexandr Bogomyakov "] edition = "2018" diff --git a/src/main.rs b/src/main.rs index 24165a4..b391e1f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,10 +7,14 @@ use swayipc::{Connection, EventType, Fallible}; async fn get_input_id() -> Vec { let mut connection = Connection::new().await.unwrap(); - let inputs = connection.get_inputs().await.unwrap(); let mut ids: Vec = Vec::new(); - for i in inputs { - ids.push(i.identifier); + match connection.get_inputs().await { + Ok(inputs) => { + for i in inputs { + ids.push(i.identifier); + } + } + _ => {} } ids } @@ -49,8 +53,11 @@ async fn main() -> Fallible<()> { match event { Ok(Event::Input(event)) => { let layouts_list = event.input.xkb_layout_names; - let layout_name = event.input.xkb_active_layout_name.unwrap(); - let index = layouts_list.iter().position(|r| *r == layout_name).unwrap() as i64; + let layout_name = event.input.xkb_active_layout_name.unwrap_or("none".to_string()); + if layout_name == "none" { + continue + } + let index = layouts_list.iter().position(|r| *r == layout_name).unwrap_or(0) as i64; let mut layouts = layouts.lock().unwrap(); let current_window = get_focus_id().await; //println!("Layout saved [{:?}] for {:?}", layout_name, current_window);