tmp commit
Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
parent
06ee68f836
commit
93a600a0a8
@ -6,6 +6,7 @@ import 'package:flutter/gestures.dart';
|
|||||||
|
|
||||||
import 'package:flutter_hbb/models/platform_model.dart';
|
import 'package:flutter_hbb/models/platform_model.dart';
|
||||||
import 'package:flutter_hbb/common.dart';
|
import 'package:flutter_hbb/common.dart';
|
||||||
|
import 'package:flutter_hbb/consts.dart';
|
||||||
import 'package:flutter_hbb/models/model.dart';
|
import 'package:flutter_hbb/models/model.dart';
|
||||||
import 'package:flutter_hbb/models/input_model.dart';
|
import 'package:flutter_hbb/models/input_model.dart';
|
||||||
|
|
||||||
@ -263,9 +264,9 @@ class _RawTouchGestureDetectorRegionState
|
|||||||
if (scale != 0) {
|
if (scale != 0) {
|
||||||
bind.sessionSendPointer(
|
bind.sessionSendPointer(
|
||||||
sessionId: sessionId,
|
sessionId: sessionId,
|
||||||
msg: json.encode({
|
msg: json.encode(
|
||||||
'touch': {'scale': scale}
|
PointerEventToRust(kPointerEventKindTouch, 'scale', scale)
|
||||||
}));
|
.toJson()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// mobile
|
// mobile
|
||||||
@ -283,9 +284,8 @@ class _RawTouchGestureDetectorRegionState
|
|||||||
if (isDesktop) {
|
if (isDesktop) {
|
||||||
bind.sessionSendPointer(
|
bind.sessionSendPointer(
|
||||||
sessionId: sessionId,
|
sessionId: sessionId,
|
||||||
msg: json.encode({
|
msg: json.encode(
|
||||||
'touch': {'scale': 0}
|
PointerEventToRust(kPointerEventKindTouch, 'scale', 0).toJson()));
|
||||||
}));
|
|
||||||
} else {
|
} else {
|
||||||
// mobile
|
// mobile
|
||||||
_scale = 1;
|
_scale = 1;
|
||||||
|
@ -54,6 +54,9 @@ const String kTabLabelSettingPage = "Settings";
|
|||||||
const String kWindowPrefix = "wm_";
|
const String kWindowPrefix = "wm_";
|
||||||
const int kWindowMainId = 0;
|
const int kWindowMainId = 0;
|
||||||
|
|
||||||
|
const String kPointerEventKindTouch = "touch";
|
||||||
|
const String kPointerEventKindMouse = "mouse";
|
||||||
|
|
||||||
// the executable name of the portable version
|
// the executable name of the portable version
|
||||||
const String kEnvPortableExecutable = "RUSTDESK_APPNAME";
|
const String kEnvPortableExecutable = "RUSTDESK_APPNAME";
|
||||||
|
|
||||||
|
@ -35,6 +35,24 @@ extension ToString on MouseButtons {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PointerEventToRust {
|
||||||
|
final String kind;
|
||||||
|
final String type;
|
||||||
|
final dynamic value;
|
||||||
|
|
||||||
|
PointerEventToRust(this.kind, this.type, this.value);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'k': kind,
|
||||||
|
'v': {
|
||||||
|
't': type,
|
||||||
|
'v': value,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class InputModel {
|
class InputModel {
|
||||||
final WeakReference<FFI> parent;
|
final WeakReference<FFI> parent;
|
||||||
String keyboardMode = "legacy";
|
String keyboardMode = "legacy";
|
||||||
@ -349,9 +367,9 @@ class InputModel {
|
|||||||
if (scale != 0) {
|
if (scale != 0) {
|
||||||
bind.sessionSendPointer(
|
bind.sessionSendPointer(
|
||||||
sessionId: sessionId,
|
sessionId: sessionId,
|
||||||
msg: json.encode({
|
msg: json.encode(
|
||||||
'touch': {'scale': scale}
|
PointerEventToRust(kPointerEventKindTouch, 'scale', scale)
|
||||||
}));
|
.toJson()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,7 +397,7 @@ class InputModel {
|
|||||||
}
|
}
|
||||||
if (x != 0 || y != 0) {
|
if (x != 0 || y != 0) {
|
||||||
if (peerPlatform == kPeerPlatformAndroid) {
|
if (peerPlatform == kPeerPlatformAndroid) {
|
||||||
handlePointerEvent('touch', 'pan_move', e.delta);
|
handlePointerEvent('touch', 'pan_update', Offset(x.toDouble(), y.toDouble()));
|
||||||
} else {
|
} else {
|
||||||
bind.sessionSendMouse(
|
bind.sessionSendMouse(
|
||||||
sessionId: sessionId,
|
sessionId: sessionId,
|
||||||
@ -447,9 +465,8 @@ class InputModel {
|
|||||||
|
|
||||||
bind.sessionSendPointer(
|
bind.sessionSendPointer(
|
||||||
sessionId: sessionId,
|
sessionId: sessionId,
|
||||||
msg: json.encode({
|
msg: json.encode(
|
||||||
'touch': {'scale': 0}
|
PointerEventToRust(kPointerEventKindTouch, 'scale', 0).toJson()));
|
||||||
}));
|
|
||||||
|
|
||||||
waitLastFlingDone();
|
waitLastFlingDone();
|
||||||
_stopFling = false;
|
_stopFling = false;
|
||||||
@ -558,15 +575,23 @@ class InputModel {
|
|||||||
|
|
||||||
void handlePointerEvent(String kind, String type, Offset offset) {
|
void handlePointerEvent(String kind, String type, Offset offset) {
|
||||||
double x = offset.dx;
|
double x = offset.dx;
|
||||||
double y = max(0.0, offset.dy);
|
double y = offset.dy;
|
||||||
if (_checkPeerControlProtected(x, y)) {
|
if (_checkPeerControlProtected(x, y)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Only touch events are handled for now. So we can just ignore buttons.
|
// Only touch events are handled for now. So we can just ignore buttons.
|
||||||
// to-do: handle mouse events
|
// to-do: handle mouse events
|
||||||
|
|
||||||
final isMoveTypes = ['pan', 'pan_start', 'pan_end'];
|
late final dynamic evtValue;
|
||||||
|
if (type == 'pan_update') {
|
||||||
|
evtValue = {
|
||||||
|
'x': '${x.toInt()}',
|
||||||
|
'y': '${y.toInt()}',
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
final isMoveTypes = ['pan_start', 'pan_end'];
|
||||||
final pos = handlePointerDevicePos(
|
final pos = handlePointerDevicePos(
|
||||||
|
kPointerEventKindTouch,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
isMoveTypes.contains(type),
|
isMoveTypes.contains(type),
|
||||||
@ -575,17 +600,15 @@ class InputModel {
|
|||||||
if (pos == null) {
|
if (pos == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
evtValue = {
|
||||||
final evt = {
|
|
||||||
kind: {
|
|
||||||
type: {
|
|
||||||
'x': '${pos.x}',
|
'x': '${pos.x}',
|
||||||
'y': '${pos.y}',
|
'y': '${pos.y}',
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
final evt = PointerEventToRust(kind, type, evtValue).toJson();
|
||||||
bind.sessionSendPointer(
|
bind.sessionSendPointer(
|
||||||
sessionId: sessionId, msg: json.encode({modify(evt)}));
|
sessionId: sessionId, msg: json.encode(modify(evt)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _checkPeerControlProtected(double x, double y) {
|
bool _checkPeerControlProtected(double x, double y) {
|
||||||
@ -639,6 +662,7 @@ class InputModel {
|
|||||||
evt['type'] = type;
|
evt['type'] = type;
|
||||||
|
|
||||||
final pos = handlePointerDevicePos(
|
final pos = handlePointerDevicePos(
|
||||||
|
kPointerEventKindMouse,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
isMove,
|
isMove,
|
||||||
@ -649,8 +673,13 @@ class InputModel {
|
|||||||
if (pos == null) {
|
if (pos == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (type != '') {
|
||||||
|
evt['x'] = 0;
|
||||||
|
evt['y'] = 0;
|
||||||
|
} else {
|
||||||
evt['x'] = '${pos.x}';
|
evt['x'] = '${pos.x}';
|
||||||
evt['y'] = '${pos.y}';
|
evt['y'] = '${pos.y}';
|
||||||
|
}
|
||||||
|
|
||||||
Map<int, String> mapButtons = {
|
Map<int, String> mapButtons = {
|
||||||
kPrimaryMouseButton: 'left',
|
kPrimaryMouseButton: 'left',
|
||||||
@ -664,6 +693,7 @@ class InputModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Point? handlePointerDevicePos(
|
Point? handlePointerDevicePos(
|
||||||
|
String kind,
|
||||||
double x,
|
double x,
|
||||||
double y,
|
double y,
|
||||||
bool isMove,
|
bool isMove,
|
||||||
@ -738,16 +768,13 @@ class InputModel {
|
|||||||
int maxY = (d.y + d.height).toInt() - 1;
|
int maxY = (d.y + d.height).toInt() - 1;
|
||||||
evtX = trySetNearestRange(evtX, minX, maxX, 5);
|
evtX = trySetNearestRange(evtX, minX, maxX, 5);
|
||||||
evtY = trySetNearestRange(evtY, minY, maxY, 5);
|
evtY = trySetNearestRange(evtY, minY, maxY, 5);
|
||||||
|
if (kind == kPointerEventKindMouse) {
|
||||||
if (evtX < minX || evtY < minY || evtX > maxX || evtY > maxY) {
|
if (evtX < minX || evtY < minY || evtX > maxX || evtY > maxY) {
|
||||||
// If left mouse up, no early return.
|
// If left mouse up, no early return.
|
||||||
if (buttons != kPrimaryMouseButton || evtType != 'up') {
|
if (!(buttons == kPrimaryMouseButton && evtType == 'up')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evtType != '') {
|
|
||||||
evtX = 0;
|
|
||||||
evtY = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Point(evtX, evtY);
|
return Point(evtX, evtY);
|
||||||
|
@ -1177,14 +1177,39 @@ pub fn session_send_pointer(session_id: SessionID, msg: String) {
|
|||||||
let ctrl = m.get("ctrl").is_some();
|
let ctrl = m.get("ctrl").is_some();
|
||||||
let shift = m.get("shift").is_some();
|
let shift = m.get("shift").is_some();
|
||||||
let command = m.get("command").is_some();
|
let command = m.get("command").is_some();
|
||||||
if let Some(touch_event) = m.get("touch") {
|
match (m.get("k"), m.get("v")) {
|
||||||
if let Some(scale) = touch_event.get("scale") {
|
(Some(k), Some(v)) => match k.as_str() {
|
||||||
if let Some(session) = SESSIONS.read().unwrap().get(&session_id) {
|
Some("touch") => match v.as_str() {
|
||||||
|
Some("scale") => match v.get("v") {
|
||||||
|
Some(scale) => {
|
||||||
if let Some(scale) = scale.as_i64() {
|
if let Some(scale) = scale.as_i64() {
|
||||||
|
if let Some(session) = SESSIONS.read().unwrap().get(&session_id) {
|
||||||
session.send_touch_scale(scale as _, alt, ctrl, shift, command);
|
session.send_touch_scale(scale as _, alt, ctrl, shift, command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
None => {}
|
||||||
|
},
|
||||||
|
Some(pan_event) => match (v.get("x"), v.get("y")) {
|
||||||
|
(Some(x), Some(y)) => {
|
||||||
|
if let Some(x) = x.as_i64() {
|
||||||
|
if let Some(y) = y.as_i64() {
|
||||||
|
if let Some(session) = SESSIONS.read().unwrap().get(&session_id)
|
||||||
|
{
|
||||||
|
session.send_touch_pan_event(
|
||||||
|
pan_event, x as _, y as _, alt, ctrl, shift, command,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1573,20 +1573,20 @@ impl Connection {
|
|||||||
pan_start.y,
|
pan_start.y,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Some(touch_event::Union::PanUpdate(pan_start)) => {
|
Some(touch_event::Union::PanUpdate(pan_update)) => {
|
||||||
call_main_service_pointer_input(
|
call_main_service_pointer_input(
|
||||||
"touch".to_string(),
|
"touch".to_string(),
|
||||||
5,
|
5,
|
||||||
pan_start.x,
|
pan_update.x,
|
||||||
pan_start.y,
|
pan_update.y,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Some(touch_event::Union::PanEnd(pan_start)) => {
|
Some(touch_event::Union::PanEnd(pan_end)) => {
|
||||||
call_main_service_pointer_input(
|
call_main_service_pointer_input(
|
||||||
"touch".to_string(),
|
"touch".to_string(),
|
||||||
6,
|
6,
|
||||||
pan_start.x,
|
pan_end.x,
|
||||||
pan_start.y,
|
pan_end.y,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_ => Ok(()),
|
_ => Ok(()),
|
||||||
|
@ -724,6 +724,49 @@ impl<T: InvokeUiSession> Session<T> {
|
|||||||
send_pointer_device_event(evt, alt, ctrl, shift, command, self);
|
send_pointer_device_event(evt, alt, ctrl, shift, command, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn send_touch_pan_event(
|
||||||
|
&self,
|
||||||
|
event: &str,
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
alt: bool,
|
||||||
|
ctrl: bool,
|
||||||
|
shift: bool,
|
||||||
|
command: bool,
|
||||||
|
) {
|
||||||
|
let mut touch_evt = TouchEvent::new();
|
||||||
|
match event {
|
||||||
|
"pan_start" => {
|
||||||
|
touch_evt.set_pan_start(TouchPanStart {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
"pan_update" => {
|
||||||
|
touch_evt.set_pan_update(TouchPanUpdate {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
"pan_end" => {
|
||||||
|
touch_evt.set_pan_end(TouchPanEnd {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
log::warn!("unknown touch pan event: {}", event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut evt = PointerDeviceEvent::new();
|
||||||
|
evt.set_touch_event(touch_evt);
|
||||||
|
send_pointer_device_event(evt, alt, ctrl, shift, command, self);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn send_mouse(
|
pub fn send_mouse(
|
||||||
&self,
|
&self,
|
||||||
mask: i32,
|
mask: i32,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user