wails icon indicating copy to clipboard operation
wails copied to clipboard

[v3,linux] fix: enable to run natively in wayland

Open stendler opened this issue 1 year ago • 7 comments

Description

Incorporated from this v2 change: https://github.com/wailsapp/wails/pull/1811

Type of change

  • [x] Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • [x] Linux

Verified using xeyes: if the eyes follow the mouse when entering the wails app window, then it is running on X11; if they stop following when entering the window it is running on wayland.

Test Configuration

# Build Environment
┌─────────────────────────────────────────────────────────┐
| Wails CLI    | v3.0.0-alpha.4                           |
| Go Version   | go1.22.4                                 |
| Revision     | 5fcebd02741eea738dfcb7fc43d8d86f139293fe |
| Modified     | true                                     |
| -buildmode   | exe                                      |
| -compiler    | gc                                       |
| CGO_CFLAGS   |                                          |
| CGO_CPPFLAGS |                                          |
| CGO_CXXFLAGS |                                          |
| CGO_ENABLED  | 1                                        |
| CGO_LDFLAGS  |                                          |
| GOAMD64      | v1                                       |
| GOARCH       | amd64                                    |
| GOOS         | linux                                    |
| vcs          | git                                      |
| vcs.modified | true                                     |
| vcs.revision | 5fcebd02741eea738dfcb7fc43d8d86f139293fe |
| vcs.time     | 2024-07-02T08:49:19Z                     |
└─────────────────────────────────────────────────────────┘

# Dependencies
┌────────────────────────────────────────┐
| npm        | 10.8.2                    |
| pkg-config | 2.1.1-1                   |
| webkit2gtk | 2.44.2-1                  |
| gcc        | 14.1.1+r58+gfc9fb69ad62-1 |
| gtk3       | 1:3.24.43-1               |
└─────── * - Optional Dependency ────────┘

Checklist:

  • [ ] I have updated website/src/pages/changelog.mdx with details of this PR
  • [ ] My code follows the general coding style of this project
  • [x] I have performed a self-review of my own code
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] My changes generate no new warnings
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] New and existing unit tests pass locally with my changes

stendler avatar Jul 16 '24 14:07 stendler

Walkthrough

The changes involve updates to the changelog and modifications to the initialization logic in the Linux application code. A new entry in the changelog highlights a fix for native Wayland support, referencing previous pull requests. In the application code, a conditional check is introduced to prevent overwriting the GDK_BACKEND environment variable, ensuring smoother integration for users running Linux.

Changes

Files Change Summary
mkdocs-website/docs/en/changelog.md Added a new entry in the changelog under "Fixed" for Wayland support, referencing previous PRs.
v3/pkg/application/application_linux.go Introduced a conditional check for setting the GDK_BACKEND variable in the init function.

Poem

🐰 In a world where code does play,
Changes hop in, brightening the day.
With checks and fixes, oh what a sight!
Wayland support now feels just right!
Let's leap ahead, embrace the fun,
For every rabbit knows, the work's never done! 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Jul 16 '24 14:07 coderabbitai[bot]

This looks fine to me. Have you noticed any other artifacts of using wayland backend in the webkit window?

atterpac avatar Jul 16 '24 18:07 atterpac

Haven't noticed any issues with wayland so far. Though, I've only used the cgo version. The purego code seems to set _ = os.Setenv("GDK_BACKEND", "x11") without any checks as well. But that also does not seem on par feature wise?

stendler avatar Jul 16 '24 20:07 stendler

Thanks 🙏 Please could you add an entry to the changelog located at mkdocs-website/docs/changelog.md? Thanks!

leaanthony avatar Jul 22 '24 20:07 leaanthony

Done!

stendler avatar Jul 22 '24 20:07 stendler

Can you please fix the merge conflicts 👍

leaanthony avatar Aug 18 '24 11:08 leaanthony

I've rebased and moved the changelog line to the new unreleased section.

Although now I seem to have trouble building on linux (likely due to changes in https://github.com/wailsapp/wails/pull/3667):

 WARNING  -: # github.com/wailsapp/wails/v3/pkg/application                                                                                                                                                                                                                                                         
          wails/v3/pkg/application/webview_window_linux.go:383:69: could not determine kind of name for C.GDK_ALL_EVENTS_MASK
          wails/v3/pkg/application/webview_window_linux.go:381:69: could not determine kind of name for C.GDK_ENTER_NOTIFY_MASK
          wails/v3/pkg/application/webview_window_linux.go:381:93: could not determine kind of name for C.GDK_LEAVE_NOTIFY_MASK
          wails/v3/pkg/application/webview_window_linux.go:381:29: could not determine kind of name for C.GtkWidget
          wails/v3/pkg/application/webview_window_linux.go:381:3: could not determine kind of name for C.gtk_widget_set_events
 WARNING  /myapp/wails/v3/pkg/application/application_linux.go:15:8: could not import C (no metadata for C)                                                                                                                                                             
 WARNING  /myapp/wails/v3/pkg/application/webview_window_linux.go:285:25: undefined: options                                                                                                                                                                            
 WARNING  /myapp/wails/v3/pkg/application/webview_window_linux.go:381:42: undefined: unsafe                                                                                                                                                                             
 WARNING  /myapp/wails/v3/pkg/application/webview_window_linux.go:383:42: undefined: unsafe  

See also the CI in my fork: https://github.com/stendler/wails/actions/runs/10525939856/job/29165722019#step:6:381

EDIT: I got it to run, but ... (click to expand)

in webview_window_linux.go options was used instead of w.parent.options, and I've moved the C calls into linux_cgo.go.

But I could not get the "ignoreMouseEvents" behaviour to work correclty. Neither with the moved implementation, nor with the already existing windowIgnoreMouseEvents (which errors as the GdkWindow is not yet "realized"), and also not when detecting if the GdkWindow is not realised and deferring the gdk_window_set_pass_through with signal_connect on the "realize" signal. The last one at least does not throw CRITICAL, but also does not work as I would expect.

At least it builds again, and the tests pass: https://github.com/stendler/wails/actions/runs/10530008414

stendler avatar Aug 23 '24 12:08 stendler