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 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. +#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. @@ -67,6 +77,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 cebd469..8b6d751 100644
  29. --- a/surf.c
  30. +++ b/surf.c
  31. @@ -32,7 +32,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. typedef union Arg Arg;
  37. union Arg {
  38. @@ -137,6 +137,8 @@ static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec,
  39. Client *c);
  40. static void loaduri(Client *c, const Arg *arg);
  41. static void navigate(Client *c, const Arg *arg);
  42. +static void selhist(Client *c, const Arg *arg);
  43. +static void navhist(Client *c, const Arg *arg);
  44. static Client *newclient(void);
  45. static void newwindow(Client *c, const Arg *arg, gboolean noembed);
  46. static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
  47. @@ -649,6 +651,59 @@ navigate(Client *c, const Arg *arg) {
  48. webkit_web_view_go_back_or_forward(c->view, steps);
  49. }
  50. +static void
  51. +selhist(Client *c, const Arg *arg) {
  52. + WebKitWebBackForwardList *lst;
  53. + WebKitWebHistoryItem *cur;
  54. + gint i;
  55. + gchar *out;
  56. + gchar *tmp;
  57. + gchar *line;
  58. +
  59. + out = g_strdup("");
  60. +
  61. + if(!(lst = webkit_web_view_get_back_forward_list(c->view)))
  62. + return;
  63. +
  64. + for(i = webkit_web_back_forward_list_get_back_length(lst); i > 0; i--) {
  65. + if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, -i)))
  66. + break;
  67. + line = g_strdup_printf("%d: %s\n", -i,
  68. + webkit_web_history_item_get_original_uri(cur));
  69. + tmp = g_strconcat(out, line, NULL);
  70. + g_free(out);
  71. + out = tmp;
  72. + }
  73. +
  74. + if((cur = webkit_web_back_forward_list_get_nth_item(lst, 0))) {
  75. + line = g_strdup_printf("%d: %s", 0,
  76. + webkit_web_history_item_get_original_uri(cur));
  77. + tmp = g_strconcat(out, line, NULL);
  78. + g_free(out);
  79. + out = tmp;
  80. + }
  81. +
  82. + for(i = 1; i <= webkit_web_back_forward_list_get_forward_length(lst); i++) {
  83. + if(!(cur = webkit_web_back_forward_list_get_nth_item(lst, i)))
  84. + break;
  85. + line = g_strdup_printf("\n%d: %s", i,
  86. + webkit_web_history_item_get_original_uri(cur));
  87. + tmp = g_strconcat(out, line, NULL);
  88. + g_free(out);
  89. + out = tmp;
  90. + }
  91. +
  92. + setatom(c, AtomHist, out);
  93. + g_free(out);
  94. + spawn(c, arg);
  95. +}
  96. +
  97. +static void
  98. +navhist(Client *c, const Arg *arg) {
  99. + Arg a = { .i = atoi(arg->v) };
  100. + navigate(c, &a);
  101. +}
  102. +
  103. static Client *
  104. newclient(void) {
  105. Client *c;
  106. @@ -805,6 +860,7 @@ newclient(void) {
  107. setatom(c, AtomFind, "");
  108. setatom(c, AtomUri, "about:blank");
  109. + setatom(c, AtomHist, "");
  110. if(hidebackground)
  111. webkit_web_view_set_transparent(c->view, TRUE);
  112. @@ -923,6 +979,9 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
  113. arg.v = getatom(c, AtomGo);
  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. @@ -1004,6 +1063,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 = buildpath(cookiefile);