patches: auto-detect Zoom/VoiceOver; single variable gates both

Changes:
- EmacsApp gets ns_update_accessibility_state and
  ns_accessibility_did_change: methods (patch 0005)
- At startup: UAZoomEnabled() + AXIsProcessTrustedWithOptions()
  determine initial ns_accessibility_enabled state
- com.apple.accessibility.api distributed notification updates it
  whenever any AT connects or disconnects
- All Zoom call sites (UAZoomChangeFocus) now gated by
  ns_accessibility_enabled in addition to ns_zoom_enabled_p()
- ns-accessibility-enabled docstring updated to describe auto-detect

Result: zero config needed; zero overhead when no AT is active;
single variable overrides auto-detection when needed.
This commit is contained in:
2026-03-01 06:39:37 +01:00
parent cc7b288e99
commit 636545c2a5
9 changed files with 163 additions and 54 deletions

View File

@@ -1,4 +1,4 @@
From 03bc19846230e9df6545948e6a431fdb7bdce031 Mon Sep 17 00:00:00 2001
From a5041ede13b2bbcea1ebcb501f8c7317c0fe998f Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 14:46:25 +0100
Subject: [PATCH 8/9] ns: announce overlay completion candidates for VoiceOver
@@ -61,10 +61,10 @@ index 6e830de..2102fb9 100644
@property (nonatomic, assign) BOOL cachedMarkActive;
@property (nonatomic, copy) NSString *cachedCompletionAnnouncement;
diff --git a/src/nsterm.m b/src/nsterm.m
index 1577338..71b6d2e 100644
index 4ad451f..5654283 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -7209,11 +7209,154 @@ Accessibility virtual elements (macOS / Cocoa only)
@@ -7257,11 +7257,154 @@ Accessibility virtual elements (macOS / Cocoa only)
/* ---- Helper: extract buffer text for accessibility ---- */
@@ -220,7 +220,7 @@ index 1577338..71b6d2e 100644
static NSString *
ns_ax_buffer_text (struct window *w, ptrdiff_t *out_start,
ns_ax_visible_run **out_runs, NSUInteger *out_nruns)
@@ -7284,7 +7427,7 @@ Accessibility virtual elements (macOS / Cocoa only)
@@ -7332,7 +7475,7 @@ Accessibility virtual elements (macOS / Cocoa only)
/* Extract this visible run's text. Use
Fbuffer_substring_no_properties which correctly handles the
@@ -229,7 +229,7 @@ index 1577338..71b6d2e 100644
include garbage bytes when the run spans the gap position. */
Lisp_Object lstr = Fbuffer_substring_no_properties (
make_fixnum (pos), make_fixnum (run_end));
@@ -7365,7 +7508,7 @@ Mode lines using icon fonts (e.g. doom-modeline with nerd-font)
@@ -7413,7 +7556,7 @@ Mode lines using icon fonts (e.g. doom-modeline with nerd-font)
return NSZeroRect;
/* charpos_start and charpos_len are already in buffer charpos
@@ -238,7 +238,7 @@ index 1577338..71b6d2e 100644
charposForAccessibilityIndex which handles invisible text. */
ptrdiff_t cp_start = charpos_start;
ptrdiff_t cp_end = cp_start + charpos_len;
@@ -7844,6 +7987,7 @@ @implementation EmacsAccessibilityBuffer
@@ -7892,6 +8035,7 @@ @implementation EmacsAccessibilityBuffer
@synthesize cachedOverlayModiff;
@synthesize cachedTextStart;
@synthesize cachedModiff;
@@ -246,7 +246,7 @@ index 1577338..71b6d2e 100644
@synthesize cachedPoint;
@synthesize cachedMarkActive;
@synthesize cachedCompletionAnnouncement;
@@ -7941,7 +8085,7 @@ - (void)ensureTextCache
@@ -7989,7 +8133,7 @@ - (void)ensureTextCache
NSTRACE ("EmacsAccessibilityBuffer ensureTextCache");
/* This method is only called from the main thread (AX getters
dispatch_sync to main first). Reads of cachedText/cachedTextModiff
@@ -255,7 +255,7 @@ index 1577338..71b6d2e 100644
write section at the end needs synchronization to protect
against concurrent reads from AX server thread. */
eassert ([NSThread isMainThread]);
@@ -7953,25 +8097,16 @@ - (void)ensureTextCache
@@ -8001,25 +8145,16 @@ - (void)ensureTextCache
if (!b)
return;
@@ -289,7 +289,7 @@ index 1577338..71b6d2e 100644
&& cachedTextStart == BUF_BEGV (b)
&& pt >= cachedTextStart
&& (textLen == 0
@@ -7987,7 +8122,7 @@ included in the cached AX text (it is handled separately via
@@ -8035,7 +8170,7 @@ included in the cached AX text (it is handled separately via
{
[cachedText release];
cachedText = [text retain];
@@ -298,7 +298,7 @@ index 1577338..71b6d2e 100644
cachedTextStart = start;
if (visibleRuns)
@@ -8052,7 +8187,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
@@ -8100,7 +8235,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
/* Binary search: runs are sorted by charpos (ascending). Find the
run whose [charpos, charpos+length) range contains the target,
or the nearest run after an invisible gap. O(log n) instead of
@@ -307,7 +307,7 @@ index 1577338..71b6d2e 100644
NSUInteger lo = 0, hi = visibleRunCount;
while (lo < hi)
{
@@ -8065,7 +8200,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
@@ -8113,7 +8248,7 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
else
{
/* Found: charpos is inside this run. Compute UTF-16 delta
@@ -316,7 +316,7 @@ index 1577338..71b6d2e 100644
NSUInteger chars_in = (NSUInteger)(charpos - r->charpos);
if (chars_in == 0 || !cachedText)
return r->ax_start;
@@ -8090,10 +8225,10 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
@@ -8138,10 +8273,10 @@ - (NSUInteger)accessibilityIndexForCharpos:(ptrdiff_t)charpos
/* Convert accessibility string index to buffer charpos.
Safe to call from any thread: uses only cachedText (NSString) and
@@ -329,7 +329,7 @@ index 1577338..71b6d2e 100644
@synchronized (self)
{
if (visibleRunCount == 0)
@@ -8127,7 +8262,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
@@ -8175,7 +8310,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
return cp;
}
}
@@ -338,7 +338,7 @@ index 1577338..71b6d2e 100644
if (lo > 0)
{
ns_ax_visible_run *last = &visibleRuns[visibleRunCount - 1];
@@ -8149,7 +8284,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
@@ -8197,7 +8332,7 @@ - (ptrdiff_t)charposForAccessibilityIndex:(NSUInteger)ax_idx
deadlocking the AX server thread. This is prevented by:
1. validWindow checks WINDOW_LIVE_P and BUFFERP before every
@@ -347,7 +347,7 @@ index 1577338..71b6d2e 100644
2. All dispatch_sync blocks run on the main thread where no
concurrent Lisp code can modify state between checks.
3. block_input prevents timer events and process output from
@@ -8503,6 +8638,50 @@ - (NSInteger)accessibilityInsertionPointLineNumber
@@ -8551,6 +8686,50 @@ - (NSInteger)accessibilityInsertionPointLineNumber
return [self lineForAXIndex:point_idx];
}
@@ -398,7 +398,7 @@ index 1577338..71b6d2e 100644
- (NSRange)accessibilityRangeForLine:(NSInteger)line
{
if (![NSThread isMainThread])
@@ -8725,7 +8904,7 @@ - (NSRect)accessibilityFrame
@@ -8773,7 +8952,7 @@ - (NSRect)accessibilityFrame
/* ===================================================================
@@ -407,7 +407,7 @@ index 1577338..71b6d2e 100644
These methods notify VoiceOver of text and selection changes.
Called from the redisplay cycle (postAccessibilityUpdates).
@@ -8740,7 +8919,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
@@ -8788,7 +8967,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
if (point > self.cachedPoint
&& point - self.cachedPoint == 1)
{
@@ -416,7 +416,7 @@ index 1577338..71b6d2e 100644
[self invalidateTextCache];
[self ensureTextCache];
if (cachedText)
@@ -8759,7 +8938,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
@@ -8807,7 +8986,7 @@ - (void)postTextChangedNotification:(ptrdiff_t)point
/* Update cachedPoint here so the selection-move branch does NOT
fire for point changes caused by edits. WebKit and Chromium
never send both ValueChanged and SelectedTextChanged for the
@@ -425,7 +425,7 @@ index 1577338..71b6d2e 100644
self.cachedPoint = point;
NSDictionary *change = @{
@@ -9092,16 +9271,83 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
@@ -9140,16 +9319,83 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
BOOL markActive = !NILP (BVAR (b, mark_active));
/* --- Text changed (edit) --- */
@@ -513,7 +513,7 @@ index 1577338..71b6d2e 100644
{
ptrdiff_t oldPoint = self.cachedPoint;
BOOL oldMarkActive = self.cachedMarkActive;
@@ -9269,7 +9515,7 @@ - (NSRect)accessibilityFrame
@@ -9317,7 +9563,7 @@ - (NSRect)accessibilityFrame
/* ===================================================================
@@ -522,7 +522,7 @@ index 1577338..71b6d2e 100644
=================================================================== */
/* Scan visible range of window W for interactive spans.
@@ -9477,7 +9723,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
@@ -9525,7 +9771,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
dispatch_async (dispatch_get_main_queue (), ^{
/* lwin is a Lisp_Object captured by value. This is GC-safe
because Lisp_Objects are tagged integers/pointers that
@@ -531,7 +531,7 @@ index 1577338..71b6d2e 100644
Emacs. The WINDOW_LIVE_P check below guards against the
window being deleted between capture and execution. */
if (!WINDOWP (lwin) || NILP (Fwindow_live_p (lwin)))
@@ -9503,7 +9749,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
@@ -9551,7 +9797,7 @@ - (void) setAccessibilityFocused: (BOOL) focused
@end
@@ -540,7 +540,7 @@ index 1577338..71b6d2e 100644
Methods are kept here (same .m file) so they access the ivars
declared in the @interface ivar block. */
@implementation EmacsAccessibilityBuffer (InteractiveSpans)
@@ -12225,7 +12471,7 @@ - (int) fullscreenState
@@ -12273,7 +12519,7 @@ - (int) fullscreenState
if (WINDOW_LEAF_P (w))
{
@@ -549,7 +549,7 @@ index 1577338..71b6d2e 100644
EmacsAccessibilityBuffer *elem
= [existing objectForKey:[NSValue valueWithPointer:w]];
if (!elem)
@@ -12259,7 +12505,7 @@ - (int) fullscreenState
@@ -12307,7 +12553,7 @@ - (int) fullscreenState
}
else
{
@@ -558,7 +558,7 @@ index 1577338..71b6d2e 100644
Lisp_Object child = w->contents;
while (!NILP (child))
{
@@ -12371,7 +12617,7 @@ - (void)postAccessibilityUpdates
@@ -12419,7 +12665,7 @@ - (void)postAccessibilityUpdates
accessibilityUpdating = YES;
/* Detect window tree change (split, delete, new buffer). Compare
@@ -567,7 +567,7 @@ index 1577338..71b6d2e 100644
Lisp_Object curRoot = FRAME_ROOT_WINDOW (emacsframe);
if (!EQ (curRoot, lastRootWindow))
{
@@ -12380,12 +12626,12 @@ - (void)postAccessibilityUpdates
@@ -12428,12 +12674,12 @@ - (void)postAccessibilityUpdates
}
/* If tree is stale, rebuild FIRST so we don't iterate freed