From d9dad4305092f5022fd493ca8b5d5d7af60a0b24 Mon Sep 17 00:00:00 2001 From: clavin Date: Fri, 8 Aug 2025 14:26:18 -0600 Subject: [PATCH] Remove ELECTRON_OZONE_PLATFORM_HINT env var 6819616: Remove OzonePlatformHint | https://chromium-review.googlesource.com/c/chromium/src/+/6819616 See: https://github.com/electron/electron/issues/48001 --- docs/api/environment-variables.md | 10 -- docs/breaking-changes.md | 8 ++ shell/browser/electron_browser_main_parts.cc | 2 +- shell/browser/electron_browser_main_parts.h | 2 +- .../electron_browser_main_parts_linux.cc | 120 +----------------- 5 files changed, 14 insertions(+), 128 deletions(-) diff --git a/docs/api/environment-variables.md b/docs/api/environment-variables.md index cbd3525d03..f6b05c4cf8 100644 --- a/docs/api/environment-variables.md +++ b/docs/api/environment-variables.md @@ -125,16 +125,6 @@ Options: * `kioclient5` * `kioclient` -### `ELECTRON_OZONE_PLATFORM_HINT` _Linux_ _Deprecated_ - -Selects the preferred platform backend used on Linux. `auto` selects Wayland if possible, X11 otherwise. - -Options: - -* `auto` (Default) -* `wayland` -* `x11` - ## Development Variables The following environment variables are intended primarily for development and diff --git a/docs/breaking-changes.md b/docs/breaking-changes.md index 2045088031..5e89a297bd 100644 --- a/docs/breaking-changes.md +++ b/docs/breaking-changes.md @@ -12,6 +12,14 @@ This document uses the following convention to categorize breaking changes: * **Deprecated:** An API was marked as deprecated. The API will continue to function, but will emit a deprecation warning, and will be removed in a future release. * **Removed:** An API or feature was removed, and is no longer supported by Electron. +## Planned Breaking API Changes (39.0) + +### Removed: `ELECTRON_OZONE_PLATFORM_HINT` evironment variable + +The default value of the `--ozone-plaftform` flag [changed to `auto`](https://chromium-review.googlesource.com/c/chromium/src/+/6775426) in Electron 38. + +You should use the `XDG_SESSION_TYPE=wayland` environment variable instead to use Wayland. + ## Planned Breaking API Changes (38.0) ### Deprecated: `ELECTRON_OZONE_PLATFORM_HINT` environment variable diff --git a/shell/browser/electron_browser_main_parts.cc b/shell/browser/electron_browser_main_parts.cc index aaa45b0826..15bd0de368 100644 --- a/shell/browser/electron_browser_main_parts.cc +++ b/shell/browser/electron_browser_main_parts.cc @@ -210,7 +210,7 @@ int ElectronBrowserMainParts::PreEarlyInitialization() { HandleSIGCHLD(); #endif #if BUILDFLAG(IS_LINUX) - DetectOzonePlatform(); + SetDesktopStartupId(); ui::OzonePlatform::PreEarlyInitialization(); #endif #if BUILDFLAG(IS_MAC) diff --git a/shell/browser/electron_browser_main_parts.h b/shell/browser/electron_browser_main_parts.h index ebf3e10ff1..d8cced5abf 100644 --- a/shell/browser/electron_browser_main_parts.h +++ b/shell/browser/electron_browser_main_parts.h @@ -125,7 +125,7 @@ class ElectronBrowserMainParts : public content::BrowserMainParts { #endif #if BUILDFLAG(IS_LINUX) - void DetectOzonePlatform(); + void SetDesktopStartupId(); #endif #if BUILDFLAG(IS_MAC) diff --git a/shell/browser/electron_browser_main_parts_linux.cc b/shell/browser/electron_browser_main_parts_linux.cc index 87e2f50d2a..e6ab3e4c1b 100644 --- a/shell/browser/electron_browser_main_parts_linux.cc +++ b/shell/browser/electron_browser_main_parts_linux.cc @@ -6,127 +6,15 @@ #include "base/command_line.h" #include "base/environment.h" -#include "base/strings/cstring_view.h" -#include "ui/base/ozone_buildflags.h" -#include "ui/ozone/public/ozone_switches.h" - -#if BUILDFLAG(IS_OZONE_WAYLAND) -#include "base/files/file_path.h" -#include "base/files/file_util.h" -#include "base/nix/xdg_util.h" -#include "shell/common/thread_restrictions.h" -#endif namespace electron { -namespace { - -constexpr base::cstring_view kElectronOzonePlatformHint{ - "ELECTRON_OZONE_PLATFORM_HINT"}; - -#if BUILDFLAG(IS_OZONE_WAYLAND) - -constexpr char kPlatformWayland[] = "wayland"; - -bool HasWaylandDisplay(base::Environment* env) { - if (std::optional wayland_display = - env->GetVar("WAYLAND_DISPLAY")) { - return true; - } - - if (std::optional xdg_runtime_dir = - env->GetVar("XDG_RUNTIME_DIR")) { - auto wayland_server_pipe = - base::FilePath(*xdg_runtime_dir).Append("wayland-0"); - // Normally, this should happen exactly once, at the startup of the main - // process. - electron::ScopedAllowBlockingForElectron allow_blocking; - return base::PathExists(wayland_server_pipe); - } - - return false; -} - -#endif // BUILDFLAG(IS_OZONE_WAYLAND) - -#if BUILDFLAG(IS_OZONE_X11) -constexpr char kPlatformX11[] = "x11"; -#endif - -// Evaluates the environment and returns the effective platform name for the -// given |ozone_platform_hint|. -// For the "auto" value, returns "wayland" if the XDG session type is "wayland", -// "x11" otherwise. -// For the "wayland" value, checks if the Wayland server is available, and -// returns "x11" if it is not. -// See https://crbug.com/1246928. -std::string MaybeFixPlatformName(const std::string& ozone_platform_hint) { -#if BUILDFLAG(IS_OZONE_WAYLAND) - // Wayland is selected if both conditions below are true: - // 1. The user selected either 'wayland' or 'auto'. - // 2. The XDG session type is 'wayland', OR the user has selected 'wayland' - // explicitly and a Wayland server is running. - // Otherwise, fall back to X11. - if (ozone_platform_hint == kPlatformWayland || - ozone_platform_hint == "auto") { - auto env(base::Environment::Create()); - - std::optional xdg_session_type = - env->GetVar(base::nix::kXdgSessionTypeEnvVar); - if ((xdg_session_type.has_value() && *xdg_session_type == "wayland") || - (ozone_platform_hint == kPlatformWayland && - HasWaylandDisplay(env.get()))) { - return kPlatformWayland; - } - } -#endif // BUILDFLAG(IS_OZONE_WAYLAND) - -#if BUILDFLAG(IS_OZONE_X11) - if (ozone_platform_hint == kPlatformX11) { - return kPlatformX11; - } -#if BUILDFLAG(IS_OZONE_WAYLAND) - if (ozone_platform_hint == kPlatformWayland || - ozone_platform_hint == "auto") { - // We are here if: - // - The binary has both X11 and Wayland backends. - // - The user wanted Wayland but that did not work, otherwise it would have - // been returned above. - if (ozone_platform_hint == kPlatformWayland) { - LOG(WARNING) << "No Wayland server is available. Falling back to X11."; - } else { - LOG(WARNING) << "This is not a Wayland session. Falling back to X11. " - "If you need to run Chrome on Wayland using some " - "embedded compositor, e. g., Weston, please specify " - "Wayland as your preferred Ozone platform, or use " - "--ozone-platform=wayland."; - } - return kPlatformX11; - } -#endif // BUILDFLAG(IS_OZONE_WAYLAND) -#endif // BUILDFLAG(OZONE_PLATFORM_X11) - - return ozone_platform_hint; -} - -} // namespace - -void ElectronBrowserMainParts::DetectOzonePlatform() { +void ElectronBrowserMainParts::SetDesktopStartupId() { + // TODO(clavin): this was removed upstream in + // https://chromium-review.googlesource.com/c/chromium/src/+/6819616 but it's + // not clear if that was intentional. auto const env = base::Environment::Create(); auto* const command_line = base::CommandLine::ForCurrentProcess(); - if (!command_line->HasSwitch(switches::kOzonePlatform)) { - auto ozone_platform_hint = - command_line->GetSwitchValueASCII(switches::kOzonePlatformHint); - if (ozone_platform_hint.empty()) { - ozone_platform_hint = - env->GetVar(kElectronOzonePlatformHint).value_or(""); - } - if (!ozone_platform_hint.empty()) { - command_line->AppendSwitchASCII( - switches::kOzonePlatform, MaybeFixPlatformName(ozone_platform_hint)); - } - } - if (std::optional desktop_startup_id = env->GetVar("DESKTOP_STARTUP_ID")) command_line->AppendSwitchASCII("desktop-startup-id", *desktop_startup_id);