5 Commits

5 changed files with 32 additions and 22 deletions

View File

@ -1,7 +1,7 @@
# Maintainer: Alexandr Bogomyakov (ultradesu) <ab@hexor.ru> # Maintainer: Alexandr Bogomyakov (ultradesu) <ab@hexor.ru>
pkgname=swkb pkgname=swkb
pkgver=0.2.0 pkgver=0.2.1
pkgrel=1 pkgrel=1
pkgdesc="swkb" pkgdesc="swkb"
url="https://github.com/house-of-vanity/swkb.git" url="https://github.com/house-of-vanity/swkb.git"

24
Cargo.lock generated
View File

@ -521,18 +521,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "sway-layout"
version = "0.2.0"
dependencies = [
"async-std",
"failure",
"futures-core",
"serde",
"serde_json",
"swayipc",
]
[[package]] [[package]]
name = "swayipc" name = "swayipc"
version = "2.7.0" version = "2.7.0"
@ -546,6 +534,18 @@ dependencies = [
"serde_json", "serde_json",
] ]
[[package]]
name = "swkb"
version = "0.2.1"
dependencies = [
"async-std",
"failure",
"futures-core",
"serde",
"serde_json",
"swayipc",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.35" version = "1.0.35"

View File

@ -1,6 +1,6 @@
[package] [package]
name = "swkb" name = "swkb"
version = "0.2.0" version = "0.2.2"
authors = ["Alexandr Bogomyakov <abogomyakov@iponweb.net>"] authors = ["Alexandr Bogomyakov <abogomyakov@iponweb.net>"]
edition = "2018" edition = "2018"

3
README Normal file
View File

@ -0,0 +1,3 @@
swkb - simple per-window keyboard layout switching daemon for Sway WM.
prebuild ArchLinux packages here - https://repo.hexor.ru/

View File

@ -7,10 +7,14 @@ use swayipc::{Connection, EventType, Fallible};
async fn get_input_id() -> Vec<String> { async fn get_input_id() -> Vec<String> {
let mut connection = Connection::new().await.unwrap(); let mut connection = Connection::new().await.unwrap();
let inputs = connection.get_inputs().await.unwrap();
let mut ids: Vec<String> = Vec::new(); let mut ids: Vec<String> = Vec::new();
for i in inputs { match connection.get_inputs().await {
ids.push(i.identifier); Ok(inputs) => {
for i in inputs {
ids.push(i.identifier);
}
}
_ => {}
} }
ids ids
} }
@ -46,17 +50,20 @@ async fn main() -> Fallible<()> {
let subs = [EventType::Input, EventType::Window]; let subs = [EventType::Input, EventType::Window];
let mut events = connection.subscribe(&subs).await?; let mut events = connection.subscribe(&subs).await?;
while let Some(event) = events.next().await { while let Some(event) = events.next().await {
match event.unwrap() { match event {
Event::Input(event) => { Ok(Event::Input(event)) => {
let layouts_list = event.input.xkb_layout_names; let layouts_list = event.input.xkb_layout_names;
let layout_name = event.input.xkb_active_layout_name.unwrap(); let layout_name = event.input.xkb_active_layout_name.unwrap_or("none".to_string());
let index = layouts_list.iter().position(|r| *r == layout_name).unwrap() as i64; 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 mut layouts = layouts.lock().unwrap();
let current_window = get_focus_id().await; let current_window = get_focus_id().await;
//println!("Layout saved [{:?}] for {:?}", layout_name, current_window); //println!("Layout saved [{:?}] for {:?}", layout_name, current_window);
layouts.insert(current_window, index); layouts.insert(current_window, index);
} }
Event::Window(event) => match event.change { Ok(Event::Window(event)) => match event.change {
swayipc::reply::WindowChange::Focus => { swayipc::reply::WindowChange::Focus => {
let layouts = layouts.lock().unwrap(); let layouts = layouts.lock().unwrap();
let mut connection = Connection::new().await?; let mut connection = Connection::new().await?;