[wiki] [sites] [surf][patch] Add Web Search Patch || Bryon Meinka

From: <git_AT_suckless.org>
Date: Sat, 11 May 2019 07:15:34 +0200

commit bca12b5ad2850cc50267170d9729c37a3f05e251
Author: Bryon Meinka <bryon.meinka_AT_gmail.com>
Date: Sat May 11 01:13:03 2019 -0400

    [surf][patch] Add Web Search Patch

diff --git a/surf.suckless.org/patches/web-search/index.md b/surf.suckless.org/patches/web-search/index.md
new file mode 100644
index 00000000..ed9ca374
--- /dev/null
+++ b/surf.suckless.org/patches/web-search/index.md
_AT_@ -0,0 +1,12 @@
+# Web Search
+
+Simple patch that adds a search feature. Use MODKEY+s to search DuckDuckGo. The
+search engine and keybinding can be configured.
+
+## Download
+
+* [surf-websearch-20190510-d068a38.diff](surf-websearch-20190510-d068a38.diff)
+
+## Author
+
+* Bryon Meinka <bryon.meinka_AT_gmail.com>
diff --git a/surf.suckless.org/patches/web-search/surf-websearch-20190510-d068a38.diff b/surf.suckless.org/patches/web-search/surf-websearch-20190510-d068a38.diff
new file mode 100644
index 00000000..7e7f92a7
--- /dev/null
+++ b/surf.suckless.org/patches/web-search/surf-websearch-20190510-d068a38.diff
_AT_@ -0,0 +1,107 @@
+From c5ca896c5ba969b90f1e098d117c205a9b71d0db Mon Sep 17 00:00:00 2001
+From: Bryon Meinka <bryon.meinka_AT_gmail.com>
+Date: Sat, 11 May 2019 00:52:29 -0400
+Subject: [PATCH] Web Search
+
+---
+ config.def.h | 10 ++++++++++
+ surf.c | 20 +++++++++++++++++++-
+ 2 files changed, 29 insertions(+), 1 deletion(-)
+
+diff --git a/config.def.h b/config.def.h
+index 34265f6..69657bf 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -6,6 +6,7 @@ static char *styledir = "~/.surf/styles/";
+ static char *certdir = "~/.surf/certificates/";
+ static char *cachedir = "~/.surf/cache/";
+ static char *cookiefile = "~/.surf/cookies.txt";
++static char *searchurl = "duckduckgo.com/?q=%s";
+
+ /* Webkit default features */
+ /* Highest priority value will be used.
+_AT_@ -76,6 +77,14 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
+ } \
+ }
+
++#define SEARCH() { \
++ .v = (const char *[]){ "/bin/sh", "-c", \
++ "xprop -id $1 -f $2 8s -set $2 \"" \
++ "$(dmenu -p Search: -w $1 < /dev/null)\"", \
++ "surf-search", winid, "_SURF_SEARCH", NULL \
++ } \
++}
++
+ /* DOWNLOAD(URI, referer) */
+ #define DOWNLOAD(u, r) { \
+ .v = (const char *[]){ "st", "-e", "/bin/sh", "-c",\
+_AT_@ -133,6 +142,7 @@ static Key keys[] = {
+ { MODKEY, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) },
+ { MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) },
+ { MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) },
++ { MODKEY, GDK_KEY_s, spawn, SEARCH() },
+
+ { 0, GDK_KEY_Escape, stop, { 0 } },
+ { MODKEY, GDK_KEY_c, stop, { 0 } },
+diff --git a/surf.c b/surf.c
+index 2b54e3c..077fb76 100644
+--- a/surf.c
++++ b/surf.c
+_AT_@ -35,7 +35,7 @@
+ #define LENGTH(x) (sizeof(x) / sizeof(x[0]))
+ #define CLEANMASK(mask) (mask & (MODKEY|GDK_SHIFT_MASK))
+
+-enum { AtomFind, AtomGo, AtomUri, AtomLast };
++enum { AtomFind, AtomSearch, AtomGo, AtomUri, AtomLast };
+
+ enum {
+ OnDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
+_AT_@ -231,6 +231,7 @@ static void togglefullscreen(Client *c, const Arg *a);
+ static void togglecookiepolicy(Client *c, const Arg *a);
+ static void toggleinspector(Client *c, const Arg *a);
+ static void find(Client *c, const Arg *a);
++static void search(Client *c, const Arg *a);
+
+ /* Buttons */
+ static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h);
+_AT_@ -326,6 +327,7 @@ setup(void)
+
+ /* atoms */
+ atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
++ atoms[AtomSearch] = XInternAtom(dpy, "_SURF_SEARCH", False);
+ atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
+ atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
+
+_AT_@ -577,6 +579,19 @@ loaduri(Client *c, const Arg *a)
+ g_free(url);
+ }
+
++void
++search(Client *c, const Arg *a)
++{
++ Arg arg;
++ char *url;
++
++ url = g_strdup_printf(searchurl, a->v);
++ arg.v = url;
++ loaduri(c, &arg);
++
++ g_free(url);
++}
++
+ const char *
+ geturi(Client *c)
+ {
+_AT_@ -1311,6 +1326,9 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d)
+ find(c, NULL);
+
+ return GDK_FILTER_REMOVE;
++ } else if (ev->atom == atoms[AtomSearch]) {
++ a.v = getatom(c, AtomSearch);
++ search(c, &a);
+ } else if (ev->atom == atoms[AtomGo]) {
+ a.v = getatom(c, AtomGo);
+ loaduri(c, &a);
+--
+2.21.0
+
Received on Sat May 11 2019 - 07:15:34 CEST

This archive was generated by hypermail 2.3.0 : Sat May 11 2019 - 07:24:29 CEST