leftwm_core/models/
manager.rs1#[cfg(test)]
2use leftwm_layouts::layouts::Layouts;
3
4use crate::config::Config;
5use crate::display_servers::DisplayServer;
6use crate::state::State;
7use crate::utils::child_process::Children;
8use std::sync::{atomic::AtomicBool, Arc};
9
10use super::Handle;
11
12#[derive(Debug)]
14pub struct Manager<H: Handle, C, SERVER> {
15 pub state: State<H>,
16 pub config: C,
17
18 pub(crate) children: Children,
19 pub(crate) reap_requested: Arc<AtomicBool>,
20 pub(crate) reload_requested: bool,
21 pub display_server: SERVER,
22}
23
24impl<H: Handle, C, SERVER> Manager<H, C, SERVER>
25where
26 C: Config,
27 SERVER: DisplayServer<H>,
28{
29 pub fn new(config: C) -> Self {
30 Self {
31 display_server: SERVER::new(&config),
32 state: State::new(&config),
33 config,
34 children: Default::default(),
35 reap_requested: Default::default(),
36 reload_requested: false,
37 }
38 }
39}
40
41impl<H: Handle, C, SERVER> Manager<H, C, SERVER> {
42 pub fn register_child_hook(&self) {
43 crate::child_process::register_child_hook(self.reap_requested.clone());
44 }
45
46 pub fn hard_reload(&mut self) {
48 self.reload_requested = true;
49 }
50}
51
52impl<H: Handle, C: Config, SERVER: DisplayServer<H>> Manager<H, C, SERVER> {
53 pub fn load_theme_config(&mut self) -> bool {
55 let focused = self
56 .state
57 .focus_manager
58 .window_history
59 .front()
60 .and_then(|o| *o);
61 self.display_server
62 .reload_config(&self.config, focused, &self.state.windows);
63 self.state.load_theme_config(&self.config);
64 true
65 }
66}
67
68#[cfg(test)]
69impl
70 Manager<
71 crate::models::window::MockHandle,
72 crate::config::tests::TestConfig,
73 crate::display_servers::MockDisplayServer<crate::models::window::MockHandle>,
74 >
75{
76 pub fn new_test(tags: Vec<String>) -> Self {
77 use crate::config::tests::TestConfig;
78 let defs = Layouts::default().layouts;
79 let names = defs.iter().map(|def| def.name.clone()).collect();
80 Self::new(TestConfig {
81 tags,
82 layouts: names,
83 layout_definitions: defs,
84 ..TestConfig::default()
85 })
86 }
87
88 pub fn new_test_with_border(tags: Vec<String>, border_width: i32) -> Self {
89 use crate::config::tests::TestConfig;
90 let defs = Layouts::default().layouts;
91 let names = defs.iter().map(|def| def.name.clone()).collect();
92 Self::new(TestConfig {
93 tags,
94 layouts: names,
95 layout_definitions: defs,
96 border_width,
97 single_window_border: false,
98 ..TestConfig::default()
99 })
100 }
101}