-
Notifications
You must be signed in to change notification settings - Fork 686
eventtap: setProperty choose CGEventField setter based on value type #3859
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -793,6 +793,18 @@ static int eventtap_event_getButtonState(lua_State* L) { | |
| return 1; | ||
| } | ||
|
|
||
| // Undocumented event fields | ||
| static const CGEventField kCGEventGestureHIDType = (CGEventField)110; | ||
| static const CGEventField kCGEventGesturePhase = (CGEventField)132; | ||
| static const CGEventField kCGEventGestureScrollY = (CGEventField)119; | ||
| static const CGEventField kCGEventGestureSwipeMotion = (CGEventField)123; | ||
| static const CGEventField kCGEventGestureSwipeProgress = (CGEventField)124; | ||
| static const CGEventField kCGEventGestureSwipeVelocityX = (CGEventField)129; | ||
| static const CGEventField kCGEventGestureSwipeVelocityY = (CGEventField)130; | ||
| static const CGEventField kCGEventGestureZoomDeltaX = (CGEventField)139; | ||
| static const CGEventField kCGEventScrollGestureFlagBits = (CGEventField)135; | ||
| static const CGEventField kCGSEventTypeField = (CGEventField)55; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this it's the same as setType |
||
|
|
||
| /// hs.eventtap.event:setProperty(prop, value) | ||
| /// Method | ||
| /// Sets a property of the event | ||
|
|
@@ -809,15 +821,20 @@ static int eventtap_event_getButtonState(lua_State* L) { | |
| static int eventtap_event_setProperty(lua_State* L) { | ||
| CGEventRef event = *(CGEventRef*)luaL_checkudata(L, 1, EVENT_USERDATA_TAG); | ||
| CGEventField field = (CGEventField)(luaL_checkinteger(L, 2)); | ||
| if ((field == kCGMouseEventPressure) || // These fields use a double (floating point number) | ||
| if ((field == kCGEventGestureScrollY) || // These fields use a double (floating point number) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really a very small list of properties - with just these added, and still no way to explicitly specify that you want to set (or get) the property as a double, eventually someone will have to come back to this list and add more. Let's not throw out the code to dynamically detect whether you want to set the value as an integer or double. In fact that code is always correct, since CG seems to internally cast values from int to double and vice versa when you get or set them with the wrong function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My bad - turns out when you get or set a float property using ints, it just gets or sets 0. I'm now convinced it's really best to add special getPropertyFloat and setPropertyFloat functions. (Using floats to get or set an int property works fine, though.) |
||
| (field == kCGEventGestureSwipeProgress) || | ||
| (field == kCGEventGestureSwipeVelocityX) || | ||
| (field == kCGEventGestureSwipeVelocityY) || | ||
| (field == kCGEventGestureZoomDeltaX) || | ||
| (field == kCGMouseEventPressure) || | ||
| (field == kCGScrollWheelEventFixedPtDeltaAxis1) || | ||
| (field == kCGScrollWheelEventFixedPtDeltaAxis2) || | ||
| (field == kCGScrollWheelEventFixedPtDeltaAxis3) || | ||
| (field == kCGTabletEventPointPressure) || | ||
| (field == kCGTabletEventTiltX) || | ||
| (field == kCGTabletEventTiltY) || | ||
| (field == kCGTabletEventRotation) || | ||
| (field == kCGTabletEventTangentialPressure)) { | ||
| (field == kCGTabletEventTangentialPressure) || | ||
| (field == kCGTabletEventTiltX) || | ||
| (field == kCGTabletEventTiltY)) { | ||
| double value = luaL_checknumber(L, 3) ; | ||
| CGEventSetDoubleValueField(event, field, value); | ||
| } else { | ||
|
|
@@ -1409,13 +1426,23 @@ static void pushtypestable(lua_State* L) { | |
| /// * The constants defined in this table are as follows: | ||
| /// (I) in the description indicates that this property is returned or set as an integer | ||
| /// (N) in the description indicates that this property is returned or set as a number (floating point) | ||
| /// * eventGestureHIDType -- (I) The HID gesture type | ||
| /// * eventGesturePhase -- (I) Gesture phase bitfield | ||
| /// * eventGestureScrollY -- (N) Scroll gesture Y coordinate | ||
| /// * eventGestureSwipeMotion -- (I) Swipe gesture motion direction | ||
| /// * eventGestureSwipeProgress -- (N) Swipe gesture distance | ||
| /// * eventGestureSwipeVelocityX -- (N) Swipe gesture X velocity | ||
| /// * eventGestureSwipeVelocityY -- (N) Swipe gesture Y velocity | ||
| /// * eventGestureZoomDeltaX -- (N) Zoom gesture delta X | ||
| /// * eventScrollGestureFlagBits -- (I) Gesture flags | ||
| /// * eventSourceGroupID -- (I) The event source Unix effective GID. | ||
| /// * eventSourceStateID -- (I) The event source state ID used to create this event. | ||
| /// * eventSourceUnixProcessID -- (I) The event source Unix process ID. | ||
| /// * eventSourceUserData -- (I) Event source user-supplied data, up to 64 bits. | ||
| /// * eventSourceUserID -- (I) The event source Unix effective UID. | ||
| /// * eventTargetProcessSerialNumber -- (I) The event target process serial number. The value is a 64-bit long word. | ||
| /// * eventTargetUnixProcessID -- (I) The event target Unix process ID. | ||
| /// * eventTypeField -- (I) The event type | ||
| /// * eventUnacceleratedPointerMovementX -- Undocumented, assumed Integer | ||
| /// * eventUnacceleratedPointerMovementY -- Undocumented, assumed Integer | ||
| /// * keyboardEventAutorepeat -- (I) Non-zero when this is an autorepeat of a key-down, and zero otherwise. | ||
|
|
@@ -1532,6 +1559,17 @@ static void pushpropertiestable(lua_State* L) { | |
| lua_pushinteger(L, kCGMouseEventWindowUnderMousePointerThatCanHandleThisEvent) ; lua_setfield(L, -2, "mouseEventWindowUnderMousePointerThatCanHandleThisEvent") ; | ||
| lua_pushinteger(L, kCGEventUnacceleratedPointerMovementX) ; lua_setfield(L, -2, "eventUnacceleratedPointerMovementX") ; | ||
| lua_pushinteger(L, kCGEventUnacceleratedPointerMovementY) ; lua_setfield(L, -2, "eventUnacceleratedPointerMovementY") ; | ||
|
|
||
| lua_pushinteger(L, kCGEventGestureHIDType) ; lua_setfield(L, -2, "eventGestureHIDType") ; | ||
| lua_pushinteger(L, kCGEventGesturePhase) ; lua_setfield(L, -2, "eventGesturePhase") ; | ||
| lua_pushinteger(L, kCGEventGestureScrollY) ; lua_setfield(L, -2, "eventGestureScrollY") ; | ||
| lua_pushinteger(L, kCGEventGestureSwipeMotion) ; lua_setfield(L, -2, "eventGestureSwipeMotion") ; | ||
| lua_pushinteger(L, kCGEventGestureSwipeProgress) ; lua_setfield(L, -2, "eventGestureSwipeProgress") ; | ||
| lua_pushinteger(L, kCGEventGestureSwipeVelocityX) ; lua_setfield(L, -2, "eventGestureSwipeVelocityX") ; | ||
| lua_pushinteger(L, kCGEventGestureSwipeVelocityY) ; lua_setfield(L, -2, "eventGestureSwipeVelocityY") ; | ||
| lua_pushinteger(L, kCGEventGestureZoomDeltaX) ; lua_setfield(L, -2, "eventGestureZoomDeltaX") ; | ||
| lua_pushinteger(L, kCGEventScrollGestureFlagBits) ; lua_setfield(L, -2, "eventScrollGestureFlagBits") ; | ||
| lua_pushinteger(L, kCGSEventTypeField) ; lua_setfield(L, -2, "eventTypeField") ; | ||
| } | ||
|
|
||
| /// hs.eventtap.event.rawFlagMasks[] | ||
|
|
||
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.
We should grab the full list as it was published in WebKit open source: https://github.com/WebKit/WebKit/blob/4f1b310945dff0f6827a5e4329c2883698fbc47e/Tools/TestRunnerShared/spi/CoreGraphicsTestSPI.h#L76