Skip to content

Commit

Permalink
Merge branch 'master' of github.com-rustdesk:rustdesk/rustdesk
Browse files Browse the repository at this point in the history
  • Loading branch information
rustdesk committed Dec 4, 2023
2 parents f0d9dee + 3a82bdd commit 7934fa2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 27 deletions.
56 changes: 29 additions & 27 deletions flutter/lib/desktop/pages/remote_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,6 @@ class ImagePaint extends StatefulWidget {

class _ImagePaintState extends State<ImagePaint> {
bool _lastRemoteCursorMoved = false;
final ScrollController _horizontal = ScrollController();
final ScrollController _vertical = ScrollController();

String get id => widget.id;
RxBool get zoomCursor => widget.zoomCursor;
Expand Down Expand Up @@ -610,24 +608,18 @@ class _ImagePaintState extends State<ImagePaint> {
: _buildScrollbarNonTextureRender(m, paintSize, s);
return NotificationListener<ScrollNotification>(
onNotification: (notification) {
final percentX = _horizontal.hasClients
? _horizontal.position.extentBefore /
(_horizontal.position.extentBefore +
_horizontal.position.extentInside +
_horizontal.position.extentAfter)
: 0.0;
final percentY = _vertical.hasClients
? _vertical.position.extentBefore /
(_vertical.position.extentBefore +
_vertical.position.extentInside +
_vertical.position.extentAfter)
: 0.0;
c.setScrollPercent(percentX, percentY);
c.updateScrollPercent();
return false;
},
child: mouseRegion(
child: Obx(() => _buildCrossScrollbarFromLayout(
context, _buildListener(paintWidget), c.size, paintSize)),
context,
_buildListener(paintWidget),
c.size,
paintSize,
c.scrollHorizontal,
c.scrollVertical,
)),
));
} else {
if (c.size.width > 0 && c.size.height > 0) {
Expand Down Expand Up @@ -740,7 +732,13 @@ class _ImagePaintState extends State<ImagePaint> {
}

Widget _buildCrossScrollbarFromLayout(
BuildContext context, Widget child, Size layoutSize, Size size) {
BuildContext context,
Widget child,
Size layoutSize,
Size size,
ScrollController horizontal,
ScrollController vertical,
) {
final scrollConfig = CustomMouseWheelScrollConfig(
scrollDuration: kDefaultScrollDuration,
scrollCurve: Curves.linearToEaseOut,
Expand All @@ -752,7 +750,7 @@ class _ImagePaintState extends State<ImagePaint> {
widget = ScrollConfiguration(
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
child: SingleChildScrollView(
controller: _horizontal,
controller: horizontal,
scrollDirection: Axis.horizontal,
physics: cursorOverImage.isTrue
? const NeverScrollableScrollPhysics()
Expand All @@ -774,7 +772,7 @@ class _ImagePaintState extends State<ImagePaint> {
widget = ScrollConfiguration(
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
child: SingleChildScrollView(
controller: _vertical,
controller: vertical,
physics: cursorOverImage.isTrue
? const NeverScrollableScrollPhysics()
: null,
Expand All @@ -793,13 +791,13 @@ class _ImagePaintState extends State<ImagePaint> {
}
if (layoutSize.width < size.width) {
widget = ImprovedScrolling(
scrollController: _horizontal,
scrollController: horizontal,
enableCustomMouseWheelScrolling: cursorOverImage.isFalse,
customMouseWheelScrollConfig: scrollConfig,
child: RawScrollbar(
thickness: kScrollbarThickness,
thumbColor: Colors.grey,
controller: _horizontal,
controller: horizontal,
thumbVisibility: false,
trackVisibility: false,
notificationPredicate: layoutSize.height < size.height
Expand All @@ -811,13 +809,13 @@ class _ImagePaintState extends State<ImagePaint> {
}
if (layoutSize.height < size.height) {
widget = ImprovedScrolling(
scrollController: _vertical,
scrollController: vertical,
enableCustomMouseWheelScrolling: cursorOverImage.isFalse,
customMouseWheelScrollConfig: scrollConfig,
child: RawScrollbar(
thickness: kScrollbarThickness,
thumbColor: Colors.grey,
controller: _vertical,
controller: vertical,
thumbVisibility: false,
trackVisibility: false,
child: widget,
Expand Down Expand Up @@ -874,10 +872,14 @@ class CursorPaint extends StatelessWidget {
debugPrint('unreachable! The displays rect is null.');
return Container();
}
final imageWidth = rect.width * c.scale;
final imageHeight = rect.height * c.scale;
cx = -imageWidth * c.scrollX;
cy = -imageHeight * c.scrollY;
if (cx < 0) {
final imageWidth = rect.width * c.scale;
cx = -imageWidth * c.scrollX;
}
if (cy < 0) {
final imageHeight = rect.height * c.scale;
cy = -imageHeight * c.scrollY;
}
}

double x = (m.x - hotx) * c.scale + cx;
Expand Down
22 changes: 22 additions & 0 deletions flutter/lib/models/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,9 @@ class CanvasModel with ChangeNotifier {
ScrollStyle _scrollStyle = ScrollStyle.scrollauto;
ViewStyle _lastViewStyle = ViewStyle.defaultViewStyle();

final ScrollController _horizontal = ScrollController();
final ScrollController _vertical = ScrollController();

final _imageOverflow = false.obs;

WeakReference<FFI> parent;
Expand All @@ -1229,6 +1232,8 @@ class CanvasModel with ChangeNotifier {
_scrollY = y;
}

ScrollController get scrollHorizontal => _horizontal;
ScrollController get scrollVertical => _vertical;
double get scrollX => _scrollX;
double get scrollY => _scrollY;

Expand Down Expand Up @@ -1289,6 +1294,7 @@ class CanvasModel with ChangeNotifier {
if (refreshMousePos) {
parent.target?.inputModel.refreshMousePos();
}
updateScrollPercent();
}

updateScrollStyle() async {
Expand Down Expand Up @@ -1424,6 +1430,22 @@ class CanvasModel with ChangeNotifier {
_scale = 1.0;
if (notify) notifyListeners();
}

updateScrollPercent() {
final percentX = _horizontal.hasClients
? _horizontal.position.extentBefore /
(_horizontal.position.extentBefore +
_horizontal.position.extentInside +
_horizontal.position.extentAfter)
: 0.0;
final percentY = _vertical.hasClients
? _vertical.position.extentBefore /
(_vertical.position.extentBefore +
_vertical.position.extentInside +
_vertical.position.extentAfter)
: 0.0;
setScrollPercent(percentX, percentY);
}
}

// data for cursor
Expand Down

0 comments on commit 7934fa2

Please sign in to comment.