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

[WIP] MacOS inputcapture #131

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

meck
Copy link
Contributor

@meck meck commented May 12, 2024

I had a stab at writing a macos input capture module as i was tired not being able to cross the pointer back and forth between mac and linux, and it seemed a good rust exercise. There as some things left mainly modifier handling and updating the bounds on a monitor config change. But i wanted to put it up as a draft for now if there is any other pointers or if i missed something in the architecture.

@feschber
Copy link
Owner

Very nice, thank you! Unfortunately my MacOS VM nuked itself so I will have to set that up again before I can test this... Sorry about thay

@feschber feschber marked this pull request as ready for review May 13, 2024 21:57
@feschber feschber mentioned this pull request May 14, 2024
4 tasks
@rohitsangwan01
Copy link

Works for me

src/capture/macos.rs Outdated Show resolved Hide resolved

// After the cursor is warped the next event will carry the delta from the warp
// so only half the delta is needed to move the cursor
let delta_y = event.get_double_value_field(EventField::MOUSE_EVENT_DELTA_Y) / 2.0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about the / 2.0 part?

The documentation for CGWarpMouseCursorPosition states: "You can use this function to “warp” or alter the cursor position without generating or posting an event. For example, this function is often used to move the cursor position back to the center of the screen by games that do not want the cursor pinned by display edges."

So no event should be generated, if I understand that correctly.

Apparently it works like this though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, no synthetic event is produced, however the movement delta is tacked onto the next event. This explains the issue https://stackoverflow.com/questions/40904830/constrain-mouse-movement-to-region-in-os-x-without-jitter/40922095#40922095

src/capture/macos.rs Outdated Show resolved Hide resolved
src/capture/macos.rs Outdated Show resolved Hide resolved
src/capture/macos.rs Outdated Show resolved Hide resolved
src/capture/macos.rs Outdated Show resolved Hide resolved
src/capture/macos.rs Outdated Show resolved Hide resolved
@feschber
Copy link
Owner

And just FYI: I'm still debating on whether or not Modifier events should even be handled "server side" at all.
The only backend that currently reports them is the wayland / layershell backend and similarly the only emulation backend that needs modifier events is the wlroots one.
Still good to have them but they also dont work in Windows and Libei Input Captures (even though libei should report them but apparently does not do so)

@meck
Copy link
Contributor Author

meck commented May 16, 2024

I see, im using Hyprland so wayland/wlroots is what im using. I guess removing the events would mean tracking modifier state in wlroots emulation.

@feschber
Copy link
Owner

I see, im using Hyprland so wayland/wlroots is what im using. I guess removing the events would mean tracking modifier state in wlroots emulation.

Yeah exactly. Definitely keep it in though! Better to have it working in MacOS now.

@meck
Copy link
Contributor Author

meck commented Jun 4, 2024

I hope to get back to this soon, haven't had the time, the only thing i wanted to add was detection of monitor layout changes, there is a API in CGDisplayRegisterReconfigurationCallback however it needs a CFRunLoop to run on the main thread for the callback to actually be called, That would mean a lot of architectural changes to rest of the project so I'm looking for alternatives.

@feschber
Copy link
Owner

feschber commented Jun 4, 2024

no worries! I just got round to testing this. One thing I'm noticing is that the mouse is behaving weird when dragging:
When I press the mouse down and drag it to the left and then release the mouse button, while the mouse is still moving, the mouse jumps back to its original position.

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.

None yet

3 participants