-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global NSEvent listener and some mouse methods #94
Conversation
src/events.rs
Outdated
LeftMouseDown = 1, | ||
LeftMouseUp = 2, | ||
RightMouseDown = 3, | ||
RightMouseUp = 4, | ||
MouseMoved = 5, | ||
LeftMouseDragged = 6, | ||
RightMouseDragged = 7, | ||
MouseEntered = 8, | ||
MouseExited = 9, | ||
KeyDown = 10, | ||
KeyUp = 11, | ||
FlagsChanged = 12, | ||
AppKitDefined = 13, | ||
SystemDefined = 14, | ||
ApplicationDefined = 15, | ||
Periodic = 16, | ||
CursorUpdate = 17, | ||
|
||
ScrollWheel = 22, | ||
TabletPoint = 23, | ||
TabletProximity = 24, | ||
OtherMouseDown = 25, | ||
OtherMouseUp = 26, | ||
OtherMouseDragged = 27, | ||
|
||
Gesture = 29, | ||
Magnify = 30, | ||
Swipe = 31, | ||
Rotate = 18, | ||
BeginGesture = 19, | ||
EndGesture = 20, | ||
|
||
SmartMagnify = 32, | ||
QuickLook = 33, | ||
Pressure = 34, | ||
DirectTouch = 37, | ||
|
||
ChangeMode = 38, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be really nice if these shift values didn't have to be duplicated, though I don't think there's a nice way to do it. Apple assumedly has a set of k*
constants that feed both enums.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, one thing I experimented with in the color
module was this:
cacao/src/color/appkit_dynamic_color.rs
Lines 27 to 33 in 9f8d946
#[cfg(target_os = "macos")] | |
extern "C" { | |
static NSAppearanceNameAqua: id; | |
static NSAppearanceNameAccessibilityHighContrastAqua: id; | |
static NSAppearanceNameDarkAqua: id; | |
static NSAppearanceNameAccessibilityHighContrastDarkAqua: id; | |
} |
Maybe there's a similar approach here? e.g somehow just pulling in the already linked NSEventMaskLeftMouseDown
variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that would work, as enums need const
s (basically #define
) to set their values, so we would need to pull out the constant from the header. It works that way in your example because those strings aren't true constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... you're right about that - was a late night last night so disregard my rambling thoughts. I thought I had encountered and found a workaround for this some years ago but guess I'm misremembering.
This is probably good in its current result to merge then, unless you've got anything else you can think of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine by me for now.
This PR is great and I'm totally down to merge it once we're finished addressing the comments and all (non-iOS) checks pass. I threw together the initial NSEvent stuff in a rush for demo purposes (the calculator IIRC) and then just never have time to circle back. It's very useful tho so happy to see it! Thanks! |
Merged - thanks! |
I found that global NSEvent monitoring was not currently implemented, and on further investigation, local monitoring only used a single possible mask value.
This PR introduces a mechanism for handling bitmasks from enums (though I understand if you'd like me to remove it), unblocking the proper implementation of those methods. It also adds the missing event type enum values and a few NSEvent getters (though there are many more still to do).