Most events in AppKit go through `sendEvent:`, and they contain a lot of
information, so it's nice to surface this when debugging.
We could override `sendEvent:` in UIKit and track this in there too, but
that's much less important, since there the relevant events are fairly
narrowly scoped, see the link below, other events go through CFRunLoop.
https://developer.apple.com/documentation/uikit/uievent/eventtype
Add two run loop observers that:
- Create a TRACE-level span when the run loop enters a new state.
- Drops the span when the run loop exits that state.
These spans attach information to events, such that e.g. resizing a view
produces messages like:
```
TRACE inside runloop{mode=NSEventTrackingRunLoopMode}:timers:
winit_appkit::util: Triggered `drawRect:` target="winit_appkit::view"
TRACE inside runloop{mode=NSEventTrackingRunLoopMode}:timers:
winit_appkit::util: Completed `drawRect:` target="winit_appkit::view"
```
macOS native Pinyin IME can send a selected_range that exceeds the
marked text string length (e.g. index 8 for a 6-character string).
This caused an NSRangeException in substringToIndex:, crashing the
application with SIGABRT.
Clamp both location and end to the string's UTF-16 length before
calling substringToIndex.
Added a common interface that:
- Uses closures instead of static functions. This should allow easier
refactoring in the future.
- Returns a handle which is invalidated on `Drop`. This should avoid
situations where the event loop has exited, but an observer is still
called because the user spawned the application later on.
- Is properly main-thread safe.
This interface is placed in winit-common, to allow using it in both
winit-appkit and winit-uikit.
Unify the values of `MouseButton` and thus remove `Other` variant in
limit possible buttons to 32, which was picked based on platform
capabilities, where 32 is the highest.
For the reference, SDL has identical limit.
On macOS 26+ the window drop was leading to unwrap, since
events were coming after the window was already destroyed,
while it sounds rather strange, guard against such things just
in case.
Fixes#4333.
Allow updating IME state atomically to make it easier for platforms
where it's atomic by its nature, like Wayland. The old API is marked
as deprecated and is routed to the new atomic API.
Co-authored-by: dcz <gilapfco.dcz@porcupinefactory.org>