From 8fd18048a46b71a55046470bde22e2a321149282 Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Tue, 4 Mar 2025 14:51:40 +0000 Subject: [PATCH] remove(wm): remove workspace_reconciliator --- komorebi/src/border_manager/mod.rs | 3 - komorebi/src/lib.rs | 1 - komorebi/src/main.rs | 2 - komorebi/src/workspace_reconciliator.rs | 130 ------------------------ 4 files changed, 136 deletions(-) delete mode 100644 komorebi/src/workspace_reconciliator.rs diff --git a/komorebi/src/border_manager/mod.rs b/komorebi/src/border_manager/mod.rs index 326e3d99..869ae090 100644 --- a/komorebi/src/border_manager/mod.rs +++ b/komorebi/src/border_manager/mod.rs @@ -7,7 +7,6 @@ use crate::core::WindowKind; use crate::ring::Ring; use crate::windows_api; use crate::workspace::WorkspaceLayer; -use crate::workspace_reconciliator::ALT_TAB_HWND; use crate::Colour; use crate::Rgb; use crate::WindowManager; @@ -333,8 +332,6 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result if !BORDER_ENABLED.load_consume() // Or if the wm is paused || is_paused - // Or if we are handling an alt-tab across workspaces - || ALT_TAB_HWND.load().is_some() { // Destroy the borders we know about for (_, border) in borders.drain() { diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index 21de7624..af392fbd 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -30,7 +30,6 @@ pub mod windows_callbacks; pub mod winevent; pub mod winevent_listener; pub mod workspace; -pub mod workspace_reconciliator; use lazy_static::lazy_static; use monitor_reconciliator::MonitorNotification; diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index 789d566c..b972cecc 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -50,7 +50,6 @@ use komorebi::window_manager::State; use komorebi::window_manager::WindowManager; use komorebi::windows_api::WindowsApi; use komorebi::winevent_listener; -use komorebi::workspace_reconciliator; use komorebi::CUSTOM_FFM; use komorebi::DATA_DIR; use komorebi::HOME_DIR; @@ -303,7 +302,6 @@ fn main() -> Result<()> { 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(), wm.lock().known_hwnds.clone()); focus_manager::listen_for_notifications(wm.clone()); diff --git a/komorebi/src/workspace_reconciliator.rs b/komorebi/src/workspace_reconciliator.rs deleted file mode 100644 index d3417ea1..00000000 --- a/komorebi/src/workspace_reconciliator.rs +++ /dev/null @@ -1,130 +0,0 @@ -#![deny(clippy::unwrap_used, clippy::expect_used)] - -use crate::border_manager; -use crate::WindowManager; -use crossbeam_channel::Receiver; -use crossbeam_channel::Sender; -use crossbeam_utils::atomic::AtomicCell; -use lazy_static::lazy_static; -use parking_lot::Mutex; -use std::sync::Arc; -use std::sync::OnceLock; -use std::time::Duration; -use std::time::Instant; - -#[derive(Copy, Clone)] -pub struct Notification { - pub monitor_idx: usize, - pub workspace_idx: usize, -} - -pub static ALT_TAB_HWND: AtomicCell> = AtomicCell::new(None); - -lazy_static! { - pub static ref ALT_TAB_HWND_INSTANT: Arc> = Arc::new(Mutex::new(Instant::now())); -} - -static CHANNEL: OnceLock<(Sender, Receiver)> = OnceLock::new(); - -pub fn channel() -> &'static (Sender, Receiver) { - CHANNEL.get_or_init(|| crossbeam_channel::bounded(1)) -} - -fn event_tx() -> Sender { - channel().0.clone() -} - -fn event_rx() -> Receiver { - channel().1.clone() -} - -pub fn send_notification(monitor_idx: usize, workspace_idx: usize) { - if event_tx() - .try_send(Notification { - monitor_idx, - workspace_idx, - }) - .is_err() - { - tracing::warn!("channel is full; dropping notification") - } -} - -pub fn listen_for_notifications(wm: Arc>) { - std::thread::spawn(move || loop { - match handle_notifications(wm.clone()) { - Ok(()) => { - tracing::warn!("restarting finished thread"); - } - Err(error) => { - if cfg!(debug_assertions) { - tracing::error!("restarting failed thread: {:?}", error) - } else { - tracing::error!("restarting failed thread: {}", error) - } - } - } - }); -} -pub fn handle_notifications(wm: Arc>) -> color_eyre::Result<()> { - tracing::info!("listening"); - - let receiver = event_rx(); - let arc = wm.clone(); - - for notification in receiver { - tracing::info!("running reconciliation"); - - let mut wm = wm.lock(); - let focused_monitor_idx = wm.focused_monitor_idx(); - let focused_workspace_idx = - wm.focused_workspace_idx_for_monitor_idx(focused_monitor_idx)?; - - let focused_pair = (focused_monitor_idx, focused_workspace_idx); - let updated_pair = (notification.monitor_idx, notification.workspace_idx); - - if focused_pair != updated_pair { - wm.focus_monitor(notification.monitor_idx)?; - let mouse_follows_focus = wm.mouse_follows_focus; - - if let Some(monitor) = wm.focused_monitor_mut() { - let previous_idx = monitor.focused_workspace_idx(); - monitor.set_last_focused_workspace(Option::from(previous_idx)); - monitor.focus_workspace(notification.workspace_idx)?; - monitor.load_focused_workspace(mouse_follows_focus)?; - } - - // Drop our lock on the window manager state here to not slow down updates - drop(wm); - - // Check if there was an alt-tab across workspaces in the last second - if let Some(hwnd) = ALT_TAB_HWND.load() { - if ALT_TAB_HWND_INSTANT - .lock() - .elapsed() - .lt(&Duration::from_secs(1)) - { - // Sleep for 100 millis to let other events pass - std::thread::sleep(Duration::from_millis(100)); - tracing::info!("focusing alt-tabbed window"); - - // Take a new lock on the wm and try to focus the container with - // the recorded HWND from the alt-tab - let mut wm = arc.lock(); - if let Ok(workspace) = wm.focused_workspace_mut() { - // Regardless of if this fails, we need to get past this part - // to unblock the border manager below - let _ = workspace.focus_container_by_window(hwnd); - } - - // Unblock the border manager - ALT_TAB_HWND.store(None); - // Send a notification to the border manager to update the borders - border_manager::send_notification(None); - } - } - } - } - - Ok(()) -}