mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-29 11:52:50 +01:00
fix(mac): the registry keeps inert copies of the application
BEHAVIOUR (cost only; nothing reads the registry yet except the unused MacosBackend). Review finding 1. Application::drop does a blocking Accessibility round trip (is_valid -> copy_attribute_names) when is_observable, and invalidates the observer that every clone shares if that fails. AxEntry held a clone of the Application, so every register (which drops the entry it replaces), forget and forget_pid ran that call, on the event thread with the window manager lock held, and an unresponsive app made it slow or made it invalidate the observer of a live app. Window::entry() now stores Application::inert(), a clone with is_observable false, whose drop does nothing, and Window::from_entry therefore builds windows with an inert application as well (it only affects Drop). Tests (run on a Mac; the flag is plain data and needs no Accessibility permission): a registered entry and a window made from an entry have is_observable false even when the window's own application is observable. Verified: macOS fake-CC type-check (tools/fast-check) PASS. Not verified: any run. Verified on the Mini: not yet. Hand check: H3 of docs/dev/macos-handcheck.md.
This commit is contained in:
1 parent
a68668840d
commit
a501c05809
3 files changed
+53
-1
No files matched your search
@@ -121,6 +121,16 @@ impl Application {
|
||||
})
|
||||
}
|
||||
|
||||
/// A clone that does nothing when it is dropped: [`Application::drop`] asks the application
|
||||
/// whether it is still there (a blocking Accessibility round trip) and may invalidate the
|
||||
/// observer that every clone shares, which is for the clones a window carries and not for the
|
||||
/// ones that a table keeps.
|
||||
pub fn inert(&self) -> Self {
|
||||
let mut inert = self.clone();
|
||||
inert.is_observable = false;
|
||||
inert
|
||||
}
|
||||
|
||||
/// The AX element of the application itself, as opposed to one of its windows
|
||||
pub fn element(&self) -> &AccessibilityUiElement {
|
||||
&self.element
|
||||
|
||||
@@ -112,3 +112,44 @@ pub fn identify(
|
||||
) -> std::result::Result<u32, crate::accessibility::error::AccessibilityError> {
|
||||
crate::accessibility::AccessibilityApi::window_id(element)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn window_of(id: u32, pid: i32) -> Window {
|
||||
let mut window = Window::from(id);
|
||||
window.application.process_id = pid;
|
||||
window
|
||||
}
|
||||
|
||||
fn id(raw: u32) -> WindowId {
|
||||
WindowId::from_u32(raw)
|
||||
}
|
||||
|
||||
/// `Application::drop` asks the application whether it is still there (a blocking
|
||||
/// Accessibility round trip) when `is_observable`; the table must hold copies that skip it.
|
||||
#[test]
|
||||
fn a_registered_entry_does_not_ask_the_app_when_it_is_dropped() {
|
||||
let mut window = window_of(0x5101, 6_100_001);
|
||||
window.application.is_observable = true;
|
||||
|
||||
assert!(!window.entry().application.is_observable);
|
||||
|
||||
register(&window);
|
||||
assert!(!get(id(0x5101)).unwrap().application.is_observable);
|
||||
|
||||
forget(0x5101);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_window_made_from_an_entry_is_inert_too() {
|
||||
let mut window = window_of(0x5102, 6_100_002);
|
||||
window.application.is_observable = true;
|
||||
register(&window);
|
||||
|
||||
assert!(!super::window(id(0x5102)).unwrap().application.is_observable);
|
||||
|
||||
forget(0x5102);
|
||||
}
|
||||
}
|
||||
@@ -578,7 +578,8 @@ impl Window {
|
||||
crate::ax_registry::AxEntry {
|
||||
element: self.element.clone(),
|
||||
observer: self.observer.clone(),
|
||||
application: self.application.clone(),
|
||||
// inert: dropping an entry must not ask the application anything (see `Application::inert`)
|
||||
application: self.application.inert(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user