Skip to content

[Feature Request]: Support xdg-session-management on Wayland to restore window placement #56078

Backlog

Description

@julianmesa-gitkraken

Preflight Checklist

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 held uninstall_metrics, also 2 s after the last window closed).
  • persisted-state-restored never 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 windowStatePersistence to it on Wayland: Electron persists the compositor-issued session id and a window id per name, passes them in session_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 restoreId constructor 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. With WAYLAND_DEBUG=1, Mutter 51.1 advertises xdg_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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions