-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wm): run orphan reaper in a dedicated thread
Until now the orphan window/container reaper has always run on every WinEvent. Unfortunately Windows Terminal does not sent a WinEvent when it is closed. This is a problem for the new border_manager module which draws and destroys borders based on notifications sent to it after WinEvents and SocketMessages have been processed. Since Windows Terminal is not sending a WinEvent on close, this means that user interaction is required to remove the ghost border that gets left behind. This commit starts a separate thread for the reaper where it runs once every second in a loop. This is quite wasteful and definitely not something I wanted to implement, but a temporary solution is needed given the popularity of the buggy application in question. An issue on the Windows Terminal tracker has been opened here: microsoft/terminal#17298
- Loading branch information
Showing
5 changed files
with
83 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#![deny(clippy::unwrap_used, clippy::expect_used)] | ||
|
||
use crate::border_manager; | ||
use crate::WindowManager; | ||
use parking_lot::Mutex; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
|
||
pub fn watch_for_orphans(wm: Arc<Mutex<WindowManager>>) { | ||
std::thread::spawn(move || loop { | ||
match find_orphans(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 find_orphans(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result<()> { | ||
tracing::info!("watching"); | ||
|
||
let arc = wm.clone(); | ||
|
||
loop { | ||
std::thread::sleep(Duration::from_secs(1)); | ||
|
||
let mut wm = arc.lock(); | ||
let offset = wm.work_area_offset; | ||
|
||
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() { | ||
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 | ||
}; | ||
|
||
for (j, workspace) in monitor.workspaces_mut().iter_mut().enumerate() { | ||
let reaped_orphans = workspace.reap_orphans()?; | ||
if reaped_orphans.0 > 0 || reaped_orphans.1 > 0 { | ||
workspace.update(&work_area, offset, window_based_work_area_offset)?; | ||
border_manager::event_tx().send(border_manager::Notification)?; | ||
tracing::info!( | ||
"reaped {} orphan window(s) and {} orphaned container(s) on monitor: {}, workspace: {}", | ||
reaped_orphans.0, | ||
reaped_orphans.1, | ||
i, | ||
j | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters