slowshell_core/
monitors.rs1use std::{
2 collections::HashMap,
3 sync::{OnceLock, RwLock},
4};
5
6use crate::types::{ToUstr, Ustr};
7
8static MONITORS: OnceLock<RwLock<HashMap<Ustr, (u32, u32)>>> = OnceLock::new();
10
11fn cache() -> &'static RwLock<HashMap<Ustr, (u32, u32)>> {
12 MONITORS.get_or_init(|| RwLock::new(HashMap::new()))
13}
14
15pub fn set(monitors: impl IntoIterator<Item = (Ustr, u32, u32)>) {
16 let Ok(mut guard) = cache().write() else {
17 return;
18 };
19
20 for (name, width, height) in monitors {
21 if width > 0 && height > 0 {
22 guard.insert(name, (width, height));
23 }
24 }
25}
26
27pub fn size(name: &str) -> Option<(u32, u32)> {
28 cache().read().ok()?.get(&name.to_ustr()).copied()
29}