diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index 7d60d2af..a76d97f9 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -244,16 +244,10 @@ fn main() -> Result<()> { StaticConfig::postload(config, &wm)?; } - listen_for_commands(wm.clone()); - if !opts.await_configuration && !INITIAL_CONFIGURATION_LOADED.load(Ordering::SeqCst) { INITIAL_CONFIGURATION_LOADED.store(true, Ordering::SeqCst); }; - if let Some(port) = opts.tcp_port { - listen_for_commands_tcp(wm.clone(), port); - } - if static_config.is_none() { std::thread::spawn(|| load_configuration().expect("could not load configuration")); @@ -280,21 +274,27 @@ fn main() -> Result<()> { wm.lock().retile_all(false)?; - listen_for_events(wm.clone()); - - if CUSTOM_FFM.load(Ordering::SeqCst) { - listen_for_movements(wm.clone()); - } - border_manager::listen_for_notifications(wm.clone()); stackbar_manager::listen_for_notifications(wm.clone()); transparency_manager::listen_for_notifications(wm.clone()); workspace_reconciliator::listen_for_notifications(wm.clone()); monitor_reconciliator::listen_for_notifications(wm.clone())?; - reaper::listen_for_notifications(wm.clone()); + reaper::listen_for_notifications(wm.clone(), wm.lock().known_hwnds.clone()); focus_manager::listen_for_notifications(wm.clone()); theme_manager::listen_for_notifications(); + listen_for_commands(wm.clone()); + + if let Some(port) = opts.tcp_port { + listen_for_commands_tcp(wm.clone(), port); + } + + listen_for_events(wm.clone()); + + if CUSTOM_FFM.load(Ordering::SeqCst) { + listen_for_movements(wm.clone()); + } + let (ctrlc_sender, ctrlc_receiver) = crossbeam_channel::bounded(1); ctrlc::set_handler(move || { ctrlc_sender diff --git a/komorebi/src/reaper.rs b/komorebi/src/reaper.rs index ef919db7..f79771eb 100644 --- a/komorebi/src/reaper.rs +++ b/komorebi/src/reaper.rs @@ -47,8 +47,11 @@ pub fn send_notification(hwnds: HashMap) { } } -pub fn listen_for_notifications(wm: Arc>) { - watch_for_orphans(wm.clone()); +pub fn listen_for_notifications( + wm: Arc>, + known_hwnds: HashMap, +) { + watch_for_orphans(known_hwnds); std::thread::spawn(move || loop { match handle_notifications(wm.clone()) { @@ -70,25 +73,12 @@ fn handle_notifications(wm: Arc>) -> color_eyre::Result<()> for notification in receiver { let orphan_hwnds = notification.0; let mut wm = wm.lock(); - let offset = wm.work_area_offset; let mut update_borders = false; for (hwnd, (m_idx, w_idx)) in orphan_hwnds.iter() { if let Some(monitor) = wm.monitors_mut().get_mut(*m_idx) { let focused_workspace_idx = monitor.focused_workspace_idx(); - let work_area = *monitor.work_area_size(); - let window_based_work_area_offset = ( - monitor.window_based_work_area_offset_limit(), - monitor.window_based_work_area_offset(), - ); - - let offset = if monitor.work_area_offset().is_some() { - monitor.work_area_offset() - } else { - offset - }; - if let Some(workspace) = monitor.workspaces_mut().get_mut(*w_idx) { // Remove orphan window if let Err(error) = workspace.remove_window(*hwnd) { @@ -105,7 +95,7 @@ fn handle_notifications(wm: Arc>) -> color_eyre::Result<()> // If this is not a focused workspace there is no need to update the // workspace or the borders. That will already be done when the user // changes to this workspace. - workspace.update(&work_area, offset, window_based_work_area_offset)?; + workspace.update()?; update_borders = true; } tracing::info!( @@ -150,11 +140,11 @@ fn handle_notifications(wm: Arc>) -> color_eyre::Result<()> Ok(()) } -fn watch_for_orphans(wm: Arc>) { +fn watch_for_orphans(known_hwnds: HashMap) { // Cache current hwnds { let mut cache = HWNDS_CACHE.lock(); - *cache = wm.lock().known_hwnds.clone(); + *cache = known_hwnds; } std::thread::spawn(move || loop {