feat: enable Windows Control Overlay on Linux (#42681)
* feat: enable Windows Control Overlay on Linux Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * docs: update documentation for Linux WCO Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * fix: initial symbol painting Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * test: enable WCO tests for Linux Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * fix: add missing Layer include Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * chore: fix gn-check failure Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * fix: enable BrowserWindow.setTitleBarOverlay on Linux Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * test: fix test for maximize event on Linux Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * fix: geometry updating on BrowserWindow.setTitleBarOverlay Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * fix: crash when invalid titleBarStyle set Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * chore: clean up ordering and comments Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * Update docs/api/structures/base-window-options.md Co-authored-by: Erick Zhao <erick@hotmail.ca> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * feat: enable customizing symbolColor Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * docs: correct symbolColor reference Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * chore: update patches Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> * chore: remove Chrome-specific padding Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * fixup .patches after rebase --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
parent
287119d447
commit
0a73b80127
24 changed files with 1026 additions and 107 deletions
|
@ -2958,7 +2958,7 @@ describe('BrowserWindow module', () => {
|
|||
});
|
||||
});
|
||||
|
||||
ifdescribe(['win32', 'darwin'].includes(process.platform))('"titleBarStyle" option', () => {
|
||||
describe('"titleBarStyle" option', () => {
|
||||
const testWindowsOverlay = async (style: any) => {
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
|
@ -2997,10 +2997,12 @@ describe('BrowserWindow module', () => {
|
|||
const [, newOverlayRect] = await geometryChange;
|
||||
expect(newOverlayRect.width).to.equal(overlayRect.width + 400);
|
||||
};
|
||||
|
||||
afterEach(async () => {
|
||||
await closeAllWindows();
|
||||
ipcMain.removeAllListeners('geometrychange');
|
||||
});
|
||||
|
||||
it('creates browser window with hidden title bar', () => {
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
|
@ -3011,6 +3013,7 @@ describe('BrowserWindow module', () => {
|
|||
const contentSize = w.getContentSize();
|
||||
expect(contentSize).to.deep.equal([400, 400]);
|
||||
});
|
||||
|
||||
ifit(process.platform === 'darwin')('creates browser window with hidden inset title bar', () => {
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
|
@ -3021,14 +3024,16 @@ describe('BrowserWindow module', () => {
|
|||
const contentSize = w.getContentSize();
|
||||
expect(contentSize).to.deep.equal([400, 400]);
|
||||
});
|
||||
|
||||
it('sets Window Control Overlay with hidden title bar', async () => {
|
||||
await testWindowsOverlay('hidden');
|
||||
});
|
||||
|
||||
ifit(process.platform === 'darwin')('sets Window Control Overlay with hidden inset title bar', async () => {
|
||||
await testWindowsOverlay('hiddenInset');
|
||||
});
|
||||
|
||||
ifdescribe(process.platform === 'win32')('when an invalid titleBarStyle is initially set', () => {
|
||||
ifdescribe(process.platform !== 'darwin')('when an invalid titleBarStyle is initially set', () => {
|
||||
let w: BrowserWindow;
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -3064,7 +3069,7 @@ describe('BrowserWindow module', () => {
|
|||
});
|
||||
});
|
||||
|
||||
ifdescribe(['win32', 'darwin'].includes(process.platform))('"titleBarOverlay" option', () => {
|
||||
describe('"titleBarOverlay" option', () => {
|
||||
const testWindowsOverlayHeight = async (size: any) => {
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
|
@ -3079,6 +3084,7 @@ describe('BrowserWindow module', () => {
|
|||
height: size
|
||||
}
|
||||
});
|
||||
|
||||
const overlayHTML = path.join(__dirname, 'fixtures', 'pages', 'overlay.html');
|
||||
if (process.platform === 'darwin') {
|
||||
await w.loadFile(overlayHTML);
|
||||
|
@ -3087,48 +3093,52 @@ describe('BrowserWindow module', () => {
|
|||
await w.loadFile(overlayHTML);
|
||||
await overlayReady;
|
||||
}
|
||||
|
||||
const overlayEnabled = await w.webContents.executeJavaScript('navigator.windowControlsOverlay.visible');
|
||||
expect(overlayEnabled).to.be.true('overlayEnabled');
|
||||
const overlayRectPreMax = await w.webContents.executeJavaScript('getJSOverlayProperties()');
|
||||
|
||||
if (!w.isMaximized()) {
|
||||
const maximize = once(w, 'maximize');
|
||||
w.show();
|
||||
w.maximize();
|
||||
await maximize;
|
||||
}
|
||||
|
||||
expect(w.isMaximized()).to.be.true('not maximized');
|
||||
const overlayRectPostMax = await w.webContents.executeJavaScript('getJSOverlayProperties()');
|
||||
|
||||
expect(overlayRectPreMax.y).to.equal(0);
|
||||
if (process.platform === 'darwin') {
|
||||
expect(overlayRectPreMax.x).to.be.greaterThan(0);
|
||||
} else {
|
||||
expect(overlayRectPreMax.x).to.equal(0);
|
||||
}
|
||||
expect(overlayRectPreMax.width).to.be.greaterThan(0);
|
||||
|
||||
expect(overlayRectPreMax.width).to.be.greaterThan(0);
|
||||
expect(overlayRectPreMax.height).to.equal(size);
|
||||
// Confirm that maximization only affected the height of the buttons and not the title bar
|
||||
expect(overlayRectPostMax.height).to.equal(size);
|
||||
|
||||
// 'maximize' event is not emitted on Linux in CI.
|
||||
if (process.platform !== 'linux' && !w.isMaximized()) {
|
||||
const maximize = once(w, 'maximize');
|
||||
w.show();
|
||||
w.maximize();
|
||||
|
||||
await maximize;
|
||||
expect(w.isMaximized()).to.be.true('not maximized');
|
||||
|
||||
const overlayRectPostMax = await w.webContents.executeJavaScript('getJSOverlayProperties()');
|
||||
expect(overlayRectPostMax.height).to.equal(size);
|
||||
}
|
||||
};
|
||||
|
||||
afterEach(async () => {
|
||||
await closeAllWindows();
|
||||
ipcMain.removeAllListeners('geometrychange');
|
||||
});
|
||||
|
||||
it('sets Window Control Overlay with title bar height of 40', async () => {
|
||||
await testWindowsOverlayHeight(40);
|
||||
});
|
||||
});
|
||||
|
||||
ifdescribe(process.platform === 'win32')('BrowserWindow.setTitlebarOverlay', () => {
|
||||
ifdescribe(process.platform !== 'darwin')('BrowserWindow.setTitlebarOverlay', () => {
|
||||
afterEach(async () => {
|
||||
await closeAllWindows();
|
||||
ipcMain.removeAllListeners('geometrychange');
|
||||
});
|
||||
|
||||
it('does not crash when an invalid titleBarStyle was initially set', () => {
|
||||
it('throws when an invalid titleBarStyle is initially set', () => {
|
||||
const win = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
|
@ -3146,7 +3156,7 @@ describe('BrowserWindow module', () => {
|
|||
win.setTitleBarOverlay({
|
||||
color: '#000000'
|
||||
});
|
||||
}).to.not.throw();
|
||||
}).to.throw('Titlebar overlay is not enabled');
|
||||
});
|
||||
|
||||
it('correctly updates the height of the overlay', async () => {
|
||||
|
@ -3160,22 +3170,25 @@ describe('BrowserWindow module', () => {
|
|||
|
||||
const overlayEnabled = await w.webContents.executeJavaScript('navigator.windowControlsOverlay.visible');
|
||||
expect(overlayEnabled).to.be.true('overlayEnabled');
|
||||
const { height: preMaxHeight } = await w.webContents.executeJavaScript('getJSOverlayProperties()');
|
||||
|
||||
if (!w.isMaximized()) {
|
||||
const { height: preMaxHeight } = await w.webContents.executeJavaScript('getJSOverlayProperties()');
|
||||
expect(preMaxHeight).to.equal(size);
|
||||
|
||||
// 'maximize' event is not emitted on Linux in CI.
|
||||
if (process.platform !== 'linux' && !w.isMaximized()) {
|
||||
const maximize = once(w, 'maximize');
|
||||
w.show();
|
||||
w.maximize();
|
||||
await maximize;
|
||||
}
|
||||
|
||||
expect(w.isMaximized()).to.be.true('not maximized');
|
||||
const { x, y, width, height } = await w.webContents.executeJavaScript('getJSOverlayProperties()');
|
||||
expect(x).to.equal(0);
|
||||
expect(y).to.equal(0);
|
||||
expect(width).to.be.greaterThan(0);
|
||||
expect(height).to.equal(size);
|
||||
expect(preMaxHeight).to.equal(size);
|
||||
await maximize;
|
||||
expect(w.isMaximized()).to.be.true('not maximized');
|
||||
|
||||
const { x, y, width, height } = await w.webContents.executeJavaScript('getJSOverlayProperties()');
|
||||
expect(x).to.equal(0);
|
||||
expect(y).to.equal(0);
|
||||
expect(width).to.be.greaterThan(0);
|
||||
expect(height).to.equal(size);
|
||||
}
|
||||
};
|
||||
|
||||
const INITIAL_SIZE = 40;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue