Skip to content

Commit

Permalink
Improve button handling for autopilot.
Browse files Browse the repository at this point in the history
Button handling should be more fine grained now and no unnecessary
button events are simulated on pointerup. This may fix erroneously sent
events on Windows, that made pointerup events always appear as right
clicks.
  • Loading branch information
H-M-H committed May 4, 2021
1 parent d80891f commit 7e9a6ef
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/input/autopilot_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tracing::warn;

use crate::input::device::{InputDevice, InputDeviceType};
use crate::protocol::{
Button, KeyboardEvent, KeyboardEventType, PointerEvent, PointerEventType, WheelEvent,
Button, KeyboardEvent, KeyboardEventType, PointerEvent, WheelEvent,
};

use crate::capturable::Capturable;
Expand Down Expand Up @@ -50,17 +50,15 @@ impl InputDevice for AutoPilotDevice {
)) {
warn!("Could not move mouse: {}", err);
}
match event.event_type {
PointerEventType::DOWN => match event.button {
Button::PRIMARY => mouse::toggle(mouse::Button::Left, true),
Button::AUXILARY => mouse::toggle(mouse::Button::Middle, true),
Button::SECONDARY => mouse::toggle(mouse::Button::Right, true),
_ => (),
},
PointerEventType::UP => {
mouse::toggle(mouse::Button::Left, false);
mouse::toggle(mouse::Button::Middle, false);
mouse::toggle(mouse::Button::Right, false);
match event.button {
Button::PRIMARY => {
mouse::toggle(mouse::Button::Left, event.buttons.contains(event.button))
}
Button::AUXILARY => {
mouse::toggle(mouse::Button::Middle, event.buttons.contains(event.button))
}
Button::SECONDARY => {
mouse::toggle(mouse::Button::Right, event.buttons.contains(event.button))
}
_ => (),
}
Expand Down

0 comments on commit 7e9a6ef

Please sign in to comment.