Created
March 2, 2023 14:49
-
-
Save aperezdc/f6a65a95f2baa222c0ce9d65e516e13b to your computer and use it in GitHub Desktop.
Minimal WPE launcher using libcogcore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* SPDX-License-Identifier: MIT | |
* | |
* cc -o minicog minicog.c $(pkg-config wpe-webkit-1.1 cogcore --cflags --libs) | |
*/ | |
#include <cog/cog.h> | |
static const char *s_starturl = NULL; | |
static WebKitWebView* | |
on_create_view(CogShell *shell, CogPlatform *platform) | |
{ | |
g_autoptr(GError) error = NULL; | |
WebKitWebViewBackend *view_backend = cog_platform_get_view_backend(platform, NULL, &error); | |
if (!view_backend) | |
g_error("Cannot obtain view backend: %s", error->message); | |
g_autoptr(WebKitWebView) web_view = | |
g_object_new(WEBKIT_TYPE_WEB_VIEW, | |
"settings", cog_shell_get_web_settings(shell), | |
"web-context", cog_shell_get_web_context(shell), | |
"backend", view_backend, | |
NULL); | |
cog_platform_init_web_view(platform, web_view); | |
webkit_web_view_load_uri(web_view, s_starturl); | |
return g_steal_pointer(&web_view); | |
} | |
int | |
main(int argc, char *argv[]) | |
{ | |
g_set_application_name("minicog"); | |
if (argc != 2 && argc != 3) { | |
g_printerr("Usage: %s [URL [platform]]\n", argv[0]); | |
return EXIT_FAILURE; | |
} | |
g_autoptr(GError) error = NULL; | |
if (!(s_starturl = cog_uri_guess_from_user_input(argv[1], TRUE, &error))) | |
g_error("Invalid URL '%s': %s", argv[1], error->message); | |
cog_modules_add_directory(COG_MODULEDIR); | |
g_autoptr(GApplication) app = g_application_new(NULL, G_APPLICATION_DEFAULT_FLAGS); | |
g_autoptr(CogShell) shell = cog_shell_new("minicog", FALSE); | |
g_autoptr(CogPlatform) platform = | |
cog_platform_new((argc == 3) ? argv[2] : g_getenv("COG_PLATFORM"), &error); | |
if (!platform) | |
g_error("Cannot create platform: %s", error->message); | |
if (!cog_platform_setup(platform, shell, "", &error)) | |
g_error("Cannot setup platform: %s\n", error->message); | |
g_signal_connect(shell, "create-view", G_CALLBACK(on_create_view), platform); | |
g_signal_connect_swapped(app, "shutdown", G_CALLBACK(cog_shell_shutdown), shell); | |
g_signal_connect_swapped(app, "startup", G_CALLBACK(cog_shell_startup), shell); | |
g_signal_connect(app, "activate", G_CALLBACK(g_application_hold), NULL); | |
return g_application_run(app, 1, argv); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
Running this on a raspberry pi 3b+ (
./app index.html drm
), with a yocto build image with Mesa VC4 driver, DRM and wpebackend-fdo, I only get the mouse cursor; the web page doesn't show on the framebuffer.If I run
cog -P index.html
it works tho. Any idea?I'm using wpewebkit-2.0