diff -r e83fbd17d63a surf.c --- a/surf.c Tue Jun 08 09:06:15 2010 +0200 +++ b/surf.c Thu Jul 08 13:10:57 2010 +0100 @@ -23,7 +23,7 @@ #define LENGTH(x) (sizeof x / sizeof x[0]) #define CLEANMASK(mask) (mask & ~(GDK_MOD2_MASK)) -enum { AtomFind, AtomGo, AtomUri, AtomLast }; +enum { AtomFind, AtomGo, AtomUri, AtomProxy, AtomLast }; typedef union Arg Arg; union Arg { @@ -99,6 +99,7 @@ static void scroll(Client *c, const Arg *arg); static void setatom(Client *c, int a, const char *v); static void setcookie(SoupCookie *c); +static void setproxy(SoupSession *s, char *proxy); static void setup(void); static void sigchld(int unused); static void source(Client *c, const Arg *arg); @@ -593,6 +594,11 @@ loaduri(c, &arg); return GDK_FILTER_REMOVE; } + else if(ev->atom == atoms[AtomProxy]) { + arg.v = getatom(c, AtomProxy); + setproxy(webkit_get_default_session(), (char *)arg.v); + return GDK_FILTER_REMOVE; + } } } return GDK_FILTER_CONTINUE; @@ -667,10 +673,25 @@ } void +setproxy(SoupSession *s, char *proxy) { + char *new_proxy; + SoupURI *puri; + + if(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); + } + else + g_object_set(G_OBJECT(s), "proxy-uri", (SoupURI *)NULL, NULL); +} + +void setup(void) { char *proxy; - char *new_proxy; - SoupURI *puri; SoupSession *s; /* clean up any zombies immediately */ @@ -686,6 +707,7 @@ atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False); atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False); atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False); + atoms[AtomProxy] = XInternAtom(dpy, "_SURF_PROXY", False); /* dirs and files */ cookiefile = buildpath(cookiefile); @@ -699,14 +721,8 @@ g_signal_connect_after(G_OBJECT(s), "request-started", G_CALLBACK(newrequest), NULL); /* proxy */ - 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); - } + if((proxy = getenv("http_proxy")) && strcmp(proxy, "")) + setproxy(s, proxy); } void