surf-tip-navhist.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       surf-tip-navhist.diff (4318B)
       ---
            1 diff --git a/config.def.h b/config.def.h
            2 index 5245129..604028f 100644
            3 --- a/config.def.h
            4 +++ b/config.def.h
            5 @@ -45,6 +45,16 @@ static Bool allowgeolocation      = TRUE;
            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/\\n/g'" \
           13 +                " | dmenu -i -l 10`\"" \
           14 +                " && xprop -id $0 -f _SURF_NAV 8s -set _SURF_NAV \"$prop\"", \
           15 +                winid, NULL \
           16 +        } \
           17 +}
           18 +
           19  /* DOWNLOAD(URI, referer) */
           20  #define DOWNLOAD(d, r) { \
           21          .v = (char *[]){ "/bin/sh", "-c", \
           22 @@ -99,6 +109,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 0fae80b..1c09336 100644
           32 --- a/surf.c
           33 +++ b/surf.c
           34 @@ -36,7 +36,7 @@ char *argv0;
           35  #define COOKIEJAR_TYPE          (cookiejar_get_type ())
           36  #define COOKIEJAR(obj)          (G_TYPE_CHECK_INSTANCE_CAST ((obj), COOKIEJAR_TYPE, CookieJar))
           37  
           38 -enum { AtomFind, AtomGo, AtomUri, AtomLast };
           39 +enum { AtomFind, AtomGo, AtomUri, AtomHist, AtomNav, AtomLast };
           40  enum {
           41          ClkDoc   = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
           42          ClkLink  = WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK,
           43 @@ -177,6 +177,8 @@ static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec,
           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, gpointer d);
           52 @@ -813,6 +815,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 > 0; i--) {
           71 +                if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, -i)))
           72 +                        break;
           73 +                line = g_strdup_printf("%d: %s\n", -i,
           74 +                                       webkit_web_history_item_get_original_uri(cur));
           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_original_uri(cur));
           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(lst); i++) {
           89 +                if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, i)))
           90 +                        break;
           91 +                line = g_strdup_printf("\n%d: %s", i,
           92 +                                       webkit_web_history_item_get_original_uri(cur));
           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 @@ -1014,6 +1069,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 @@ -1153,6 +1209,9 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
          121                                  loaduri(c, &arg);
          122  
          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 @@ -1247,6 +1306,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 = buildfile(cookiefile);