fix(linux): force XWayland on KDE Wayland (Electron 39)#495
Conversation
On Electron 39+, appendSwitch("ozone-platform-hint", "x11") has no
effect — the ozone platform is selected during Chromium init, before
any JS runs. This causes the app to silently start on native Wayland
on KDE, breaking overlay positioning, focus, and always-on-top.
Self-relaunch with --ozone-platform=x11 before require("electron")
is the only way to get the flag onto the native command line in time.
|
I have been thinking about this more. The self-relaunch works but it's not great long-term - extra PID, Ctrl+C doesn't kill the child in terminal, etc. Looking at how other apps handle this on Linux, several use a wrapper script pattern:
The pattern: rename the real binary (e.g. Could be done with an Bonus: if we add a I can prepare a PR with the wrapper approach if you're interested. The self-relaunch in this PR works as a quick fix, but the wrapper would be the proper solution. EDIT: reviewed pattern examples. |
|
Thank you so much for the work on this! Closing for now since it's been superseded by #498, which includes this self-relaunch fix plus the remaining hotkey registration, clipboard timing, and dev-mode fixes needed for KDE Wayland. |
1 similar comment
|
Thank you so much for the work on this! Closing for now since it's been superseded by #498, which includes this self-relaunch fix plus the remaining hotkey registration, clipboard timing, and dev-mode fixes needed for KDE Wayland. |
Summary
On Electron 39 the app silently ends up on native Wayland on KDE, which breaks the overlay bubble (centered instead of corner, steals focus, doesn't stay on top). This replaces the broken
appendSwitchapproach with a self-relaunch that actually gets the flag to Chromium in time.Problem
PR #470 used
appendSwitch("ozone-platform-hint", "x11")to force XWayland on KDE. On E39 this does nothing because the ozone platform is selected during Chromium init, before any JS runs.ELECTRON_OZONE_PLATFORM_HINTenv var was also removed in E39 (electron#48001).On native Wayland, overlay windows are fundamentally broken:
setPosition()/setBounds()ignored by the compositor (electron#40886)showInactive()not supported on Wayland (electron#48436)focusable: falseis X11-onlyVS Code hit the same wall with
appendSwitchfor ozone and closed it as "not planned" (microsoft/vscode#135191).Solution
Self-relaunch with
--ozone-platform=x11beforerequire("electron"), so the flag is on the real command line when Chromium initializes. The oldappendSwitchKDE branch is removed since it has no effect on E39.Side effects are minor: extra PID (parent exits immediately),
Ctrl+Cin terminal doesn't kill child (detached). Doesn't matter for.desktoplaunches.An alternative used by some Electron apps is a bash wrapper script that
execs the real binary with the flag (no extra process,Ctrl+Cworks). Cleaner but requires anafterPackhook and touches the packaging pipeline. Could be a follow-up.Test plan
Tested on Kubuntu 25.10, KDE Plasma 6, E39.8.1 / E39.8.3.