opt: mac scroll to fast

This commit is contained in:
xxrl
2022-11-07 01:25:36 +08:00
parent 866224ecec
commit 260c924010
3 changed files with 111 additions and 10 deletions

View File

@@ -1529,6 +1529,25 @@ pub async fn handle_test_delay(t: TestDelay, peer: &mut Stream) {
}
}
#[inline]
#[cfg(target_os = "macos")]
fn check_scroll_on_mac(mask: i32, x: i32, y: i32) -> bool {
if mask & 3 != 3 {
return false;
}
let btn = mask >> 3;
if y == -1 {
btn != 0xff88 && btn != -0x780000
} else if y == 1 {
btn != 0x78 && btn != 0x780000
} else if x != 0 {
// No mouse support horizontal scrolling.
true
} else {
false
}
}
/// Send mouse data.
///
/// # Arguments
@@ -1574,6 +1593,10 @@ pub fn send_mouse(
if command {
mouse_event.modifiers.push(ControlKey::Meta.into());
}
#[cfg(target_os = "macos")]
if check_scroll_on_mac(mask, x, y) {
mouse_event.modifiers.push(ControlKey::Scroll.into());
}
msg_out.set_mouse_event(mouse_event);
interface.send(Data::Message(msg_out));
}

View File

@@ -429,18 +429,39 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) {
x = -x;
y = -y;
}
// fix shift + scroll(down/up)
#[cfg(target_os = "macos")]
if evt.modifiers.contains(&EnumOrUnknown::new(ControlKey::Shift)){
x = y;
y = 0;
{
// TODO: support track pad on win.
let is_track_pad = evt
.modifiers
.contains(&EnumOrUnknown::new(ControlKey::Scroll));
// fix shift + scroll(down/up)
if !is_track_pad
&& evt
.modifiers
.contains(&EnumOrUnknown::new(ControlKey::Shift))
{
x = y;
y = 0;
}
if x != 0 {
en.mouse_scroll_x(x, is_track_pad);
}
if y != 0 {
en.mouse_scroll_y(y, is_track_pad);
}
}
if x != 0 {
en.mouse_scroll_x(x);
}
if y != 0 {
en.mouse_scroll_y(y);
#[cfg(not(target_os = "macos"))]
{
if x != 0 {
en.mouse_scroll_x(x);
}
if y != 0 {
en.mouse_scroll_y(y);
}
}
}
_ => {}