From 11c21c06dbd922ae95eb60c9a83054b3dba94b37 Mon Sep 17 00:00:00 2001 From: wes Date: Mon, 7 Oct 2019 20:36:29 -0400 Subject: [PATCH] initial commit --- .gitignore | 3 +++ browser.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 1 + 3 files changed, 60 insertions(+) create mode 100644 .gitignore create mode 100644 browser.c create mode 100644 build.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0f089ca --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.gch +a.out +*.wav diff --git a/browser.c b/browser.c new file mode 100644 index 0000000..24ffbb9 --- /dev/null +++ b/browser.c @@ -0,0 +1,56 @@ +#include +#include + +static void +destroyWindowCb(GtkWidget *widget, 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) { + gtk_widget_destroy(window); + return TRUE; +} + +int main(int argc, char *argv[]) { + // Initialize GTK+ + gtk_init(&argc, &argv); + + // 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); + + // Create a browser instance + WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + + // Put the browser area into the main window + gtk_container_add(GTK_CONTAINER(main_window), 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); + + // Load a web page into the browser instance + webkit_web_view_load_uri(webView, "http://www.webkitgtk.org/"); + + // Make sure that when the browser area becomes visible, it will get mouse + // and keyboard events + gtk_widget_grab_focus(GTK_WIDGET(webView)); + + // 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 0; +} + diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..67262cf --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +gcc $(pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0) browser.c