-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[feat] expose tao::Window::set_cursor_position
#3890
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
Comments
tao::Window::et_cursor_position
tao::Window::et_cursor_position
tao::Window::set_cursor_position
I have tried using the exposed API function.
my tauri command looks like this: #[tauri::command]
fn set_pointer_position(window: tauri::Window, x: i32, y: i32) {
let result = window.set_cursor_position(tauri::Position::Physical(tauri::PhysicalPosition{x, y}));
if result.is_err() {
panic!("setting cursor failed");
}
println!("cursor set {} {}", x, y);
} and the console output is as expected. // relevant cargo.toml data
[build-dependencies]
tauri-build = { git = "https://github.com/tauri-apps/tauri", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { git = "https://github.com/tauri-apps/tauri", features = ["api-all"] }
winapi = { version = "0.3.9" }
mouse-rs = { version = "0.4" }
[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = [ "custom-protocol" ]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ] what is the problem here? |
It is not implemented yet on Linux, see https://github.com/tauri-apps/tao/blob/edf6e766704a3f10d62673e6be6f168a1daa0b15/src/platform_impl/linux/window.rs#L565 I documented this in the function but you'd need to build the docs manually to see it. |
@CaptainTux I plan to implement this for linux soon. In a week maybe. |
I guess I lied 😁, here it is tauri-apps/tao#373 if you want to test it and give feedback. |
|
You can try it now by adding this to your Cargo.toml: [patch.crates-io]
tao = { git = "https://github.com/tauri-apps/tao" } Don't forget to run |
Cursor grab means to restrict the cursor movement from escaping the window coordinates, not just the icon change. I wanted to implement it too in the PR but that one might need some trial and error to match the behavior of other platforms or close to it so I delayed it for now. Relevant gtk apis: |
works! #[tauri::command]
fn set_cursor_position(window: tauri::Window, x: i32, y: i32) {
let inner_pos = window.inner_position().unwrap();
let inner_size = window.inner_size().unwrap();
let outer_size = window.outer_size().unwrap();
if window.set_cursor_position
(Logical(LogicalPosition{x: (x + inner_pos.x) as f64,
y: (y + inner_pos.y + (outer_size.height as i32 - inner_size.height as i32)) as f64
})).is_err() {
panic!("setting cursor failed");
}
}
|
It's not in window coordinates, it's in overall monitor coordinates (I think) so you're not limited to the window. |
My bad for the compilation error, can't belive I didn't see it. Pushed the fix. |
That is correct, but the tooltip - from rust-analyzer - (I assume also the docs) claims the repositioning is in window coordinates, which is incorrect |
Ahh you're right. We'll need to change that. |
Opened a PR to fix it: tauri-apps/tao#375 thanks for catching this! |
Describe the problem
I want to reposition the mouse pointer within the tauri window.
I have read that
winit
has functions to do that, so I would assumetao
can also do that.Since tao is not exposed by tauri, I cannot use those capabilities.
Describe the solution you'd like
I would like an API function where I can pass coordinates relative to the top left corner of the tauri window which would reposition the mouse pointer.
For example, if I would do
set_pointer_position(0,0)
, the cursor would jump to the top left corner.Alternatives considered
I have created a custom tauri command using
winapi
, which looks like this:Additional context
No response
The text was updated successfully, but these errors were encountered: