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: calling of X11 functions when running under Wayland #33355

Merged
merged 17 commits into from Mar 28, 2022

Conversation

p2004a
Copy link
Contributor

@p2004a p2004a commented Mar 20, 2022

Description of Change

TLDR: I primarily try to address the #33325 and #32436 issues with this PR.

In #30814 there was fe40088 committed that removed all if (!features::IsUsingOzonePlatform()) { blocks. Those blocks were guarding calls to X11 functions under wayland and were added as part of #26022. Calling X11 functions under wayland can cause the application to crash (as visible in #33325 and #32436).

This PR:

  • Replaces USE_X11 with USE_OZONE blocks as ozone is the only build of chrome nowadays (Ref: [Bug]: segfault on startup at gpu_init.cc under native Wayland #32436 (comment)) and only call X11 code only when running under X11. I believe the functionality hidden on non-x11 platform is not critical and this is overall net positive to current state.

  • Replaces WindowStateWatcher with ozone native implementation in ElectronDesktopWindowTreeHostLinux: it is always instantiated under ozone, but the wayland decorations remain guarded by the WaylandWindowDecorations feature flag (As was added in fix: Add support for Wayland window decorations #29618).

    This makes the maximize, enter-full-screen, etc. events of BrowserWindow work under wayland.

  • Eliminates the X11 calls in file and message dialogs. Frankly I'm not sure if call to gtk_window_present is needed at all: under my system it's noop, but maybe there are DEs where it matters, so keeping it.

Checklist

Release Notes

notes: Fixed multiple issues when running under Wayland caused by calling X11 functions.

[1]: clean e init --bootstrap testing followed by e test I failing for me with Running "ninja -j 200 node:headers" in /home/p2004a/Workspace/electron/e/src/out/Testing ninja: error: unknown target 'node:headers', did you mean 'node_headers_1'?, I can't make it work :(, I was testing functions with my own draft app. I hope CI run as part of this PR will handle this omission.

@welcome
Copy link

welcome bot commented Mar 20, 2022

💖 Thanks for opening this pull request! 💖

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Mar 20, 2022
@p2004a p2004a changed the title fix: Fix calling of X11 functions when running under Wayland fix: fix calling of X11 functions when running under Wayland Mar 20, 2022
@miniak miniak changed the title fix: fix calling of X11 functions when running under Wayland fix: calling of X11 functions when running under Wayland Mar 20, 2022
@codebytere
Copy link
Member

codebytere commented Mar 21, 2022

This also addresses #31382 cc @deepak1556

Copy link
Member

@dsanders11 dsanders11 left a comment

Choose a reason for hiding this comment

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

Added some comments. I haven't tested this, just adding some suggested changes.

[1]: clean e init --bootstrap testing followed by e test I failing for me with Running "ninja -j 200 node:headers" in /home/p2004a/Workspace/electron/e/src/out/Testing ninja: error: unknown target 'node:headers', did you mean 'node_headers_1'?, I can't make it work :(, I was testing functions with my own draft app. I hope CI run as part of this PR will handle this omission.

Thanks for mentioning that! Fixing it over in electron/build-tools#351.

shell/browser/ui/file_dialog_gtk.cc Outdated Show resolved Hide resolved
shell/browser/ui/message_box_gtk.cc Outdated Show resolved Hide resolved
shell/browser/native_window_views.cc Outdated Show resolved Hide resolved
shell/browser/ui/electron_desktop_window_tree_host_linux.h Outdated Show resolved Hide resolved
@p2004a
Copy link
Contributor Author

p2004a commented Mar 22, 2022

I've rebased the branch because there was a merge conflict.

Thank you @dsanders11 for taking a look and fixing build tools!

I've run the tests and I've got exactly the same result on the origin:main and on my p2004a:wayland-fixes branches so I don't think I've broken anything ;). It doesn't mean that tests pass though, 10 tests don't, and those are the same tests on both main and my branch: https://gist.github.com/p2004a/480d7248de118c86c204c785bd05a9fd. I don't plan on debugging those here.

@zcbenz zcbenz added semver/patch backwards-compatible bug fixes target/16-x-y labels Mar 22, 2022
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Mar 22, 2022
shell/browser/native_window_views.cc Outdated Show resolved Hide resolved
shell/browser/ui/file_dialog_gtk.cc Show resolved Hide resolved
shell/browser/native_window_views.cc Show resolved Hide resolved
Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, really appreciate it!

Reviews are based on first pass on the PR,

  1. Can you also remove the USE_X11 define from

    "USE_X11=1",

  2. Can you apply the changes from https://chromium-review.googlesource.com/c/chromium/src/+/2289772/ and https://chromium-review.googlesource.com/c/chromium/src/+/2317185 to GlobalMenuBarX11 which better aligns with upstream. Should end up in a state similar to https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/BUILD.gn;l=3873-3882

shell/browser/native_window_views.cc Outdated Show resolved Hide resolved
shell/browser/ui/file_dialog_gtk.cc Outdated Show resolved Hide resolved
@p2004a p2004a requested review from a team as code owners March 23, 2022 19:37
@p2004a
Copy link
Contributor Author

p2004a commented Mar 23, 2022

Can you also remove the USE_X11 define from

Done, I also had to cleanup usage in shell/browser/ui/gtk/menu_util.cc

Can you apply the changes from upstream to GlobalMenuBarX11

I would prefer to not do it as part of this PR, there are many more places where X11 code needs to dropped and replaced with proper ozone abstractions.

Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

LGTM with minor change.

@p2004a p2004a requested a review from deepak1556 March 24, 2022 19:34
Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

@p2004a can you rebase to resolve the conflicts, thanks!

@trop
Copy link
Contributor

trop bot commented Mar 29, 2022

@deepak1556 has manually backported this PR to "18-x-y", please check out #33498

@trop
Copy link
Contributor

trop bot commented Mar 29, 2022

@deepak1556 has manually backported this PR to "17-x-y", please check out #33499

@prusnak
Copy link

prusnak commented Apr 1, 2022

ISTM this still has to be backported to 16.x.x

@deepak1556
Copy link
Member

The PR has not been backported to 16-x-y yet, I didn't spend time on it because 16-x-y also requires the following #32603 for the runtime to work on wayland. If anyone is interested to work on both these backports, feel free to!

bavulapati pushed a commit to bavulapati/electron that referenced this pull request Apr 29, 2022
)

* fix: don't call X11 functions in file dialog and message box

* refactor: remove unused GtkUiPlatform declaration

* fix: set gtk darktheme only when running under X11

* fix: replace X11 window state watcher with implementation using ozone

* fix: make sure global menu barr is used only when supported

* fix: don't call X11 function in native window views under wayland

* style: fix lint issues

* fix: use GtkUiPlatform::ShowGtkWindow instead of gtk_window_present directly

* refactor: extract CreateGlobalMenuBar into separate function

* refactor: move checking for WaylandWindowDecorations inside class

* fix: check if we run under X11 only in ozone build

* refactor: drop including unused ui/base/ui_base_features.h header

* fix: modify ui_gtk_public_header.patch to also export gtk_ui.h

* fix: refactor guarding of X11 calls

- Introduce patch exposing new electron_can_call_x11 property
- Replace defined(USE_OZONE) with BUILDFLAG(OZONE_PLATFORM_X11) flags

* fix: remove the last remaining usage of USE_X11

* fix: usage of BUILDFLAG(OZONE_PLATFORM_X11) not building on non ozone

* fix: call UpdateWindowState from OnBoundsChanged only under X11
khalwa pushed a commit to solarwindscloud/electron that referenced this pull request Feb 22, 2023
)

* fix: don't call X11 functions in file dialog and message box

* refactor: remove unused GtkUiPlatform declaration

* fix: set gtk darktheme only when running under X11

* fix: replace X11 window state watcher with implementation using ozone

* fix: make sure global menu barr is used only when supported

* fix: don't call X11 function in native window views under wayland

* style: fix lint issues

* fix: use GtkUiPlatform::ShowGtkWindow instead of gtk_window_present directly

* refactor: extract CreateGlobalMenuBar into separate function

* refactor: move checking for WaylandWindowDecorations inside class

* fix: check if we run under X11 only in ozone build

* refactor: drop including unused ui/base/ui_base_features.h header

* fix: modify ui_gtk_public_header.patch to also export gtk_ui.h

* fix: refactor guarding of X11 calls

- Introduce patch exposing new electron_can_call_x11 property
- Replace defined(USE_OZONE) with BUILDFLAG(OZONE_PLATFORM_X11) flags

* fix: remove the last remaining usage of USE_X11

* fix: usage of BUILDFLAG(OZONE_PLATFORM_X11) not building on non ozone

* fix: call UpdateWindowState from OnBoundsChanged only under X11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants