Skip to content

fix: position window titlebar buttons correctly in Ubuntu on Wayland - #48490

Merged
VerteDinde merged 2 commits into
electron:mainfrom
mitchchn:main
Oct 20, 2025
Merged

VerteDinde merged 2 commits into
electron:mainfrom
mitchchn:main

Conversation

@mitchchn

@mitchchn mitchchn commented Oct 8, 2025 •

Copy link
Copy Markdown
Member

Description of Change

Fixes #48422.

The CSD-drawn titlebar buttons were drawn as leading (left-aligned) when running on Wayland in Ubuntu. This happened because:

  • Electron has been pretending to be running on the Unity desktop environment (by setting XDG_CURRENT_DESKTOP=Unity) to work around decade-old tray icon issues (Elementary OS tray icon / indicator missing - again #5050)
  • Unity defaulted to left-aligned titlebar buttons, and the schema to left-align icons on Unity is still included in Ubuntu 24.04
  • The previous SSD-drawn titlebar ignored this schema, but the new CSD titlebar (correctly!) does not.

My solution to fix the icon alignment is to remove the old workaround code that emulates Unity. Unity is an unsupported desktop environment that has not been included in Ubuntu since 2018. An app claiming to be running on Unity when it isn't will cause much more harm than good on modern Linux. (See: #45310.)

Tray icons on Linux (appindicators) also do not depend on the Unity workaround anymore as you can see in the screenshot. It is possible but unlikely that users of very old (obsolete) or unusually configured distributions might lose their tray icons as a result of this fix, but they can always set the XDG_CURRENT_DESKTOP variable manually if they choose. Electron should not be overriding it in any event.

Screenshot_20251008_105013

Checklist

Release Notes

Notes: Titlebar buttons now appear on the correct side of windows on Wayland in Ubuntu

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Oct 8, 2025
@codebytere

codebytere commented Oct 8, 2025 •

Copy link
Copy Markdown
Member

@mitchchn could you please add release notes? You also need to sign your commit :)

@absidue

absidue commented Oct 8, 2025

Copy link
Copy Markdown

The docs will also need updating: https://www.electronjs.org/docs/latest/api/environment-variables#original_xdg_current_desktop

@mitchchn

mitchchn commented Oct 8, 2025

Copy link
Copy Markdown
Member Author

Done and done! Apologies for the force push, I did not realize my commit signing hadn't been set up properly on Linux.

@clavin
clavin self-requested a review October 8, 2025 17:32
@clavin clavin added target/37-x-y PR should also be added to the "37-x-y" branch. target/38-x-y PR should also be added to the "38-x-y" branch. target/39-x-y PR should also be added to the "39-x-y" branch. semver/minor backwards-compatible functionality labels Oct 8, 2025
@mitchchn

mitchchn commented Oct 8, 2025

Copy link
Copy Markdown
Member Author

One more thing for future readers: Vanilla GNOME does not have tray icon/appindicator support. This is true both before and after this change. (No tray icons in Fedora out of the box for example.)

If your distribution does not include a shell extension for GNOME appindicators, you need to install one to see tray icons. Forcing "Unity" will have no effect on modern Linux distributions.

@VerteDinde VerteDinde left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging into this and for such a detailed write up, @mitchchn!

@erickzhao erickzhao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@clavin

clavin commented Oct 8, 2025

Copy link
Copy Markdown
Member

Did a search of Chromium and Electron for everywhere that XDG_CURRENT_DESKTOP=Unity specifically is used to make sure we don't see anything break from this change.

  • base/nix/xdg_util.cc - GetDesktopEnvironment: Parses XDG_CURRENT_DESKTOP and returns different values for Unity vs GNOME. All uses of DESKTOP_ENVIRONMENT_UNITY and DESKTOP_ENVIRONMENT_GNOME are considered in this analysis.

There are a handful of switch groups where Unity is treated the exact same as GNOME:

There is one instance where the behavior of Unity significantly overlaps with GNOME:

There are a few instances where the use of Unity and/or GNOME are insignificant in Electron:

There were a few places that I found clones of Chromium code in Electron:

Finally, there are some instances where there is a meaningful difference in behavior:

@clavin clavin left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the analysis, I think there are only three things I'm concerned about:

  1. The global accelerator listener being disabled due to a bug in GNOME. (Admittedly, this isn't an issue in current stable releases, but may be in an upcoming or most recent nightly.)
  2. Our copy of chrome_views_delegate_linux.cc that may change titlebar behavior.
  3. Knowing what the existing behavior of our Unity service is and what it will be after this change. There's a handful of Electron code depending on this old service. It's not gated on XDG_CURRENT_DESKTOP=Unity but I want to rule out any other interference too.

I'd like to rule out any blockers in those three areas ahead of landing this if we can! 😄 I haven't tested or poked at anything, just flagging some concerns to discuss.

@mitchchn

mitchchn commented Oct 8, 2025

Copy link
Copy Markdown
Member Author

Thanks for the analysis @clavin! I don't know the answers to these questions 100%, but for what it's worth:

The global accelerator listener

I tested global shortcuts in this branch and they work for me on GNOME and KDE in X11 and Wayland (although it's a bit clunky in KDE on Wayland). Global shortcuts have been a rocky area for Wayland in general, so there might be current issues or future regressions but I do not believe it would help at all to pretend to be Unity.

chrome_views_delegate_linux.cc (WindowManagerProvidesTitleBar)

I tested on GNOME/Wayland, GNOME/X11, KDE/Wayland and KDE/X11 with maximized and un-maximized windows with no apparent titlebar issues.

Not sure how to exercise the Unity service or anything that uses libunity.so.

@clavin clavin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I think we are good to land this. Thanks for looking into this! 😁👍

@dsanders11

Copy link
Copy Markdown
Member

@mitchchn, could you rebase on main to pick up the change needed for CI on macOS to run?

@nikwen

nikwen commented Oct 10, 2025 •

Copy link
Copy Markdown
Member

Unity is an unsupported desktop environment that has not been included in Ubuntu since 2018.

Our README says that supported Ubuntu versions are 18.04 and higher. 18.04 was the first version to not use Unity.

@jkleinsc jkleinsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@nikwen nikwen removed the target/37-x-y PR should also be added to the "37-x-y" branch. label Oct 15, 2025
@nikwen

nikwen commented Oct 15, 2025

Copy link
Copy Markdown
Member

Removing target/37-x-y as it fixes an issue introduced in v38.

@codebytere

Copy link
Copy Markdown
Member

@mitchchn is this ready for final review? I see you closed and reopened it.

@mitchchn

Copy link
Copy Markdown
Member Author

@codebytere yep, closed it accidentally.

@VerteDinde
VerteDinde merged commit 0c27c1a into electron:main Oct 20, 2025
@release-clerk

release-clerk Bot commented Oct 20, 2025

Copy link
Copy Markdown

Release Notes Persisted

Titlebar buttons now appear on the correct side of windows on Wayland in Ubuntu

@trop

trop Bot commented Oct 20, 2025

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "38-x-y", please check out #48602

@trop

trop Bot commented Oct 20, 2025

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "39-x-y", please check out #48603

@trop trop Bot added in-flight/39-x-y and removed target/38-x-y PR should also be added to the "38-x-y" branch. target/39-x-y PR should also be added to the "39-x-y" branch. labels Oct 20, 2025
codebytere pushed a commit that referenced this pull request Oct 21, 2025
…48603)

fix: position window titlebar buttons correctly in Ubuntu on Wayland (#48490)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Mitchell Cohen <[email protected]>
@trop trop Bot added merged/39-x-y PR was merged to the "39-x-y" branch. and removed in-flight/39-x-y labels Oct 21, 2025
codebytere pushed a commit that referenced this pull request Oct 21, 2025
…48602)

fix: position window titlebar buttons correctly in Ubuntu on Wayland (#48490)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Mitchell Cohen <[email protected]>
@trop trop Bot added merged/38-x-y PR was merged to the "38-x-y" branch. and removed in-flight/38-x-y labels Oct 21, 2025
TheCommieAxolotl pushed a commit to TheCommieAxolotl/electron that referenced this pull request Nov 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review/approved ✅ merged/38-x-y PR was merged to the "38-x-y" branch. merged/39-x-y PR was merged to the "39-x-y" branch. semver/minor backwards-compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Window chrome buttons are on the left in Electron 38.2.0 on Ubuntu 22

9 participants