patches: fix forward dependency (helpers moved to patch 1)
This commit is contained in:
@@ -1,36 +1,39 @@
|
||||
From 53a22c5d2014002256acf1c1bc14af2dfbb26469 Mon Sep 17 00:00:00 2001
|
||||
From de04e84b555706cfe0d39ed4a388895443e19e02 Mon Sep 17 00:00:00 2001
|
||||
From: Martin Sukany <martin@sukany.cz>
|
||||
Date: Sat, 28 Feb 2026 10:10:55 +0100
|
||||
Date: Sat, 28 Feb 2026 10:24:30 +0100
|
||||
Subject: [PATCH 1/5] ns: add accessibility base classes and text extraction
|
||||
|
||||
Add the foundation for macOS VoiceOver accessibility in the NS
|
||||
(Cocoa) port. No existing code paths are modified.
|
||||
|
||||
* src/nsterm.h (ns_ax_visible_run): New struct for buffer-to-UTF-16
|
||||
index mapping.
|
||||
(EmacsAccessibilityElement): New base class for virtual AX elements.
|
||||
* src/nsterm.h (ns_ax_visible_run): New struct.
|
||||
(EmacsAccessibilityElement): New base class.
|
||||
(EmacsAccessibilityBuffer, EmacsAccessibilityModeLine)
|
||||
(EmacsAccessibilityInteractiveSpan): Forward declarations.
|
||||
(EmacsAXSpanType): New enum for span classification.
|
||||
(EmacsView): New ivars accessibilityElements, lastSelectedWindow,
|
||||
accessibilityTreeValid, lastAccessibilityCursorRect.
|
||||
(EmacsAXSpanType): New enum.
|
||||
(EmacsView): New ivars for accessibility state.
|
||||
* src/nsterm.m: Include intervals.h for TEXT_PROP_MEANS_INVISIBLE.
|
||||
(ns_ax_buffer_text): New function. Build accessibility string with
|
||||
visible-run mapping; skip invisible text per spec.
|
||||
(ns_ax_mode_line_text): New function. Extract CHAR_GLYPH text.
|
||||
(ns_ax_frame_for_range): New function. Screen rect via glyph matrix.
|
||||
(ns_ax_post_notification, ns_ax_post_notification_with_info): New
|
||||
functions. dispatch_async wrappers preventing VoiceOver deadlock.
|
||||
(ns_ax_completion_string_from_prop, ns_ax_window_buffer_object)
|
||||
(ns_ax_window_end_charpos, ns_ax_text_prop_at)
|
||||
(ns_ax_next_prop_change, ns_ax_get_span_label): New utility helpers.
|
||||
(NS_AX_TEXT_CAP): New macro, 100000.
|
||||
(ns_ax_buffer_text): New function.
|
||||
(ns_ax_mode_line_text): New function.
|
||||
(ns_ax_frame_for_range): New function.
|
||||
(ns_ax_completion_string_from_prop): New function.
|
||||
(ns_ax_window_buffer_object): New function.
|
||||
(ns_ax_window_end_charpos): New function.
|
||||
(ns_ax_text_prop_at): New function.
|
||||
(ns_ax_next_prop_change): New function.
|
||||
(ns_ax_get_span_label): New function.
|
||||
(ns_ax_post_notification): New function.
|
||||
(ns_ax_post_notification_with_info): New function.
|
||||
(EmacsAccessibilityElement): Implement base class.
|
||||
(syms_of_nsterm): Register accessibility DEFSYM and DEFVAR
|
||||
ns-accessibility-enabled.
|
||||
|
||||
Tested on macOS 14 Sonoma. Builds cleanly; no functional change.
|
||||
---
|
||||
src/nsterm.h | 119 +++++++++++++++++
|
||||
src/nsterm.m | 355 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 474 insertions(+)
|
||||
src/nsterm.h | 119 +++++++++++++
|
||||
src/nsterm.m | 468 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 587 insertions(+)
|
||||
|
||||
diff --git a/src/nsterm.h b/src/nsterm.h
|
||||
index 7c1ee4c..393fc4c 100644
|
||||
@@ -177,7 +180,7 @@ index 7c1ee4c..393fc4c 100644
|
||||
|
||||
|
||||
diff --git a/src/nsterm.m b/src/nsterm.m
|
||||
index 74e4ad5..c91ec90 100644
|
||||
index 74e4ad5..935919f 100644
|
||||
--- a/src/nsterm.m
|
||||
+++ b/src/nsterm.m
|
||||
@@ -46,6 +46,7 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
|
||||
@@ -188,7 +191,7 @@ index 74e4ad5..c91ec90 100644
|
||||
#include "systime.h"
|
||||
#include "character.h"
|
||||
#include "xwidget.h"
|
||||
@@ -6856,6 +6857,329 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action)
|
||||
@@ -6856,6 +6857,442 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -453,9 +456,122 @@ index 74e4ad5..c91ec90 100644
|
||||
+ ns_ax_text_selection_granularity_line = 3,
|
||||
+};
|
||||
+
|
||||
+/* Extract announcement string from completion--string property value.
|
||||
+ The property can be a plain Lisp string (simple completion) or
|
||||
+ a list ("candidate" "annotation") for annotated completions.
|
||||
+ Returns nil on failure. */
|
||||
+static NSString *
|
||||
+ns_ax_completion_string_from_prop (Lisp_Object cstr)
|
||||
+{
|
||||
+ if (STRINGP (cstr))
|
||||
+ return [NSString stringWithLispString: cstr];
|
||||
+ if (CONSP (cstr) && STRINGP (XCAR (cstr)))
|
||||
+ return [NSString stringWithLispString: XCAR (cstr)];
|
||||
+ return nil;
|
||||
+}
|
||||
+
|
||||
+/* Return the Emacs buffer Lisp object for window W, or Qnil. */
|
||||
+static Lisp_Object
|
||||
+ns_ax_window_buffer_object (struct window *w)
|
||||
+{
|
||||
+ if (!w)
|
||||
+ return Qnil;
|
||||
+ if (!BUFFERP (w->contents))
|
||||
+ return Qnil;
|
||||
+ return w->contents;
|
||||
+}
|
||||
+
|
||||
+/* Compute visible-end charpos for window W.
|
||||
+ Emacs stores it as BUF_Z - window_end_pos.
|
||||
+ Falls back to BUF_ZV when window_end_valid is false (e.g., when
|
||||
+ called from an AX getter before the next redisplay cycle). */
|
||||
+static ptrdiff_t
|
||||
+ns_ax_window_end_charpos (struct window *w, struct buffer *b)
|
||||
+{
|
||||
+ if (!w->window_end_valid)
|
||||
+ return BUF_ZV (b);
|
||||
+ return BUF_Z (b) - w->window_end_pos;
|
||||
+}
|
||||
+
|
||||
+/* Fetch text property PROP at charpos POS in BUF_OBJ. */
|
||||
+static Lisp_Object
|
||||
+ns_ax_text_prop_at (ptrdiff_t pos, Lisp_Object prop, Lisp_Object buf_obj)
|
||||
+{
|
||||
+ Lisp_Object plist = Ftext_properties_at (make_fixnum (pos), buf_obj);
|
||||
+ /* Third argument to Fplist_get is PREDICATE (Emacs 29+), not a
|
||||
+ default value. Qnil selects the default `eq' comparison. */
|
||||
+ return Fplist_get (plist, prop, Qnil);
|
||||
+}
|
||||
+
|
||||
+/* Next charpos where PROP changes, capped at LIMIT. */
|
||||
+static ptrdiff_t
|
||||
+ns_ax_next_prop_change (ptrdiff_t pos, Lisp_Object prop,
|
||||
+ Lisp_Object buf_obj, ptrdiff_t limit)
|
||||
+{
|
||||
+ Lisp_Object result
|
||||
+ = Fnext_single_property_change (make_fixnum (pos), prop,
|
||||
+ buf_obj, make_fixnum (limit));
|
||||
+ return FIXNUMP (result) ? XFIXNUM (result) : limit;
|
||||
+}
|
||||
+
|
||||
+/* Build label for span [START, END) in BUF_OBJ.
|
||||
+ Priority: completion--string → buffer text → help-echo. */
|
||||
+static NSString *
|
||||
+ns_ax_get_span_label (ptrdiff_t start, ptrdiff_t end,
|
||||
+ Lisp_Object buf_obj)
|
||||
+{
|
||||
+ Lisp_Object cs = ns_ax_text_prop_at (start, Qns_ax_completion__string,
|
||||
+ buf_obj);
|
||||
+ if (STRINGP (cs))
|
||||
+ return [NSString stringWithLispString: cs];
|
||||
+
|
||||
+ if (end > start)
|
||||
+ {
|
||||
+ Lisp_Object substr = Fbuffer_substring_no_properties (
|
||||
+ make_fixnum (start), make_fixnum (end));
|
||||
+ if (STRINGP (substr))
|
||||
+ {
|
||||
+ NSString *s = [NSString stringWithLispString: substr];
|
||||
+ s = [s stringByTrimmingCharactersInSet:
|
||||
+ [NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
+ if (s.length > 0)
|
||||
+ return s;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ Lisp_Object he = ns_ax_text_prop_at (start, Qhelp_echo, buf_obj);
|
||||
+ if (STRINGP (he))
|
||||
+ return [NSString stringWithLispString: he];
|
||||
+
|
||||
+ return @"";
|
||||
+}
|
||||
+
|
||||
+/* Post AX notifications asynchronously to prevent deadlock.
|
||||
+ NSAccessibilityPostNotification may synchronously invoke VoiceOver
|
||||
+ callbacks that dispatch_sync back to the main queue. If we are
|
||||
+ already on the main queue (e.g., inside postAccessibilityUpdates
|
||||
+ called from ns_update_end), that dispatch_sync deadlocks.
|
||||
+ Deferring via dispatch_async lets the current method return first,
|
||||
+ freeing the main queue for VoiceOver's dispatch_sync calls. */
|
||||
+
|
||||
+static inline void
|
||||
+ns_ax_post_notification (id element,
|
||||
+ NSAccessibilityNotificationName name)
|
||||
+{
|
||||
+ dispatch_async (dispatch_get_main_queue (), ^{
|
||||
+ NSAccessibilityPostNotification (element, name);
|
||||
+ });
|
||||
+}
|
||||
+
|
||||
+static inline void
|
||||
+ns_ax_post_notification_with_info (id element,
|
||||
+ NSAccessibilityNotificationName name,
|
||||
+ NSDictionary *info)
|
||||
+{
|
||||
+ dispatch_async (dispatch_get_main_queue (), ^{
|
||||
+ NSAccessibilityPostNotificationWithUserInfo (element, name, info);
|
||||
+ });
|
||||
+}
|
||||
+
|
||||
+@implementation EmacsAccessibilityElement
|
||||
+
|
||||
@@ -518,7 +634,7 @@ index 74e4ad5..c91ec90 100644
|
||||
/* ==========================================================================
|
||||
|
||||
EmacsView implementation
|
||||
@@ -11312,6 +11636,28 @@ syms_of_nsterm (void)
|
||||
@@ -11312,6 +11749,28 @@ syms_of_nsterm (void)
|
||||
DEFSYM (Qns_drag_operation_generic, "ns-drag-operation-generic");
|
||||
DEFSYM (Qns_handle_drag_motion, "ns-handle-drag-motion");
|
||||
|
||||
@@ -547,7 +663,7 @@ index 74e4ad5..c91ec90 100644
|
||||
Fput (Qalt, Qmodifier_value, make_fixnum (alt_modifier));
|
||||
Fput (Qhyper, Qmodifier_value, make_fixnum (hyper_modifier));
|
||||
Fput (Qmeta, Qmodifier_value, make_fixnum (meta_modifier));
|
||||
@@ -11460,6 +11806,15 @@ Note that this does not apply to images.
|
||||
@@ -11460,6 +11919,15 @@ Note that this does not apply to images.
|
||||
This variable is ignored on Mac OS X < 10.7 and GNUstep. */);
|
||||
ns_use_srgb_colorspace = YES;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user