Fixed a few resizing issues (#2703)

* Fix bad handler on resize for Linux

* Fix maximize/minimize issue again

* Fix macOS rapid resizing issue

* Make sure #2638 is still fixed

* Still don't need this

* Added comment and fixed test
This commit is contained in:
Devin Binnie
2023-05-03 08:48:54 -04:00
committed by GitHub
parent e227c6bf1d
commit 1049b0763c
3 changed files with 37 additions and 14 deletions

View File

@@ -88,7 +88,6 @@ import {
GET_ORDERED_SERVERS, GET_ORDERED_SERVERS,
GET_ORDERED_TABS_FOR_SERVER, GET_ORDERED_TABS_FOR_SERVER,
SERVERS_UPDATE, SERVERS_UPDATE,
VIEW_FINISHED_RESIZING,
} from 'common/communication'; } from 'common/communication';
console.log('Preload initialized'); console.log('Preload initialized');
@@ -253,6 +252,3 @@ const createKeyDownListener = () => {
}; };
createKeyDownListener(); createKeyDownListener();
window.addEventListener('resize', () => {
ipcRenderer.send(VIEW_FINISHED_RESIZING);
});

View File

@@ -85,6 +85,7 @@ describe('main/windows/mainWindow', () => {
describe('init', () => { describe('init', () => {
const baseWindow = { const baseWindow = {
setMenuBarVisibility: jest.fn(), setMenuBarVisibility: jest.fn(),
setAutoHideMenuBar: jest.fn(),
loadURL: jest.fn(), loadURL: jest.fn(),
once: jest.fn(), once: jest.fn(),
on: jest.fn(), on: jest.fn(),

View File

@@ -91,12 +91,13 @@ export class MainWindow extends EventEmitter {
} }
this.win = new BrowserWindow(windowOptions); this.win = new BrowserWindow(windowOptions);
this.win.setMenuBarVisibility(false);
if (!this.win) { if (!this.win) {
throw new Error('unable to create main window'); throw new Error('unable to create main window');
} }
this.win.setAutoHideMenuBar(true);
this.win.setMenuBarVisibility(false);
const localURL = getLocalURLString('index.html'); const localURL = getLocalURLString('index.html');
this.win.loadURL(localURL).catch( this.win.loadURL(localURL).catch(
(reason) => { (reason) => {
@@ -129,13 +130,13 @@ export class MainWindow extends EventEmitter {
this.win.on('unresponsive', this.onUnresponsive); this.win.on('unresponsive', this.onUnresponsive);
this.win.on('maximize', this.onMaximize); this.win.on('maximize', this.onMaximize);
this.win.on('unmaximize', this.onUnmaximize); this.win.on('unmaximize', this.onUnmaximize);
this.win.on('enter-full-screen', () => this.win?.webContents.send('enter-full-screen')); this.win.on('enter-full-screen', this.onEnterFullScreen);
this.win.on('leave-full-screen', () => this.win?.webContents.send('leave-full-screen')); this.win.on('leave-full-screen', this.onLeaveFullScreen);
this.win.on('will-resize', this.onWillResize); this.win.on('will-resize', this.onWillResize);
this.win.on('resized', this.onResized); this.win.on('resized', this.onResized);
this.win.on('moved', this.onResized); this.win.on('moved', this.onResized);
if (process.platform !== 'darwin') { if (process.platform === 'linux') {
mainWindow.on('resize', this.onResize); this.win.on('resize', this.onResize);
} }
this.win.webContents.on('before-input-event', this.onBeforeInputEvent); this.win.webContents.on('before-input-event', this.onBeforeInputEvent);
@@ -406,14 +407,37 @@ export class MainWindow extends EventEmitter {
}); });
} }
private emitBoundsForMaximize = () => {
// Workaround for Linux since the window bounds aren't updated immediately when the window is maximized for some reason
if (process.platform !== 'linux') {
return;
}
setTimeout(() => {
this.emit(MAIN_WINDOW_RESIZED, this.getBounds());
}, 10);
}
private onMaximize = () => { private onMaximize = () => {
this.win?.webContents.send(MAXIMIZE_CHANGE, true); this.win?.webContents.send(MAXIMIZE_CHANGE, true);
this.emit(MAIN_WINDOW_RESIZED, this.getBounds()); this.emitBoundsForMaximize();
} }
private onUnmaximize = () => { private onUnmaximize = () => {
this.win?.webContents.send(MAXIMIZE_CHANGE, false); this.win?.webContents.send(MAXIMIZE_CHANGE, false);
this.emit(MAIN_WINDOW_RESIZED, this.getBounds()); this.emitBoundsForMaximize();
}
private onEnterFullScreen = () => {
this.win?.webContents.send('enter-full-screen');
this.emitBoundsForMaximize();
// For some reason on Linux I've seen the menu bar popup again
this.win?.setMenuBarVisibility(false);
}
private onLeaveFullScreen = () => {
this.win?.webContents.send('leave-full-screen');
this.emitBoundsForMaximize();
} }
/** /**
@@ -434,7 +458,8 @@ export class MainWindow extends EventEmitter {
return; return;
} }
if (this.isResizing) { // Workaround for macOS to stop the window from sending too many resize calls to the BrowserViews
if (process.platform === 'darwin' && this.isResizing) {
log.debug('prevented resize'); log.debug('prevented resize');
event.preventDefault(); event.preventDefault();
return; return;
@@ -447,7 +472,8 @@ export class MainWindow extends EventEmitter {
private onResize = () => { private onResize = () => {
log.silly('onResize'); log.silly('onResize');
if (this.isResizing) { // Workaround for macOS to stop the window from sending too many resize calls to the BrowserViews
if (process.platform === 'darwin' && this.isResizing) {
return; return;
} }
this.emit(MAIN_WINDOW_RESIZED, this.getBounds()); this.emit(MAIN_WINDOW_RESIZED, this.getBounds());