Skip to content

Commit

Permalink
Renamed mouse_location function to location
Browse files Browse the repository at this point in the history
  • Loading branch information
pentamassiv committed Nov 8, 2023
1 parent fa8d701 commit 83c02d4
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- All: Renamed `send_mouse_button_event` function to `mouse_button`
- All: Renamed `send_motion_notify_event` function to `move_mouse`
- All: Renamed `mouse_scroll_event` function to `scroll`
- All: Renamed `mouse_location` function to `location`

## Added
- Linux: Support X11 without `xdotools`. Use the experimental feature `x11rb` to test it
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ where
/// ```
#[must_use]
fn mouse_location(&self) -> (i32, i32) {
match self.mouse_loc() {
match self.location() {
Ok(loc) => loc,
Err(e) => {
error!("{e}");
Expand Down Expand Up @@ -597,7 +597,7 @@ pub trait MouseControllableNext {
/// # Errors
/// Have a look at the documentation of `InputError` to see under which
/// conditions an error will be returned.
fn mouse_loc(&self) -> InputResult<(i32, i32)>;
fn location(&self) -> InputResult<(i32, i32)>;
}

pub type InputResult<T> = Result<T, InputError>;
Expand Down
8 changes: 4 additions & 4 deletions src/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,17 @@ impl MouseControllableNext for Enigo {
Err(InputError::Simulate("No protocol to enter the result"))
}

fn mouse_loc(&self) -> InputResult<(i32, i32)> {
debug!("\x1b[93mmouse_loc()\x1b[0m");
fn location(&self) -> InputResult<(i32, i32)> {
debug!("\x1b[93mlocation()\x1b[0m");
#[cfg(feature = "wayland")]
if let Some(con) = self.wayland.as_ref() {
trace!("try getting the mouse location via wayland");
return con.mouse_loc();
return con.location();
}
#[cfg(any(feature = "x11rb", feature = "xdo"))]
if let Some(con) = self.x11.as_ref() {
trace!("try getting the mouse location via x11");
return con.mouse_loc();
return con.location();
}
Err(InputError::Simulate("No protocol to enter the result"))
}
Expand Down
2 changes: 1 addition & 1 deletion src/linux/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ impl MouseControllableNext for Con {
Err(InputError::Simulate("Not implemented yet"))
}

fn mouse_loc(&self) -> InputResult<(i32, i32)> {
fn location(&self) -> InputResult<(i32, i32)> {
// TODO Implement this
error!("You tried to get the mouse location. I don't know how this is possible under Wayland. Let me know if there is a new protocol");
Err(InputError::Simulate("Not implemented yet"))
Expand Down
2 changes: 1 addition & 1 deletion src/linux/x11rb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ impl MouseControllableNext for Con {
Ok((main_display.width as i32, main_display.height as i32))
}

fn mouse_loc(&self) -> InputResult<(i32, i32)> {
fn location(&self) -> InputResult<(i32, i32)> {
let reply = self
.connection
.query_pointer(self.screen.root)
Expand Down
2 changes: 1 addition & 1 deletion src/linux/xdo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl MouseControllableNext for Con {
Ok((width, height))
}

fn mouse_loc(&self) -> InputResult<(i32, i32)> {
fn location(&self) -> InputResult<(i32, i32)> {
let mut x = 0;
let mut y = 0;
let mut unused_screen_index = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/macos/macos_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl MouseControllableNext for Enigo {
// Sends a button event to the X11 server via `XTest` extension
fn mouse_button(&mut self, button: MouseButton, direction: Direction) -> InputResult<()> {
debug!("\x1b[93mmouse_button(button: {button:?}, direction: {direction:?})\x1b[0m");
let (current_x, current_y) = self.mouse_loc()?;
let (current_x, current_y) = self.location()?;

if direction == Direction::Click || direction == Direction::Press {
let click_count = self.nth_button_press(button, Direction::Press);
Expand Down Expand Up @@ -221,7 +221,7 @@ impl MouseControllableNext for Enigo {
fn move_mouse(&mut self, x: i32, y: i32, coordinate: Coordinate) -> InputResult<()> {
debug!("\x1b[93mmove_mouse(x: {x:?}, y: {y:?}, coordinate:{coordinate:?})\x1b[0m");
let pressed = Self::pressed_buttons()?;
let (current_x, current_y) = self.mouse_loc()?;
let (current_x, current_y) = self.location()?;

let (absolute, relative) = match coordinate {
// TODO: Check the bounds
Expand Down Expand Up @@ -292,8 +292,8 @@ impl MouseControllableNext for Enigo {
))
}

fn mouse_loc(&self) -> InputResult<(i32, i32)> {
debug!("\x1b[93mmouse_loc()\x1b[0m");
fn location(&self) -> InputResult<(i32, i32)> {
debug!("\x1b[93mlocation()\x1b[0m");
let ns_event = Class::get("NSEvent").ok_or(InputError::Simulate(
"failed creating event to get the mouse location",
))?;
Expand Down
6 changes: 3 additions & 3 deletions src/win/win_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl MouseControllableNext for Enigo {
fn move_mouse(&mut self, x: i32, y: i32, coordinate: Coordinate) -> InputResult<()> {
debug!("\x1b[93mmove_mouse(x: {x:?}, y: {y:?}, coordinate:{coordinate:?})\x1b[0m");
let (x_absolute, y_absolute) = if coordinate == Coordinate::Relative {
let (x_absolute, y_absolute) = self.mouse_loc()?;
let (x_absolute, y_absolute) = self.location()?;
(x_absolute + x, y_absolute + y)
} else {
(x, y)
Expand Down Expand Up @@ -182,8 +182,8 @@ impl MouseControllableNext for Enigo {
}
}

fn mouse_loc(&self) -> InputResult<(i32, i32)> {
debug!("\x1b[93mmouse_loc()\x1b[0m");
fn location(&self) -> InputResult<(i32, i32)> {
debug!("\x1b[93mlocation()\x1b[0m");
let mut point = POINT { x: 0, y: 0 };
if unsafe { GetCursorPos(&mut point) }.is_ok() {
Ok((point.x, point.y))
Expand Down

0 comments on commit 83c02d4

Please sign in to comment.