_SURF_URI gets initialised as soon as the window opens.
[surf.git] / surf.c
diff --git a/surf.c b/surf.c
index bb59493..62b4948 100644 (file)
--- a/surf.c
+++ b/surf.c
@@ -435,14 +435,23 @@ void
 loaduri(Client *c, const Arg *arg) {
        char *u;
        const char *uri = (char *)arg->v;
+       Arg a = { .b = FALSE };
 
+       if(strcmp(uri, "") == 0)
+               return;
        u = g_strrstr(uri, "://") ? g_strdup(uri)
                : g_strdup_printf("http://%s", uri);
-       webkit_web_view_load_uri(c->view, u);
-       c->progress = 0;
-       c->title = copystr(&c->title, u);
-       g_free(u);
-       update(c);
+       /* prevents endless loop */
+       if(c->uri && strcmp(u, c->uri) == 0) {
+               reload(c, &a);
+       }
+       else {
+               webkit_web_view_load_uri(c->view, u);
+               c->progress = 0;
+               c->title = copystr(&c->title, u);
+               g_free(u);
+               update(c);
+       }
 }
 
 void
@@ -457,7 +466,7 @@ newclient(void) {
        Client *c;
        WebKitWebSettings *settings;
        GdkGeometry hints = { 1, 1 };
-       char *uri;
+       char *uri, *ua;
 
        if(!(c = calloc(1, sizeof(Client))))
                die("Cannot malloc!\n");
@@ -467,7 +476,19 @@ newclient(void) {
        }
        else {
                c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+               /* TA:  20091214:  Despite what the GNOME docs say, the ICCCM
+                * is always correct, so we should still call this function.
+                * But when doing so, we *must* differentiate between a
+                * WM_CLASS and a resource on the window.  By convention, the
+                * window class (WM_CLASS) is capped, while the resource is in
+                * lowercase.   Both these values come as a pair.
+                */
                gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "surf");
+
+               /* TA:  20091214:  And set the role here as well -- so that
+                * sessions can pick this up.
+                */
+               gtk_window_set_role(GTK_WINDOW(c->win), "Surf");
        }
        gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
        g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c);
@@ -532,11 +553,14 @@ newclient(void) {
        gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c);
        webkit_web_view_set_full_content_zoom(c->view, TRUE);
        settings = webkit_web_view_get_settings(c->view);
-       g_object_set(G_OBJECT(settings), "user-agent", useragent, NULL);
+       if(!(ua = getenv("SURF_USERAGENT")))
+               ua = useragent;
+       g_object_set(G_OBJECT(settings), "user-agent", ua, NULL);
        uri = g_strconcat("file://", stylefile, NULL);
        g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
        g_free(uri);
        setatom(c, findprop, "");
+       setatom(c, uriprop, "");
 
        c->download = NULL;
        c->title = NULL;
@@ -681,6 +705,9 @@ setatom(Client *c, Atom a, const char *v) {
 void
 setup(void) {
        SoupSession *s;
+       char *proxy;
+       char *new_proxy;
+       SoupURI *puri;
 
        /* clean up any zombies immediately */
        sigchld(0);
@@ -704,6 +731,15 @@ setup(void) {
        cookies = soup_cookie_jar_new();
        soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookies));
        g_signal_connect(cookies, "changed", G_CALLBACK(changecookie), NULL);
+       if((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
+               new_proxy = g_strrstr(proxy, "http://") ? g_strdup(proxy) :
+                           g_strdup_printf("http://%s", proxy);
+
+               puri = soup_uri_new(new_proxy);
+               g_object_set(G_OBJECT(s), "proxy-uri", puri, NULL);
+               soup_uri_free(puri);
+               g_free(new_proxy);
+       }
        reloadcookies();
 }