Subject: Re: bug#69525: 30.0.50; MacOS: New warnings on stderr

From: Gerd Möllmann <[email-masked]>
Date: Tue, 30 Jul 2024 08:00:35 +0200

Eli Zaretskii <[email-masked]> writes:

>> From: Gerd Möllmann <[email-masked]>
>> Cc: [email-masked],  Eli Zaretskii <[email-masked]>
>> Date: Sat, 27 Jul 2024 05:56:30 +0200
>> 
>> Alan Third <[email-masked]> writes:
>> 
>> > I would agree that Apple's documentation is abysmal. AFAICT most new
>> > features are exclusively documented in WWDC talks, so if you're not
>> > immersed in the Apple eco-system it can be very hard to keep track of
>> > what's changed. I assume that's some sort of marketing ploy.
>> 
>> Yeah, could be. Although I wonder what advantage they expect from making
>> such stuff effectively a secret :-/.
>
> Companies that develop proprietary software for macOS can probably
> fund courses for their employees, or buy auxiliary documentation that
> is not available for free, or ask Apple questions and get answers,
> something that could be available only for those who have contracts
> with Apple.

Yeah, maybe :-/.

Meanwhile, I think I pulled this off anyway by studying and mimicking
what others did. At least it works for me on macOS 14.5 just like the
old code did, at least for entering accented characters, which is the
only thing I know how to use.

I'll push that to master, if nobody objects.

>From 65d5ace8e85111ecbd5035541ab24fdcfc065c7b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <[email-masked]>
Date: Tue, 30 Jul 2024 07:47:44 +0200
Subject: [PATCH] NS: Let EmacsView implement NSTextInputClient

* src/nsterm.h (@interface EmacsView): Implement NSTextInputClient protocol.
* src/nsterm.m: Implement required NSTextInputClient methods, forwarding
to existing NSTextInput methods.
---
 src/nsterm.h |  4 ++--
 src/nsterm.m | 37 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/src/nsterm.h b/src/nsterm.h
index 5d4810cba4a..f3dcb07a0f1 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -463,9 +463,9 @@ #define NSTRACE_UNSILENCE()
 @class EmacsLayer;
 
 #ifdef NS_IMPL_COCOA
-@interface EmacsView : NSView <NSTextInput, NSWindowDelegate>
+@interface EmacsView : NSView <NSTextInput, NSTextInputClient, NSWindowDelegate>
 #else
-@interface EmacsView : NSView <NSTextInput>
+@interface EmacsView : NSView <NSTextInput, NSTextInputClient>
 #endif
 {
 #ifdef NS_IMPL_COCOA
diff --git a/src/nsterm.m b/src/nsterm.m
index cd6ffabddde..c659ef40c73 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -7049,9 +7049,44 @@ In that case we use UCKeyTranslate (ns_get_shifted_character)
   [nsEvArray removeObject: theEvent];
 }
 
+/***********************************************************************
+			   NSTextInputClient
+ ***********************************************************************/
 
-/* <NSTextInput> implementation (called through [super interpretKeyEvents:]).  */
+- (void) insertText: (id) string
+   replacementRange: (NSRange) replacementRange
+{
+  if ([string isKindOfClass:[NSAttributedString class]])
+    string = [string string];
+  [self unmarkText];
+  [self insertText:string];
+}
+
+- (void) setMarkedText: (id) string
+	 selectedRange: (NSRange) selectedRange
+      replacementRange: (NSRange) replacementRange
+{
+  [self setMarkedText: string selectedRange: selectedRange];
+}
+
+- (nullable NSAttributedString *)
+  attributedSubstringForProposedRange: (NSRange) range
+			  actualRange: (nullable NSRangePointer) actualRange
+{
+  return nil;
+}
 
+- (NSRect) firstRectForCharacterRange: (NSRange) range
+			  actualRange: (nullable NSRangePointer) actualRange
+{
+  return NSZeroRect;
+}
+
+/***********************************************************************
+			      NSTextInput
+ ***********************************************************************/
+
+/* <NSTextInput> implementation (called through [super interpretKeyEvents:]).  */
 
 /* <NSTextInput>: called when done composing;
    NOTE: also called when we delete over working text, followed
-- 
2.45.2