Merge pull request #2745 from fufesou/fix/scale_original_ignore_dpi

scale original ignore dpi
This commit is contained in:
RustDesk 2023-01-06 21:00:40 +08:00 committed by GitHub
commit 15512070fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 143 additions and 124 deletions

View File

@ -100,6 +100,8 @@ const kRemoteImageQualityLow = 'low';
/// [kRemoteImageQualityCustom] Custom image quality. /// [kRemoteImageQualityCustom] Custom image quality.
const kRemoteImageQualityCustom = 'custom'; const kRemoteImageQualityCustom = 'custom';
const kIgnoreDpi = true;
/// flutter/packages/flutter/lib/src/services/keyboard_key.dart -> _keyLabels /// flutter/packages/flutter/lib/src/services/keyboard_key.dart -> _keyLabels
/// see [LogicalKeyboardKey.keyLabel] /// see [LogicalKeyboardKey.keyLabel]
const Map<int, String> logicalKeyMap = <int, String>{ const Map<int, String> logicalKeyMap = <int, String>{

View File

@ -402,35 +402,36 @@ class _ImagePaintState extends State<ImagePaint> {
onHover: (evt) {}, onHover: (evt) {},
child: child)); child: child));
if (c.scrollStyle == ScrollStyle.scrollbar) { if (c.imageOverflow.isTrue && c.scrollStyle == ScrollStyle.scrollbar) {
final imageWidth = c.getDisplayWidth() * s; final imageWidth = c.getDisplayWidth() * s;
final imageHeight = c.getDisplayHeight() * s; final imageHeight = c.getDisplayHeight() * s;
final imageSize = Size(imageWidth, imageHeight);
final imageWidget = CustomPaint( final imageWidget = CustomPaint(
size: Size(imageWidth, imageHeight), size: imageSize,
painter: ImagePainter(image: m.image, x: 0, y: 0, scale: s), painter: ImagePainter(image: m.image, x: 0, y: 0, scale: s),
); );
return NotificationListener<ScrollNotification>( return NotificationListener<ScrollNotification>(
onNotification: (notification) { onNotification: (notification) {
final percentX = _horizontal.hasClients final percentX = _horizontal.hasClients
? _horizontal.position.extentBefore / ? _horizontal.position.extentBefore /
(_horizontal.position.extentBefore + (_horizontal.position.extentBefore +
_horizontal.position.extentInside + _horizontal.position.extentInside +
_horizontal.position.extentAfter) _horizontal.position.extentAfter)
: 0.0; : 0.0;
final percentY = _vertical.hasClients final percentY = _vertical.hasClients
? _vertical.position.extentBefore / ? _vertical.position.extentBefore /
(_vertical.position.extentBefore + (_vertical.position.extentBefore +
_vertical.position.extentInside + _vertical.position.extentInside +
_vertical.position.extentAfter) _vertical.position.extentAfter)
: 0.0; : 0.0;
c.setScrollPercent(percentX, percentY); c.setScrollPercent(percentX, percentY);
return false; return false;
}, },
child: mouseRegion( child: mouseRegion(
child: _buildCrossScrollbar(context, _buildListener(imageWidget), child: Obx(() => _buildCrossScrollbarFromLayout(
Size(imageWidth, imageHeight))), context, _buildListener(imageWidget), c.size, imageSize)),
); ));
} else { } else {
final imageWidget = CustomPaint( final imageWidget = CustomPaint(
size: Size(c.size.width, c.size.height), size: Size(c.size.width, c.size.height),
@ -565,24 +566,6 @@ class _ImagePaintState extends State<ImagePaint> {
return widget; return widget;
} }
Widget _buildCrossScrollbar(BuildContext context, Widget child, Size size) {
var layoutSize = MediaQuery.of(context).size;
// If minimized, w or h may be negative here.
final w = layoutSize.width - kWindowBorderWidth * 2;
final h =
layoutSize.height - kWindowBorderWidth * 2 - kDesktopRemoteTabBarHeight;
layoutSize = Size(
w < 0 ? 0 : w,
h < 0 ? 0 : h,
);
bool overflow =
layoutSize.width < size.width || layoutSize.height < size.height;
return overflow
? Obx(() =>
_buildCrossScrollbarFromLayout(context, child, layoutSize, size))
: _buildCrossScrollbarFromLayout(context, child, layoutSize, size);
}
Widget _buildListener(Widget child) { Widget _buildListener(Widget child) {
if (listenerBuilder != null) { if (listenerBuilder != null) {
return listenerBuilder!(child); return listenerBuilder!(child);

View File

@ -118,6 +118,15 @@ abstract class MenuEntryBase<T> {
this.enabled, this.enabled,
}); });
List<mod_menu.PopupMenuEntry<T>> build(BuildContext context, MenuConfig conf); List<mod_menu.PopupMenuEntry<T>> build(BuildContext context, MenuConfig conf);
enabledStyle(BuildContext context) => TextStyle(
color: Theme.of(context).textTheme.titleLarge?.color,
fontSize: MenuConfig.fontSize,
fontWeight: FontWeight.normal);
disabledStyle() => TextStyle(
color: Colors.grey,
fontSize: MenuConfig.fontSize,
fontWeight: FontWeight.normal);
} }
class MenuEntryDivider<T> extends MenuEntryBase<T> { class MenuEntryDivider<T> extends MenuEntryBase<T> {
@ -189,54 +198,76 @@ class MenuEntryRadios<T> extends MenuEntryBase<T> {
mod_menu.PopupMenuEntry<T> _buildMenuItem( mod_menu.PopupMenuEntry<T> _buildMenuItem(
BuildContext context, MenuConfig conf, MenuEntryRadioOption opt) { BuildContext context, MenuConfig conf, MenuEntryRadioOption opt) {
Widget getTextChild() {
final enabledTextChild = Text(
opt.text,
style: enabledStyle(context),
);
final disabledTextChild = Text(
opt.text,
style: disabledStyle(),
);
if (opt.enabled == null) {
return enabledTextChild;
} else {
return Obx(
() => opt.enabled!.isTrue ? enabledTextChild : disabledTextChild);
}
}
final child = Container(
padding: padding,
alignment: AlignmentDirectional.centerStart,
constraints:
BoxConstraints(minHeight: conf.height, maxHeight: conf.height),
child: Row(
children: [
getTextChild(),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Transform.scale(
scale: MenuConfig.iconScale,
child: Obx(() => opt.value == curOption.value
? IconButton(
padding:
const EdgeInsets.fromLTRB(8.0, 0.0, 8.0, 0.0),
hoverColor: Colors.transparent,
focusColor: Colors.transparent,
onPressed: () {},
icon: Icon(
Icons.check,
color: (opt.enabled ?? true.obs).isTrue
? conf.commonColor
: Colors.grey,
))
: const SizedBox.shrink()),
))),
],
),
);
onPressed() {
if (opt.dismissOnClicked && Navigator.canPop(context)) {
Navigator.pop(context);
}
setOption(opt.value);
}
return mod_menu.PopupMenuItem( return mod_menu.PopupMenuItem(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
height: conf.height, height: conf.height,
child: Container( child: Container(
width: conf.boxWidth, width: conf.boxWidth,
child: TextButton( child: opt.enabled == null
child: Container( ? TextButton(
padding: padding, child: child,
alignment: AlignmentDirectional.centerStart, onPressed: onPressed,
constraints: BoxConstraints( )
minHeight: conf.height, maxHeight: conf.height), : Obx(() => TextButton(
child: Row( child: child,
children: [ onPressed: opt.enabled!.isTrue ? onPressed : null,
Text( )),
opt.text, ),
style: TextStyle(
color: Theme.of(context).textTheme.titleLarge?.color,
fontSize: MenuConfig.fontSize,
fontWeight: FontWeight.normal),
),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Transform.scale(
scale: MenuConfig.iconScale,
child: Obx(() => opt.value == curOption.value
? IconButton(
padding: const EdgeInsets.fromLTRB(
8.0, 0.0, 8.0, 0.0),
hoverColor: Colors.transparent,
focusColor: Colors.transparent,
onPressed: () {},
icon: Icon(
Icons.check,
color: conf.commonColor,
))
: const SizedBox.shrink()),
))),
],
),
),
onPressed: () {
if (opt.dismissOnClicked && Navigator.canPop(context)) {
Navigator.pop(context);
}
setOption(opt.value);
},
)),
); );
} }
@ -567,12 +598,9 @@ class MenuEntrySubMenu<T> extends MenuEntryBase<T> {
const SizedBox(width: MenuConfig.midPadding), const SizedBox(width: MenuConfig.midPadding),
Obx(() => Text( Obx(() => Text(
text, text,
style: TextStyle( style: super.enabled!.value
color: super.enabled!.value ? enabledStyle(context)
? Theme.of(context).textTheme.titleLarge?.color : disabledStyle(),
: Colors.grey,
fontSize: MenuConfig.fontSize,
fontWeight: FontWeight.normal),
)), )),
Expanded( Expanded(
child: Align( child: Align(
@ -605,14 +633,6 @@ class MenuEntryButton<T> extends MenuEntryBase<T> {
); );
Widget _buildChild(BuildContext context, MenuConfig conf) { Widget _buildChild(BuildContext context, MenuConfig conf) {
final enabledStyle = TextStyle(
color: Theme.of(context).textTheme.titleLarge?.color,
fontSize: MenuConfig.fontSize,
fontWeight: FontWeight.normal);
const disabledStyle = TextStyle(
color: Colors.grey,
fontSize: MenuConfig.fontSize,
fontWeight: FontWeight.normal);
super.enabled ??= true.obs; super.enabled ??= true.obs;
return Obx(() => Container( return Obx(() => Container(
width: conf.boxWidth, width: conf.boxWidth,
@ -631,7 +651,7 @@ class MenuEntryButton<T> extends MenuEntryBase<T> {
constraints: constraints:
BoxConstraints(minHeight: conf.height, maxHeight: conf.height), BoxConstraints(minHeight: conf.height, maxHeight: conf.height),
child: childBuilder( child: childBuilder(
super.enabled!.value ? enabledStyle : disabledStyle), super.enabled!.value ? enabledStyle(context) : disabledStyle()),
), ),
))); )));
} }

View File

@ -699,7 +699,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
if (_screen == null) { if (_screen == null) {
return false; return false;
} }
double scale = _screen!.scaleFactor; final scale = kIgnoreDpi ? 1.0 : _screen!.scaleFactor;
double selfWidth = _screen!.visibleFrame.width; double selfWidth = _screen!.visibleFrame.width;
double selfHeight = _screen!.visibleFrame.height; double selfHeight = _screen!.visibleFrame.height;
if (isFullscreen) { if (isFullscreen) {
@ -936,11 +936,13 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
text: translate('ScrollAuto'), text: translate('ScrollAuto'),
value: kRemoteScrollStyleAuto, value: kRemoteScrollStyleAuto,
dismissOnClicked: true, dismissOnClicked: true,
enabled: widget.ffi.canvasModel.imageOverflow,
), ),
MenuEntryRadioOption( MenuEntryRadioOption(
text: translate('Scrollbar'), text: translate('Scrollbar'),
value: kRemoteScrollStyleBar, value: kRemoteScrollStyleBar,
dismissOnClicked: true, dismissOnClicked: true,
enabled: widget.ffi.canvasModel.imageOverflow,
), ),
], ],
curOptionGetter: () async => curOptionGetter: () async =>
@ -986,15 +988,17 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
wndRect.bottom - wndRect.top - mediaSize.height * scale; wndRect.bottom - wndRect.top - mediaSize.height * scale;
final canvasModel = widget.ffi.canvasModel; final canvasModel = widget.ffi.canvasModel;
final width = (canvasModel.getDisplayWidth() + final width =
canvasModel.windowBorderWidth * 2) * (canvasModel.getDisplayWidth() * canvasModel.scale +
scale + canvasModel.windowBorderWidth * 2) *
magicWidth; scale +
final height = (canvasModel.getDisplayHeight() + magicWidth;
canvasModel.tabBarHeight + final height =
canvasModel.windowBorderWidth * 2) * (canvasModel.getDisplayHeight() * canvasModel.scale +
scale + canvasModel.tabBarHeight +
magicHeight; canvasModel.windowBorderWidth * 2) *
scale +
magicHeight;
double left = wndRect.left + (wndRect.width - width) / 2; double left = wndRect.left + (wndRect.width - width) / 2;
double top = wndRect.top + (wndRect.height - height) / 2; double top = wndRect.top + (wndRect.height - height) / 2;
@ -1198,7 +1202,6 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
}, },
optionSetter: (String oldValue, String newValue) async { optionSetter: (String oldValue, String newValue) async {
await bind.sessionSetKeyboardMode(id: widget.id, value: newValue); await bind.sessionSetKeyboardMode(id: widget.id, value: newValue);
widget.ffi.canvasModel.updateViewStyle();
}, },
) )
]; ];

