| surf-0.6-navhist.diff - sites - public wiki contents of suckless.org | |
| git clone git://git.suckless.org/sites | |
| Log | |
| Files | |
| Refs | |
| --- | |
| surf-0.6-navhist.diff (4276B) | |
| --- | |
| 1 diff --git a/config.def.h b/config.def.h | |
| 2 index a221c86..9840736 100644 | |
| 3 --- a/config.def.h | |
| 4 +++ b/config.def.h | |
| 5 @@ -32,6 +32,16 @@ static Bool hidebackground = FALSE; | |
| 6 } \ | |
| 7 } | |
| 8 | |
| 9 +#define SELNAV { \ | |
| 10 + .v = (char *[]){ "/bin/sh", "-c", \ | |
| 11 + "prop=\"`xprop -id $0 _SURF_HIST" \ | |
| 12 + " | sed -e 's/^.[^\"]*\"//' -e 's/\"$//' -e 's/\\\\\\n/… | |
| 13 + " | dmenu -i -l 10`\"" \ | |
| 14 + " && xprop -id $0 -f _SURF_NAV 8s -set _SURF_NAV \"$pro… | |
| 15 + winid, NULL \ | |
| 16 + } \ | |
| 17 +} | |
| 18 + | |
| 19 /* DOWNLOAD(URI, referer) */ | |
| 20 #define DOWNLOAD(d, r) { \ | |
| 21 .v = (char *[]){ "/bin/sh", "-c", \ | |
| 22 @@ -67,6 +77,7 @@ static Key keys[] = { | |
| 23 | |
| 24 { MODKEY, GDK_l, navigate, { .i = +1 } }, | |
| 25 { MODKEY, GDK_h, navigate, { .i = -1 } }, | |
| 26 + { MODKEY|GDK_SHIFT_MASK,GDK_h, selhist, SELNAV }, | |
| 27 | |
| 28 { MODKEY, GDK_j, scroll_v, { .i = +1 } }, | |
| 29 { MODKEY, GDK_k, scroll_v, { .i = -1 } }, | |
| 30 diff --git a/surf.c b/surf.c | |
| 31 index cebd469..8b6d751 100644 | |
| 32 --- a/surf.c | |
| 33 +++ b/surf.c | |
| 34 @@ -32,7 +32,7 @@ char *argv0; | |
| 35 #define COOKIEJAR_TYPE (cookiejar_get_type ()) | |
| 36 #define COOKIEJAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COO… | |
| 37 | |
| 38 -enum { AtomFind, AtomGo, AtomUri, AtomLast }; | |
| 39 +enum { AtomFind, AtomGo, AtomUri, AtomHist, AtomNav, AtomLast }; | |
| 40 | |
| 41 typedef union Arg Arg; | |
| 42 union Arg { | |
| 43 @@ -137,6 +137,8 @@ static void loadstatuschange(WebKitWebView *view, GP… | |
| 44 Client *c); | |
| 45 static void loaduri(Client *c, const Arg *arg); | |
| 46 static void navigate(Client *c, const Arg *arg); | |
| 47 +static void selhist(Client *c, const Arg *arg); | |
| 48 +static void navhist(Client *c, const Arg *arg); | |
| 49 static Client *newclient(void); | |
| 50 static void newwindow(Client *c, const Arg *arg, gboolean noembed); | |
| 51 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointe… | |
| 52 @@ -649,6 +651,59 @@ navigate(Client *c, const Arg *arg) { | |
| 53 webkit_web_view_go_back_or_forward(c->view, steps); | |
| 54 } | |
| 55 | |
| 56 +static void | |
| 57 +selhist(Client *c, const Arg *arg) { | |
| 58 + WebKitWebBackForwardList *lst; | |
| 59 + WebKitWebHistoryItem *cur; | |
| 60 + gint i; | |
| 61 + gchar *out; | |
| 62 + gchar *tmp; | |
| 63 + gchar *line; | |
| 64 + | |
| 65 + out = g_strdup(""); | |
| 66 + | |
| 67 + if(!(lst = webkit_web_view_get_back_forward_list(c->view))) | |
| 68 + return; | |
| 69 + | |
| 70 + for(i = webkit_web_back_forward_list_get_back_length(lst); i > … | |
| 71 + if(!(cur = webkit_web_back_forward_list_get_nth_item(ls… | |
| 72 + break; | |
| 73 + line = g_strdup_printf("%d: %s\n", -i, | |
| 74 + webkit_web_history_item_get_orig… | |
| 75 + tmp = g_strconcat(out, line, NULL); | |
| 76 + g_free(out); | |
| 77 + out = tmp; | |
| 78 + } | |
| 79 + | |
| 80 + if((cur = webkit_web_back_forward_list_get_nth_item(lst, 0))) { | |
| 81 + line = g_strdup_printf("%d: %s", 0, | |
| 82 + webkit_web_history_item_get_orig… | |
| 83 + tmp = g_strconcat(out, line, NULL); | |
| 84 + g_free(out); | |
| 85 + out = tmp; | |
| 86 + } | |
| 87 + | |
| 88 + for(i = 1; i <= webkit_web_back_forward_list_get_forward_length… | |
| 89 + if(!(cur = webkit_web_back_forward_list_get_nth_item(ls… | |
| 90 + break; | |
| 91 + line = g_strdup_printf("\n%d: %s", i, | |
| 92 + webkit_web_history_item_get_orig… | |
| 93 + tmp = g_strconcat(out, line, NULL); | |
| 94 + g_free(out); | |
| 95 + out = tmp; | |
| 96 + } | |
| 97 + | |
| 98 + setatom(c, AtomHist, out); | |
| 99 + g_free(out); | |
| 100 + spawn(c, arg); | |
| 101 +} | |
| 102 + | |
| 103 +static void | |
| 104 +navhist(Client *c, const Arg *arg) { | |
| 105 + Arg a = { .i = atoi(arg->v) }; | |
| 106 + navigate(c, &a); | |
| 107 +} | |
| 108 + | |
| 109 static Client * | |
| 110 newclient(void) { | |
| 111 Client *c; | |
| 112 @@ -805,6 +860,7 @@ newclient(void) { | |
| 113 | |
| 114 setatom(c, AtomFind, ""); | |
| 115 setatom(c, AtomUri, "about:blank"); | |
| 116 + setatom(c, AtomHist, ""); | |
| 117 if(hidebackground) | |
| 118 webkit_web_view_set_transparent(c->view, TRUE); | |
| 119 | |
| 120 @@ -923,6 +979,9 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) { | |
| 121 arg.v = getatom(c, AtomGo); | |
| 122 loaduri(c, &arg); | |
| 123 return GDK_FILTER_REMOVE; | |
| 124 + } else if(ev->atom == atoms[AtomNav]) { | |
| 125 + arg.v = getatom(c, AtomNav); | |
| 126 + navhist(c, &arg); | |
| 127 } | |
| 128 } | |
| 129 } | |
| 130 @@ -1004,6 +1063,8 @@ setup(void) { | |
| 131 atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False); | |
| 132 atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False); | |
| 133 atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False); | |
| 134 + atoms[AtomHist] = XInternAtom(dpy, "_SURF_HIST", False); | |
| 135 + atoms[AtomNav] = XInternAtom(dpy, "_SURF_NAV", False); | |
| 136 | |
| 137 /* dirs and files */ | |
| 138 cookiefile = buildpath(cookiefile); |