From 0c2ae8ae5bf813c0df161ea5c0321f1560e93840 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 9 Nov 2024 16:39:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D'=E5=A4=B1=E5=8E=BB=E7=84=A6?= =?UTF-8?q?=E7=82=B9=E9=9A=90=E8=97=8F'=E6=9C=89=E6=97=B6=E6=97=A0?= =?UTF-8?q?=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/main/index.ts | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/electron/main/main/index.ts b/electron/main/main/index.ts index 6d41445..d71f5b4 100644 --- a/electron/main/main/index.ts +++ b/electron/main/main/index.ts @@ -215,6 +215,8 @@ function createMainWindow() { // 中间单击 showHideMouseWheelClick(); } + // 失去焦点隐藏 + onBlurHide(); } }); // 禁用标题栏右键 @@ -229,6 +231,49 @@ function createMainWindow() { }); } +/** + * 失去焦点隐藏 + */ +function onBlurHide() { + if ( + mainWindow.isVisible() && + global.setting.general.hideLoseFocus && + !global.setting.general.alwaysTop && + mainWindow.getChildWindows().length === 0 && + !global.mainWindowShowDialog && + !hasCursorPosWindow(mainWindow) + ) { + // 隐藏窗口 + hideMainWindow(); + } +} + +/** + * 判断鼠标是否在置顶的窗口范围内 + */ +function hasCursorPosWindow(window: BrowserWindow) { + if (window && !window.isDestroyed() && window.isVisible()) { + // 获取鼠标位置 + let point = screen.getCursorScreenPoint(); + // 窗口位置信息 + let bounds = window.getBounds(); + // 判断鼠标是否在窗口以外 + if ( + point.x < bounds.x || + point.x > bounds.x + bounds.width || + point.y < bounds.y || + point.y > bounds.y + bounds.height + ) { + // 窗口以外 + return false; + } else { + // 窗口以内 + return true; + } + } + return false; +} + /** * 显示窗口之前 * @param blurHide