diff -r f94ad8014e32 surf.c --- a/surf.c Wed May 12 16:40:00 2010 +0200 +++ b/surf.c Sun May 16 16:50:14 2010 +0200 @@ -37,6 +37,8 @@ WebKitDownload *download; char *title, *linkhover; const char *uri, *needle; + gchar *prevuri; + gboolean savesession; gint progress; struct Client *next; gboolean zoomed; @@ -113,6 +115,7 @@ static void runscript(Client *c, const Arg *arg); static void eval(Client *c, const Arg *arg); static void stop(Client *c, const Arg *arg); +static void suspend(Client *c, const Arg *arg); static void titlechange(WebKitWebView *v, WebKitWebFrame* frame, const char* title, Client *c); static void update(Client *c); static void updatedownload(WebKitDownload *o, GParamSpec *pspec, Client *c); @@ -156,6 +159,15 @@ } void +sessionupd(Client* c, char* cmd, char* uri) { + char* pid = malloc(20); + sprintf(pid, "%d", getpid()); + Arg arg = { .v = (const char *[]){ "surfsession", cmd, pid, uri, NULL } }; + spawn(c, &arg); + free(pid); +} + +void evalscript(WebKitWebFrame *frame, JSContextRef js, char *script, char* scriptname) { JSStringRef jsscript, jsscriptname; JSValueRef exception = NULL; @@ -264,6 +276,7 @@ p->next = c->next; else clients = c->next; + g_free(c->prevuri); free(c); if(clients == NULL) gtk_main_quit(); @@ -271,6 +284,9 @@ void destroywin(GtkWidget* w, Client *c) { + if (!c->savesession) { + sessionupd(c, "remove", geturi(c)); + } destroyclient(c); } @@ -452,11 +468,18 @@ void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) { + char* uri = geturi(c); switch(webkit_web_view_get_load_status (c->view)) { case WEBKIT_LOAD_COMMITTED: if(c->download) stop(c, NULL); setatom(c, uriprop, geturi(c)); + if(c->prevuri) { + sessionupd(c, "remove", c->prevuri); + g_free(c->prevuri); + } + sessionupd(c, "add", uri); + c->prevuri = g_strdup(uri); break; case WEBKIT_LOAD_FINISHED: c->progress = 0; @@ -609,6 +632,8 @@ c->download = NULL; c->title = NULL; c->next = clients; + c->prevuri = NULL; + c->savesession = FALSE; clients = c; if(showxid) { gdk_display_sync(gtk_widget_get_display(c->win)); @@ -867,6 +892,12 @@ } void +suspend(Client *c, const Arg *arg) { + c->savesession = TRUE; + gtk_widget_destroy(c->win); +} + +void titlechange(WebKitWebView *v, WebKitWebFrame *f, const char *t, Client *c) { c->title = copystr(&c->title, t); update(c);