Comments (3)
Chiming in for the macOS side. Just a note, with #21 this would change the behavior described above -- coordinates will be treated as global (not relative to the main display) if the PR is accepted.
The core_graphics
crate has a lot of 1-to-1 analogs for Core Graphics functions, but others are behind "Rust" specific implementations. For example CGEventCreateMouseEvent
is behind CGEvent::new_mouse_event
.
To specifically answer your question, I think you would be looking for CGGetDisplaysWithPoint
, however I don't see that when searching the core_graphics
docs.
Doing some quick digging, I think you mainly want to work with core_graphics::CGDisplay
. Do take this with a pinch of salt, I am not a CG expert and the crate documentation is a bit sparse:
- Get all active displays:
CGDisplay::active_displays
- Create a new
CGDisplay
from aCGDirectDisplayID
(e.g., the list of results from theactive_displays
associated function):CGDisplay::new
- Get the bounds of a
CGDisplay
in global coordinates:CGDisplay::bounds
(you can use this to sample points and move to them; again, these are global coordinates, so if the above PR is accepted you can directly use them without converting relative to the main display) - Check what monitor the mouse is on: use this library's
Mouse::get_position
and check which bounds returned fromCGDisplay::bounds
contains that point
It also has some lower level stuff but I'd recommend staying away from them if you're not comfortable with their patterns (e.g., the whole "call this function with some null/0 values, fill paramter with a length, allocate space for length, call again to fill with results" -- this is very common in low level APIs like Win32, Vulkan, etc.).
Edit: fix wording
from mouse-rs.
I'm not sure how this would work in windows see: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setcursorpos
for x11, we currently https://github.com/AltF02/mouse-rs/blob/main/src/sys/linux.rs#L59 default to screen 0? I'm not sure if win32.h
has something similar?
same thing for macos where we default to the main display https://github.com/AltF02/mouse-rs/blob/main/src/sys/macos.rs#L69
I am unable to test for macos and fully rely on external contributors for that :(
For x11, it could be a new function, or a new parameter. What do u think?
from mouse-rs.
Thanks a lot for your response :)
Actually the system I am currently most concerned about (as its needed for my use case) would be OSX. I understand that it would be most preferable to have this on all target systems, though.
Is it possible to determine displays on OSX or do we only have access to the main display?
If we get access to all possible displays we could implement this for OSX and x11 and make a note, that the feature is not available on windows.
Could that work?
Unfortunately I am not at all familiar with these system specific things (though the core-graphics
crate for OSX you are already using looks quite promising)
from mouse-rs.
Related Issues (12)
- Wayland support HOT 3
- [feature request] lock mouse in a rectangle
- Windows scaling also scales mouse-rs locations HOT 1
- MIT license? HOT 13
- How can I get current location of cursor? HOT 2
- Animation? HOT 3
- Mouse move does not generate events on macOS HOT 3
- cannot move the mouse in osu game HOT 3
- Implement move_by HOT 2
- Getting the mouse position relative to the window HOT 1
- move_to and get_position are using different types
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mouse-rs.