From 76edc528c4245391b53a08a8fb56cfdba926e57d Mon Sep 17 00:00:00 2001 From: Peter Hofmann Date: Sat, 14 Jun 2014 10:40:03 +0200 Subject: [PATCH] Initial draft --- LICENSE | 7 ++++ Makefile | 9 +++++ README | 36 ++++++++++++++++++++ sn.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README create mode 100644 sn.c diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..292bf97 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +------------------------------------------------------------------ +"THE PIZZA-WARE LICENSE" (Revision 42): +Peter Hofmann wrote these files. As long as you +retain this notice you can do whatever you want with this stuff. If we +meet some day, and you think this stuff is worth it, you can buy me a +pizza in return. +------------------------------------------------------------------ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..48cec60 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +CFLAGS += -Wall -Wextra -O3 + +sn: sn.c + $(CC) $(CFLAGS) $(LDFLAGS) \ + -o $@ $< \ + `pkg-config --cflags --libs gtk+-3.0 webkitgtk-3.0` + +clean: + rm -f sn diff --git a/README b/README new file mode 100644 index 0000000..0d91d11 --- /dev/null +++ b/README @@ -0,0 +1,36 @@ +sn - sonst nix +============== + +This is a minimalistic web browser using Gtk3 and WebKit. "Sonst nix" is +german and translates roughly to "nothing else". sn is simple and meant +to stay simple. + +Features: + + - A WebKit viewport + - Global content zoom + +Planned features: + + - An input box to change the current URL + - vi-like shortcuts + - Adblock + - Pluggability into suckless' tabbed (preferred) or native tabs + + +Why WebKit instead of WebKit2? +============================== + +While WebKit2 has fancy process separation and all that stuff, it turned +out to be pretty slow and clunky. Plus, ideally, sn will be plugged into +suckless' tabbed -- so it wouldn't benefit from process separation +anyway. + + +Literature +========== + +API references: + + - http://webkitgtk.org/reference/webkitgtk/stable/index.html + - https://developer.gnome.org/gtk3/stable/index.html diff --git a/sn.c b/sn.c new file mode 100644 index 0000000..2452016 --- /dev/null +++ b/sn.c @@ -0,0 +1,101 @@ +#include +#include + +#include +#include + + +struct sn_gui +{ + GtkWidget *window; + GtkWidget *web_view; + GtkWidget *scroll; +}; + +struct sn_app +{ + struct sn_gui gui; + double global_zoom; +}; + +static void sn_create_gui(struct sn_app *app); +static void sn_init_defaults(struct sn_app *app); +static void sn_title_changed(GObject *obj, GParamSpec *pspec, gpointer app); + + +void +sn_create_gui(struct sn_app *app) +{ + app->gui.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + g_signal_connect(G_OBJECT(app->gui.window), "delete_event", + G_CALLBACK(gtk_main_quit), NULL); + g_signal_connect(G_OBJECT(app->gui.window), "destroy", + G_CALLBACK(gtk_main_quit), NULL); + gtk_window_set_has_resize_grip(GTK_WINDOW(app->gui.window), FALSE); + gtk_window_set_title(GTK_WINDOW(app->gui.window), "sn"); + + app->gui.web_view = webkit_web_view_new(); + webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(app->gui.web_view), + TRUE); + webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(app->gui.web_view), + app->global_zoom); + g_signal_connect(G_OBJECT(app->gui.web_view), "notify::title", + G_CALLBACK(sn_title_changed), app); + + app->gui.scroll = gtk_scrolled_window_new(NULL, NULL); + + gtk_container_add(GTK_CONTAINER(app->gui.scroll), app->gui.web_view); + gtk_container_add(GTK_CONTAINER(app->gui.window), app->gui.scroll); + + gtk_widget_show_all(app->gui.window); +} + +void +sn_init_defaults(struct sn_app *app) +{ + app->global_zoom = 1.0; +} + +void +sn_title_changed(GObject *obj, GParamSpec *pspec, gpointer data) +{ + const gchar *t; + WebKitWebView *view = WEBKIT_WEB_VIEW(obj); + struct sn_app *app = data; + + (void)pspec; + + t = webkit_web_view_get_title(view); + gtk_window_set_title(GTK_WINDOW(app->gui.window), (t == NULL ? "sn" : t)); +} + +int +main(int argc, char **argv) +{ + int opt; + struct sn_app app; + + gtk_init(&argc, &argv); + sn_init_defaults(&app); + + while ((opt = getopt(argc, argv, "z:")) != -1) + { + switch (opt) + { + case 'z': + app.global_zoom = atof(optarg); + break; + } + } + + if (optind >= argc) + { + fprintf(stderr, "Usage: sn [OPTIONS] \n"); + exit(EXIT_FAILURE); + } + + sn_create_gui(&app); + webkit_web_view_load_uri(WEBKIT_WEB_VIEW(app.gui.web_view), argv[optind]); + gtk_main(); + exit(EXIT_SUCCESS); +} -- 2.39.2