Skip to content
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

Merged
merged 4 commits into from
Jul 14, 2023

Conversation

agg23
Copy link
Contributor

@agg23 agg23 commented Jul 13, 2023

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).

src/appkit/event/mod.rs Outdated Show resolved Hide resolved
src/events.rs Outdated
Comment on lines 54 to 91
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,
Copy link
Contributor Author

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.

Copy link
Owner

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:

#[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.

Copy link
Contributor Author

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 consts (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.

Copy link
Owner

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?

Copy link
Contributor Author

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.

@ryanmcgrath
Copy link
Owner

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!

@ryanmcgrath ryanmcgrath merged commit 01507f7 into ryanmcgrath:trunk Jul 14, 2023
5 checks passed
@ryanmcgrath
Copy link
Owner

Merged - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants