trackpad scale, mid commit
Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
parent
f0ded8498a
commit
7bbc5183db
@ -55,6 +55,8 @@ class InputModel {
|
||||
final _trackpadSpeed = 0.06;
|
||||
var _trackpadScrollUnsent = Offset.zero;
|
||||
|
||||
var _lastScale = 1.0;
|
||||
|
||||
// mouse
|
||||
final isPhysicalMouse = false.obs;
|
||||
int _lastButtons = 0;
|
||||
@ -272,7 +274,7 @@ class InputModel {
|
||||
sendMouse('down', button);
|
||||
}
|
||||
|
||||
void tapUp(MouseButtons button) {
|
||||
void tapUp(MouseButtons button) {
|
||||
sendMouse('up', button);
|
||||
}
|
||||
|
||||
@ -337,12 +339,15 @@ class InputModel {
|
||||
}
|
||||
|
||||
void onPointerPanZoomStart(PointerPanZoomStartEvent e) {
|
||||
_lastScale = 1.0;
|
||||
_stopFling = true;
|
||||
}
|
||||
|
||||
// https://docs.flutter.dev/release/breaking-changes/trackpad-gestures
|
||||
// TODO(support zoom in/out)
|
||||
void onPointerPanZoomUpdate(PointerPanZoomUpdateEvent e) {
|
||||
final scale = ((e.scale - _lastScale) * 100).toInt();
|
||||
_lastScale = e.scale;
|
||||
|
||||
final delta = e.panDelta;
|
||||
_trackpadLastDelta = delta;
|
||||
|
||||
@ -366,7 +371,7 @@ class InputModel {
|
||||
if (x != 0 || y != 0) {
|
||||
bind.sessionSendMouse(
|
||||
sessionId: sessionId,
|
||||
msg: '{"type": "trackpad", "x": "$x", "y": "$y"}');
|
||||
msg: '{"type": "trackpad", "x": "$x", "y": "$y", "scale": "$scale"}');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,7 @@ message MouseEvent {
|
||||
sint32 x = 2;
|
||||
sint32 y = 3;
|
||||
repeated ControlKey modifiers = 4;
|
||||
sint32 scale = 5;
|
||||
}
|
||||
|
||||
enum KeyboardMode{
|
||||
|
@ -1109,7 +1109,8 @@ impl LoginConfigHandler {
|
||||
self.remember = !config.password.is_empty();
|
||||
self.config = config;
|
||||
let mut sid = rand::random();
|
||||
if sid == 0 { // you won the lottery
|
||||
if sid == 0 {
|
||||
// you won the lottery
|
||||
sid = 1;
|
||||
}
|
||||
self.session_id = sid;
|
||||
@ -1928,6 +1929,7 @@ pub fn send_mouse(
|
||||
mask: i32,
|
||||
x: i32,
|
||||
y: i32,
|
||||
scale: i32,
|
||||
alt: bool,
|
||||
ctrl: bool,
|
||||
shift: bool,
|
||||
@ -1939,6 +1941,7 @@ pub fn send_mouse(
|
||||
mask,
|
||||
x,
|
||||
y,
|
||||
scale,
|
||||
..Default::default()
|
||||
};
|
||||
if alt {
|
||||
@ -1971,12 +1974,12 @@ pub fn send_mouse(
|
||||
///
|
||||
/// * `interface` - The interface for sending data.
|
||||
fn activate_os(interface: &impl Interface) {
|
||||
send_mouse(0, 0, 0, false, false, false, false, interface);
|
||||
send_mouse(0, 0, 0, 0, false, false, false, false, interface);
|
||||
std::thread::sleep(Duration::from_millis(50));
|
||||
send_mouse(0, 3, 3, false, false, false, false, interface);
|
||||
send_mouse(0, 3, 3, 0, false, false, false, false, interface);
|
||||
std::thread::sleep(Duration::from_millis(50));
|
||||
send_mouse(1 | 1 << 3, 0, 0, false, false, false, false, interface);
|
||||
send_mouse(2 | 1 << 3, 0, 0, false, false, false, false, interface);
|
||||
send_mouse(1 | 1 << 3, 0, 0, 0, false, false, false, false, interface);
|
||||
send_mouse(2 | 1 << 3, 0, 0, 0, false, false, false, false, interface);
|
||||
/*
|
||||
let mut key_event = KeyEvent::new();
|
||||
// do not use Esc, which has problem with Linux
|
||||
|
@ -1103,8 +1103,12 @@ pub fn session_send_mouse(session_id: SessionID, msg: String) {
|
||||
_ => 0,
|
||||
} << 3;
|
||||
}
|
||||
let scale = m
|
||||
.get("scale")
|
||||
.map(|x| x.parse::<i32>().unwrap_or(0))
|
||||
.unwrap_or(0);
|
||||
if let Some(session) = SESSIONS.read().unwrap().get(&session_id) {
|
||||
session.send_mouse(mask, x, y, alt, ctrl, shift, command);
|
||||
session.send_mouse(mask, x, y, scale, alt, ctrl, shift, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -759,7 +759,7 @@ pub fn handle_mouse_(evt: &MouseEvent, conn: i32) {
|
||||
let mut en = ENIGO.lock().unwrap();
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let mut to_release = Vec::new();
|
||||
if evt_type == 1 {
|
||||
if evt_type == MOUSE_TYPE_DOWN {
|
||||
fix_modifiers(&evt.modifiers[..], &mut en, 0);
|
||||
#[cfg(target_os = "macos")]
|
||||
en.reset_flag();
|
||||
@ -883,6 +883,15 @@ pub fn handle_mouse_(evt: &MouseEvent, conn: i32) {
|
||||
for key in to_release {
|
||||
en.key_up(key.clone());
|
||||
}
|
||||
handle_mouse_scale(evt.scale);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn handle_mouse_scale(scale: i32) {
|
||||
let mut en = ENIGO.lock().unwrap();
|
||||
en.key_down(Key::Control);
|
||||
en.mouse_scroll_y(scale);
|
||||
en.key_up(Key::Control);
|
||||
}
|
||||
|
||||
pub fn is_enter(evt: &KeyEvent) -> bool {
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::input::{MOUSE_BUTTON_LEFT, MOUSE_TYPE_DOWN, MOUSE_TYPE_UP};
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use std::{collections::HashMap, sync::atomic::AtomicBool};
|
||||
use std::{
|
||||
@ -50,7 +51,7 @@ const CHANGE_RESOLUTION_VALID_TIMEOUT_SECS: u64 = 15;
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Session<T: InvokeUiSession> {
|
||||
pub session_id: SessionID, // different from the one in LoginConfigHandler, used for flutter UI message pass
|
||||
pub id: String, // peer id
|
||||
pub id: String, // peer id
|
||||
pub password: String,
|
||||
pub args: Vec<String>,
|
||||
pub lc: Arc<RwLock<LoginConfigHandler>>,
|
||||
@ -306,8 +307,7 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
}
|
||||
|
||||
pub fn get_audit_server(&self, typ: String) -> String {
|
||||
if LocalConfig::get_option("access_token").is_empty()
|
||||
{
|
||||
if LocalConfig::get_option("access_token").is_empty() {
|
||||
return "".to_owned();
|
||||
}
|
||||
crate::get_audit_server(
|
||||
@ -695,6 +695,7 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
mask: i32,
|
||||
x: i32,
|
||||
y: i32,
|
||||
scale: i32,
|
||||
alt: bool,
|
||||
ctrl: bool,
|
||||
shift: bool,
|
||||
@ -713,15 +714,28 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
let (alt, ctrl, shift, command) =
|
||||
keyboard::client::get_modifiers_state(alt, ctrl, shift, command);
|
||||
|
||||
send_mouse(mask, x, y, alt, ctrl, shift, command, self);
|
||||
send_mouse(mask, x, y, scale, alt, ctrl, shift, command, self);
|
||||
// on macos, ctrl + left button down = right button down, up won't emit, so we need to
|
||||
// emit up myself if peer is not macos
|
||||
// to-do: how about ctrl + left from win to macos
|
||||
if cfg!(target_os = "macos") {
|
||||
let buttons = mask >> 3;
|
||||
let evt_type = mask & 0x7;
|
||||
if buttons == 1 && evt_type == 1 && ctrl && self.peer_platform() != "Mac OS" {
|
||||
self.send_mouse((1 << 3 | 2) as _, x, y, alt, ctrl, shift, command);
|
||||
if buttons == MOUSE_BUTTON_LEFT
|
||||
&& evt_type == MOUSE_TYPE_DOWN
|
||||
&& ctrl
|
||||
&& self.peer_platform() != "Mac OS"
|
||||
{
|
||||
self.send_mouse(
|
||||
(MOUSE_BUTTON_LEFT << 3 | MOUSE_TYPE_UP) as _,
|
||||
x,
|
||||
y,
|
||||
scale,
|
||||
alt,
|
||||
ctrl,
|
||||
shift,
|
||||
command,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user