Skip to content

Commit 1e332fe

Browse files
Caldisclaude
andcommitted
fix: remove maximize border artifact on Windows frameless window
Remove the body padding compensation hack that was causing a visible white border when maximized. Electron 28 handles WM_NCCALCSIZE internally, making the manual offset unnecessary. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 41682c6 commit 1e332fe

3 files changed

Lines changed: 10 additions & 23 deletions

File tree

src/main/index.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import os from 'os';
88
import path from 'path';
99
import type { OpenDialogOptions, SaveDialogOptions } from 'electron';
10-
import { app, BrowserWindow, ipcMain, dialog, shell, screen } from 'electron';
10+
import { app, BrowserWindow, ipcMain, dialog, shell } from 'electron';
1111
import { autoUpdater } from 'electron-updater';
1212
import MenuBuilder from './menu';
1313
import mainI18n from './i18n';
@@ -111,6 +111,7 @@ if (!gotLock) {
111111
hasShadow: true,
112112
// 窗口背景透明 (在非启用AERO的Win机器上会有窗口冻结的BUG
113113
transparent: false,
114+
backgroundColor: '#18191b',
114115
// 无边框窗口
115116
frame: platform === 'darwin',
116117
// OSX下, 窗口按钮内置
@@ -160,17 +161,10 @@ if (!gotLock) {
160161

161162
// Forward maximize/unmaximize events to renderer (for title bar button sync)
162163
mainWindow.on('maximize', () => {
163-
// Detect the invisible border size (window extends beyond screen when maximized)
164-
let border = 0;
165-
if (mainWindow) {
166-
const bounds = mainWindow.getBounds();
167-
const display = screen.getDisplayMatching(bounds);
168-
border = Math.max(0, display.workArea.x - bounds.x);
169-
}
170-
mainWindow?.webContents.send('window-maximized-change', true, border);
164+
mainWindow?.webContents.send('window-maximized-change', true);
171165
});
172166
mainWindow.on('unmaximize', () => {
173-
mainWindow?.webContents.send('window-maximized-change', false, 0);
167+
mainWindow?.webContents.send('window-maximized-change', false);
174168
});
175169

176170
// ── Close guard ────────────────────────────────────────────

src/renderer/components/TitleBar/button/index.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,26 @@ import useAppStore from '../../../store';
66
// Electron API (via preload contextBridge)
77
const { electronAPI } = window;
88

9-
/** Apply or remove maximized-state styles on body/root */
10-
function applyMaximizedStyles(isMaximized: boolean, border: number) {
11-
const body = document.querySelector('body')!;
9+
/** Apply or remove maximized-state styles on root */
10+
function applyMaximizedStyles(isMaximized: boolean) {
1211
const root = document.querySelector<HTMLElement>('#root')!;
1312
if (isMaximized) {
14-
// Add padding to compensate for window extending beyond screen edges
15-
body.style.padding = border > 0 ? `${border}px` : '0';
1613
root.style.borderRadius = '0';
1714
} else {
18-
body.style.removeProperty('padding');
1915
root.style.removeProperty('border-radius');
2016
}
2117
}
2218

2319
function TitleBarButtonGroup() {
2420
const [maximized, setMaximized] = useState(() => electronAPI.windowIsMaximized());
25-
const [border, setBorder] = useState(0);
2621
const [pinned, setPinned] = useState(false);
2722
const sideEditorVisible = useAppStore((state: any) => state.sideEditorVisible);
2823

2924
// Listen to ALL maximize/unmaximize events (button click, double-click title bar, Win+Up, etc.)
3025
useEffect(() => {
31-
return electronAPI.onMaximizedChange((isMaximized, borderSize) => {
26+
return electronAPI.onMaximizedChange((isMaximized) => {
3227
setMaximized(isMaximized);
33-
setBorder(borderSize);
34-
applyMaximizedStyles(isMaximized, borderSize);
28+
applyMaximizedStyles(isMaximized);
3529
});
3630
}, []);
3731

@@ -68,8 +62,7 @@ function TitleBarButtonGroup() {
6862
} as const;
6963

7064
// Center buttons in the 58px safe area: (58-30)/2 = 14px from content edge
71-
// When maximized, add border offset to compensate for window oversize
72-
const offset = { top: border + 14, right: border + 14 };
65+
const offset = { top: 14, right: 14 };
7366

7467
return (
7568
<div

src/renderer/index.global.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ html, body {
1010
}
1111

1212
body {
13-
background-color: rgba(0,0,0,0);
13+
background-color: hsl(var(--surface));
1414
overflow: hidden;
1515
}
1616
#root {

0 commit comments

Comments
 (0)