Skip to content

Commit

Permalink
fix: repeat attempts to get keyboard on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
coffebar committed Aug 27, 2024
1 parent 0a541bf commit 961e72f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hyprland-per-window-layout"
description = "Per window keyboard layout (language) for Hyprland wayland compositor"
version = "0.2.12"
version = "0.2.13"
edition = "2021"
exclude = ["target", "Cargo.lock"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ Bug reports and PR are welcome. Thank you for your interest!

-----

Tested on Hyprland v0.41.
Tested on Hyprland v0.42.
26 changes: 17 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,30 @@ fn kb_file_isset() -> bool {

// get default layout from cli command "hyprctl devices -j"
// value of ['keyboards'][0]['active_keymap']
fn get_default_layout_name() {
fn get_default_layout_name() -> bool {
match hyprctl(["devices", "-j"].to_vec()) {
Ok(output) => {
log::debug!("input:kb_layout: {}", output);
// parse the string from stdin into serde_json::Value
let json: Value = serde_json::from_str(&output).unwrap();
let kb_layout = str::replace(
&json["keyboards"][0]["active_keymap"].to_string().trim(),
"\"",
"",
);
let keyboards = &json["keyboards"];
log::debug!("keyboards: {}", keyboards);
if keyboards.is_null() || keyboards.as_array().unwrap().len() < 1 {
log::warn!("No keyboards found");
return false;
}
let kb_layout =
str::replace(&keyboards[0]["active_keymap"].to_string().trim(), "\"", "");
if kb_layout.len() > 0 {
fullfill_layouts_list(kb_layout.to_string());
return true;
} else {
log::warn!("Keyboard layouts not found")
log::warn!("Keyboard layouts not found");
return false;
}
}
Err(_e) => {
println!("Failed to get devices from hyprctl");
return false;
}
}
}
Expand All @@ -154,7 +159,10 @@ fn main() {
println!("You don't need this program if you have only 1 keyboard layout");
std::process::exit(1);
}
get_default_layout_name();
while !get_default_layout_name() {
// repeat until success
std::thread::sleep(std::time::Duration::from_secs(1));
}

match env::var("HYPRLAND_INSTANCE_SIGNATURE") {
Ok(hypr_inst) => {
Expand Down

0 comments on commit 961e72f

Please sign in to comment.