ignore dpi while scale original

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-01-06 18:14:31 +08:00
parent f34c87bb17
commit 921b049e1e
4 changed files with 61 additions and 66 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,38 @@ class _ImagePaintState extends State<ImagePaint> {
onHover: (evt) {}, onHover: (evt) {},
child: child)); child: child));
if (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);
bool overflow =
c.size.width < imageSize.width || c.size.height < imageSize.height;
if (overflow && c.scrollStyle == ScrollStyle.scrollbar) {
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 +568,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

@ -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) {
@ -986,15 +986,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;

View File

@ -528,6 +528,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
@ -548,6 +549,7 @@ 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;
@ -562,18 +564,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 +595,12 @@ 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;
notifyListeners(); notifyListeners();
} }
@ -628,14 +642,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;