summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Marçalo <raroma09@gmail.com>2023-11-29 17:37:11 +0000
committerRafael Marçalo <raroma09@gmail.com>2023-11-29 17:37:11 +0000
commit025ce6afa7afacbadb08ec73bd22a9cf3dd7cea1 (patch)
tree997a6ec9d7f4c0f8bd1b1de12e260e8aade59e3a
parent30f5464eb11b96f740b124816cbcfa55f125cf53 (diff)
Websearch patch
-rw-r--r--config.def.h12
-rw-r--r--surf.c20
2 files changed, 31 insertions, 1 deletions
diff --git a/config.def.h b/config.def.h
index 93cfeeb..e5f217e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -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.
@@ -64,6 +65,7 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
#define PROMPT_GO "Go:"
#define PROMPT_FIND "Find:"
+#define PROMPT_SEARCH "Search:"
/* SETPROP(readprop, setprop, prompt)*/
#define SETPROP(r, s, p) { \
@@ -103,6 +105,15 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
} \
}
+/* SEARCH(searchQuery, prompt) */
+#define SEARCH(s, p) { \
+ .v = (const char *[]){ "/bin/sh", "-c", \
+ "query=\"$(dmenu -p '"p"' -w $1 < /dev/null)\" " \
+ "&& xprop -id $1 -f "s" 8u -set "s" \"$query\"", \
+ "surf-search", winid, "_SURF_SEARCH", NULL \
+ } \
+}
+
/* styles */
/*
* The iteration will stop at the first match, beginning at the beginning of
@@ -134,6 +145,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("_SURF_SEARCH", PROMPT_SEARCH) },
{ 0, GDK_KEY_Escape, stop, { 0 } },
{ MODKEY, GDK_KEY_c, stop, { 0 } },
diff --git a/surf.c b/surf.c
index f8c8dec..43e2021 100644
--- a/surf.c
+++ b/surf.c
@@ -38,7 +38,7 @@
#define LENGTH(x) (sizeof(x) / sizeof(x[0]))
#define CLEANMASK(mask) (mask & (MODKEY|GDK_SHIFT_MASK))
-enum { AtomFind, AtomGo, AtomUri, AtomUTF8, AtomLast };
+enum { AtomFind, AtomSearch, AtomGo, AtomUri, AtomUTF8, AtomLast };
enum {
OnDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
@@ -239,6 +239,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);
@@ -344,6 +345,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);
atoms[AtomUTF8] = XInternAtom(dpy, "UTF8_STRING", False);
@@ -602,6 +604,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)
{
@@ -1333,6 +1348,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);