Repository navigation
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Problem Description
On a native Wayland session, an Electron app cannot reopen a window on the monitor where the user last left it. The compositor places every new window itself; GNOME's Mutter puts it on the active monitor.
Apps can't work around this. Wayland doesn't let a client read or set its global window position: win.getBounds() keeps reporting a fixed position (x: 22, y: 19 here) wherever the window really is, and no move/moved event fires when the user drags it. App-level window state persistence therefore always saves and restores the same wrong position (#40886 documents the getPosition() side).
The built-in windowStatePersistence option has the same limitation. Tested with Electron 44.11.3 on Fedora 45, GNOME Shell / Mutter 51.1, native Wayland, two 1920x1080 monitors:
const { app, BrowserWindow, screen } = require('electron')
app.whenReady().then(() => {
const win = new BrowserWindow({ width: 700, height: 450, windowStatePersistence: { name: 'test' } })
win.loadURL('data:text/html,<h1>Move me to the other monitor and close me</h1>')
win.on('persisted-state-restored', () => console.log('restored', win.getBounds()))
setInterval(() => !win.isDestroyed() && console.log(win.getBounds(), screen.getDisplayMatching(win.getBounds()).id), 3000)
})Over three runs, moving the window to the second monitor and closing it:
getBounds()stayed at{ x: 22, y: 19 }on the first display the whole time.- Nothing was written to
Local State(it only helduninstall_metrics, also 2 s after the last window closed). persisted-state-restorednever fired on the next launch, and the window opened wherever Mutter chose.
--ozone-platform=x11 restores positioning, but it brings blurry fractional scaling and a different GPU path, and it isn't available where the distribution ships no X11 session (see #55761).
Proposed Solution
Support the xdg-session-management-v1 protocol (wayland-protocols 1.48) on Linux/Wayland, so the compositor can restore a window's monitor, position, size and state. The app never sees coordinates; it hands the compositor a session id and a per-window id and asks for restoration before the window is mapped.
Chromium already implements the platform side in Ozone/Wayland behind the WaylandSessionManagement feature (crrev.com/c/6329003, with the views bits in crrev.com/c/6329156). An embedder fills views::Widget::InitParams::session_data (session id, restore id, window id) when it creates the widget and persists those ids itself; in Chrome that persistence lives in //chrome and components/sessions, which Electron doesn't use, so enabling the feature flag alone does nothing for Electron windows (see Alternatives).
A possible shape for Electron:
- Wire
windowStatePersistenceto it on Wayland: Electron persists the compositor-issued session id and a window id pername, passes them insession_data, and lets the compositor restore placement instead of relying on bounds the client can't read. - Or expose the ids directly (for example an app-level session id plus a per-window
restoreIdconstructor option), so apps with their own window persistence can opt in.
Compositor support: GNOME 51.1 on Fedora 45 advertises xdg_session_manager_v1 out of the box, without debug flags. Mutter (MR 4806) and KWin (MR 8985) implement the protocol; GTK and Qt have client implementations.
Alternatives Considered
- App-level persistence with
getBounds()/setBounds(): impossible on Wayland, as above. windowStatePersistence: saves nothing on Wayland today.--ozone-platform=x11: works where XWayland is available and behaves, at the cost of fractional scaling quality and a different GPU path; not an option everywhere ([Feature Request]: Let setFullScreen target a display (no workaround left on Wayland) #55761).--enable-features=WaylandSessionManagement: has no effect. WithWAYLAND_DEBUG=1, Mutter 51.1 advertisesxdg_session_manager_v1(version 1) in the registry, but Electron 44.11.3 never binds it, even with the flag.
Additional Information
Related: #37494 (window restoration to virtual desktops/Spaces; a comment there asks for Wayland session management), #40886 (getPosition() on Wayland), #55761 (setFullScreen can't target a display on Wayland).
Activity