aboutsummaryrefslogtreecommitdiff
path: root/src/ipc/client.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-08-25 09:38:45 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2024-08-25 09:38:45 +0300
commitf19e1711a7999f9b4d97cf1a1b2e03f273b2f120 (patch)
treeaa9832280c4e604f1ed0d962e39c096449e90214 /src/ipc/client.rs
parent20cd4f5d0470d1755f351c53eb2c0f63c27529cf (diff)
downloadniri-f19e1711a7999f9b4d97cf1a1b2e03f273b2f120.tar.gz
niri-f19e1711a7999f9b4d97cf1a1b2e03f273b2f120.tar.bz2
niri-f19e1711a7999f9b4d97cf1a1b2e03f273b2f120.zip
Add niri msg keyboard-layouts
Diffstat (limited to 'src/ipc/client.rs')
-rw-r--r--src/ipc/client.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/ipc/client.rs b/src/ipc/client.rs
index 3192925f..e9312933 100644
--- a/src/ipc/client.rs
+++ b/src/ipc/client.rs
@@ -1,6 +1,7 @@
use anyhow::{anyhow, bail, Context};
use niri_ipc::{
- LogicalOutput, Mode, Output, OutputConfigChanged, Request, Response, Socket, Transform,
+ KeyboardLayouts, LogicalOutput, Mode, Output, OutputConfigChanged, Request, Response, Socket,
+ Transform,
};
use serde_json::json;
@@ -19,6 +20,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
action: action.clone(),
},
Msg::Workspaces => Request::Workspaces,
+ Msg::KeyboardLayouts => Request::KeyboardLayouts,
Msg::RequestError => Request::ReturnError,
};
@@ -238,6 +240,27 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
println!("{is_active}{idx}{name}");
}
}
+ Msg::KeyboardLayouts => {
+ let Response::KeyboardLayouts(response) = response else {
+ bail!("unexpected response: expected KeyboardLayouts, got {response:?}");
+ };
+
+ if json {
+ let response =
+ serde_json::to_string(&response).context("error formatting response")?;
+ println!("{response}");
+ return Ok(());
+ }
+
+ let KeyboardLayouts { names, current_idx } = response;
+ let current_idx = usize::from(current_idx);
+
+ println!("Keyboard layouts:");
+ for (idx, name) in names.iter().enumerate() {
+ let is_active = if idx == current_idx { " * " } else { " " };
+ println!("{is_active}{idx} {name}");
+ }
+ }
}
Ok(())