diff --git a/src/main/desktop-pick.ts b/src/main/desktop-pick.ts index e3fb8a6..769bfb6 100644 --- a/src/main/desktop-pick.ts +++ b/src/main/desktop-pick.ts @@ -717,16 +717,19 @@ function regionOverlayHtml(): string { export async function pickScreenRegion(): Promise<{ x: number; y: number; width: number; height: number; scale: number; imagePath: string }> { const appWindows = BrowserWindow.getAllWindows().filter(w => !w.isDestroyed()); for (const w of appWindows) w.minimize(); - // 每个显示器各开一个覆盖层, 支持在任意副屏上框选 + // 每个显示器各开一个覆盖层, 支持在任意副屏上框选。 + // 注意: 构造参数里直接传副屏 bounds 在混合 DPI 下会按主屏 DPI 虚拟化导致尺寸不对, + // 必须先创建(隐藏)再 setBounds, 此时窗口已关联副屏 DPI const displays = screen.getAllDisplays(); const url = "data:text/html;charset=utf-8," + encodeURIComponent(regionOverlayHtml()); const overlays = displays.map(display => { const win = new BrowserWindow({ - x: display.bounds.x, y: display.bounds.y, width: display.bounds.width, height: display.bounds.height, + show: false, frame: false, transparent: true, alwaysOnTop: true, skipTaskbar: true, resizable: false, movable: false, webPreferences: { contextIsolation: true, nodeIntegration: false, sandbox: true } }); void win.loadURL(url); + win.setBounds({ x: display.bounds.x, y: display.bounds.y, width: display.bounds.width, height: display.bounds.height }); win.show(); return { win, display }; });