electron icon indicating copy to clipboard operation
electron copied to clipboard

[Bug]: Calling setAlwaysOnTop(false) and then setAlwaysOnTop(true) seems to cause other always-on-top windows to lose their always on top status

Open pushkin- opened this issue 4 years ago • 18 comments

Preflight Checklist

Electron Version

15.1.2 -> 2.0.0

What operating system are you using?

Windows

Operating System Version

Windows 10

What arch are you using?

x64

Last Known Working Electron version

n/a

Expected Behavior

I expect that calling setAlwaysOnTop(false); setAlwaysOnTop(true) on a window will keep other always-on-top windows always on top.

Actual Behavior

Other windows lose their always-on-top status

Testcase Gist URL

https://gist.github.com/132060ee8a94ceda7c049187f2ec2dab

Additional Information

I'm working around this bug by detecting focus on an always-on-top window and calling setAlwaysOnTop(false) and setAlwaysOnTop(true) to bring it back to the front.

It seems like doing that makes the other window that was previously on top not on top anymore (isAlwaysOnTop() returns false).

  1. start main.js
  2. open two always on top windows
  3. focus on one of them, focus on another
  4. click on a background app
  5. the main window and the non-focused window (which should be always on top) get sent to the back. Only the focused window is always on top

main.js:

const {app, BrowserWindow} = require('electron')

function createWindow () {
  const mainWindow = new BrowserWindow()

  mainWindow.loadFile('index.html')

  mainWindow.webContents.setWindowOpenHandler(_ => {
    return {
      action: "allow",
      overrideBrowserWindowOptions: {
        alwaysOnTop: true,
        parent: mainWindow
      }
    }
  })

  mainWindow.webContents.on("did-create-window", (win) => {
    win.on("focus", () => {
      win.setAlwaysOnTop(false);
      win.setAlwaysOnTop(true);
    })
  });
}

app.on('ready', () => {
  createWindow()
})

app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') app.quit()
})

index.html:

<button onclick="window.open('https://google.com')">Open Always-on-top Window</button>

Possibly related to this issue

pushkin- avatar Oct 21 '21 19:10 pushkin-

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

github-actions[bot] avatar Oct 05 '22 02:10 github-actions[bot]

repros with latest stable (21)

pushkin- avatar Oct 05 '22 19:10 pushkin-

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

github-actions[bot] avatar Jan 10 '23 02:01 github-actions[bot]

repros in v22

pushkin- avatar Jan 12 '23 16:01 pushkin-

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

github-actions[bot] avatar Apr 14 '23 01:04 github-actions[bot]

repros in v24

pushkin- avatar Apr 14 '23 14:04 pushkin-

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

github-actions[bot] avatar Jul 14 '23 02:07 github-actions[bot]

bump

pushkin- avatar Jul 14 '23 16:07 pushkin-

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

repros in v27

pushkin- avatar Oct 16 '23 18:10 pushkin-

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

bump

pushkin- avatar Jan 15 '24 15:01 pushkin-

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

repros in v29.3.0

pushkin- avatar Apr 15 '24 14:04 pushkin-

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

bump

pushkin- avatar Jul 17 '24 16:07 pushkin-

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

repros in v33

pushkin- avatar Oct 16 '24 15:10 pushkin-

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

repros in v34

pushkin- avatar Jan 16 '25 15:01 pushkin-

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

I can no longer repro this, even with v34 where it used to repro. This may have been fixed by Windows. Currently on 24H2 - OS Build 26100.3476

pushkin- avatar Apr 17 '25 14:04 pushkin-

@pushkin- Just wanted to say I appreciate you closing out older issues that work fine now. :)

nikwen avatar Apr 17 '25 16:04 nikwen