tmp commit
Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
parent
200fc56a4a
commit
8999bbf297
@ -223,14 +223,8 @@ class InputModel {
|
|||||||
command: command);
|
command: command);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> getEvent(PointerEvent evt, String type) {
|
Map<String, dynamic> _getMouseEvent(PointerEvent evt, String type) {
|
||||||
final Map<String, dynamic> out = {};
|
final Map<String, dynamic> out = {};
|
||||||
out['x'] = evt.position.dx;
|
|
||||||
out['y'] = evt.position.dy;
|
|
||||||
if (alt) out['alt'] = 'true';
|
|
||||||
if (shift) out['shift'] = 'true';
|
|
||||||
if (ctrl) out['ctrl'] = 'true';
|
|
||||||
if (command) out['command'] = 'true';
|
|
||||||
|
|
||||||
// Check update event type and set buttons to be sent.
|
// Check update event type and set buttons to be sent.
|
||||||
int buttons = _lastButtons;
|
int buttons = _lastButtons;
|
||||||
@ -260,7 +254,6 @@ class InputModel {
|
|||||||
|
|
||||||
out['buttons'] = buttons;
|
out['buttons'] = buttons;
|
||||||
out['type'] = type;
|
out['type'] = type;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,7 +285,7 @@ class InputModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Modify the given modifier map [evt] based on current modifier key status.
|
/// Modify the given modifier map [evt] based on current modifier key status.
|
||||||
Map<String, String> modify(Map<String, String> evt) {
|
Map<String, dynamic> modify(Map<String, dynamic> evt) {
|
||||||
if (ctrl) evt['ctrl'] = 'true';
|
if (ctrl) evt['ctrl'] = 'true';
|
||||||
if (shift) evt['shift'] = 'true';
|
if (shift) evt['shift'] = 'true';
|
||||||
if (alt) evt['alt'] = 'true';
|
if (alt) evt['alt'] = 'true';
|
||||||
@ -334,13 +327,14 @@ class InputModel {
|
|||||||
isPhysicalMouse.value = true;
|
isPhysicalMouse.value = true;
|
||||||
}
|
}
|
||||||
if (isPhysicalMouse.value) {
|
if (isPhysicalMouse.value) {
|
||||||
handleMouse(getEvent(e, _kMouseEventMove));
|
handleMouse(_getMouseEvent(e, _kMouseEventMove), e.position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onPointerPanZoomStart(PointerPanZoomStartEvent e) {
|
void onPointerPanZoomStart(PointerPanZoomStartEvent e) {
|
||||||
_lastScale = 1.0;
|
_lastScale = 1.0;
|
||||||
_stopFling = true;
|
_stopFling = true;
|
||||||
|
handlePointerEvent('touch', 'pan_start', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://docs.flutter.dev/release/breaking-changes/trackpad-gestures
|
// https://docs.flutter.dev/release/breaking-changes/trackpad-gestures
|
||||||
@ -465,21 +459,21 @@ class InputModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isPhysicalMouse.value) {
|
if (isPhysicalMouse.value) {
|
||||||
handleMouse(getEvent(e, _kMouseEventDown));
|
handleMouse(_getMouseEvent(e, _kMouseEventDown), e.position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onPointUpImage(PointerUpEvent e) {
|
void onPointUpImage(PointerUpEvent e) {
|
||||||
if (e.kind != ui.PointerDeviceKind.mouse) return;
|
if (e.kind != ui.PointerDeviceKind.mouse) return;
|
||||||
if (isPhysicalMouse.value) {
|
if (isPhysicalMouse.value) {
|
||||||
handleMouse(getEvent(e, _kMouseEventUp));
|
handleMouse(_getMouseEvent(e, _kMouseEventUp), e.position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onPointMoveImage(PointerMoveEvent e) {
|
void onPointMoveImage(PointerMoveEvent e) {
|
||||||
if (e.kind != ui.PointerDeviceKind.mouse) return;
|
if (e.kind != ui.PointerDeviceKind.mouse) return;
|
||||||
if (isPhysicalMouse.value) {
|
if (isPhysicalMouse.value) {
|
||||||
handleMouse(getEvent(e, _kMouseEventMove));
|
handleMouse(_getMouseEvent(e, _kMouseEventMove), e.position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,19 +498,16 @@ class InputModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void refreshMousePos() => handleMouse({
|
void refreshMousePos() => handleMouse({
|
||||||
'x': lastMousePos.dx,
|
|
||||||
'y': lastMousePos.dy,
|
|
||||||
'buttons': 0,
|
'buttons': 0,
|
||||||
'type': _kMouseEventMove,
|
'type': _kMouseEventMove,
|
||||||
});
|
}, lastMousePos);
|
||||||
|
|
||||||
void tryMoveEdgeOnExit(Offset pos) => handleMouse(
|
void tryMoveEdgeOnExit(Offset pos) => handleMouse(
|
||||||
{
|
{
|
||||||
'x': pos.dx,
|
|
||||||
'y': pos.dy,
|
|
||||||
'buttons': 0,
|
'buttons': 0,
|
||||||
'type': _kMouseEventMove,
|
'type': _kMouseEventMove,
|
||||||
},
|
},
|
||||||
|
pos,
|
||||||
onExit: true,
|
onExit: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -550,17 +541,27 @@ class InputModel {
|
|||||||
return Offset(x, y);
|
return Offset(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleMouse(
|
void handlePointerEvent(String kind, String type, PointerEvent e) {
|
||||||
Map<String, dynamic> evt, {
|
if (checkPeerControlProtected(e.position.dx, max(0.0, e.position.dy))) {
|
||||||
bool onExit = false,
|
return;
|
||||||
}) {
|
}
|
||||||
double x = evt['x'];
|
// Only touch events are handled for now. So we can just ignore buttons.
|
||||||
double y = max(0.0, evt['y']);
|
// to-do: handle mouse events
|
||||||
final cursorModel = parent.target!.cursorModel;
|
bind.sessionSendPointer(
|
||||||
|
sessionId: sessionId,
|
||||||
|
msg: json.encode({
|
||||||
|
modify({
|
||||||
|
kind: {type: e.position.toString()}
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkPeerControlProtected(double x, double y) {
|
||||||
|
final cursorModel = parent.target!.cursorModel;
|
||||||
if (cursorModel.isPeerControlProtected) {
|
if (cursorModel.isPeerControlProtected) {
|
||||||
lastMousePos = ui.Offset(x, y);
|
lastMousePos = ui.Offset(x, y);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cursorModel.gotMouseControl) {
|
if (!cursorModel.gotMouseControl) {
|
||||||
@ -571,10 +572,23 @@ class InputModel {
|
|||||||
cursorModel.gotMouseControl = true;
|
cursorModel.gotMouseControl = true;
|
||||||
} else {
|
} else {
|
||||||
lastMousePos = ui.Offset(x, y);
|
lastMousePos = ui.Offset(x, y);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastMousePos = ui.Offset(x, y);
|
lastMousePos = ui.Offset(x, y);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleMouse(
|
||||||
|
Map<String, dynamic> evt,
|
||||||
|
Offset offset, {
|
||||||
|
bool onExit = false,
|
||||||
|
}) {
|
||||||
|
double x = offset.dx;
|
||||||
|
double y = max(0.0, offset.dy);
|
||||||
|
if (checkPeerControlProtected(x, y)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var type = '';
|
var type = '';
|
||||||
var isMove = false;
|
var isMove = false;
|
||||||
@ -615,8 +629,7 @@ class InputModel {
|
|||||||
kForwardMouseButton: 'forward'
|
kForwardMouseButton: 'forward'
|
||||||
};
|
};
|
||||||
evt['buttons'] = mapButtons[evt['buttons']] ?? '';
|
evt['buttons'] = mapButtons[evt['buttons']] ?? '';
|
||||||
|
bind.sessionSendMouse(sessionId: sessionId, msg: json.encode(modify(evt)));
|
||||||
bind.sessionSendMouse(sessionId: sessionId, msg: json.encode(evt));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Point? handlePointerDevicePos(
|
Point? handlePointerDevicePos(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user