Merge pull request #3429 from fufesou/refact/canvas_pos_size

refact canvas position and size
This commit is contained in:
RustDesk 2023-02-28 15:18:48 +08:00 committed by GitHub
commit 69add96f6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 20 deletions

View File

@ -953,12 +953,13 @@ class _DisplayMenuState extends State<_DisplayMenu> {
final canvasModel = widget.ffi.canvasModel; final canvasModel = widget.ffi.canvasModel;
final width = (canvasModel.getDisplayWidth() * canvasModel.scale + final width = (canvasModel.getDisplayWidth() * canvasModel.scale +
canvasModel.windowBorderWidth * 2) * CanvasModel.leftToEdge +
CanvasModel.rightToEdge) *
scale + scale +
magicWidth; magicWidth;
final height = (canvasModel.getDisplayHeight() * canvasModel.scale + final height = (canvasModel.getDisplayHeight() * canvasModel.scale +
canvasModel.tabBarHeight + CanvasModel.topToEdge +
canvasModel.windowBorderWidth * 2) * CanvasModel.bottomToEdge) *
scale + scale +
magicHeight; magicHeight;
double left = wndRect.left + (wndRect.width - width) / 2; double left = wndRect.left + (wndRect.width - width) / 2;
@ -1027,10 +1028,10 @@ class _DisplayMenuState extends State<_DisplayMenu> {
final canvasModel = widget.ffi.canvasModel; final canvasModel = widget.ffi.canvasModel;
final displayWidth = canvasModel.getDisplayWidth(); final displayWidth = canvasModel.getDisplayWidth();
final displayHeight = canvasModel.getDisplayHeight(); final displayHeight = canvasModel.getDisplayHeight();
final requiredWidth = displayWidth + final requiredWidth =
(canvasModel.tabBarHeight + canvasModel.windowBorderWidth * 2); CanvasModel.leftToEdge + displayWidth + CanvasModel.rightToEdge;
final requiredHeight = displayHeight + final requiredHeight =
(canvasModel.tabBarHeight + canvasModel.windowBorderWidth * 2); CanvasModel.topToEdge + displayHeight + CanvasModel.bottomToEdge;
return selfWidth > (requiredWidth * scale) && return selfWidth > (requiredWidth * scale) &&
selfHeight > (requiredHeight * scale); selfHeight > (requiredHeight * scale);
} }

View File

@ -459,8 +459,8 @@ class InputModel {
} }
evt['type'] = type; evt['type'] = type;
if (isDesktop) { if (isDesktop) {
y = y - stateGlobal.tabBarHeight - stateGlobal.windowBorderWidth.value; y -= CanvasModel.topToEdge;
x -= stateGlobal.windowBorderWidth.value; x -= CanvasModel.leftToEdge;
} }
final canvasModel = parent.target!.canvasModel; final canvasModel = parent.target!.canvasModel;
final nearThr = 3; final nearThr = 3;

View File

@ -727,19 +727,21 @@ class CanvasModel with ChangeNotifier {
double get scrollX => _scrollX; double get scrollX => _scrollX;
double get scrollY => _scrollY; double get scrollY => _scrollY;
static double get leftToEdge =>
windowBorderWidth + kDragToResizeAreaPadding.left;
static double get rightToEdge =>
windowBorderWidth + kDragToResizeAreaPadding.right;
static double get topToEdge =>
tabBarHeight + windowBorderWidth + kDragToResizeAreaPadding.top;
static double get bottomToEdge =>
windowBorderWidth + kDragToResizeAreaPadding.bottom;
updateViewStyle() async { updateViewStyle() async {
Size getSize() { Size getSize() {
final size = MediaQueryData.fromWindow(ui.window).size; final size = MediaQueryData.fromWindow(ui.window).size;
// If minimized, w or h may be negative here. // If minimized, w or h may be negative here.
double w = size.width - double w = size.width - leftToEdge - rightToEdge;
windowBorderWidth * 2 - double h = size.height - topToEdge - bottomToEdge;
kDragToResizeAreaPadding.left -
kDragToResizeAreaPadding.right;
double h = size.height -
tabBarHeight -
windowBorderWidth * 2 -
kDragToResizeAreaPadding.top -
kDragToResizeAreaPadding.bottom;
return Size(w < 0 ? 0 : w, h < 0 ? 0 : h); return Size(w < 0 ? 0 : w, h < 0 ? 0 : h);
} }
@ -813,8 +815,8 @@ class CanvasModel with ChangeNotifier {
return parent.target?.ffiModel.display.height ?? defaultHeight; return parent.target?.ffiModel.display.height ?? defaultHeight;
} }
double get windowBorderWidth => stateGlobal.windowBorderWidth.value; static double get windowBorderWidth => stateGlobal.windowBorderWidth.value;
double get tabBarHeight => stateGlobal.tabBarHeight; static double get tabBarHeight => stateGlobal.tabBarHeight;
moveDesktopMouse(double x, double y) { moveDesktopMouse(double x, double y) {
if (size.width == 0 || size.height == 0) { if (size.width == 0 || size.height == 0) {