Browse Source

Share webview pointer with atomics, add dockerfile for CI

master
Wesley Kerfoot 5 years ago
parent
commit
3165baf286
  1. 2
      .vimrc
  2. 7
      Dockerfile
  3. 49
      browser.c

2
.vimrc

@ -0,0 +1,2 @@
set makeprg=./build.sh\ %
set autowrite

7
Dockerfile

@ -0,0 +1,7 @@
FROM archlinux/base
RUN pacman -Syu --noconfirm pkgconf base-devel gtk3 webkit2gtk guile xorg-xauth
WORKDIR /schemekit
COPY browser.c /schemekit/browser.c
RUN gcc $(pkg-config --cflags --libs guile-2.2 gtk+-3.0 webkit2gtk-4.0) browser.c -o schemekit
CMD ["/schemekit/schemekit"]

49
browser.c

@ -22,10 +22,9 @@ closeWebViewCb(WebKitWebView *webView,
return TRUE; return TRUE;
} }
WebKitWebView *webView;
SCM SCM
launch_webkit(void) { launch_webkit(SCM webview) {
WebKitWebView *webView = scm_to_pointer(webview);
/* Initialize GTK+ */ /* Initialize GTK+ */
gtk_init(0, NULL); gtk_init(0, NULL);
@ -34,9 +33,6 @@ launch_webkit(void) {
gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600); gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);
/* Create a browser instance */
webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
/* Put the browser area into the main window */ /* Put the browser area into the main window */
gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(webView)); gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(webView));
@ -61,20 +57,47 @@ launch_webkit(void) {
} }
static SCM static SCM
open_page(SCM scm_url) { open_page(SCM webview, SCM scm_url) {
char *url = scm_to_locale_string(scm_url); char *url = scm_to_locale_string(scm_url);
printf("Opening %s\n", url); printf("Opening %s\n", url);
WebKitWebView *webView = scm_to_pointer(webview);
webkit_web_view_load_uri(webView, url); webkit_web_view_load_uri(webView, url);
return SCM_BOOL_T; return SCM_BOOL_T;
} }
static void static SCM
inner_main(void *data, int argc, char **argv) { make_webview() {
scm_c_define_gsubr("launch-webkit-blocking", 0, 0, 0, launch_webkit); WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
scm_c_define_gsubr("open-page", 1, 0, 0, open_page); return scm_from_pointer(webView, NULL);
}
const char *start_expr = "(call-with-new-thread (lambda () (launch-webkit-blocking)))"; static void
load_modules(void) {
scm_c_use_module("ice-9 threads"); scm_c_use_module("ice-9 threads");
scm_c_use_module("ice-9 atomic");
}
static void
run_repl(void *data, int argc, char **argv) {
load_modules();
scm_c_define_gsubr("launch-webkit-blocking", 1, 0, 0, launch_webkit);
scm_c_define_gsubr("open-page-with-webview", 2, 0, 0, open_page);
scm_c_define_gsubr("make-webview", 0, 0, 0, make_webview);
const char *start_expr = ""
"(define atomic-webview (make-atomic-box #f))"
"(define (open-page url)"
"(cond"
"((atomic-box-ref atomic-webview)"
"(open-page-with-webview (atomic-box-ref atomic-webview) url))"
"(else #f)))"
"(call-with-new-thread"
"(lambda () "
"(define webview (make-webview))"
"(atomic-box-set! atomic-webview webview)"
"(launch-webkit-blocking webview)))";
scm_c_eval_string(start_expr); scm_c_eval_string(start_expr);
scm_shell(argc, argv); scm_shell(argc, argv);
@ -82,6 +105,6 @@ inner_main(void *data, int argc, char **argv) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
/* Initialize Guile */ /* Initialize Guile */
scm_boot_guile(argc, argv, inner_main, 0); scm_boot_guile(argc, argv, run_repl, 0);
return 0; return 0;
} }

Loading…
Cancel
Save