You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Electron transparent window use maximize() can not emit 'maximize' event #12854
Operating System (Platform and Version): windows 8.1
Last known working Electron version: none
Expected Behavior
I create a browerwindow with frame: false and transparent: true, when i use maximize(), i need the event 'maximize' and isMaximized() return true.
Actual behavior
no event emited, and isMaximize() return false.
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
To help make it easier for us to investigate your issue, please follow the contributing guidelines.
We haven't gotten a response to our questions in our comment above. With only the information that is currently in the issue, we don't have enough information to take action. I'm going to close this but don't hesitate to reach out if you have or find the answers we need, we'll be happy to reopen the issue.
This is still happening for Electron 5.0.6 on Windows 10 (1903) very old bug that wasn't been fixed.
To reproduce it you need to do exactly what the original poster said, set BrowserWindow with frame: false and transparent: true and do win.on('maximize', function() {});
No event 'maximize is triggered and the function will not be called when you maximize the window.
I wrote a plug-in to fix this problem. See electron-frameless-window-plugin. In fact, I rewrote several methods of BrowserWindow instance, including getNormalBounds(), maximize(), unmaximize() and isMaximzed(). And I've added some features to make frameless windows work better. Such as disable the menu when right clicking the drag region.
Code:
if(win.webContents.browserWindowOptions.transparent){// rewrite getNormalBounds, maximize, unmaximize and isMaximized API for the transparent windowletresizable=win.isResizable()letnormalBounds=win.getNormalBounds ? win.getNormalBounds() : win.getBounds()win.getNormalBounds=function(){if(!this.isMaximized()){if(BrowserWindow.prototype.getNormalBounds){normalBounds=BrowserWindow.prototype.getNormalBounds.call(this)}else{normalBounds=BrowserWindow.prototype.getBounds.call(this)}}returnnormalBounds}.bind(win)win.maximize=function(){normalBounds=this.getNormalBounds()// store the bounds of normal windowresizable=this.isResizable()// store resizable valueBrowserWindow.prototype.maximize.call(this)if(!BrowserWindow.prototype.isMaximized.call(this)){// while isMaximized() was returning false, it will not emit 'maximize' eventthis.emit('maximize',{sender: this,preventDefault: ()=>{}})}this.setResizable(false)// disable resize when the window is maximized}.bind(win)win.unmaximize=function(){constfromMaximized=BrowserWindow.prototype.isMaximized.call(this)BrowserWindow.prototype.unmaximize.call(this)if(!fromMaximized){// isMaximized() returned false before unmaximize was called, it will not emit 'unmaximize' eventthis.emit('unmaximize',{sender: this,preventDefault: ()=>{}})}this.setResizable(resizable)// restore resizable}.bind(win)win.isMaximized=function(){constnativeIsMaximized=BrowserWindow.prototype.isMaximized.call(this)if(!nativeIsMaximized){// determine whether the window is full of the screen work areaconstbounds=this.getBounds()constworkArea=electron.screen.getDisplayMatching(bounds).workAreaif(bounds.x<=workArea.x&&bounds.y<=workArea.y&&bounds.width>=workArea.width&&bounds.height>=workArea.height){returntrue}}returnnativeIsMaximized}.bind(win)}
Reacted by DuannHang, Amr Bashir, weedsboy, Nihilo, looading, Izaak Kuipers and rmill777
@chenjietao thanks, man. you're a life saver.
if you don't mind me asking, do you have any solution to get the window to dock/snap to the edges of screen. transparent:true also mess up the snapping functionality.
I wrote a plug-in to fix this problem. See electron-frameless-window-plugin. In fact, I rewrote several methods of BrowserWindow instance, including getNormalBounds(), maximize(), unmaximize() and isMaximzed(). And I've added some features to make frameless windows work better. Such as disable the menu when right clicking the drag region.
I wrote a plug-in to fix this problem. See electron-frameless-window-plugin. In fact, I rewrote several methods of BrowserWindow instance, including getNormalBounds(), maximize(), unmaximize() and isMaximzed(). And I've added some features to make frameless windows work better. Such as disable the menu when right clicking the drag region.
Code:
if(win.webContents.browserWindowOptions.transparent){// rewrite getNormalBounds, maximize, unmaximize and isMaximized API for the transparent windowletresizable=win.isResizable()letnormalBounds=win.getNormalBounds ? win.getNormalBounds() : win.getBounds()win.getNormalBounds=function(){if(!this.isMaximized()){if(BrowserWindow.prototype.getNormalBounds){normalBounds=BrowserWindow.prototype.getNormalBounds.call(this)}else{normalBounds=BrowserWindow.prototype.getBounds.call(this)}}returnnormalBounds}.bind(win)win.maximize=function(){normalBounds=this.getNormalBounds()// store the bounds of normal windowresizable=this.isResizable()// store resizable valueBrowserWindow.prototype.maximize.call(this)if(!BrowserWindow.prototype.isMaximized.call(this)){// while isMaximized() was returning false, it will not emit 'maximize' eventthis.emit('maximize',{sender: this,preventDefault: ()=>{}})}this.setResizable(false)// disable resize when the window is maximized}.bind(win)win.unmaximize=function(){constfromMaximized=BrowserWindow.prototype.isMaximized.call(this)BrowserWindow.prototype.unmaximize.call(this)if(!fromMaximized){// isMaximized() returned false before unmaximize was called, it will not emit 'unmaximize' eventthis.emit('unmaximize',{sender: this,preventDefault: ()=>{}})}this.setResizable(resizable)// restore resizable}.bind(win)win.isMaximized=function(){constnativeIsMaximized=BrowserWindow.prototype.isMaximized.call(this)if(!nativeIsMaximized){// determine whether the window is full of the screen work areaconstbounds=this.getBounds()constworkArea=electron.screen.getDisplayMatching(bounds).workAreaif(bounds.x<=workArea.x&&bounds.y<=workArea.y&&bounds.width>=workArea.width&&bounds.height>=workArea.height){returntrue}}returnnativeIsMaximized}.bind(win)}
Wonderful job, this is the key to near perfect transparent frameless windows, mainly for use with say for example a window that needs border-radius. I love this plugin and will be using it very often. Thanks, @chenjietao
@chenjietao Thanks, it doesn't seem to work (anymore) though. For one, browserWindowOptions has been removed from win.webContents, and when I remove this check (and adding const electron = require('electron'); at the top of my main.js file) it makes the window act weirdly when maximizing/unmaximizing; but the maximize, unmaximize and minimize events are not fired.
// if (win.webContents.browserWindowOptions&&win.webContents.browserWindowOptions.transparent) {}// edit to// if(true)win.unmaximize=function(){constfromMaximized=BrowserWindow.prototype.isMaximized.call(this)BrowserWindow.prototype.unmaximize.call(this)if(!fromMaximized){// isMaximized() returned false before unmaximize was called, it will not emit 'unmaximize' eventthis.emit('unmaximize',{sender: this,preventDefault: ()=>{}})// add+win.setBounds(normalBounds)}this.setResizable(resizable)// restore resizable}.bind(win)
Escrevi um plug-in para corrigir esse problema. Ver plug-in de janela sem estrutura eletrônica. . Na verdade, reescrevi vários métodos de instância do BrowserWindow, inclusive getNormalBounds(), maximize(), unmaximize() e isMaximzed(). E adicionei alguns recursos para fazer com que as janelas sem moldura funcionem melhor. Como desabilitar o menu ao clicar com o botão direito na região de arrastar.
Código:
se (ganhar.conteúdos Web.browserWindowOpções.transparente) {
// reescrever getNormalBounds, maximizar, desmaximizar e isMaximized API para a janela transparente
deixar redimensionável = ganhar.é redimensionável()
deixar limites normais = ganhar.obterLimites normais ? ganhar.obterLimites normais() : ganhar.obter limites()
ganhar.obterLimites normais = função () {
se (!isto.isMaximizado()) {
se (Janela do navegador.protótipo.obterLimites normais) {
limites normais = Janela do navegador.protótipo.obterLimites normais.ligar(isto)
} outra outra {
limites normais = Janela do navegador.protótipo.obter limites.ligar(isto)
}
}
retorno limites normais
}.ligar(ganhar)
ganhar.maximizar = função () {
limites normais = isto.obterLimites normais() // armazene os limites da janela normal
redimensionável = isto.é redimensionável() // armazenar valor redimensionável
Janela do navegador.protótipo.maximizar.ligar(isto)
se (!Janela do navegador.protótipo.isMaximizado.ligar(isto)) {
//enquanto isMaximized () estava retornando falso, ele não emitirá evento 'maximizar'
isto.emitir('maximizar', { remetente: isto, prevenir padrão: () => {} })
}
isto.definirResizável(falso) //desativar redimensionar quando a janela estiver maximizada
}.ligar(ganhar)
ganhar.não maximizar = função () {
const doMaximizado = Janela do navegador.protótipo.isMaximizado.ligar(isto)
Janela do navegador.protótipo.não maximizar.ligar(isto)
se (!doMaximizado) {
// isMaximized () retornou falso antes de unmaximize foi chamado, ele não vai emitir 'unmaximize' evento
isto.emitir('desmaximizar', { remetente: isto, prevenir padrão: () => {} })
}
isto.definirResizável(redimensionável) // restaurar redimensionável
}.ligar(ganhar)
ganhar.isMaximizado = função () {
const nativoIsMaximizado = Janela do navegador.protótipo.isMaximizado.ligar(isto)
se (!nativoIsMaximizado) {
//determinar se a janela está cheia da área de trabalho do ecrã
const limites = isto.obter limites()
const área de trabalho = elétron.tela.getDisplayMatching(limites).área de trabalho
se (limites.x <= área de trabalho.x && limites.y <= área de trabalho.y && limites.largura >= área de trabalho.largura && limites.altura >= área de trabalho.altura) {
retorno verdadeiro
}
}
retorno nativoIsMaximizado
}.ligar(ganhar)
}
como faço para usar sua soluçao?
I wrote a plug-in to fix this problem. See electron-frameless-window-plugin. In fact, I rewrote several methods of BrowserWindow instance, including getNormalBounds(), maximize(), unmaximize() and isMaximzed(). And I've added some features to make frameless windows work better. Such as disable the menu when right clicking the drag region.
Code:
if (win.webContents.browserWindowOptions.transparent) {
// rewrite getNormalBounds, maximize, unmaximize and isMaximized API for the transparent window
let resizable = win.isResizable()
let normalBounds = win.getNormalBounds ? win.getNormalBounds() : win.getBounds()
win.getNormalBounds = function () {
if (!this.isMaximized()) {
if (BrowserWindow.prototype.getNormalBounds) {
normalBounds = BrowserWindow.prototype.getNormalBounds.call(this)
} else {
normalBounds = BrowserWindow.prototype.getBounds.call(this)
}
}
return normalBounds
}.bind(win)
win.maximize = function () {
normalBounds = this.getNormalBounds() // store the bounds of normal window
resizable = this.isResizable() // store resizable value
BrowserWindow.prototype.maximize.call(this)
if (!BrowserWindow.prototype.isMaximized.call(this)) {
// while isMaximized() was returning false, it will not emit 'maximize' event
this.emit('maximize', { sender: this, preventDefault: () => {} })
}
this.setResizable(false) // disable resize when the window is maximized
}.bind(win)
win.unmaximize = function () {
const fromMaximized = BrowserWindow.prototype.isMaximized.call(this)
BrowserWindow.prototype.unmaximize.call(this)
if (!fromMaximized) {
// isMaximized() returned false before unmaximize was called, it will not emit 'unmaximize' event
this.emit('unmaximize', { sender: this, preventDefault: () => {} })
}
this.setResizable(resizable) // restore resizable
}.bind(win)
win.isMaximized = function () {
const nativeIsMaximized = BrowserWindow.prototype.isMaximized.call(this)
if (!nativeIsMaximized) {
// determine whether the window is full of the screen work area
const bounds = this.getBounds()
const workArea = electron.screen.getDisplayMatching(bounds).workArea
if (bounds.x <= workArea.x && bounds.y <= workArea.y && bounds.width >= workArea.width && bounds.height >= workArea.height) {
return true
}
}
return nativeIsMaximized
}.bind(win)
Activity
welcome commentedon May 8, 2018
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
To help make it easier for us to investigate your issue, please follow the contributing guidelines.
ckerr commentedon May 8, 2018
@wunairuoshi, thanks for reporting this issue!
Would it be possible for you to create a small test app -- e.g., forking https://github.com/electron/electron-quick-start and adding a few lines -- for the Electron team to test with?
sofianguy commentedon May 21, 2018
Thank you for your issue!
We haven't gotten a response to our questions in our comment above. With only the information that is currently in the issue, we don't have enough information to take action. I'm going to close this but don't hesitate to reach out if you have or find the answers we need, we'll be happy to reopen the issue.
ZaDarkSide commentedon Jul 15, 2019
This is still happening for Electron 5.0.6 on Windows 10 (1903) very old bug that wasn't been fixed.
To reproduce it you need to do exactly what the original poster said, set BrowserWindow with frame: false and transparent: true and do win.on('maximize', function() {});
No event 'maximize is triggered and the function will not be called when you maximize the window.
a1292999652 commentedon Aug 28, 2019
I also encountered this problem in Electron 6.02, transparent: true in Windows10 will lead to isMaximized() being false all the time
Keep track of maximized state
chenjietao commentedon Mar 21, 2020
I wrote a plug-in to fix this problem. See electron-frameless-window-plugin. In fact, I rewrote several methods of BrowserWindow instance, including
getNormalBounds(),maximize(),unmaximize()andisMaximzed(). And I've added some features to make frameless windows work better. Such as disable the menu when right clicking the drag region.Code:
DuannHang commentedon May 3, 2020
楼上老哥,真佩服你!
codebytere commentedon Jun 19, 2020
Duplicate of #23275
amrbashir commentedon Jun 22, 2020
@chenjietao thanks, man. you're a life saver.
if you don't mind me asking, do you have any solution to get the window to dock/snap to the edges of screen.
transparent:truealso mess up the snapping functionality.Nihilop commentedon Jan 9, 2021
Genius !
IzKuipers commentedon Apr 28, 2021
Wonderful job, this is the key to near perfect transparent frameless windows, mainly for use with say for example a window that needs border-radius. I love this plugin and will be using it very often. Thanks, @chenjietao
paddotk commentedon Jun 26, 2022
@chenjietao Thanks, it doesn't seem to work (anymore) though. For one,
browserWindowOptionshas been removed fromwin.webContents, and when I remove this check (and addingconst electron = require('electron');at the top of my main.js file) it makes the window act weirdly when maximizing/unmaximizing; but themaximize,unmaximizeandminimizeevents are not fired.distant-xingsu commentedon Jul 8, 2023
winchestercanal commentedon Jan 29, 2025
como faço para usar sua soluçao?
How do I use your solution?