Repository: electron/electron
Pull request: fix: position window titlebar buttons correctly in Ubuntu on Wayland

#### 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 (#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: https://github.com/electron/electron/pull/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.

<img width="1412" height="996" alt="Screenshot_20251008_105013" src="https://github.com/user-attachments/assets/b786a58b-7874-46d7-bdbb-30522ff75019" />


#### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [ ] PR description included and stakeholders cc'd
- [ ] `npm test` passes
- [ ] tests are [changed or added](https://github.com/electron/electron/blob/main/docs/development/testing.md)
- [ ] relevant API documentation, tutorials, and examples are updated and follow the [documentation style guide](https://github.com/electron/electron/blob/main/docs/development/style-guide.md)
- [ ] [PR release notes](https://github.com/electron/clerk/blob/main/README.md) describe the change in a way relevant to app developers, and are [capitalized, punctuated, and past tense](https://github.com/electron/clerk/blob/main/README.md#examples).

#### Release Notes

Notes: Titlebar buttons now appear on the correct side of windows on Wayland in Ubuntu


Changed files:
filename: docs/api/environment-variables.md
patch: @@ -186,14 +186,3 @@ the one downloaded by `npm install`. Usage:
 ```sh
 export ELECTRON_OVERRIDE_DIST_PATH=/Users/username/projects/electron/out/Testing
 ```
-
-## Set By Electron
-
-Electron sets some variables in your environment at runtime.
-
-### `ORIGINAL_XDG_CURRENT_DESKTOP`
-
-This variable is set to the value of `XDG_CURRENT_DESKTOP` that your application
-originally launched with.  Electron sometimes modifies the value of `XDG_CURRENT_DESKTOP`
-to affect other logic within Chromium so if you want access to the _original_ value
-you should look up this environment variable instead.

filename: docs/breaking-changes.md
patch: @@ -47,9 +47,15 @@ See [here](https://www.electronjs.org/docs/latest/api/structures/offscreen-share
 
 ### Removed: `ELECTRON_OZONE_PLATFORM_HINT` environment variable
 
-The default value of the `--ozone-plaftform` flag [changed to `auto`](https://chromium-review.googlesource.com/c/chromium/src/+/6775426).
+The default value of the `--ozone-platform` flag [changed to `auto`](https://chromium-review.googlesource.com/c/chromium/src/+/6775426).
 
-You should use the `XDG_SESSION_TYPE=wayland` environment variable instead to use Wayland.
+Electron now defaults to running as a native Wayland app when launched in a Wayland session (when `XDG_SESSION_TYPE=wayland`).
+Users can force XWayland by passing `--ozone-platform=x11`.
+
+### Removed: `ORIGINAL_XDG_CURRENT_DESKTOP` environment variable
+
+Previously, Electron changed the value of `XDG_CURRENT_DESKTOP` internally to `Unity`, and stored the original name of the desktop session
+in a separate variable. `XDG_CURRENT_DESKTOP` is no longer overriden and now reflects the actual desktop environment.
 
 ### Removed: macOS 11 support
 

filename: lib/browser/init.ts
patch: @@ -162,27 +162,6 @@ require('@electron/internal/browser/api/web-contents-view');
 // Set main startup script of the app.
 const mainStartupScript = packageJson.main || 'index.js';
 
-const KNOWN_XDG_DESKTOP_VALUES = new Set(['Pantheon', 'Unity:Unity7', 'pop:GNOME']);
-
-function currentPlatformSupportsAppIndicator () {
-  if (process.platform !== 'linux') return false;
-  const currentDesktop = process.env.XDG_CURRENT_DESKTOP;
-
-  if (!currentDesktop) return false;
-  if (KNOWN_XDG_DESKTOP_VALUES.has(currentDesktop)) return true;
-  // ubuntu based or derived session (default ubuntu one, communitheme…) supports
-  // indicator too.
-  if (/ubuntu/ig.test(currentDesktop)) return true;
-
-  return false;
-}
-
-// Workaround for electron/electron#5050 and electron/electron#9046
-process.env.ORIGINAL_XDG_CURRENT_DESKTOP = process.env.XDG_CURRENT_DESKTOP;
-if (currentPlatformSupportsAppIndicator()) {
-  process.env.XDG_CURRENT_DESKTOP = 'Unity';
-}
-
 // Quit when all windows are closed and no other one is listening to this.
 app.on('window-all-closed', () => {
   if (app.listenerCount('window-all-closed') === 1) {

filename: shell/common/platform_util_linux.cc
patch: @@ -15,7 +15,6 @@
 
 #include "base/cancelable_callback.h"
 #include "base/containers/contains.h"
-#include "base/containers/map_util.h"
 #include "base/environment.h"
 #include "base/files/file_util.h"
 #include "base/files/scoped_file.h"
@@ -59,8 +58,6 @@ const char kFreedesktopPortalName[] = "org.freedesktop.portal.Desktop";
 const char kFreedesktopPortalPath[] = "/org/freedesktop/portal/desktop";
 const char kFreedesktopPortalOpenURI[] = "org.freedesktop.portal.OpenURI";
 
-const char kOriginalXdgCurrentDesktopEnvVar[] = "ORIGINAL_XDG_CURRENT_DESKTOP";
-
 const char kMethodOpenDirectory[] = "OpenDirectory";
 
 class ShowItemHelper {
@@ -279,12 +276,6 @@ bool XDGUtil(const std::vector<std::string>& argv,
     base::nix::CreateLaunchOptionsWithXdgActivation(base::BindOnce(
         [](base::RepeatingClosure quit_loop, base::LaunchOptions* options_out,
            base::LaunchOptions options) {
-          // Correct the XDG_CURRENT_DESKTOP environment variable before calling
-          // XDG, in case it was changed for compatibility.
-          if (const auto* orig = base::FindOrNull(
-                  options.environment, kOriginalXdgCurrentDesktopEnvVar))
-            options.environment.emplace(base::nix::kXdgCurrentDesktopEnvVar,
-                                        *orig);
           *options_out = std::move(options);
           std::move(quit_loop).Run();
         },