mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-24 01:28:39 +02:00
fix(borders): reap untracked hwnds in destroy_all
This commit ensures that even border hwnds that may now be untracked as a result of events such as monitor changes will now be reaped in the destroy_all_borders function.
This commit is contained in:
@@ -19,6 +19,7 @@ use std::sync::atomic::Ordering;
|
|||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use windows::core::PCWSTR;
|
use windows::core::PCWSTR;
|
||||||
|
use windows::Win32::Foundation::BOOL;
|
||||||
use windows::Win32::Foundation::COLORREF;
|
use windows::Win32::Foundation::COLORREF;
|
||||||
use windows::Win32::Foundation::HWND;
|
use windows::Win32::Foundation::HWND;
|
||||||
use windows::Win32::Foundation::LPARAM;
|
use windows::Win32::Foundation::LPARAM;
|
||||||
@@ -47,10 +48,28 @@ use windows::Win32::UI::WindowsAndMessaging::WM_DESTROY;
|
|||||||
use windows::Win32::UI::WindowsAndMessaging::WM_PAINT;
|
use windows::Win32::UI::WindowsAndMessaging::WM_PAINT;
|
||||||
use windows::Win32::UI::WindowsAndMessaging::WNDCLASSW;
|
use windows::Win32::UI::WindowsAndMessaging::WNDCLASSW;
|
||||||
|
|
||||||
|
pub extern "system" fn border_hwnds(hwnd: HWND, lparam: LPARAM) -> BOOL {
|
||||||
|
let hwnds = unsafe { &mut *(lparam.0 as *mut Vec<isize>) };
|
||||||
|
|
||||||
|
if let Ok(class) = WindowsApi::real_window_class_w(hwnd) {
|
||||||
|
if class.starts_with("komoborder") {
|
||||||
|
hwnds.push(hwnd.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
true.into()
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Border {
|
pub struct Border {
|
||||||
pub hwnd: isize,
|
pub hwnd: isize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<isize> for Border {
|
||||||
|
fn from(value: isize) -> Self {
|
||||||
|
Self { hwnd: value }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Border {
|
impl Border {
|
||||||
pub const fn hwnd(&self) -> HWND {
|
pub const fn hwnd(&self) -> HWND {
|
||||||
HWND(self.hwnd)
|
HWND(self.hwnd)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ use crate::Rect;
|
|||||||
use crate::Rgb;
|
use crate::Rgb;
|
||||||
use crate::WindowManager;
|
use crate::WindowManager;
|
||||||
use crate::WindowsApi;
|
use crate::WindowsApi;
|
||||||
|
use border::border_hwnds;
|
||||||
use border::Border;
|
use border::Border;
|
||||||
use komorebi_core::WindowKind;
|
use komorebi_core::WindowKind;
|
||||||
|
|
||||||
@@ -77,6 +78,17 @@ pub fn destroy_all_borders() -> color_eyre::Result<()> {
|
|||||||
BORDERS_MONITORS.lock().clear();
|
BORDERS_MONITORS.lock().clear();
|
||||||
FOCUS_STATE.lock().clear();
|
FOCUS_STATE.lock().clear();
|
||||||
|
|
||||||
|
let mut remaining_hwnds = vec![];
|
||||||
|
|
||||||
|
WindowsApi::enum_windows(
|
||||||
|
Some(border_hwnds),
|
||||||
|
&mut remaining_hwnds as *mut Vec<isize> as isize,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
for hwnd in remaining_hwnds {
|
||||||
|
Border::from(hwnd).destroy()?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user