Skip to content

Commit

Permalink
all: Renamed send_mouse_button_event to mouse_button
Browse files Browse the repository at this point in the history
  • Loading branch information
pentamassiv committed Nov 8, 2023
1 parent ab0b116 commit 9cda7b2
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- All: Split off entering raw keycodes into it's own function
- All: Renamed `key_sequence` function to `text`
- All: Renamed `enter_key` function to `key`
- All: Renamed `send_mouse_button_event` function to `mouse_button`

## Added
- Linux: Support X11 without `xdotools`. Use the experimental feature `x11rb` to test it
Expand Down
12 changes: 4 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ where
/// enigo.mouse_down(MouseButton::Left);
/// ```
fn mouse_down(&mut self, button: MouseButton) {
match self.send_mouse_button_event(button, Direction::Press) {
match self.mouse_button(button, Direction::Press) {
Ok(()) => {}
Err(e) => {
error!("{e}");
Expand All @@ -210,7 +210,7 @@ where
/// enigo.mouse_up(MouseButton::Right);
/// ```
fn mouse_up(&mut self, button: MouseButton) {
match self.send_mouse_button_event(button, Direction::Release) {
match self.mouse_button(button, Direction::Release) {
Ok(()) => {}
Err(e) => {
error!("{e}");
Expand All @@ -234,7 +234,7 @@ where
/// enigo.mouse_click(MouseButton::Right);
/// ```
fn mouse_click(&mut self, button: MouseButton) {
match self.send_mouse_button_event(button, Direction::Click) {
match self.mouse_button(button, Direction::Click) {
Ok(()) => {}
Err(e) => {
error!("{e}");
Expand Down Expand Up @@ -546,11 +546,7 @@ pub trait MouseControllableNext {
/// # Errors
/// Have a look at the documentation of `InputError` to see under which
/// conditions an error will be returned.
fn send_mouse_button_event(
&mut self,
button: MouseButton,
direction: Direction,
) -> InputResult<()>;
fn mouse_button(&mut self, button: MouseButton, direction: Direction) -> InputResult<()>;

/// Move the mouse cursor to the specified x and y coordinates.
///
Expand Down
14 changes: 4 additions & 10 deletions src/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,20 @@ impl Enigo {
}

impl MouseControllableNext for Enigo {
fn send_mouse_button_event(
&mut self,
button: MouseButton,
direction: Direction,
) -> InputResult<()> {
debug!(
"\x1b[93msend_mouse_button_event(button: {button:?}, direction: {direction:?})\x1b[0m"
);
fn mouse_button(&mut self, button: MouseButton, direction: Direction) -> InputResult<()> {
debug!("\x1b[93mmouse_button(button: {button:?}, direction: {direction:?})\x1b[0m");
let mut success = false;
#[cfg(feature = "wayland")]
if let Some(con) = self.wayland.as_mut() {
trace!("try sending button event via wayland");
con.send_mouse_button_event(button, direction)?;
con.mouse_button(button, direction)?;
debug!("sent button event via wayland");
success = true;
}
#[cfg(any(feature = "x11rb", feature = "xdo"))]
if let Some(con) = self.x11.as_mut() {
trace!("try sending button event via x11");
con.send_mouse_button_event(button, direction)?;
con.mouse_button(button, direction)?;
debug!("sent button event via x11");
success = true;
}
Expand Down
6 changes: 1 addition & 5 deletions src/linux/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,7 @@ impl KeyboardControllableNext for Con {
}
}
impl MouseControllableNext for Con {
fn send_mouse_button_event(
&mut self,
button: MouseButton,
direction: Direction,
) -> InputResult<()> {
fn mouse_button(&mut self, button: MouseButton, direction: Direction) -> InputResult<()> {
if let Some(vp) = &self.virtual_pointer {
// Do nothing if one of the mouse scroll buttons was released
// Releasing one of the scroll mouse buttons has no effect
Expand Down
8 changes: 2 additions & 6 deletions src/linux/x11rb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,7 @@ impl KeyboardControllableNext for Con {
}

impl MouseControllableNext for Con {
fn send_mouse_button_event(
&mut self,
button: MouseButton,
direction: Direction,
) -> InputResult<()> {
fn mouse_button(&mut self, button: MouseButton, direction: Direction) -> InputResult<()> {
let detail = match button {
MouseButton::Left => 1,
MouseButton::Middle => 2,
Expand Down Expand Up @@ -467,7 +463,7 @@ impl MouseControllableNext for Con {
}
};
for _ in 0..length {
self.send_mouse_button_event(button, Direction::Click)?;
self.mouse_button(button, Direction::Click)?;
}
Ok(())
}
Expand Down
8 changes: 2 additions & 6 deletions src/linux/xdo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,7 @@ impl KeyboardControllableNext for Con {
}

impl MouseControllableNext for Con {
fn send_mouse_button_event(
&mut self,
button: MouseButton,
direction: Direction,
) -> InputResult<()> {
fn mouse_button(&mut self, button: MouseButton, direction: Direction) -> InputResult<()> {
let mouse_button = mousebutton(button);
let res = match direction {
Direction::Press => {
Expand Down Expand Up @@ -302,7 +298,7 @@ impl MouseControllableNext for Con {
}
};
for _ in 0..length {
self.send_mouse_button_event(button, Direction::Click)?;
self.mouse_button(button, Direction::Click)?;
}
Ok(())
}
Expand Down
10 changes: 2 additions & 8 deletions src/macos/macos_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,8 @@ pub struct Enigo {

impl MouseControllableNext for Enigo {
// Sends a button event to the X11 server via `XTest` extension
fn send_mouse_button_event(
&mut self,
button: MouseButton,
direction: Direction,
) -> InputResult<()> {
debug!(
"\x1b[93msend_mouse_button_event(button: {button:?}, direction: {direction:?})\x1b[0m"
);
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()?;

if direction == Direction::Click || direction == Direction::Press {
Expand Down
10 changes: 2 additions & 8 deletions src/win/win_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,8 @@ fn keybd_event(flags: KEYBD_EVENT_FLAGS, vk: VIRTUAL_KEY, scan: ScanCode) -> INP

impl MouseControllableNext for Enigo {
// Sends a button event to the X11 server via `XTest` extension
fn send_mouse_button_event(
&mut self,
button: MouseButton,
direction: Direction,
) -> InputResult<()> {
debug!(
"\x1b[93msend_mouse_button_event(button: {button:?}, direction: {direction:?})\x1b[0m"
);
fn mouse_button(&mut self, button: MouseButton, direction: Direction) -> InputResult<()> {
debug!("\x1b[93mmouse_button(button: {button:?}, direction: {direction:?})\x1b[0m");
let mut input = vec![];
let button_no = match button {
MouseButton::Back => 1,
Expand Down

0 comments on commit 9cda7b2

Please sign in to comment.