diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 5f205e294d7c..67818b4b6bdf 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -543,6 +543,11 @@ void NativeWindowViews::ShowInactive() { #if BUILDFLAG(IS_LINUX) if (global_menu_bar_) global_menu_bar_->OnWindowMapped(); + + // On X11, setting Z order before showing the window doesn't take effect, + // so we have to call it again. + if (IsX11()) + widget()->SetZOrderLevel(widget()->GetZOrderLevel()); #endif } diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 51386dda5f03..32b4b82d67c2 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -2508,6 +2508,22 @@ describe('BrowserWindow module', () => { expect(c.isAlwaysOnTop()).to.be.true('child is not always on top'); expect(c._getAlwaysOnTopLevel()).to.equal('screen-saver'); }); + + it('works when called prior to show', async () => { + w = new BrowserWindow({ show: false }); + w.setAlwaysOnTop(true, 'screen-saver'); + w.show(); + await setTimeout(1000); + expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop'); + }); + + it('works when called prior to showInactive', async () => { + w = new BrowserWindow({ show: false }); + w.setAlwaysOnTop(true, 'screen-saver'); + w.showInactive(); + await setTimeout(1000); + expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop'); + }); }); describe('preconnect feature', () => {