eclipse.platform.swt
eclipse.platform.swt copied to clipboard
[macOS] Warning about "SWTCanvasView doesn't conform to NSTextInputClient protocol"
- This is on macOS 15.7.1 and 26.0 and 26.1. Possibly on other versions.
- Any recent version of Eclipse
This is a follow on from #2621 where it was noted from @danishmau that a warning is written to Mac's Console app.
- On Mac launch the Console app, start message streaming and filter on text "SWTCanvasView"
- Launch Eclipse and open some code
The following console warning is emitted:
-[TUINSCursorUIController activate:]: SWTCanvasView doesn't conform to NSTextInputClient protocol.
At the moment this doesn't seem to cause any problems but I've opened this issue as a heads up in case of future problems.
Refer to #2621 for more investigations and analysis.
Area of interest in the Display class:
https://github.com/eclipse-platform/eclipse.platform.swt/blob/2d43ce9373c690cba59c876e8df41f9ee8b5be46/bundles/org.eclipse.swt/Eclipse%20SWT/cocoa/org/eclipse/swt/widgets/Display.java#L2798-L2814
See https://developer.apple.com/documentation/appkit/nstextinput
Important NSTextInput protocol is slated for deprecation. Please use the NSTextInputClient protocol instead.
Replacing
OS.class_addProtocol(cls, OS.protocol_NSTextInput);
with
OS.class_addProtocol(cls, OS.protocol_NSTextInputClient);
eliminates the warning but when text is selected in a StyledText control this error occurs in the Console app
-[SWTCanvasView insertText:replacementRange:]: unrecognized selector sent to instance 0x82e88c280
See these comments for why this might occur and what might need to change:
https://github.com/eclipse-platform/eclipse.platform.swt/issues/2621#issuecomment-3448448112 https://github.com/eclipse-platform/eclipse.platform.swt/issues/2621#issuecomment-3448464240 https://github.com/eclipse-platform/eclipse.platform.swt/issues/2621#issuecomment-3451856286
The following changes work with no warnings written to the log:
OS.class_addProtocol(cls, OS.protocol_NSTextInputClient);
OS.class_addMethod(cls, OS.sel_hasMarkedText, proc2, "@:");
OS.class_addMethod(cls, OS.sel_markedRange, markedRangeProc, "@:");
OS.class_addMethod(cls, OS.sel_selectedRange, selectedRangeProc, "@:");
OS.class_addMethod(cls, OS.sel_setMarkedText_selectedRange_, setMarkedText_selectedRangeProc, "@:@{NSRange}");
OS.class_addMethod(cls, OS.sel_unmarkText, proc2, "@:");
//OS.class_addMethod(cls, OS.sel_validAttributesForMarkedText, proc2, "@:");
OS.class_addMethod(cls, OS.sel_attributedSubstringFromRange_, attributedSubstringFromRangeProc, "@:{NSRange}");
OS.class_addMethod(cls, OS.sel_insertText_, proc3, "@:@");
OS.class_addMethod(cls, OS.sel_characterIndexForPoint_, characterIndexForPointProc, "@:{NSPoint}");
OS.class_addMethod(cls, OS.sel_firstRectForCharacterRange_, firstRectForCharacterRangeProc, "@:{NSRange}");
OS.class_addMethod(cls, OS.sel_doCommandBySelector_, proc3, "@::");
Replace
OS.class_addProtocol(cls, OS.protocol_NSTextInput);
with
OS.class_addProtocol(cls, OS.protocol_NSTextInputClient);
And comment out this line:
OS.class_addMethod(cls, OS.sel_validAttributesForMarkedText, proc2, "@:");
So it's the above line that leads to the message -[SWTCanvasView insertText:replacementRange:]: unrecognized selector sent to instance 0x82e88c280
I don't know what to do to fix OS.sel_validAttributesForMarkedText. @DenisUngemach do you have an idea?
The callbacks are handled in org.eclipse.swt.widgets.Display.windowProc(...) and then typically delegate to implementations in Widget. There, they are overridden in Control and Canvas and also IME.
The new methods of NSTextInputClient are different and do more than once thing at a time, so updating to this is not trivial as the logic in IME needs to be adapted.
@Phillipus There are some things to do, to use NSTextInputClient.
1.) Install SWT Tools:
2.) Open the view SWT Tools for the mac generation. There remove NSTextInput from the list and setup NSTextInputClient with the same parameters to make it fit. Then if you press save, the new methods, including the replacement for OS.sel_validAttributesForMarkedText will be generated.
3.) Build the native library on mac.
4.) Rework the java class OS Then the class OS must be reworked, because there are too much modifications.
5.) Use the new modifications in Display.
And here then comes the point of @sratz It might be possible that the new API might be fine, but it is also possible that bigger modification in the SWT code is necessary.
I don't know the NSTextInput feature, so i can't tell.
@DenisUngemach Thanks for the info. I think this kind of change is beyond my capabilities and perhaps prone to regressions, so I'll not continue with it. But this issue is a useful heads up if there are problems on Mac in the future.
I think we should plan to tackle (remove) the usage of these kind of deprecated stuff proactively. Getting forced to tackle them on short notice, because we find out that something to removed by Apple is some beta version, is the worst situation we could get in.
Maybe we can somehow prioritise this and try to work on the "oldest" deprecation-warnings.