Last active
December 14, 2015 02:39
-
-
Save anak10thn/5015361 to your computer and use it in GitHub Desktop.
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
/*anak10thn.web.id license WTFPL*/ | |
#include <stdio.h> | |
#include <gtk/gtk.h> | |
#include <webkit/webkit.h> | |
#include <seed.h> | |
#include <JavaScriptCore/JavaScript.h> | |
SeedEngine *engine; | |
static GdkPixbuf *create_pixbuf(const gchar * filename) | |
{ | |
GdkPixbuf *pixbuf; | |
GError *error = NULL; | |
pixbuf = gdk_pixbuf_new_from_file(filename, &error); | |
if(!pixbuf) { | |
fprintf(stderr, "%s\n", error->message); | |
g_error_free(error); | |
} | |
return pixbuf; | |
} | |
static void window_object_cleared_cb(WebKitWebView *web_view, | |
WebKitWebFrame *frame, | |
gpointer context, | |
gpointer arg3, | |
gpointer user_data) | |
{ | |
JSGlobalContextRef jsContext = webkit_web_frame_get_global_context(frame); | |
engine = seed_init_with_context (NULL, NULL, jsContext); | |
} | |
static void destroy_cb(GtkWidget* widget, gpointer data) | |
{ | |
g_free (engine); | |
gtk_main_quit (); | |
} | |
static GtkWidget* main_window; | |
static WebKitWebView* web_view; | |
static GtkWidget* create_browser() | |
{ | |
GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL); | |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ()); | |
gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view)); | |
g_signal_connect (G_OBJECT (web_view), "window-object-cleared", G_CALLBACK(window_object_cleared_cb), web_view); | |
return scrolled_window; | |
} | |
static GtkWidget* create_window() | |
{ | |
GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
gtk_window_set_default_size (GTK_WINDOW (window), IGNAPPWIDTH, IGNAPPHEIGHT); | |
gtk_window_set_icon(GTK_WINDOW(window), create_pixbuf("icon.png")); | |
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy_cb), NULL); | |
return window; | |
} | |
int main (int argc, char* argv[]) { | |
gtk_init (&argc, &argv); | |
if (!g_thread_supported()) | |
g_thread_init (NULL); | |
GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | |
gtk_box_pack_start(GTK_BOX(vbox), create_browser (), TRUE, TRUE, 0); | |
main_window = create_window(); | |
gtk_container_add(GTK_CONTAINER (main_window), vbox); | |
gchar* uri = (gchar*) argv[1]; | |
webkit_web_view_load_uri(web_view, uri); | |
gtk_widget_grab_focus (GTK_WIDGET (web_view)); | |
gtk_widget_show_all (main_window); | |
gtk_main (); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment