[webkit-gtk] Nothing shown in the widget when compiling with Fedora 37
Lothar Scholz
scholz.lothar at gmail.com
Wed Jan 4 15:31:44 PST 2023
Hello,
So after a year of silence i tried again to get things going in the
hope that it now reached some workable out of the box state. But using
the CMakeLists.txt and C++ Code below it compiles and runs, it does
only show a naked empty window.
By the way, where is the example code from the website? It seems they
are removed.
-----------------------------------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.25)
project(example LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(PkgConfig REQUIRED)
pkg_check_modules(lib_gtk REQUIRED IMPORTED_TARGET gtk4 cairo)
pkg_check_modules(lib_glib REQUIRED IMPORTED_TARGET glib-2.0
gio-unix-2.0 gio-2.0)
pkg_check_modules(lib_webkit REQUIRED IMPORTED_TARGET webkit2gtk-5.0)
add_executable(FooBar "code.cpp")
target_link_libraries(FooBar PRIVATE PkgConfig::lib_glib)
target_link_libraries(FooBar PRIVATE PkgConfig::lib_gtk)
target_link_libraries(FooBar PRIVATE PkgConfig::lib_webkit)
install(TARGETS FooBar)
install(DIRECTORY "share/" DESTINATION "/app/share")
-----------------------------------------------------------------------------------------------------------
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>
static gboolean closeWebViewCb(WebKitWebView*, GtkWidget* window) {
gtk_window_destroy(GTK_WINDOW(window));
return TRUE;
}
static void activate (GtkApplication* app, gpointer) {
GtkWidget *window = gtk_application_window_new(app);
gtk_window_set_title (GTK_WINDOW (window), "FooBar in WebKit2Gtk");
gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
g_signal_connect(webView, "close", G_CALLBACK(closeWebViewCb), window);
webkit_web_view_load_uri(webView, "https://www.webkitgtk.org/");
gtk_window_set_child (GTK_WINDOW (window), GTK_WIDGET(webView));
gtk_widget_grab_focus(GTK_WIDGET(webView));
gtk_widget_show(window);
}
int main(int argc, char* argv[]) {
GtkApplication *app = gtk_application_new ("app.filesqueezer.example",
G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run(G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
More information about the webkit-gtk
mailing list