webkit2gtk-rs icon indicating copy to clipboard operation
webkit2gtk-rs copied to clipboard

GTK4 support?

Open ghost opened this issue 3 years ago • 13 comments

This blog post has got me wanting to port my WebKit-powered browser project over to GTK4-rs, as I'm seeking to replacing my implementation of tabs with the Libadwaita widget. This would accomplish two things for me: it removes the burden on me to solely develop & maintain a major component of my project, and it would additionally allow my project to match the design guidelines that other GTK projects follow.

As of present, I'm unable to make this switch to GTK4 + Libadwaita. I've:

  1. Updated the dependencies to rely on the latest GTK4-rs crate versions (as libadwaita-rs uses release numbers and not Git for its dependencies)
  2. Updated the GIR files locally (remember to do this yourself if you're checking out my current progress)
  3. Regenerated the bindings (using make gir)

However, I still encounter 6 build errors within webkit2gtk-sys, which reflect the following errors given by GIR:

[WARN  libgir::parser] <boxed name=Some("ByteArray")>
[ERROR libgir::analysis::record] Missing memory management functions for Gdk.EventKey
[ERROR libgir::analysis::record] Missing memory management functions for JavaScriptCore.ValueRef
[WARN  libgir::analysis::trampolines] Can't generate WebKit2.BackForwardList trampoline for signal 'changed'
[WARN  libgir::analysis::functions] Function webkit_input_method_context_get_preedit has unsupported outs

Specifically, webkit2gtk-rs is currently expecting GdkEventKey, GtkContainerClass, GtkContainer, and GtkAction to still exist.

During my work on getting this repository building again (see: #89), I became a little familiar with how this all works, but I must admit there's still a lot I don't know. I'm not good with Rust or C (hell, software development in general), I'm not familiar with the technical work being done in the GTK/GNOME world, nor am I familiar with the goings on with GTK-rs, so I'm sorry I can't work on this myself. I wish I had the knowledge and ability to contribute directly instead of just opening a GitHub issue.

ghost avatar Jul 18 '21 19:07 ghost

I'm not sure whether webkit2gtk has a release supporting gtk4, you might have to build it with some cli options as specified here.

antoyo avatar Jul 18 '21 19:07 antoyo

I have a super hacky branch for Gtk4 here: https://github.com/jangernert/webkit2gtk-rs/tree/gtk4

Just enough for me to port my application to Gtk4. For this to work you still need to compile webkitgtk with the Gtk4 platform support and libsoup3 yourself. I am not aware of any binary packages for these two libraries at the moment.

jangernert avatar Jul 18 '21 19:07 jangernert

@jangernert, would it be beneficial to move your branch over to the main webkit2gtk-rs repository? I'm thinking it would lead to increased development and attention. I'd like to know your thoughts.

Additionally, for those finding this GitHub issue, I've written a script to build & install WebKitGTK with GTK4 support (webkit2gtk-5.0):

#!/bin/bash

# Cleanup
rm -rf ./gtk4-dependencies
mkdir gtk4-dependencies && cd gtk4-dependencies

# GLib
git clone --depth 1 --recurse-submodules --shallow-submodules https://gitlab.gnome.org/GNOME/glib.git
cd ./glib
meson _build && ninja -C _build
sudo ninja -C _build install
cd ../

# glib-networking
git clone --depth 1 --recurse-submodules --shallow-submodules https://gitlab.gnome.org/GNOME/glib-networking.git
cd ./glib-networking
mkdir build && cd build
meson --prefix=/usr --buildtype=release .. && ninja
sudo ninja install
cd ../../

# libsoup 3
git clone --depth 1 --recurse-submodules --shallow-submodules https://gitlab.gnome.org/GNOME/libsoup.git
cd ./libsoup
mkdir build && cd build
meson --prefix=/usr --buildtype=release .. && ninja
sudo ninja install
cd ../../

# WebKitGTK 5.0
git clone --depth 1 --recurse-submodules --shallow-submodules https://github.com/WebKit/WebKit.git
cd ./WebKit
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_SKIP_RPATH=ON -DPORT=GTK \
-DLIB_INSTALL_DIR=/usr/lib \
-DUSE_GTK4=ON \
-DUSE_AVIF=ON \
-GNinja .. && ninja
sudo ninja install
cd ../../

ghost avatar Jul 20 '21 23:07 ghost

I don't see any reason for that. It's just as easy to reference the fork in your cargo.toml. And once webkitgtk 5.0 is released and packaged I would start generating bindings from scratch. I manually copied and patched the .gir-files and then manually patched the generated bindings to get things working quick & dirty.

jangernert avatar Jul 21 '21 03:07 jangernert

I've since encountered two issues which I suspect are upstream:

  1. WebView content being near-invisible
  2. ~~HTTPS connections failing~~ (resolved by adding glib-networking to the dependency build process, as suggested by Michael Catanzaro)

I've filed a bug report in the WebKit Bugzilla: https://bugs.webkit.org/show_bug.cgi?id=228268

ghost avatar Jul 25 '21 20:07 ghost

Well, this is weird. Epiphany uses Gtk4, what exactly is stopping webkit2gtk-rs?

ergpopler avatar Aug 29 '21 21:08 ergpopler

@ergpopler: Well, this is weird. Epiphany uses Gtk4, what exactly is stopping webkit2gtk-rs?

Epiphany does not use GTK4. It uses GTK3 with libhandy. It does appear that WebKitGTK 5.0 (WebKit for GTK 4) cannot render properly on Nvidia GPUs.

ghost avatar Aug 31 '21 20:08 ghost

@jangernert I've been unable to get your branch working with my project as of recent, and would appreciate some quick assistance.

I've been compiling libsoup3 and WebKitGTK 5.0 (with the USE_GTK4 compilation flag), as I did in the past, but nowadays I get the following error when attempting to run my program: libsoup-ERROR **: libsoup2 symbols detected. Using libsoup2 and libsoup3 in the same process is not supported.

I encounter the same exact error when using the libsoup3 and webkit2gtk-5.0 Arch Linux packages (as opposed to compiling them myself).

I do have libsoup2 and libsoup3 co-existing on my Arch Linux system. Could this be the source of the issue? Any thoughts on how I can fix this, short of uninstalling libsoup2?

ghost avatar Dec 03 '21 16:12 ghost

You should try the official WIP bindings: https://gitlab.gnome.org/World/Rust/webkit2gtk5-rs

You'll need to use the Gtk-Bindings from git as well.

jangernert avatar Dec 03 '21 18:12 jangernert

It appears WebKit2Gtk now supports GTK-4 bindings in its new stable release:

https://webkitgtk.org/2023/03/17/webkitgtk2.40.0-released.html

Of course, this release was only a week or two ago, so it'll be a while until this version is available on most "scheduled-release" distros (debian, ubuntu, etc.).

Regardless, I think this is an issue to keep a look out for 👀

grantshandy avatar Apr 03 '23 14:04 grantshandy

for tauri, becuase it depends on https://github.com/tauri-apps/libappindicator-rs , which depends on libayatana, and libayatana only support gtk3 (see https://github.com/AyatanaIndicators/libayatana-appindicator/issues/22 ).

I do not think it can upgrade to gtk4 for the current.

ttys3 avatar Apr 06 '23 18:04 ttys3

Just for my understanding, does this mean that there is no way to use webkit2gtk in rust with gtk4 right now and for the foreseeable future?

jeena avatar May 12 '23 09:05 jeena

@jeena there is no webkit2gtk anymore. The new API is called webkitgtk-6.0 and there are rust bindings here: https://gitlab.gnome.org/World/Rust/webkit6-rs

jangernert avatar May 12 '23 09:05 jangernert