aboutsummaryrefslogtreecommitdiff
path: root/src/ipc
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipc')
-rw-r--r--src/ipc/client.rs21
-rw-r--r--src/ipc/server.rs9
2 files changed, 30 insertions, 0 deletions
diff --git a/src/ipc/client.rs b/src/ipc/client.rs
index 66cdaf7d..d4165733 100644
--- a/src/ipc/client.rs
+++ b/src/ipc/client.rs
@@ -20,6 +20,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
Msg::FocusedWindow => Request::FocusedWindow,
Msg::FocusedOutput => Request::FocusedOutput,
Msg::PickWindow => Request::PickWindow,
+ Msg::PickColor => Request::PickColor,
Msg::Action { action } => Request::Action(action.clone()),
Msg::Output { output, action } => Request::Output {
output: output.clone(),
@@ -270,6 +271,26 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
println!("No window selected.");
}
}
+ Msg::PickColor => {
+ let Response::PickedColor(color) = response else {
+ bail!("unexpected response: expected PickedColor, got {response:?}");
+ };
+
+ if json {
+ let color = serde_json::to_string(&color).context("error formatting response")?;
+ println!("{color}");
+ return Ok(());
+ }
+
+ if let Some(color) = color {
+ let [r, g, b] = color.rgb.map(|v| (v.clamp(0., 1.) * 255.).round() as u8);
+
+ println!("Picked color: rgb({r}, {g}, {b})",);
+ println!("Hex: #{:02x}{:02x}{:02x}", r, g, b);
+ } else {
+ println!("No color was picked.");
+ }
+ }
Msg::Action { .. } => {
let Response::Handled = response else {
bail!("unexpected response: expected Handled, got {response:?}");
diff --git a/src/ipc/server.rs b/src/ipc/server.rs
index c8f8edcf..2c948cac 100644
--- a/src/ipc/server.rs
+++ b/src/ipc/server.rs
@@ -356,6 +356,15 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply {
});
Response::PickedWindow(window)
}
+ Request::PickColor => {
+ let (tx, rx) = async_channel::bounded(1);
+ ctx.event_loop.insert_idle(move |state| {
+ state.handle_pick_color(tx);
+ });
+ let result = rx.recv().await;
+ let color = result.map_err(|_| String::from("error getting picked color"))?;
+ Response::PickedColor(color)
+ }
Request::Action(action) => {
let (tx, rx) = async_channel::bounded(1);