From d3b488c95817c75ad6ac892e9826da8d9dd189b3 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Mon, 17 Apr 2023 12:26:43 +0300 Subject: refactor cache management --- src/state.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs index 0f8e4a7..86eb45d 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,3 +1,4 @@ +use crate::blocks_cache::BlocksCache; use crate::protocol::*; use crate::wm_info_provider::*; @@ -13,7 +14,7 @@ use wayrs_utils::shm_alloc::ShmAlloc; use crate::{ bar::Bar, config::Config, i3bar_protocol::Block, pointer_btn::PointerBtn, - shared_state::SharedState, status_cmd::StatusCmd, text::ComputedText, wm_info_provider, + shared_state::SharedState, status_cmd::StatusCmd, wm_info_provider, }; pub struct State { @@ -84,8 +85,7 @@ impl State { shm: ShmAlloc::new(wl_shm), config, status_cmd, - blocks: Vec::new(), - blocks_cache: Vec::new(), + blocks_cache: BlocksCache::default(), wm_info_provider: wm_info_provider::bind_wayland(conn, globals, wm_info_cb), }, @@ -105,7 +105,9 @@ impl State { } pub fn set_blocks(&mut self, conn: &mut Connection, blocks: Vec) { - self.shared_state.blocks = blocks; + self.shared_state + .blocks_cache + .process_new_blocks(&self.shared_state.config, &blocks); self.draw_all(conn); } @@ -448,14 +450,6 @@ fn wm_info_cb(conn: &mut Connection, state: &mut State, output: WlOutput, bar.request_frame(conn); } -#[derive(Debug)] -pub struct ComputedBlock { - pub block: Block, - pub full: ComputedText, - pub short: Option, - pub min_width: Option, -} - #[derive(Debug, Default, Clone, Copy)] pub struct ScrollFrame { stop: bool, -- cgit v1.3.1