From 5eb07118b04121c0957ec525e5269416c80509f6 Mon Sep 17 00:00:00 2001 From: layyback <505187749@qq.com> Date: Sat, 1 Apr 2023 23:08:50 +0800 Subject: [PATCH] =?UTF-8?q?:hammer:=20=E9=80=82=E9=85=8Dwindows=20125%?= =?UTF-8?q?=E4=B8=8B=E7=AA=97=E5=8F=A3=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/utils/dragWindow.ts | 10 +++++++++- src/main/common/api.ts | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/common/utils/dragWindow.ts b/src/common/utils/dragWindow.ts index bfc7cd0..785b8f7 100644 --- a/src/common/utils/dragWindow.ts +++ b/src/common/utils/dragWindow.ts @@ -4,12 +4,20 @@ const useDrag = () => { let animationId: number; let mouseX: number; let mouseY: number; + let clientWidth = 0; + let clientHeight = 0; let draggable = true; const onMouseDown = (e) => { draggable = true; mouseX = e.clientX; mouseY = e.clientY; + if (Math.abs(document.body.clientWidth - clientWidth) > 5) { + clientWidth = document.body.clientWidth; + } + if (Math.abs(document.body.clientHeight - clientHeight) > 5) { + clientHeight = document.body.clientHeight; + } document.addEventListener('mouseup', onMouseUp); animationId = requestAnimationFrame(moveWindow); }; @@ -23,7 +31,7 @@ const useDrag = () => { const moveWindow = () => { ipcRenderer.send('msg-trigger', { type: 'windowMoving', - data: { mouseX, mouseY }, + data: { mouseX, mouseY, width: clientWidth, height: clientHeight }, }); if (draggable) animationId = requestAnimationFrame(moveWindow); }; diff --git a/src/main/common/api.ts b/src/main/common/api.ts index 139e4ed..745dcaf 100644 --- a/src/main/common/api.ts +++ b/src/main/common/api.ts @@ -60,7 +60,7 @@ class API { const { x, y } = screen.getCursorScreenPoint(); const originWindow = this.getCurrentWindow(window, e); if (!originWindow) return; - originWindow.setBounds({ x: x - mouseX, y: y - mouseY }); + originWindow.setBounds({ x: x - mouseX, y: y - mouseY, width, height }); } public loadPlugin({ data: plugin }, window) {