From 7282e876f4629bb33411e01e2b735cc7d84b34b1 Mon Sep 17 00:00:00 2001 From: alger Date: Sun, 19 Apr 2026 15:42:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(lyric-window):=20=E9=94=81=E5=AE=9A?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=90=AF=E5=8A=A8=E6=97=B6=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E7=A9=BF=E9=80=8F=E5=B9=B6=E7=A6=81=E7=94=A8=20resize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重启应用恢复锁定时, 主进程主动 setIgnoreMouseEvents(true), 修复鼠标无法穿透 - 锁定时 setResizable(false), 隐藏窗口边缘 resize 光标 - 由 set-lyric-lock-state IPC 统一驱动, 后续 polling 按位置精细纠正 --- src/main/lyric.ts | 10 +++++++--- src/renderer/views/lyric/index.vue | 2 -- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/lyric.ts b/src/main/lyric.ts index 61e9925..46b31e9 100644 --- a/src/main/lyric.ts +++ b/src/main/lyric.ts @@ -10,7 +10,7 @@ let isDragging = false; // 添加窗口大小变化防护 let originalSize = { width: 0, height: 0 }; -// 轮询只在 "锁定 + 窗口可见" 时启用:解锁状态下 DOM 事件足够,避免常驻 50ms 轮询 +// 鼠标位置轮询仅在"锁定 + 可见"时启用,解锁态下 DOM 事件已足够 let mousePresenceTimer: ReturnType | null = null; let lastMouseInside: boolean | null = null; let isLyricLocked = false; @@ -170,7 +170,6 @@ const createWin = () => { } }); - // 窗口可见性变化时同步轮询状态,避免最小化/隐藏时空转 lyricWindow.on('show', () => { isLyricWindowVisible = true; syncMousePresenceTracking(); @@ -285,9 +284,14 @@ export const loadLyricWindow = (ipcMain: IpcMain, mainWin: BrowserWindow): void } }); - // 渲染端同步锁定状态 → 决定主进程是否需要轮询鼠标位置 ipcMain.on('set-lyric-lock-state', (_, isLocked: boolean) => { isLyricLocked = isLocked; + if (lyricWindow && !lyricWindow.isDestroyed()) { + // 锁定时禁用 resize,避免鼠标移到边缘仍显示调整光标 + lyricWindow.setResizable(!isLocked); + // 设置初始穿透状态,后续 polling 会按实际位置纠正 + lyricWindow.setIgnoreMouseEvents(isLocked, { forward: true }); + } syncMousePresenceTracking(); }); diff --git a/src/renderer/views/lyric/index.vue b/src/renderer/views/lyric/index.vue index 56536fb..b189fb9 100644 --- a/src/renderer/views/lyric/index.vue +++ b/src/renderer/views/lyric/index.vue @@ -401,7 +401,6 @@ watch( // 锁定时自动关闭主题色面板 showThemeColorPanel.value = false; } - // 通知主进程,按需启停鼠标位置轮询 windowData.electron.ipcRenderer.send('set-lyric-lock-state', newLock); } ); @@ -797,7 +796,6 @@ onMounted(() => { } ); - // 同步初始锁定状态到主进程,使其按需启动鼠标位置轮询 windowData.electron.ipcRenderer.send('set-lyric-lock-state', lyricSetting.value.isLock); });