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

Add set_mouse_pos function #321

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ impl Window {
self.0.set_icon(icon)
}

/// TODO: make this work on other platforms (macos, posix, redox, wasm)
pub fn set_mouse_pos(&mut self, top: u32, left: u32) {
self.0.set_mouse_pos(top, left)
}

///
/// Returns the native handle for a window which is an opaque pointer/handle which
/// dependens on the current operating system:
Expand Down
11 changes: 11 additions & 0 deletions src/os/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,17 @@ impl Window {
}
}

pub fn set_mouse_pos(&mut self, top: u32, left: u32) {
if left < self.width as u32 && top < self.height as u32 {
unsafe {
let pos = self.get_position();

winuser::SetCursorPos(left as i32 + pos.1 as i32, top as i32 + pos.0 as i32 + 30 /* height of title bar */);
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think hard coding height to 30 here is a good idea. The window may not have a title bar, or the user may have increased / decreased the font size of the title bar.

self.generic_update(self.window.unwrap());
}
}
}

fn message_loop(&self, _window: windef::HWND) {
unsafe {
let mut msg = mem::zeroed();
Expand Down