View File

@ -22,6 +22,7 @@ import 'package:tuple/tuple.dart';
import 'package:image/image.dart' as img2; import 'package:image/image.dart' as img2;
import 'package:flutter_custom_cursor/cursor_manager.dart'; import 'package:flutter_custom_cursor/cursor_manager.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import '../common.dart'; import '../common.dart';
import '../common/shared_state.dart'; import '../common/shared_state.dart';
@ -528,6 +529,7 @@ class CanvasModel with ChangeNotifier {
double _y = 0; double _y = 0;
// image scale // image scale
double _scale = 1.0; double _scale = 1.0;
Size _size = Size.zero;
// the tabbar over the image // the tabbar over the image
// double tabBarHeight = 0.0; // double tabBarHeight = 0.0;
// the window border's width // the window border's width
@ -541,6 +543,8 @@ class CanvasModel with ChangeNotifier {
ScrollStyle _scrollStyle = ScrollStyle.scrollauto; ScrollStyle _scrollStyle = ScrollStyle.scrollauto;
ViewStyle _lastViewStyle = ViewStyle(); ViewStyle _lastViewStyle = ViewStyle();
final _imageOverflow = false.obs;
WeakReference<FFI> parent; WeakReference<FFI> parent;
CanvasModel(this.parent); CanvasModel(this.parent);
@ -548,8 +552,10 @@ class CanvasModel with ChangeNotifier {
double get x => _x; double get x => _x;
double get y => _y; double get y => _y;
double get scale => _scale; double get scale => _scale;
Size get size => _size;
ScrollStyle get scrollStyle => _scrollStyle; ScrollStyle get scrollStyle => _scrollStyle;
ViewStyle get viewStyle => _lastViewStyle; ViewStyle get viewStyle => _lastViewStyle;
RxBool get imageOverflow => _imageOverflow;
_resetScroll() => setScrollPercent(0.0, 0.0); _resetScroll() => setScrollPercent(0.0, 0.0);
@ -562,18 +568,26 @@ class CanvasModel with ChangeNotifier {
double get scrollY => _scrollY; double get scrollY => _scrollY;
updateViewStyle() async { updateViewStyle() async {
Size getSize() {
final size = MediaQueryData.fromWindow(ui.window).size;
// If minimized, w or h may be negative here.
double w = size.width - windowBorderWidth * 2;
double h = size.height - tabBarHeight - windowBorderWidth * 2;
return Size(w < 0 ? 0 : w, h < 0 ? 0 : h);
}
final style = await bind.sessionGetViewStyle(id: id); final style = await bind.sessionGetViewStyle(id: id);
if (style == null) { if (style == null) {
return; return;
} }
final sizeWidth = size.width;
final sizeHeight = size.height; _size = getSize();
final displayWidth = getDisplayWidth(); final displayWidth = getDisplayWidth();
final displayHeight = getDisplayHeight(); final displayHeight = getDisplayHeight();
final viewStyle = ViewStyle( final viewStyle = ViewStyle(
style: style, style: style,
width: sizeWidth, width: size.width,
height: sizeHeight, height: size.height,
displayWidth: displayWidth, displayWidth: displayWidth,
displayHeight: displayHeight, displayHeight: displayHeight,
); );
@ -585,8 +599,13 @@ class CanvasModel with ChangeNotifier {
} }
_lastViewStyle = viewStyle; _lastViewStyle = viewStyle;
_scale = viewStyle.scale; _scale = viewStyle.scale;
_x = (sizeWidth - displayWidth * _scale) / 2;
_y = (sizeHeight - displayHeight * _scale) / 2; if (kIgnoreDpi && style == kRemoteViewStyleOriginal) {
_scale = 1.0 / ui.window.devicePixelRatio;
}
_x = (size.width - displayWidth * _scale) / 2;
_y = (size.height - displayHeight * _scale) / 2;
_imageOverflow.value = _x < 0 || y < 0;
notifyListeners(); notifyListeners();
} }
@ -628,14 +647,6 @@ class CanvasModel with ChangeNotifier {
double get windowBorderWidth => stateGlobal.windowBorderWidth.value; double get windowBorderWidth => stateGlobal.windowBorderWidth.value;
double get tabBarHeight => stateGlobal.tabBarHeight; double get tabBarHeight => stateGlobal.tabBarHeight;
Size get size {
final size = MediaQueryData.fromWindow(ui.window).size;
// If minimized, w or h may be negative here.
double w = size.width - windowBorderWidth * 2;
double h = size.height - tabBarHeight - windowBorderWidth * 2;
return Size(w < 0 ? 0 : w, h < 0 ? 0 : h);
}
moveDesktopMouse(double x, double y) { moveDesktopMouse(double x, double y) {
// On mobile platforms, move the canvas with the cursor. // On mobile platforms, move the canvas with the cursor.
final dw = getDisplayWidth() * _scale; final dw = getDisplayWidth() * _scale;