From aa749a15c990b70cc8df18d10bbbe2cad7e568b5 Mon Sep 17 00:00:00 2001 From: wes Date: Mon, 7 Oct 2019 21:49:10 -0400 Subject: [PATCH] Got it working --- browser.c | 85 ++++++++++++++++++++++++++++++++++++------------------- build.sh | 3 +- test.scm | 3 ++ 3 files changed, 61 insertions(+), 30 deletions(-) mode change 100644 => 100755 build.sh create mode 100644 test.scm diff --git a/browser.c b/browser.c index 24ffbb9..0f0cd99 100644 --- a/browser.c +++ b/browser.c @@ -1,56 +1,83 @@ #include #include +#include +#include +#include static void destroyWindowCb(GtkWidget *widget, GtkWidget *window); -static -gboolean closeWebViewCb(WebKitWebView *webView, GtkWidget *window); +static gboolean +closeWebViewCb(WebKitWebView *webView, GtkWidget *window); static void destroyWindowCb(GtkWidget *widget, GtkWidget *window) { gtk_main_quit(); } -static -gboolean closeWebViewCb(WebKitWebView *webView, - GtkWidget *window) { +static gboolean +closeWebViewCb(WebKitWebView *webView, + GtkWidget *window) { gtk_widget_destroy(window); return TRUE; } -int main(int argc, char *argv[]) { - // Initialize GTK+ - gtk_init(&argc, &argv); +WebKitWebView *webView; - // Create an 800x600 window that will contain the browser instance - GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600); +static SCM +start_browser(void) { + /* Initialize GTK+ */ + gtk_init(0, NULL); - // Create a browser instance - WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + /* Create an 800x600 window that will contain the browser instance */ + GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - // Put the browser area into the main window - gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(webView)); + gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600); - // Set up callbacks so that if either the main window or the browser instance is - // closed, the program will exit - g_signal_connect(main_window, "destroy", G_CALLBACK(destroyWindowCb), NULL); - g_signal_connect(webView, "close", G_CALLBACK(closeWebViewCb), main_window); + /* Create a browser instance */ + webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); - // Load a web page into the browser instance - webkit_web_view_load_uri(webView, "http://www.webkitgtk.org/"); + /* Put the browser area into the main window */ + gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(webView)); - // Make sure that when the browser area becomes visible, it will get mouse - // and keyboard events - gtk_widget_grab_focus(GTK_WIDGET(webView)); + /* Set up callbacks so that if either the main window or the browser instance is */ + /* closed, the program will exit */ + g_signal_connect(main_window, "destroy", G_CALLBACK(destroyWindowCb), NULL); + g_signal_connect(webView, "close", G_CALLBACK(closeWebViewCb), main_window); - // Make sure the main window and all its contents are visible - gtk_widget_show_all(main_window); + /* Load a web page into the browser instance */ + webkit_web_view_load_uri(webView, "http://google.com/"); - // Run the main GTK+ event loop - gtk_main(); + /* Make sure that when the browser area becomes visible, it will get mouse */ + /* and keyboard events */ + gtk_widget_grab_focus(GTK_WIDGET(webView)); - return 0; + /* Make sure the main window and all its contents are visible */ + gtk_widget_show_all(main_window); + + /* Run the main GTK+ event loop */ + gtk_main(); + + return SCM_BOOL_T; +} + +static SCM +open_page(SCM mystring) { + char *c_string = scm_to_locale_string(mystring); + printf("Opening %s\n", c_string); + webkit_web_view_load_uri(webView, c_string); + return SCM_BOOL_T; } +static void +inner_main(void *data, int argc, char **argv) { + scm_c_define_gsubr("start-browser", 0, 0, 0, start_browser); + scm_c_define_gsubr("open-page", 1, 0, 0, open_page); + scm_shell(argc, argv); +} + +int main(int argc, char *argv[]) { + /* Initialize Guile */ + scm_boot_guile(argc, argv, inner_main, 0); + return 0; +} diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 index 67262cf..dea91b0 --- a/build.sh +++ b/build.sh @@ -1 +1,2 @@ -gcc $(pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0) browser.c +#! /usr/bin/bash +gcc $(pkg-config --cflags --libs guile-2.2 gtk+-3.0 webkit2gtk-4.0) browser.c diff --git a/test.scm b/test.scm new file mode 100644 index 0000000..60607c5 --- /dev/null +++ b/test.scm @@ -0,0 +1,3 @@ +(use-modules (ice-9 threads)) + +(call-with-new-thread (lambda () (start-browser)))