Merge pull request #2684 from fufesou/fix/cursor_pos

fix remote cursor pos
This commit is contained in:
RustDesk 2022-12-30 16:16:23 +08:00 committed by GitHub
commit 385be9bff4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 11 deletions

View File

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

View File

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