Compare commits

..

1 Commits

Author SHA1 Message Date
Ferdinand Schober
1c69d4d209 macos: fix scroll capture 2025-11-03 17:19:15 +01:00
2 changed files with 48 additions and 26 deletions

View File

@@ -318,21 +318,47 @@ fn get_events(
}))) })))
} }
CGEventType::ScrollWheel => { CGEventType::ScrollWheel => {
let v = ev.get_integer_value_field(EventField::SCROLL_WHEEL_EVENT_POINT_DELTA_AXIS_1); if ev.get_integer_value_field(EventField::SCROLL_WHEEL_EVENT_IS_CONTINUOUS) != 0 {
let h = ev.get_integer_value_field(EventField::SCROLL_WHEEL_EVENT_POINT_DELTA_AXIS_2); let v =
if v != 0 { ev.get_integer_value_field(EventField::SCROLL_WHEEL_EVENT_POINT_DELTA_AXIS_1);
result.push(CaptureEvent::Input(Event::Pointer(PointerEvent::Axis { let h =
time: 0, ev.get_integer_value_field(EventField::SCROLL_WHEEL_EVENT_POINT_DELTA_AXIS_2);
axis: 0, // Vertical if v != 0 {
value: v as f64, result.push(CaptureEvent::Input(Event::Pointer(PointerEvent::Axis {
}))); time: 0,
} axis: 0, // Vertical
if h != 0 { value: v as f64,
result.push(CaptureEvent::Input(Event::Pointer(PointerEvent::Axis { })));
time: 0, }
axis: 1, // Horizontal if h != 0 {
value: h as f64, result.push(CaptureEvent::Input(Event::Pointer(PointerEvent::Axis {
}))); time: 0,
axis: 1, // Horizontal
value: h as f64,
})));
}
} else {
// line based scrolling
const LINES_PER_STEP: i32 = 3;
const V120_STEPS_PER_LINE: i32 = 120 / LINES_PER_STEP;
let v = ev.get_integer_value_field(EventField::SCROLL_WHEEL_EVENT_DELTA_AXIS_1);
let h = ev.get_integer_value_field(EventField::SCROLL_WHEEL_EVENT_DELTA_AXIS_2);
if v != 0 {
result.push(CaptureEvent::Input(Event::Pointer(
PointerEvent::AxisDiscrete120 {
axis: 0, // Vertical
value: V120_STEPS_PER_LINE * v as i32,
},
)));
}
if h != 0 {
result.push(CaptureEvent::Input(Event::Pointer(
PointerEvent::AxisDiscrete120 {
axis: 1, // Horizontal
value: V120_STEPS_PER_LINE * h as i32,
},
)));
}
} }
} }
_ => (), _ => (),

View File

@@ -223,18 +223,14 @@ async fn ping_pong(
) { ) {
loop { loop {
let (buf, len) = ProtoEvent::Ping.into(); let (buf, len) = ProtoEvent::Ping.into();
if let Err(e) = conn.send(&buf[..len]).await {
// send 4 pings, at least one must be answered log::warn!("{addr}: send error `{e}`, closing connection");
for _ in 0..4 { let _ = conn.close().await;
if let Err(e) = conn.send(&buf[..len]).await { break;
log::warn!("{addr}: send error `{e}`, closing connection");
let _ = conn.close().await;
break;
}
log::trace!("PING >->->->->- {addr}");
tokio::time::sleep(Duration::from_millis(500)).await;
} }
log::trace!("PING >->->->->- {addr}");
tokio::time::sleep(Duration::from_millis(500)).await;
if !ping_response.borrow_mut().remove(&addr) { if !ping_response.borrow_mut().remove(&addr) {
log::warn!("{addr} did not respond, closing connection"); log::warn!("{addr} did not respond, closing connection");