fix: resolve fullscreen AX tree retrieval returning ref_count: 0

- Add !t.is_empty() check to prevent false positives in partial title matching
- Add fallback to select the first window with children > 0 using count_children API
- Ensures reliable active window selection in macOS native fullscreen mode
This commit is contained in:
noy4 2026-06-06 01:04:00 +09:00
parent 594e93f4db
commit a52b7c704a

View file

@ -31,11 +31,16 @@ pub fn window_element_for(pid: i32, win_title: &str) -> AXElement {
let title = copy_string_attr(win, kAXTitleAttribute);
if title
.as_deref()
.is_some_and(|t| t.contains(win_title) || win_title.contains(t))
.is_some_and(|t| !t.is_empty() && (t.contains(win_title) || win_title.contains(t)))
{
return win.clone();
}
}
for win in &windows {
if count_children(win, None) > 0 {
return win.clone();
}
}
if let Some(first) = windows.into_iter().next() {
return first;
}