[wiki] [sites] add navigation history patch for surf || Markus Teich

From: <git_AT_suckless.org>
Date: Sun, 18 Oct 2015 13:31:09 +0200

commit 257e83bde583cef298b732437a5d6663b84a8f05
Author: Markus Teich <markus.teich_AT_stusta.mhn.de>
Date: Sun Oct 18 13:33:15 2015 +0200

    add navigation history patch for surf

diff --git a/surf.suckless.org/patches/navigation-history.md b/surf.suckless.org/patches/navigation-history.md
new file mode 100644
index 0000000..41b57b3
--- /dev/null
+++ b/surf.suckless.org/patches/navigation-history.md
_AT_@ -0,0 +1,19 @@
+navigation history
+==================
+
+Description
+-----------
+
+This patch adds the MOD-shift-h keyboard shortcut to open up dmenu with the
+recent navigation history of the current surf instance.
+
+Download
+--------
+
+* [surf-0.6-navhist.diff](surf-0.6-navhist.diff) (2015-10-18)
+* [surf-tip-navhist.diff](surf-tip-navhist.diff) (2015-10-18)
+
+Author
+------
+
+* Markus Teich
diff --git a/surf.suckless.org/patches/surf-0.6-navhist.diff b/surf.suckless.org/patches/surf-0.6-navhist.diff
new file mode 100644
index 0000000..2894da8
--- /dev/null
+++ b/surf.suckless.org/patches/surf-0.6-navhist.diff
_AT_@ -0,0 +1,138 @@
+diff --git a/config.def.h b/config.def.h
+index a221c86..9840736 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -32,6 +32,16 @@ static Bool hidebackground = FALSE;
+ } \
+ }
+
++#define SELNAV { \
++ .v = (char *[]){ "/bin/sh", "-c", \
++ "prop=\"`xprop -id $0 _SURF_HIST" \
++ " | sed -e 's/^.[^\"]*\"//' -e 's/\"$//' -e 's/\\\n/\n/g'" \
++ " | dmenu -i -l 10`\"" \
++ " && xprop -id $0 -f _SURF_NAV 8s -set _SURF_NAV \"$prop\"", \
++ winid, NULL \
++ } \
++}
++
+ /* DOWNLOAD(URI, referer) */
+ #define DOWNLOAD(d, r) { \
+ .v = (char *[]){ "/bin/sh", "-c", \
+_AT_@ -67,6 +77,7 @@ static Key keys[] = {
+
+ { MODKEY, GDK_l, navigate, { .i = +1 } },
+ { MODKEY, GDK_h, navigate, { .i = -1 } },
++ { MODKEY|GDK_SHIFT_MASK,GDK_h, selhist, SELNAV },
+
+ { MODKEY, GDK_j, scroll_v, { .i = +1 } },
+ { MODKEY, GDK_k, scroll_v, { .i = -1 } },
+diff --git a/surf.c b/surf.c
+index cebd469..8b6d751 100644
+--- a/surf.c
++++ b/surf.c
+_AT_@ -32,7 +32,7 @@ char *argv0;
+ #define COOKIEJAR_TYPE (cookiejar_get_type ())
+ #define COOKIEJAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COOKIEJAR_TYPE, CookieJar))
+
+-enum { AtomFind, AtomGo, AtomUri, AtomLast };
++enum { AtomFind, AtomGo, AtomUri, AtomHist, AtomNav, AtomLast };
+
+ typedef union Arg Arg;
+ union Arg {
+_AT_@ -137,6 +137,8 @@ static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec,
+ Client *c);
+ static void loaduri(Client *c, const Arg *arg);
+ static void navigate(Client *c, const Arg *arg);
++static void selhist(Client *c, const Arg *arg);
++static void navhist(Client *c, const Arg *arg);
+ static Client *newclient(void);
+ static void newwindow(Client *c, const Arg *arg, gboolean noembed);
+ static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
+_AT_@ -649,6 +651,59 @@ navigate(Client *c, const Arg *arg) {
+ webkit_web_view_go_back_or_forward(c->view, steps);
+ }
+
++static void
++selhist(Client *c, const Arg *arg) {
++ WebKitWebBackForwardList *lst;
++ WebKitWebHistoryItem *cur;
++ gint i;
++ gchar *out;
++ gchar *tmp;
++ gchar *line;
++
++ out = g_strdup("");
++
++ if(!(lst = webkit_web_view_get_back_forward_list(c->view)))
++ return;
++
++ for(i = webkit_web_back_forward_list_get_back_length(lst); i > 0; i--) {
++ if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, -i)))
++ break;
++ line = g_strdup_printf("%d: %s
", -i,
++ webkit_web_history_item_get_original_uri(cur));
++ tmp = g_strconcat(out, line, NULL);
++ g_free(out);
++ out = tmp;
++ }
++
++ if((cur = webkit_web_back_forward_list_get_nth_item(lst, 0))) {
++ line = g_strdup_printf("%d: %s", 0,
++ webkit_web_history_item_get_original_uri(cur));
++ tmp = g_strconcat(out, line, NULL);
++ g_free(out);
++ out = tmp;
++ }
++
++ for(i = 1; i <= webkit_web_back_forward_list_get_forward_length(lst); i++) {
++ if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, i)))
++ break;
++ line = g_strdup_printf("
%d: %s", i,
++ webkit_web_history_item_get_original_uri(cur));
++ tmp = g_strconcat(out, line, NULL);
++ g_free(out);
++ out = tmp;
++ }
++
++ setatom(c, AtomHist, out);
++ g_free(out);
++ spawn(c, arg);
++}
++
++static void
++navhist(Client *c, const Arg *arg) {
++ Arg a = { .i = atoi(arg->v) };
++ navigate(c, &a);
++}
++
+ static Client *
+ newclient(void) {
+ Client *c;
+_AT_@ -805,6 +860,7 @@ newclient(void) {
+
+ setatom(c, AtomFind, "");
+ setatom(c, AtomUri, "about:blank");
++ setatom(c, AtomHist, "");
+ if(hidebackground)
+ webkit_web_view_set_transparent(c->view, TRUE);
+
+_AT_@ -923,6 +979,9 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
+ arg.v = getatom(c, AtomGo);
+ loaduri(c, &arg);
+ return GDK_FILTER_REMOVE;
++ } else if(ev->atom == atoms[AtomNav]) {
++ arg.v = getatom(c, AtomNav);
++ navhist(c, &arg);
+ }
+ }
+ }
+_AT_@ -1004,6 +1063,8 @@ setup(void) {
+ atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
+ atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
+ atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
++ atoms[AtomHist] = XInternAtom(dpy, "_SURF_HIST", False);
++ atoms[AtomNav] = XInternAtom(dpy, "_SURF_NAV", False);
+
+ /* dirs and files */
+ cookiefile = buildpath(cookiefile);
diff --git a/surf.suckless.org/patches/surf-tip-navhist.diff b/surf.suckless.org/patches/surf-tip-navhist.diff
new file mode 100644
index 0000000..81f071d
--- /dev/null
+++ b/surf.suckless.org/patches/surf-tip-navhist.diff
_AT_@ -0,0 +1,138 @@
+diff --git a/config.def.h b/config.def.h
+index 5245129..604028f 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -45,6 +45,16 @@ static Bool allowgeolocation = TRUE;
+ } \
+ }
+
++#define SELNAV { \
++ .v = (char *[]){ "/bin/sh", "-c", \
++ "prop=\"`xprop -id $0 _SURF_HIST" \
++ " | sed -e 's/^.[^\"]*\"//' -e 's/\"$//' -e 's/\\\n/\n/g'" \
++ " | dmenu -i -l 10`\"" \
++ " && xprop -id $0 -f _SURF_NAV 8s -set _SURF_NAV \"$prop\"", \
++ winid, NULL \
++ } \
++}
++
+ /* DOWNLOAD(URI, referer) */
+ #define DOWNLOAD(d, r) { \
+ .v = (char *[]){ "/bin/sh", "-c", \
+_AT_@ -99,6 +109,7 @@ static Key keys[] = {
+
+ { MODKEY, GDK_l, navigate, { .i = +1 } },
+ { MODKEY, GDK_h, navigate, { .i = -1 } },
++ { MODKEY|GDK_SHIFT_MASK,GDK_h, selhist, SELNAV },
+
+ { MODKEY, GDK_j, scroll_v, { .i = +1 } },
+ { MODKEY, GDK_k, scroll_v, { .i = -1 } },
+diff --git a/surf.c b/surf.c
+index 0fae80b..1c09336 100644
+--- a/surf.c
++++ b/surf.c
+_AT_@ -36,7 +36,7 @@ char *argv0;
+ #define COOKIEJAR_TYPE (cookiejar_get_type ())
+ #define COOKIEJAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COOKIEJAR_TYPE, CookieJar))
+
+-enum { AtomFind, AtomGo, AtomUri, AtomLast };
++enum { AtomFind, AtomGo, AtomUri, AtomHist, AtomNav, AtomLast };
+ enum {
+ ClkDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
+ ClkLink = WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK,
+_AT_@ -177,6 +177,8 @@ static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec,
+ Client *c);
+ static void loaduri(Client *c, const Arg *arg);
+ static void navigate(Client *c, const Arg *arg);
++static void selhist(Client *c, const Arg *arg);
++static void navhist(Client *c, const Arg *arg);
+ static Client *newclient(void);
+ static void newwindow(Client *c, const Arg *arg, gboolean noembed);
+ static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
+_AT_@ -813,6 +815,59 @@ navigate(Client *c, const Arg *arg) {
+ webkit_web_view_go_back_or_forward(c->view, steps);
+ }
+
++static void
++selhist(Client *c, const Arg *arg) {
++ WebKitWebBackForwardList *lst;
++ WebKitWebHistoryItem *cur;
++ gint i;
++ gchar *out;
++ gchar *tmp;
++ gchar *line;
++
++ out = g_strdup("");
++
++ if(!(lst = webkit_web_view_get_back_forward_list(c->view)))
++ return;
++
++ for(i = webkit_web_back_forward_list_get_back_length(lst); i > 0; i--) {
++ if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, -i)))
++ break;
++ line = g_strdup_printf("%d: %s
", -i,
++ webkit_web_history_item_get_original_uri(cur));
++ tmp = g_strconcat(out, line, NULL);
++ g_free(out);
++ out = tmp;
++ }
++
++ if((cur = webkit_web_back_forward_list_get_nth_item(lst, 0))) {
++ line = g_strdup_printf("%d: %s", 0,
++ webkit_web_history_item_get_original_uri(cur));
++ tmp = g_strconcat(out, line, NULL);
++ g_free(out);
++ out = tmp;
++ }
++
++ for(i = 1; i <= webkit_web_back_forward_list_get_forward_length(lst); i++) {
++ if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, i)))
++ break;
++ line = g_strdup_printf("
%d: %s", i,
++ webkit_web_history_item_get_original_uri(cur));
++ tmp = g_strconcat(out, line, NULL);
++ g_free(out);
++ out = tmp;
++ }
++
++ setatom(c, AtomHist, out);
++ g_free(out);
++ spawn(c, arg);
++}
++
++static void
++navhist(Client *c, const Arg *arg) {
++ Arg a = { .i = atoi(arg->v) };
++ navigate(c, &a);
++}
++
+ static Client *
+ newclient(void) {
+ Client *c;
+_AT_@ -1014,6 +1069,7 @@ newclient(void) {
+
+ setatom(c, AtomFind, "");
+ setatom(c, AtomUri, "about:blank");
++ setatom(c, AtomHist, "");
+ if(hidebackground)
+ webkit_web_view_set_transparent(c->view, TRUE);
+
+_AT_@ -1153,6 +1209,9 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
+ loaduri(c, &arg);
+
+ return GDK_FILTER_REMOVE;
++ } else if(ev->atom == atoms[AtomNav]) {
++ arg.v = getatom(c, AtomNav);
++ navhist(c, &arg);
+ }
+ }
+ }
+_AT_@ -1247,6 +1306,8 @@ setup(void) {
+ atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
+ atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
+ atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
++ atoms[AtomHist] = XInternAtom(dpy, "_SURF_HIST", False);
++ atoms[AtomNav] = XInternAtom(dpy, "_SURF_NAV", False);
+
+ /* dirs and files */
+ cookiefile = buildfile(cookiefile);
Received on Sun Oct 18 2015 - 13:31:09 CEST

This archive was generated by hypermail 2.3.0 : Sun Oct 18 2015 - 13:36:13 CEST