diff --git a/config.def.h b/config.def.h index a1ab211..9f1de5f 100644 --- a/config.def.h +++ b/config.def.h @@ -16,6 +16,7 @@ static gfloat zoomlevel = 1.0; /* Default zoom level */ /* Soup default features */ static char *cookiefile = "~/.surf/cookies.txt"; +static char *historyfile = "~/.surf/history"; static char *cookiepolicies = "Aa@"; /* A: accept all; a: accept nothing, @: accept no third party */ static char *cafile = "/etc/ssl/certs/ca-certificates.crt"; @@ -35,12 +36,30 @@ static Bool loadimages = TRUE; static Bool hidebackground = FALSE; static Bool allowgeolocation = TRUE; -#define SETPROP(p, q) { \ - .v = (char *[]){ "/bin/sh", "-c", \ - "prop=\"`xprop -id $2 $0 | cut -d '\"' -f 2 | xargs -0 printf %b | dmenu`\" &&" \ - "xprop -id $2 -f $1 8s -set $1 \"$prop\"", \ - p, q, winid, NULL \ - } \ +#define SETURI { \ + .v = (char *[]){ "/bin/sh", "-c", \ + "prop=\"`xprop -id $0 _SURF_URI" \ + " | cut -d '\"' -f 2" \ + " | tac - \"${HOME}/.surf/history\"" \ + " | awk '!x[$0]++'" \ + " | dmenu -i -l 10`\"" \ + " && xprop -id $0 -f _SURF_GO 8s -set _SURF_GO \"$prop\"", \ + winid, NULL \ + } \ +} + +#define SETSEARCH { \ + .v = (char *[]){ "/bin/sh", "-c", \ + "prop=\"`xprop -id $0 _SURF_FIND" \ + " | cut -d '\"' -f 2" \ + " | tac - \"${HOME}/.surf/searches\"" \ + " | awk '!x[$0]++'" \ + " | xargs -0 printf %b" \ + " | dmenu -i -l 10`\"" \ + " && xprop -id $0 -f _SURF_FIND 8s -set _SURF_FIND \"$prop\"" \ + " && echo \"$prop\" >> \"${HOME}/.surf/searches\"", \ + winid, NULL \ + } \ } /* DOWNLOAD(URI, referer) */ @@ -110,9 +129,9 @@ static Key keys[] = { { MODKEY, GDK_o, source, { 0 } }, { MODKEY|GDK_SHIFT_MASK,GDK_o, inspector, { 0 } }, - { MODKEY, GDK_g, spawn, SETPROP("_SURF_URI", "_SURF_GO") }, - { MODKEY, GDK_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, - { MODKEY, GDK_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, + { MODKEY, GDK_g, spawn, SETURI }, + { MODKEY, GDK_f, spawn, SETSEARCH }, + { MODKEY, GDK_slash, spawn, SETSEARCH }, { MODKEY, GDK_n, find, { .b = TRUE } }, { MODKEY|GDK_SHIFT_MASK,GDK_n, find, { .b = FALSE } }, diff --git a/surf.c b/surf.c index 87c10ef..c91db86 100644 --- a/surf.c +++ b/surf.c @@ -319,6 +319,7 @@ cleanup(void) { while(clients) destroyclient(clients); g_free(cookiefile); + g_free(historyfile); g_free(scriptfile); g_free(stylefile); } @@ -772,6 +773,12 @@ loaduri(Client *c, const Arg *arg) { reload(c, &a); } else { webkit_web_view_load_uri(c->view, u); + FILE *f; + if((f = fopen(historyfile, "a+"))) { + fputs(u, f); + fputs("\n", f); + fclose(f); + } c->progress = 0; c->title = copystr(&c->title, u); updatetitle(c); @@ -1222,6 +1229,7 @@ setup(void) { /* dirs and files */ cookiefile = buildpath(cookiefile); + historyfile = buildpath(historyfile); scriptfile = buildpath(scriptfile); cachefolder = buildpath(cachefolder); styledir = buildpath(styledir);