rename NOBACKGROUND to HIDE_BACKGROUND and use TRUE/FALSE instead of 0/1
[surf.git] / surf.c
diff --git a/surf.c b/surf.c
index 5e6d777..6dc32ea 100644 (file)
--- a/surf.c
+++ b/surf.c
@@ -23,7 +23,7 @@
 #define LENGTH(x)               (sizeof x / sizeof x[0])
 #define CLEANMASK(mask)         (mask & ~(GDK_MOD2_MASK))
 
-enum { AtomFind, AtomGo, AtomUri, AtomHiLight, AtomLast };
+enum { AtomFind, AtomGo, AtomUri, AtomLast };
 
 typedef union Arg Arg;
 union Arg {
@@ -81,11 +81,11 @@ static const char *getatom(Client *c, int a);
 static const char *getcookies(SoupURI *uri);
 static char *geturi(Client *c);
 void gotheaders(SoupMessage *msg, gpointer user_data);
+static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c);
 static gboolean keypress(GtkWidget *w, GdkEventKey *ev, Client *c);
 static void linkhover(WebKitWebView *v, const char* t, const char* l, Client *c);
 static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c);
 static void loaduri(Client *c, const Arg *arg);
-static void mousemove(GtkWidget *w, GdkEventMotion *e, Client *c);
 static void navigate(Client *c, const Arg *arg);
 static Client *newclient(void);
 static void newwindow(Client *c, const Arg *arg);
@@ -188,10 +188,7 @@ createwindow(WebKitWebView  *v, WebKitWebFrame *f, Client *c) {
 gboolean
 decidedownload(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, gchar *m,  WebKitWebPolicyDecision *p, Client *c) {
        if(!webkit_web_view_can_show_mime_type(v, m)) {
-               webkit_web_policy_decision_ignore(p);
-               webkit_web_view_load_html_string(c->view,
-                               "Can't display content.",
-                               webkit_network_request_get_uri(r));
+               webkit_web_policy_decision_download(p);
                return TRUE;
        }
        return FALSE;
@@ -214,6 +211,7 @@ void
 destroyclient(Client *c) {
        Client *p;
 
+       webkit_web_view_stop_loading(c->view);
        gtk_widget_destroy(c->indicator);
        gtk_widget_destroy(GTK_WIDGET(c->view));
        gtk_widget_destroy(c->scroll);
@@ -329,6 +327,16 @@ gotheaders(SoupMessage *msg, gpointer v) {
        soup_cookies_free(l);
 }
 
+gboolean
+initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) {
+       Arg arg;
+
+       updatewinid(c);
+       arg = (Arg)DOWNLOAD((char *)webkit_download_get_uri(o));
+       spawn(c, &arg);
+       return FALSE;
+}
+
 gboolean
 keypress(GtkWidget* w, GdkEventKey *ev, Client *c) {
        guint i;
@@ -396,21 +404,6 @@ loaduri(Client *c, const Arg *arg) {
        }
 }
 
-void
-mousemove(GtkWidget *w, GdkEventMotion *e, Client *c) {
-       int result;
-       GdkEventButton coord;
-       WebKitHitTestResult *hit;
-
-       coord.x = e->x;
-       coord.y = e->y;
-       hit = webkit_web_view_get_hit_test_result(c->view, &coord);
-       g_object_get(hit, "context", &result, NULL);
-       if(result & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE && !c->linkhover) {
-               puts("Picture");
-       }
-}
-
 void
 navigate(Client *c, const Arg *arg) {
        int steps = *(int *)arg;
@@ -470,7 +463,7 @@ newclient(void) {
        g_signal_connect(G_OBJECT(c->view), "window-object-cleared", G_CALLBACK(windowobjectcleared), c);
        g_signal_connect(G_OBJECT(c->view), "notify::load-status", G_CALLBACK(loadstatuschange), c);
        g_signal_connect(G_OBJECT(c->view), "notify::progress", G_CALLBACK(progresschange), c);
-       g_signal_connect(G_OBJECT(c->view), "motion-notify-event", G_CALLBACK(mousemove), c);
+       g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c);
 
        /* Indicator */
        c->indicator = gtk_drawing_area_new();
@@ -508,12 +501,13 @@ newclient(void) {
        g_object_set(G_OBJECT(settings), "auto-load-images", loadimage, NULL);
        g_object_set(G_OBJECT(settings), "enable-plugins", plugin, NULL);
        g_object_set(G_OBJECT(settings), "enable-scripts", script, NULL);
+       g_object_set(G_OBJECT(settings), "enable-spatial-navigation", true, NULL);
+
        g_free(uri);
 
        setatom(c, AtomFind, "");
        setatom(c, AtomUri, "about:blank");
-       setatom(c, AtomHiLight, "about:blank");
-       if(NOBACKGROUND)
+       if(HIDE_BACKGROUND)
                webkit_web_view_set_transparent(c->view, TRUE);
 
        c->title = NULL;
@@ -693,7 +687,6 @@ setup(void) {
        atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
        atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
        atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
-       atoms[AtomHiLight] = XInternAtom(dpy, "_SURF_HILIGHT", False);
 
        /* dirs and files */
        cookiefile = buildpath(cookiefile);
@@ -762,14 +755,12 @@ void
 update(Client *c) {
        char *t;
 
-       if(c->progress != 100) {
+       if(c->progress != 100)
                t = g_strdup_printf("[%i%%] %s", c->progress, c->title);
-       }
        else if(c->linkhover)
                t = g_strdup(c->linkhover);
        else
                t = g_strdup(c->title);
-       setatom(c, AtomHiLight, c->linkhover ? c->linkhover : geturi(c));
        drawindicator(c);
        gtk_window_set_title(GTK_WINDOW(c->win), t);
        g_free(t);