Initialize modules in parallel with surface

This commit is contained in:
Kenny Levinsen
2019-08-05 23:16:16 +02:00
parent fbc1f058ad
commit 4e48df376b
+37 -30
View File
@@ -154,40 +154,33 @@ impl App {
// //
// Set up modules // Set up modules
// //
let mut modules = vec![ let (mod_tx, mod_rx) = channel();
Module::new(Box::new(Clock::new(tx.clone())), (0, 0, 720, 320)), std::thread::spawn(move || {
Module::new(Box::new(Calendar::new()), (0, 368, 1280, 344)), let mut modules = vec![
]; Module::new(Box::new(Clock::new(tx.clone())), (0, 0, 720, 320)),
Module::new(Box::new(Calendar::new()), (0, 368, 1280, 344)),
];
if let Ok(m) = Launcher::new() { if let Ok(m) = Launcher::new() {
modules.push(Module::new(Box::new(m), (0, 768, 1280, 32))); modules.push(Module::new(Box::new(m), (0, 768, 1280, 32)));
} }
let mut vert_off = 0; let mut vert_off = 0;
if let Ok(m) = UpowerBattery::new(tx.clone()) { if let Ok(m) = UpowerBattery::new(tx.clone()) {
modules.push(Module::new(Box::new(m), (720, vert_off, 560, 32))); modules.push(Module::new(Box::new(m), (720, vert_off, 560, 32)));
vert_off += 32; vert_off += 32;
} }
if let Ok(m) = Backlight::new() { if let Ok(m) = Backlight::new() {
modules.push(Module::new(Box::new(m), (720, vert_off, 560, 32))); modules.push(Module::new(Box::new(m), (720, vert_off, 560, 32)));
vert_off += 32; vert_off += 32;
} }
if let Ok(m) = PulseAudio::new(tx.clone()) { if let Ok(m) = PulseAudio::new(tx.clone()) {
modules.push(Module::new(Box::new(m), (720, vert_off, 560, 32))); modules.push(Module::new(Box::new(m), (720, vert_off, 560, 32)));
} }
// mod_tx.send(modules).unwrap();
// Calculate window dimensions });
//
let mut dimensions = (0, 0);
for m in modules.iter() {
let b = m.get_bounds();
dimensions = (max(dimensions.0, b.0 + b.2), max(dimensions.1, b.1 + b.3));
}
// Add padding
dimensions = (dimensions.0 + 40, dimensions.1 + 40);
let cmd_queue = Arc::new(Mutex::new(VecDeque::new())); let cmd_queue = Arc::new(Mutex::new(VecDeque::new()));
@@ -325,6 +318,20 @@ impl App {
) )
.unwrap(); .unwrap();
//
// Calculate window dimensions
//
let modules = mod_rx.recv().unwrap();
let mut dimensions = (0, 0);
for m in modules.iter() {
let b = m.get_bounds();
dimensions = (max(dimensions.0, b.0 + b.2), max(dimensions.1, b.1 + b.3));
}
// Add padding
dimensions = (dimensions.0 + 40, dimensions.1 + 40);
shell_surface.set_keyboard_interactivity(1); shell_surface.set_keyboard_interactivity(1);
shell_surface.set_size(dimensions.0, dimensions.1); shell_surface.set_size(dimensions.0, dimensions.1);
surface.commit(); surface.commit();