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