summaryrefslogtreecommitdiff
path: root/src/shared_state.rs
blob: 554d8568ed4432d607161ed0b95674433bb36170 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use smithay_client_toolkit::{
    reexports::client::QueueHandle,
    shm::{slot::SlotPool, ShmState},
};

use crate::{
    config::Config,
    i3bar_protocol::Block,
    state::{ComputedBlock, State},
    status_cmd::StatusCmd,
};

#[derive(Debug)]
pub struct SharedState {
    pub qh: QueueHandle<State>,
    pub shm_state: ShmState,
    pub pool: Option<SlotPool>,
    pub config: Config,
    pub status_cmd: Option<StatusCmd>,
    pub blocks: Vec<Block>,
    pub blocks_cache: Vec<ComputedBlock>,
}

impl SharedState {
    pub fn get_pool(&mut self, len: usize) -> &mut SlotPool {
        self.pool.get_or_insert_with(|| {
            SlotPool::new(len, &self.shm_state).expect("Failed to create pool")
        })
    }
}