Giter Club home page Giter Club logo

Comments (3)

bwpge avatar bwpge commented on September 1, 2024 1

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 a CGDirectDisplayID (e.g., the list of results from the active_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 from CGDisplay::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.

AltF02 avatar AltF02 commented on September 1, 2024

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.

on3iro avatar on3iro commented on September 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.