fix: 副屏框选覆盖层尺寸不对\n\n- 混合 DPI 多显示器下, BrowserWindow 构造参数直接传副屏 bounds 会按主屏 DPI 虚拟化, 导致副屏覆盖层盖不满或超出\n- 改为先创建隐藏窗口再 setBounds 副屏 bounds, 此时窗口已关联副屏 DPI

This commit is contained in:
yu 2026-11-03 09:39:58 +08:00
parent b40c15d5b2
commit 0641c5b91b

View File

@ -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 };
});