mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-07 11:59:59 +03:00
fix(macos): forward back/forward mouse buttons in capture and emulation (#392)
* fix(macos): forward back/forward mouse buttons in capture and emulation OtherMouseDown/Up events on macOS carry a button number field that distinguishes middle (2), back (3), and forward (4) buttons. The capture backend was unconditionally mapping all OtherMouse events to BTN_MIDDLE, silently dropping back/forward. The emulation backend had no match arms for BTN_BACK/BTN_FORWARD, causing them to be dropped with a warning. Fix capture by reading MOUSE_EVENT_BUTTON_NUMBER and mapping 3->BTN_BACK, 4->BTN_FORWARD. Fix emulation by adding match arms for BTN_BACK/BTN_FORWARD and setting MOUSE_EVENT_BUTTON_NUMBER on the emitted CGEvent so macOS apps receive the correct button identity. * fix(macos): track button state and double-clicks by evdev code instead of CGMouseButton Back, forward, and middle buttons all map to CGMouseButton::Center on macOS, which caused them to share a single pressed-state boolean and alias in double-click detection. Replace the ButtonState struct with a HashSet<u32> keyed by evdev button code so each button is tracked independently. --------- Co-authored-by: Ferdinand Schober <ferdinandschober20@gmail.com>
This commit is contained in:
@@ -18,7 +18,9 @@ use core_graphics::{
|
||||
event_source::{CGEventSource, CGEventSourceStateID},
|
||||
};
|
||||
use futures_core::Stream;
|
||||
use input_event::{BTN_LEFT, BTN_MIDDLE, BTN_RIGHT, Event, KeyboardEvent, PointerEvent};
|
||||
use input_event::{
|
||||
BTN_BACK, BTN_FORWARD, BTN_LEFT, BTN_MIDDLE, BTN_RIGHT, Event, KeyboardEvent, PointerEvent,
|
||||
};
|
||||
use keycode::{KeyMap, KeyMapping};
|
||||
use libc::c_void;
|
||||
use once_cell::unsync::Lazy;
|
||||
@@ -304,16 +306,28 @@ fn get_events(
|
||||
})))
|
||||
}
|
||||
CGEventType::OtherMouseDown => {
|
||||
let btn_num = ev.get_integer_value_field(EventField::MOUSE_EVENT_BUTTON_NUMBER);
|
||||
let button = match btn_num {
|
||||
3 => BTN_BACK,
|
||||
4 => BTN_FORWARD,
|
||||
_ => BTN_MIDDLE,
|
||||
};
|
||||
result.push(CaptureEvent::Input(Event::Pointer(PointerEvent::Button {
|
||||
time: 0,
|
||||
button: BTN_MIDDLE,
|
||||
button,
|
||||
state: 1,
|
||||
})))
|
||||
}
|
||||
CGEventType::OtherMouseUp => {
|
||||
let btn_num = ev.get_integer_value_field(EventField::MOUSE_EVENT_BUTTON_NUMBER);
|
||||
let button = match btn_num {
|
||||
3 => BTN_BACK,
|
||||
4 => BTN_FORWARD,
|
||||
_ => BTN_MIDDLE,
|
||||
};
|
||||
result.push(CaptureEvent::Input(Event::Pointer(PointerEvent::Button {
|
||||
time: 0,
|
||||
button: BTN_MIDDLE,
|
||||
button,
|
||||
state: 0,
|
||||
})))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user