core-foundation-rs
core-foundation-rs copied to clipboard
`[NSEvent type]` produces value `21` with no associated `NSEventType` variant causing SEGFAULT.
The NSEvent::eventType method produces the value 21 when spotlight is opened or one of the items on the system menu tray are opened (e.g. battery status, wifi). The value has no associated variant within the NSEventType enum and thus segfaults when a user attempts to match against a NSEventType of value 21. This was causing a segfault in winit. I've added a commit to winit that side-steps this bug, however this should be properly fixed upstream in this crate. I've been unable to find any documentation on NSEventTypes of value 21 just yet.
I wonder if we should make eventType() return an Option to avoid any similar cases.
@mitchmindtree In case you never found what the missing event types, they should be the following
- 0 NullEvent
- 21 ProcessNotification
- 32 SmartMagnify
- 33 QuickLook
- 35 Reserved
- 36 Reserved
- 37 Translate
Since they're not documented I assume these are private events and should not be relied on.
@iszak nice! Do you have any references for these events? Or did you just find them by experimenting?
@mitchmindtree I found them by disassembling AppKit, my assembly is not great so there is a chance these are wrong. But in the assembly the events were in order of their corresponding numbers.
@iszak thank you for info about '21 ProcessNotification'. Do you know anything about [NSEvent subtype] codes? In my cases (when clicked tray icons) I accept events with .type='ProcessNotification' .subtype='-3835' or ..='-32768' or ..='4096'
@ochilov I couldn't find anything in the AppKit framework, it's possible other frameworks are sending this event but without a source I can't investigate further. Does the sub type consistently send these values or does it depend on other properties? If it's consistent, it would suggest a fixed sub type constant as opposed to meta data about the event, see below.
Mouse events can also contain tablet data (as event subtypes)
Source: https://developer.apple.com/documentation/appkit/nsevent
It's worth noting the 2nd value (-32768) is the minimum value of an event sub type, that is an unsigned 16-bit integer. This suggests it could be a constant value.
Finally, I think we should discontinue discussion here as it's been merged into core-foundation.