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