From 4998cb990f91721b00ad4c379c1f3f6530ecf060 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 17 Mar 2026 05:49:05 +0100 Subject: [PATCH] AppKit: Trace sendEvent: calls 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 --- winit-appkit/src/app.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/winit-appkit/src/app.rs b/winit-appkit/src/app.rs index 25cd38392..a196a3242 100644 --- a/winit-appkit/src/app.rs +++ b/winit-appkit/src/app.rs @@ -9,6 +9,7 @@ use objc2::runtime::{Imp, Sel}; use objc2::sel; use objc2_app_kit::{NSApplication, NSEvent, NSEventModifierFlags, NSEventType}; use objc2_foundation::MainThreadMarker; +use tracing::trace_span; use winit_core::event::{DeviceEvent, ElementState}; use super::app_state::AppState; @@ -21,6 +22,10 @@ static ORIGINAL: MainThreadBound>> = { }; extern "C-unwind" fn send_event(app: &NSApplication, sel: Sel, event: &NSEvent) { + // This can be a bit noisy, since `event` is fairly large. Note that you can use + // `RUST_LOG='trace,winit_appkit::app=warn'` if you're debugging and want TRACE-level logs but + // not this. + let _entered = trace_span!("sendEvent:", ?event).entered(); let mtm = MainThreadMarker::from(app); // Normally, holding Cmd + any key never sends us a `keyUp` event for that key.