diff --git a/src-tauri/src/screenshot.rs b/src-tauri/src/screenshot.rs index 22d24f7..9db1327 100644 --- a/src-tauri/src/screenshot.rs +++ b/src-tauri/src/screenshot.rs @@ -1,9 +1,9 @@ -use std::cell::RefCell; -use std::{iter, cell::Ref}; +use std::iter; use std::sync::Arc; +use core_graphics::display::CGDisplay; use serde::{Deserialize, Serialize}; -use tauri::async_runtime::{RwLock, Mutex}; +use tauri::async_runtime::RwLock; use crate::{ambient_light::LedStripConfig, led_color::LedColor}; @@ -17,7 +17,7 @@ pub struct Screenshot { pub scale_factor: f32, } -static SINGLE_AXIS_POINTS: usize = 5; +static SINGLE_AXIS_POINTS: usize = 1; impl Screenshot { pub fn new( @@ -39,15 +39,20 @@ impl Screenshot { } pub fn get_sample_points(&self, config: &LedStripConfig) -> Vec { - let height = self.height as usize; - let width = self.width as usize; + let height = CGDisplay::new(self.display_id).bounds().size.height as usize; + let width = CGDisplay::new(self.display_id).bounds().size.width as usize; match config.border { crate::ambient_light::Border::Top => { Self::get_one_edge_sample_points(height / 18, width, config.len, SINGLE_AXIS_POINTS) } crate::ambient_light::Border::Bottom => { - let points = Self::get_one_edge_sample_points(height / 18, width, config.len, SINGLE_AXIS_POINTS); + let points = Self::get_one_edge_sample_points( + height / 18, + width, + config.len, + SINGLE_AXIS_POINTS, + ); points .into_iter() .map(|groups| -> Vec { @@ -56,7 +61,12 @@ impl Screenshot { .collect() } crate::ambient_light::Border::Left => { - let points = Self::get_one_edge_sample_points(width / 32, height, config.len, SINGLE_AXIS_POINTS); + let points = Self::get_one_edge_sample_points( + width / 32, + height, + config.len, + SINGLE_AXIS_POINTS, + ); points .into_iter() .map(|groups| -> Vec { @@ -65,7 +75,12 @@ impl Screenshot { .collect() } crate::ambient_light::Border::Right => { - let points = Self::get_one_edge_sample_points(width / 32, height, config.len, SINGLE_AXIS_POINTS); + let points = Self::get_one_edge_sample_points( + width / 32, + height, + config.len, + SINGLE_AXIS_POINTS, + ); points .into_iter() .map(|groups| -> Vec { diff --git a/src-tauri/src/screenshot_manager.rs b/src-tauri/src/screenshot_manager.rs index b91fdf2..bb9d217 100644 --- a/src-tauri/src/screenshot_manager.rs +++ b/src-tauri/src/screenshot_manager.rs @@ -1,4 +1,3 @@ -use std::cell::{Ref, RefCell}; use std::{collections::HashMap, sync::Arc}; use core_graphics::display::{ @@ -14,7 +13,7 @@ use crate::screenshot::LedSamplePoints; use crate::{ ambient_light::{SamplePointConfig, SamplePointMapper}, led_color::LedColor, - screenshot::{ScreenSamplePoints, Screenshot}, + screenshot::Screenshot, }; pub fn take_screenshot(display_id: u32, scale_factor: f32) -> anyhow::Result { diff --git a/src/components/led-strip-part.tsx b/src/components/led-strip-part.tsx index 7ffbdf1..892ee0d 100644 --- a/src/components/led-strip-part.tsx +++ b/src/components/led-strip-part.tsx @@ -24,12 +24,6 @@ type PixelProps = { color: string; }; -async function subscribeScreenshotUpdate(displayId: number) { - await invoke('subscribe_encoded_screenshot_updated', { - displayId, - }); -} - export const Pixel: Component = (props) => { const style = createMemo(() => ({ background: props.color, @@ -51,7 +45,6 @@ export const LedStripPart: Component = (props) => { const [localProps, rootProps] = splitProps(props, ['config']); const [stripConfiguration] = useContext(LedStripConfigurationContext); - const [ledSamplePoints, setLedSamplePoints] = createSignal(); const [colors, setColors] = createSignal([]); // update led strip colors from global store @@ -87,17 +80,6 @@ export const LedStripPart: Component = (props) => { setColors(colors); }); - // get led strip sample points - createEffect(() => { - if (localProps.config) { - invoke('get_led_strips_sample_points', { - config: localProps.config, - }).then((points) => { - setLedSamplePoints(points); - }); - } - }); - const [anchor, setAnchor] = createSignal(); useTippy(anchor, {