tighten visibility and clear the remaining mechanical lint noise

This commit is contained in:
2026-09-21 00:44:25 +03:00
parent 1332600148
commit 03b2fec744
11 changed files with 158 additions and 172 deletions
+14 -14
View File
@@ -14,30 +14,30 @@ use windows::Win32::UI::WindowsAndMessaging::{
IsWindowVisible, GWL_EXSTYLE, WS_EX_TOOLWINDOW,
};
unsafe fn visible_window_rect(hwnd: HWND) -> Option<RECT> {
unsafe fn visible_window_rect(hwnd: HWND) -> Option<RECT> { unsafe {
let mut rect = RECT::default();
let r = DwmGetWindowAttribute(
hwnd,
DWMWA_EXTENDED_FRAME_BOUNDS,
&mut rect as *mut RECT as *mut std::ffi::c_void,
std::mem::size_of::<RECT>() as u32,
(&raw mut rect).cast::<std::ffi::c_void>(),
size_of::<RECT>() as u32,
);
if r.is_ok() && rect.right > rect.left && rect.bottom > rect.top {
return Some(rect);
}
let mut fallback = RECT::default();
if GetWindowRect(hwnd, &mut fallback).is_ok() {
if GetWindowRect(hwnd, &raw mut fallback).is_ok() {
Some(fallback)
} else {
None
}
}
}}
const VK_LBUTTON: i32 = 0x01;
const VK_ESCAPE: i32 = 0x1B;
#[derive(Serialize, Clone)]
pub struct Rect {
pub(crate) struct Rect {
pub x: i32,
pub y: i32,
pub width: u32,
@@ -46,7 +46,7 @@ pub struct Rect {
pub struct PickerSession {
running: Arc<AtomicBool>,
handle: Option<std::thread::JoinHandle<()>>,
handle: Option<thread::JoinHandle<()>>,
}
struct EnumCtx {
@@ -68,16 +68,16 @@ const SHELL_CLASSES: &[&str] = &[
"Windows.UI.Core.CoreWindow",
];
unsafe fn class_of(hwnd: HWND) -> String {
unsafe fn class_of(hwnd: HWND) -> String { unsafe {
let mut buf = [0u16; 128];
let n = GetClassNameW(hwnd, &mut buf);
if n <= 0 {
return String::new();
}
String::from_utf16_lossy(&buf[..n as usize])
}
}}
unsafe extern "system" fn enum_at_point(hwnd: HWND, lparam: LPARAM) -> BOOL {
unsafe extern "system" fn enum_at_point(hwnd: HWND, lparam: LPARAM) -> BOOL { unsafe {
let ctx = &mut *(lparam.0 as *mut EnumCtx);
if ctx.found.is_some() {
return BOOL(1);
@@ -118,7 +118,7 @@ unsafe extern "system" fn enum_at_point(hwnd: HWND, lparam: LPARAM) -> BOOL {
}
ctx.found = Some((id, rect));
BOOL(0)
}
}}
fn top_window_at(pt: POINT, exclude: &[isize]) -> Option<(isize, RECT)> {
let mut ctx = EnumCtx {
@@ -129,13 +129,13 @@ fn top_window_at(pt: POINT, exclude: &[isize]) -> Option<(isize, RECT)> {
unsafe {
drop(EnumWindows(
Some(enum_at_point),
LPARAM(&raw mut ctx as *mut EnumCtx as isize),
LPARAM((&raw mut ctx).cast::<EnumCtx>() as isize),
));
}
ctx.found
}
pub fn start(app: AppHandle, exclude_hwnds: Vec<isize>) -> PickerSession {
pub(crate) fn start(app: AppHandle, exclude_hwnds: Vec<isize>) -> PickerSession {
let running = Arc::new(AtomicBool::new(true));
let running_clone = running.clone();
let handle = thread::spawn(move || {
@@ -149,7 +149,7 @@ pub fn start(app: AppHandle, exclude_hwnds: Vec<isize>) -> PickerSession {
}
let mut pt = POINT::default();
if unsafe { GetCursorPos(&mut pt) }.is_err() {
if unsafe { GetCursorPos(&raw mut pt) }.is_err() {
thread::sleep(Duration::from_millis(30));
continue;
}