Skip to content

Commit 1785b7b

Browse files
committed
appkit: let valid_attributes_for_marked_text report winit metadata.
- This allows IME devs to identify whether `winit` is used in the IMKTextInput client. If identified, IME devs can introduce compatibility behaviors against such IMKTextInput client. // InputMethodKit casts `NSTextInputClient` to `IMKTextInput`.
1 parent 269157b commit 1785b7b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

winit-appkit/src/view.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ define_class!(
336336
#[unsafe(method_id(validAttributesForMarkedText))]
337337
fn valid_attributes_for_marked_text(&self) -> Retained<NSArray<NSAttributedStringKey>> {
338338
trace_scope!("validAttributesForMarkedText");
339-
NSArray::new()
339+
// Advertise the winit version so IME clients can identify us.
340+
let client_identifier =
341+
NSString::from_str(concat!("_rust_winit_", env!("CARGO_PKG_VERSION")));
342+
NSArray::from_slice(&[client_identifier.as_ref()])
340343
}
341344

342345
#[unsafe(method_id(attributedSubstringForProposedRange:actualRange:))]

winit/src/changelog/unreleased.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@ changelog entry.
178178
- Rename `VideoModeHandle` to `VideoMode`, now it only stores plain data.
179179
- Make `Fullscreen::Exclusive` contain `(MonitorHandle, VideoMode)`.
180180
- Reworked the file drag-and-drop API.
181+
- On macOS, `NSTextInputClient::validAttributesForMarkedText` now automatically attaches a value
182+
called `_rust_winit_\(CARGO_PKG_VERSION)`.
183+
184+
This allows IME devs to identify whether `winit` is used in the IMKTextInput client.
185+
If identified, IME devs can introduce compatibility behaviors against such IMKTextInput client.
186+
InputMethodKit casts `NSTextInputClient` to `IMKTextInput`, but `validAttributesForMarkedText`
187+
is shared between these two protocols and can all be parsed as `Array<NSString>`.
188+
189+
`validAttributesForMarkedText` specifically returns an `NSArray<NSAttributedStringKey>` which
190+
are plain NSString*; Apple treats custom keys as legal, so slipping harmless metadata like
191+
`_rust_winit_\(CARGO_PKG_VERSION)` in there is the one slot where such data is piggybackable.
192+
181193
- On macOS, the default menu uses the bundle name or falls back to the process name as before.
182194

183195
The `WindowEvent::DroppedFile`, `WindowEvent::HoveredFile` and `WindowEvent::HoveredFileCancelled`

0 commit comments

Comments
 (0)