Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for ELECTRON_OZONE_PLATFORM_HINT env var #39792

Merged
merged 2 commits into from Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/api/environment-variables.md
Expand Up @@ -111,6 +111,16 @@ Options:
* `kioclient5`
* `kioclient`

### `ELECTRON_OZONE_PLATFORM_HINT` _Linux_

Selects the preferred platform backend used on Linux. The default one is `x11`. `auto` selects Wayland if possible, X11 otherwise.

Options:

* `auto`
* `wayland`
* `x11`

## Development Variables

The following environment variables are intended primarily for development and
Expand Down
10 changes: 8 additions & 2 deletions shell/browser/electron_browser_main_parts_linux.cc
Expand Up @@ -15,6 +15,9 @@
#include "shell/common/thread_restrictions.h"
#endif

constexpr base::StringPiece kElectronOzonePlatformHint(
"ELECTRON_OZONE_PLATFORM_HINT");

#if BUILDFLAG(OZONE_PLATFORM_WAYLAND)

constexpr char kPlatformWayland[] = "wayland";
Expand Down Expand Up @@ -115,17 +118,20 @@ std::string MaybeFixPlatformName(const std::string& ozone_platform_hint) {
} // namespace

void ElectronBrowserMainParts::DetectOzonePlatform() {
auto const env = base::Environment::Create();
auto* const command_line = base::CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(switches::kOzonePlatform)) {
const auto ozone_platform_hint =
auto ozone_platform_hint =
command_line->GetSwitchValueASCII(switches::kOzonePlatformHint);
if (ozone_platform_hint.empty()) {
env->GetVar(kElectronOzonePlatformHint, &ozone_platform_hint);
}
if (!ozone_platform_hint.empty()) {
command_line->AppendSwitchASCII(
switches::kOzonePlatform, MaybeFixPlatformName(ozone_platform_hint));
}
}

auto env = base::Environment::Create();
std::string desktop_startup_id;
if (env->GetVar("DESKTOP_STARTUP_ID", &desktop_startup_id))
command_line->AppendSwitchASCII("desktop-startup-id", desktop_startup_id);
Expand Down