Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
4.2 KiB

  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. +#define SELNAV { \
  9. + .v = (char *[]){ "/bin/sh", "-c", \
  10. + "prop=\"`xprop -id $0 _SURF_HIST" \
  11. + " | sed -e 's/^.[^\"]*\"//' -e 's/\"$//' -e 's/\\\\\\n/\\n/g'" \
  12. + " | dmenu -i -l 10`\"" \
  13. + " && xprop -id $0 -f _SURF_NAV 8s -set _SURF_NAV \"$prop\"", \
  14. + winid, NULL \
  15. + } \
  16. +}
  17. +
  18. /* DOWNLOAD(URI, referer) */
  19. #define DOWNLOAD(d, r) { \
  20. .v = (char *[]){ "/bin/sh", "-c", \
  21. @@ -99,6 +109,7 @@ static Key keys[] = {
  22. { MODKEY, GDK_l, navigate, { .i = +1 } },
  23. { MODKEY, GDK_h, navigate, { .i = -1 } },
  24. + { MODKEY|GDK_SHIFT_MASK,GDK_h, selhist, SELNAV },
  25. { MODKEY, GDK_j, scroll_v, { .i = +1 } },
  26. { MODKEY, GDK_k, scroll_v, { .i = -1 } },
  27. diff --git a/surf.c b/surf.c
  28. index 0fae80b..1c09336 100644
  29. --- a/surf.c
  30. +++ b/surf.c
  31. @@ -36,7 +36,7 @@ char *argv0;
  32. #define COOKIEJAR_TYPE (cookiejar_get_type ())
  33. #define COOKIEJAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COOKIEJAR_TYPE, CookieJar))
  34. -enum { AtomFind, AtomGo, AtomUri, AtomLast };
  35. +enum { AtomFind, AtomGo, AtomUri, AtomHist, AtomNav, AtomLast };
  36. enum {
  37. ClkDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
  38. ClkLink = WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK,
  39. @@ -177,6 +177,8 @@ static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec,
  40. Client *c);
  41. static void loaduri(Client *c, const Arg *arg);
  42. static void navigate(Client *c, const Arg *arg);
  43. +static void selhist(Client *c, const Arg *arg);
  44. +static void navhist(Client *c, const Arg *arg);
  45. static Client *newclient(void);
  46. static void newwindow(Client *c, const Arg *arg, gboolean noembed);
  47. static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
  48. @@ -813,6 +815,59 @@ navigate(Client *c, const Arg *arg) {
  49. webkit_web_view_go_back_or_forward(c->view, steps);
  50. }
  51. +static void
  52. +selhist(Client *c, const Arg *arg) {
  53. + WebKitWebBackForwardList *lst;
  54. + WebKitWebHistoryItem *cur;
  55. + gint i;
  56. + gchar *out;
  57. + gchar *tmp;
  58. + gchar *line;
  59. +
  60. + out = g_strdup("");
  61. +
  62. + if(!(lst = webkit_web_view_get_back_forward_list(c->view)))
  63. + return;
  64. +
  65. + for(i = webkit_web_back_forward_list_get_back_length(lst); i > 0; i--) {
  66. + if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, -i)))
  67. + break;
  68. + line = g_strdup_printf("%d: %s\n", -i,
  69. + webkit_web_history_item_get_original_uri(cur));
  70. + tmp = g_strconcat(out, line, NULL);
  71. + g_free(out);
  72. + out = tmp;
  73. + }
  74. +
  75. + if((cur = webkit_web_back_forward_list_get_nth_item(lst, 0))) {
  76. + line = g_strdup_printf("%d: %s", 0,
  77. + webkit_web_history_item_get_original_uri(cur));
  78. + tmp = g_strconcat(out, line, NULL);
  79. + g_free(out);
  80. + out = tmp;
  81. + }
  82. +
  83. + for(i = 1; i <= webkit_web_back_forward_list_get_forward_length(lst); i++) {
  84. + if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, i)))
  85. + break;
  86. + line = g_strdup_printf("\n%d: %s", i,
  87. + webkit_web_history_item_get_original_uri(cur));
  88. + tmp = g_strconcat(out, line, NULL);
  89. + g_free(out);
  90. + out = tmp;
  91. + }
  92. +
  93. + setatom(c, AtomHist, out);
  94. + g_free(out);
  95. + spawn(c, arg);
  96. +}
  97. +
  98. +static void
  99. +navhist(Client *c, const Arg *arg) {
  100. + Arg a = { .i = atoi(arg->v) };
  101. + navigate(c, &a);
  102. +}
  103. +
  104. static Client *
  105. newclient(void) {
  106. Client *c;
  107. @@ -1014,6 +1069,7 @@ newclient(void) {
  108. setatom(c, AtomFind, "");
  109. setatom(c, AtomUri, "about:blank");
  110. + setatom(c, AtomHist, "");
  111. if(hidebackground)
  112. webkit_web_view_set_transparent(c->view, TRUE);
  113. @@ -1153,6 +1209,9 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
  114. loaduri(c, &arg);
  115. return GDK_FILTER_REMOVE;
  116. + } else if(ev->atom == atoms[AtomNav]) {
  117. + arg.v = getatom(c, AtomNav);
  118. + navhist(c, &arg);
  119. }
  120. }
  121. }
  122. @@ -1247,6 +1306,8 @@ setup(void) {
  123. atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
  124. atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
  125. atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
  126. + atoms[AtomHist] = XInternAtom(dpy, "_SURF_HIST", False);
  127. + atoms[AtomNav] = XInternAtom(dpy, "_SURF_NAV", False);
  128. /* dirs and files */
  129. cookiefile = buildfile(cookiefile);