From 7210045b2a058c4be7bef6fd2059f337bf53b1ec Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Thu, 6 Mar 2025 17:24:44 -0500 Subject: feat: support color picker functionality chore: format code refactor: improve quality feat: implement gnomes PickColor method refactor: minor code extraction misc: fix reviews fixes --- src/dbus/gnome_shell_screenshot.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/dbus') diff --git a/src/dbus/gnome_shell_screenshot.rs b/src/dbus/gnome_shell_screenshot.rs index 742f72b2..dd762498 100644 --- a/src/dbus/gnome_shell_screenshot.rs +++ b/src/dbus/gnome_shell_screenshot.rs @@ -1,7 +1,10 @@ +use std::collections::HashMap; use std::path::PathBuf; +use niri_ipc::PickedColor; use zbus::fdo::{self, RequestNameFlags}; use zbus::interface; +use zbus::zvariant::OwnedValue; use super::Start; @@ -12,6 +15,7 @@ pub struct Screenshot { pub enum ScreenshotToNiri { TakeScreenshot { include_cursor: bool }, + PickColor(async_channel::Sender>), } pub enum NiriToScreenshot { @@ -47,6 +51,34 @@ impl Screenshot { Ok((true, filename)) } + + async fn pick_color(&self) -> fdo::Result> { + let (tx, rx) = async_channel::bounded(1); + if let Err(err) = self.to_niri.send(ScreenshotToNiri::PickColor(tx)) { + warn!("error sending pick color message to niri: {err:?}"); + return Err(fdo::Error::Failed("internal error".to_owned())); + } + + let color = match rx.recv().await { + Ok(Some(color)) => color, + Ok(None) => { + return Err(fdo::Error::Failed("no color picked".to_owned())); + } + Err(err) => { + warn!("error receiving message from niri: {err:?}"); + return Err(fdo::Error::Failed("internal error".to_owned())); + } + }; + + let mut result = HashMap::new(); + let rgb_slice: &[f64] = &color.rgb; + result.insert( + "color".to_string(), + zbus::zvariant::Value::from(rgb_slice).try_into().unwrap(), + ); + + Ok(result) + } } impl Screenshot { -- cgit