feat: add NSAccessibility AXBoundsForRange patch for macOS Zoom cursor tracking
This commit is contained in:
@@ -0,0 +1,130 @@
|
|||||||
|
From 23fd2004cb00908a37ad44d0c41a1ca223eb7c55 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Daneel <daneel@sukany.cz>
|
||||||
|
Date: Sun, 22 Feb 2026 23:21:32 +0100
|
||||||
|
Subject: [PATCH] ns: implement AXBoundsForRange for macOS Zoom cursor tracking
|
||||||
|
|
||||||
|
Add NSAccessibilityBoundsForRangeParameterizedAttribute support to
|
||||||
|
EmacsView so that macOS Zoom and other accessibility tools can track
|
||||||
|
the text cursor position.
|
||||||
|
|
||||||
|
This implements accessibilityAttributeValue:forParameter: on EmacsView,
|
||||||
|
storing the cursor rect in ns_draw_window_cursor and converting it to
|
||||||
|
screen coordinates on demand.
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
- Add lastAccessibilityCursorRect ivar to EmacsView (nsterm.h)
|
||||||
|
- Store cursor rect in ns_draw_window_cursor (nsterm.m)
|
||||||
|
- Implement accessibilityParameterizedAttributeNames
|
||||||
|
- Implement accessibilityAttributeValue:forParameter: for BoundsForRange
|
||||||
|
- Implement accessibilityIsIgnored, accessibilityFocusedUIElement, accessibilityRole
|
||||||
|
- EmacsView reports as NSAccessibilityTextAreaRole
|
||||||
|
|
||||||
|
See also: https://github.com/nicowillis/Ghostty/issues/4053
|
||||||
|
---
|
||||||
|
src/nsterm.h | 3 +++
|
||||||
|
src/nsterm.m | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
2 files changed, 71 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/src/nsterm.h b/src/nsterm.h
|
||||||
|
index 7c1ee4c..6c1ff34 100644
|
||||||
|
--- a/src/nsterm.h
|
||||||
|
+++ b/src/nsterm.h
|
||||||
|
@@ -485,6 +485,9 @@ enum ns_return_frame_mode
|
||||||
|
struct frame *emacsframe;
|
||||||
|
int scrollbarsNeedingUpdate;
|
||||||
|
NSRect ns_userRect;
|
||||||
|
+#ifdef NS_IMPL_COCOA
|
||||||
|
+ NSRect lastAccessibilityCursorRect;
|
||||||
|
+#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* AppKit-side interface. */
|
||||||
|
diff --git a/src/nsterm.m b/src/nsterm.m
|
||||||
|
index 932d209..c900d71 100644
|
||||||
|
--- a/src/nsterm.m
|
||||||
|
+++ b/src/nsterm.m
|
||||||
|
@@ -3232,6 +3232,15 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
|
||||||
|
/* Prevent the cursor from being drawn outside the text area. */
|
||||||
|
r = NSIntersectionRect (r, ns_row_rect (w, glyph_row, TEXT_AREA));
|
||||||
|
|
||||||
|
+#ifdef NS_IMPL_COCOA
|
||||||
|
+ /* Store cursor rect for accessibility (AXBoundsForRange). */
|
||||||
|
+ {
|
||||||
|
+ EmacsView *view = FRAME_NS_VIEW (f);
|
||||||
|
+ if (view)
|
||||||
|
+ view->lastAccessibilityCursorRect = r;
|
||||||
|
+ }
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
ns_focus (f, NULL, 0);
|
||||||
|
|
||||||
|
NSGraphicsContext *ctx = [NSGraphicsContext currentContext];
|
||||||
|
@@ -9474,6 +9483,65 @@ - (int) fullscreenState
|
||||||
|
return fs_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
+#ifdef NS_IMPL_COCOA
|
||||||
|
+/* Accessibility support for macOS Zoom and other assistive tools.
|
||||||
|
+ Implements AXBoundsForRange so that cursor tracking works. */
|
||||||
|
+
|
||||||
|
+- (BOOL)accessibilityIsIgnored
|
||||||
|
+{
|
||||||
|
+ return NO;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+- (id)accessibilityFocusedUIElement
|
||||||
|
+{
|
||||||
|
+ return self;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+- (NSString *)accessibilityRole
|
||||||
|
+{
|
||||||
|
+ return NSAccessibilityTextAreaRole;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+- (NSArray *)accessibilityParameterizedAttributeNames
|
||||||
|
+{
|
||||||
|
+ NSArray *superAttrs = [super accessibilityParameterizedAttributeNames];
|
||||||
|
+ if (superAttrs == nil)
|
||||||
|
+ superAttrs = @[];
|
||||||
|
+ return [superAttrs arrayByAddingObjectsFromArray:
|
||||||
|
+ @[NSAccessibilityBoundsForRangeParameterizedAttribute]];
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+- (id)accessibilityAttributeValue:(NSString *)attribute
|
||||||
|
+ forParameter:(id)parameter
|
||||||
|
+{
|
||||||
|
+ if ([attribute isEqualToString:
|
||||||
|
+ NSAccessibilityBoundsForRangeParameterizedAttribute])
|
||||||
|
+ {
|
||||||
|
+ NSRect viewRect = lastAccessibilityCursorRect;
|
||||||
|
+
|
||||||
|
+ /* lastAccessibilityCursorRect is in EmacsView coordinates
|
||||||
|
+ (flipped: y=0 at top). convertRect:toView:nil handles
|
||||||
|
+ the flipped-to-unflipped conversion automatically for
|
||||||
|
+ flipped views, so no manual flip is needed. */
|
||||||
|
+
|
||||||
|
+ if (viewRect.size.width < 1)
|
||||||
|
+ viewRect.size.width = 1;
|
||||||
|
+ if (viewRect.size.height < 1)
|
||||||
|
+ viewRect.size.height = 8;
|
||||||
|
+
|
||||||
|
+ NSWindow *win = [self window];
|
||||||
|
+ if (win == nil)
|
||||||
|
+ return [NSValue valueWithRect:NSZeroRect];
|
||||||
|
+
|
||||||
|
+ NSRect windowRect = [self convertRect:viewRect toView:nil];
|
||||||
|
+ NSRect screenRect = [win convertRectToScreen:windowRect];
|
||||||
|
+
|
||||||
|
+ return [NSValue valueWithRect:screenRect];
|
||||||
|
+ }
|
||||||
|
+ return [super accessibilityAttributeValue:attribute forParameter:parameter];
|
||||||
|
+}
|
||||||
|
+#endif /* NS_IMPL_COCOA */
|
||||||
|
+
|
||||||
|
@end /* EmacsView */
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
2.43.0
|
||||||
|
|
||||||
Reference in New Issue
Block a user