fix remote cursor pos

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-12-30 16:14:30 +08:00
parent 2d93c93bc4
commit 56041a5aac
3 changed files with 21 additions and 11 deletions

View File

@ -316,8 +316,8 @@ class _RemotePageState extends State<RemotePage>
];
if (!_ffi.canvasModel.cursorEmbeded) {
paints.add(Obx(() => Visibility(
visible: _showRemoteCursor.isTrue && _remoteCursorMoved.isTrue,
paints.add(Obx(() => Offstage(
offstage: _showRemoteCursor.isFalse || _remoteCursorMoved.isFalse,
child: CursorPaint(
id: widget.id,
zoomCursor: _zoomCursor,
@ -617,7 +617,8 @@ class CursorPaint extends StatelessWidget {
double cx = c.x;
double cy = c.y;
if (c.scrollStyle == ScrollStyle.scrollbar) {
if (c.viewStyle.style == kRemoteViewStyleOriginal &&
c.scrollStyle == ScrollStyle.scrollbar) {
final d = c.parent.target!.ffiModel.display;
final imageWidth = d.width * c.scale;
final imageHeight = d.height * c.scale;
@ -626,7 +627,7 @@ class CursorPaint extends StatelessWidget {
}
double x = (m.x - hotx) * c.scale + cx;
double y = (m.y - hoty) * c.scale + cx;
double y = (m.y - hoty) * c.scale + cy;
double scale = 1.0;
if (zoomCursor.isTrue) {
x = m.x - hotx + cx / c.scale;

View File

@ -365,8 +365,6 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
RxInt display = CurrentDisplayState.find(widget.id);
if (display.value != i) {
bind.sessionSwitchDisplay(id: widget.id, value: i);
pi.currentDisplay = i;
display.value = i;
}
},
)

View File

@ -141,7 +141,7 @@ class FfiModel with ChangeNotifier {
setConnectionType(
peerId, evt['secure'] == 'true', evt['direct'] == 'true');
} else if (name == 'switch_display') {
handleSwitchDisplay(evt);
handleSwitchDisplay(evt, peerId);
} else if (name == 'cursor_data') {
await parent.target?.cursorModel.updateCursorData(evt);
} else if (name == 'cursor_id') {
@ -214,7 +214,7 @@ class FfiModel with ChangeNotifier {
}
}
handleSwitchDisplay(Map<String, dynamic> evt) {
handleSwitchDisplay(Map<String, dynamic> evt, String peerId) {
final oldOrientation = _display.width > _display.height;
var old = _pi.currentDisplay;
_pi.currentDisplay = int.parse(evt['display']);
@ -227,6 +227,12 @@ class FfiModel with ChangeNotifier {
parent.target?.cursorModel.updateDisplayOrigin(_display.x, _display.y);
}
try {
CurrentDisplayState.find(peerId).value = _pi.currentDisplay;
} catch (e) {
//
}
// remote is mobile, and orientation changed
if ((_display.width > _display.height) != oldOrientation) {
gFFI.canvasModel.updateViewStyle();
@ -506,7 +512,7 @@ class ViewStyle {
double get scale {
double s = 1.0;
if (style == 'adaptive') {
if (style == kRemoteViewStyleAdaptive) {
final s1 = width / displayWidth;
final s2 = height / displayHeight;
s = s1 < s2 ? s1 : s2;
@ -543,6 +549,9 @@ class CanvasModel with ChangeNotifier {
double get y => _y;
double get scale => _scale;
ScrollStyle get scrollStyle => _scrollStyle;
ViewStyle get viewStyle => _lastViewStyle;
_resetScroll() => setScrollPercent(0.0, 0.0);
setScrollPercent(double x, double y) {
_scrollX = x;
@ -571,6 +580,9 @@ class CanvasModel with ChangeNotifier {
if (_lastViewStyle == viewStyle) {
return;
}
if (_lastViewStyle.style != viewStyle.style) {
_resetScroll();
}
_lastViewStyle = viewStyle;
_scale = viewStyle.scale;
_x = (sizeWidth - displayWidth * _scale) / 2;
@ -582,8 +594,7 @@ class CanvasModel with ChangeNotifier {
final style = await bind.sessionGetScrollStyle(id: id);
if (style == kRemoteScrollStyleBar) {
_scrollStyle = ScrollStyle.scrollbar;
_scrollX = 0.0;
_scrollY = 0.0;
_resetScroll();
} else {
_scrollStyle = ScrollStyle.scrollauto;
}