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

fix: add support for ELECTRON_OZONE_PLATFORM_HINT environment variable #35614

Closed
wants to merge 1 commit into from

Conversation

vially
Copy link
Contributor

@vially vially commented Sep 8, 2022

Description of Change

Add support for the ELECTRON_OZONE_PLATFORM_HINT environment variable in order to make it easier for users to enable Wayland support for all Electron apps without having to manually patch application .desktop files (or other similar workarounds #30897).

The accepted values are the same as upstream, with the special auto value being recommended for most users (especially for those switching between X11 and Wayland environments).

When both the --ozone-platform-hint command line flag and the ELECTRON_OZONE_PLATFORM_HINT environment variable are specified, the command line flag has higher priority.

Fixes #30897

Checklist

Release Notes

Notes: Added support for ELECTRON_OZONE_PLATFORM_HINT environment variable on Linux.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Sep 8, 2022
@vially vially changed the title fix: add support for ELECTRON_OZONE_PLATFORM_HINT env var fix: add support for ELECTRON_OZONE_PLATFORM_HINT environment variable Sep 8, 2022
@deepak1556
Copy link
Member

Can we instead set --ozone-platform-hint=auto by default in Electron ? We seem to have a resonable fallback to use X11 when wayland server is not found/running

// 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(OZONE_PLATFORM_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::string xdg_session_type;
const bool has_xdg_session_type =
env->GetVar(base::nix::kXdgSessionTypeEnvVar, &xdg_session_type) &&
!xdg_session_type.empty();
if ((has_xdg_session_type && xdg_session_type == "wayland") ||
(ozone_platform_hint == kPlatformWayland &&
HasWaylandDisplay(env.get()))) {
return kPlatformWayland;
}
}
#endif // BUILDFLAG(OZONE_PLATFORM_WAYLAND)
#if BUILDFLAG(OZONE_PLATFORM_X11)
if (ozone_platform_hint == kPlatformX11) {
return kPlatformX11;
}
#if BUILDFLAG(OZONE_PLATFORM_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(OZONE_PLATFORM_WAYLAND)
#endif // BUILDFLAG(OZONE_PLATFORM_X11)
, also --ozone-platform takes precedence over --ozone-platform-hint which still gives applications control over the default behavior of Electron for any edge cases they encounter. Seems like a default of --ozone-platform-hint=auto in Electron would cover all use cases mentioned in the linked issue.

@vially
Copy link
Contributor Author

vially commented Sep 9, 2022

Can we instead set --ozone-platform-hint=auto by default in Electron?

I've created #35630 which does that (set --ozone-platform-hint to auto by default). I think either one of these two pull-requests (#35614, #35630) will address #30897, but I'm personally more in favor of #35630.

@ckerr
Copy link
Member

ckerr commented Sep 12, 2022

I think I'd prefer #35630 over this PR and from #35614 (comment) it sounds like @deepak1556 would lean in the same direction

@deepak1556
Copy link
Member

Yup I prefer #35630 over the environment variable. Maybe we close this and revisit if #35630 is not viable.

@ckerr ckerr closed this Sep 13, 2022
@vially vially deleted the add-ozone-hint-env-var branch September 13, 2022 05:00
@vially vially restored the add-ozone-hint-env-var branch March 5, 2023 21:47
@vially vially deleted the add-ozone-hint-env-var branch March 5, 2023 21:48
@parcelcat
Copy link

parcelcat commented Apr 20, 2023

Since #35630 looks premature until Chromium changes the default ozone platform value, could we please reopen this pull request?

@ckerr @deepak1556 @vially

@ZtereoHYPE
Copy link

This feels way overdue considering chromium seems nowhere close to enabling their default ozone platform hint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-pr 🌱 PR opened in the last 24 hours
Projects
None yet
5 participants