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

[feat] Expose methods to get cursor_position #9250

Closed
Hacksore opened this issue Mar 22, 2024 · 1 comment · Fixed by #9297
Closed

[feat] Expose methods to get cursor_position #9250

Hacksore opened this issue Mar 22, 2024 · 1 comment · Fixed by #9297

Comments

@Hacksore
Copy link
Contributor

Describe the problem

I have a use case where I'd like to be able to detect if the mouse intersects with a tauri window.

The reason is that I use set_ignore_cursor_events(true) to create an overlay displaying something useful to a user.

However, I'd like to be able to allow the user to move their mouse over the window and control the opacity so they can see what behind the window.

Here is an MVP repo that shows you can use javascript to do this but only if the window is in focus.

https://github.com/Hacksore/mouse-intersection-when-ignore-mouse-events

Describe the solution you'd like

A way in rust to listen globally for the mouse intersecting events of windows.

  • intersecting (called once)
  • no longer intersecting (called once)

These events would let you run some "callback" rust code (unsure if that's rusty) but for my use case I'd want to toggle some body class on the app.

tl;dr set_ignore_cursor_events(true), you mouse over a tauri window you can run rust code on enter/exit.

Alternatives considered

No response

Additional context

As mentioned initially you can do this in JS but it requires the window to be focused.

Demo:

2024-03-22_09-58-31.mp4
@amrbashir
Copy link
Member

I think this could be solved by polling the current cursor position and do the intersection calculation on your end.

@amrbashir amrbashir changed the title [feat] Mouse intersection events in rust [feat] Expose method to get cursor_position Mar 28, 2024
@amrbashir amrbashir changed the title [feat] Expose method to get cursor_position [feat] Expose methods to get cursor_position Mar 28, 2024
amrbashir added a commit that referenced this issue Mar 29, 2024
amrbashir added a commit that referenced this issue Apr 29, 2024
* feat: add `cursor_position` getter

closes #9250

* js api

* Update mod.rs

* fix build on iOS and android

* use existing wrapper

* fmt

* adjust wording

* update docs

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants