surf-websearch-20190510-d068a38.diff 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. From c5ca896c5ba969b90f1e098d117c205a9b71d0db Mon Sep 17 00:00:00 2001
  2. From: Bryon Meinka <bryon.meinka@gmail.com>
  3. Date: Sat, 11 May 2019 00:52:29 -0400
  4. Subject: [PATCH] Web Search
  5. ---
  6. config.def.h | 10 ++++++++++
  7. surf.c | 20 +++++++++++++++++++-
  8. 2 files changed, 29 insertions(+), 1 deletion(-)
  9. diff --git a/config.def.h b/config.def.h
  10. index 34265f6..69657bf 100644
  11. --- a/config.def.h
  12. +++ b/config.def.h
  13. @@ -6,6 +6,7 @@ static char *styledir = "~/.surf/styles/";
  14. static char *certdir = "~/.surf/certificates/";
  15. static char *cachedir = "~/.surf/cache/";
  16. static char *cookiefile = "~/.surf/cookies.txt";
  17. +static char *searchurl = "duckduckgo.com/?q=%s";
  18. /* Webkit default features */
  19. /* Highest priority value will be used.
  20. @@ -76,6 +77,14 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
  21. } \
  22. }
  23. +#define SEARCH() { \
  24. + .v = (const char *[]){ "/bin/sh", "-c", \
  25. + "xprop -id $1 -f $2 8s -set $2 \"" \
  26. + "$(dmenu -p Search: -w $1 < /dev/null)\"", \
  27. + "surf-search", winid, "_SURF_SEARCH", NULL \
  28. + } \
  29. +}
  30. +
  31. /* DOWNLOAD(URI, referer) */
  32. #define DOWNLOAD(u, r) { \
  33. .v = (const char *[]){ "st", "-e", "/bin/sh", "-c",\
  34. @@ -133,6 +142,7 @@ static Key keys[] = {
  35. { MODKEY, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) },
  36. { MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) },
  37. { MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) },
  38. + { MODKEY, GDK_KEY_s, spawn, SEARCH() },
  39. { 0, GDK_KEY_Escape, stop, { 0 } },
  40. { MODKEY, GDK_KEY_c, stop, { 0 } },
  41. diff --git a/surf.c b/surf.c
  42. index 2b54e3c..077fb76 100644
  43. --- a/surf.c
  44. +++ b/surf.c
  45. @@ -35,7 +35,7 @@
  46. #define LENGTH(x) (sizeof(x) / sizeof(x[0]))
  47. #define CLEANMASK(mask) (mask & (MODKEY|GDK_SHIFT_MASK))
  48. -enum { AtomFind, AtomGo, AtomUri, AtomLast };
  49. +enum { AtomFind, AtomSearch, AtomGo, AtomUri, AtomLast };
  50. enum {
  51. OnDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
  52. @@ -231,6 +231,7 @@ static void togglefullscreen(Client *c, const Arg *a);
  53. static void togglecookiepolicy(Client *c, const Arg *a);
  54. static void toggleinspector(Client *c, const Arg *a);
  55. static void find(Client *c, const Arg *a);
  56. +static void search(Client *c, const Arg *a);
  57. /* Buttons */
  58. static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
  59. @@ -326,6 +327,7 @@ setup(void)
  60. /* atoms */
  61. atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
  62. + atoms[AtomSearch] = XInternAtom(dpy, "_SURF_SEARCH", False);
  63. atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
  64. atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
  65. @@ -577,6 +579,19 @@ loaduri(Client *c, const Arg *a)
  66. g_free(url);
  67. }
  68. +void
  69. +search(Client *c, const Arg *a)
  70. +{
  71. + Arg arg;
  72. + char *url;
  73. +
  74. + url = g_strdup_printf(searchurl, a->v);
  75. + arg.v = url;
  76. + loaduri(c, &arg);
  77. +
  78. + g_free(url);
  79. +}
  80. +
  81. const char *
  82. geturi(Client *c)
  83. {
  84. @@ -1311,6 +1326,9 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d)
  85. find(c, NULL);
  86. return GDK_FILTER_REMOVE;
  87. + } else if (ev->atom == atoms[AtomSearch]) {
  88. + a.v = getatom(c, AtomSearch);
  89. + search(c, &a);
  90. } else if (ev->atom == atoms[AtomGo]) {
  91. a.v = getatom(c, AtomGo);
  92. loaduri(c, &a);
  93. --
  94. 2.21.0