surf

Simple browser by suckless.org (fork)
git clone git://git.ckyln.com/surf.git
Log | Files | Refs | README | LICENSE

commit e2916c7ad2daa25bb5df83c2842c3ad8d2168a7c
parent 8340aea4434a5241a0d621ae6ba26f7e3971b595
Author: Cem Keylan <cem@ckyln.com>
Date:   Sat, 23 Nov 2019 17:42:37 +0300

use a single search option

Diffstat:
Mconfig.def.h | 20++++++++++----------
Msurf.c | 44++++++++++++++++++++------------------------
2 files changed, 30 insertions(+), 34 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -7,16 +7,7 @@ static char *certdir = "~/.surf/certificates/"; static char *cachedir = "~/.surf/cache/"; static char *cookiefile = "~/.surf/cookies.txt"; static char *historyfile = "~/.surf/history.txt"; - -/* Search Engines */ -static SearchEngine searchengines[] = { - { "s", "https://duckduckgo.com/?q=%s" }, - { "aw", "https://wiki.archlinux.org/?search=%s" }, - { "docker", "https://hub.docker.com/search?q=%s" }, - { "gl", "https://gitlab.cemkeylan.com/cemkeylan/%s"}, - { "gl3", "https://gitlab.cemkeylan.com/3c1b/%s" }, - { "r", "https://reddit.com/r/%s" }, -}; +static char *searchurl = "duckduckgo.com/?q=%s"; /* Webkit default features */ /* Highest priority value will be used. @@ -88,6 +79,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",\ @@ -232,6 +231,7 @@ static Key keys[] = { { MODKEY|GDK_SHIFT_MASK, GDK_KEY_e, externalpipe, { .v = editscreen } }, { MODKEY, GDK_KEY_y, externalpipe, { .v = yanklink } }, { MODKEY, GDK_KEY_m, spawn, BM_ADD("_SURF_URI") }, + { MODKEY, GDK_KEY_s, spawn, SEARCH() }, }; /* button definitions */ diff --git a/surf.c b/surf.c @@ -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, @@ -129,11 +129,6 @@ typedef struct { } Button; typedef struct { - char *token; - char *uri; -} SearchEngine; - -typedef struct { const char *uri; Parameter config[ParameterLast]; regex_t re; @@ -221,7 +216,6 @@ static void webprocessterminated(WebKitWebView *v, Client *c); static void closeview(WebKitWebView *v, Client *c); static void destroywin(GtkWidget* w, Client *c); -static gchar *parseuri(const gchar *uri); /* Hotkeys */ static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d); @@ -241,6 +235,7 @@ static void toggleinspector(Client *c, const Arg *a); static void find(Client *c, const Arg *a); static void insert(Client *c, const Arg *a); static void externalpipe(Client *c, const Arg *a); +static void search(Client *c, const Arg *a); /* Buttons */ static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h); @@ -410,6 +405,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); @@ -644,7 +640,7 @@ loaduri(Client *c, const Arg *a) url = g_strdup_printf("file://%s", path); free(path); } else { - url = parseuri(uri); + url = g_strdup_printf("http://%s", uri); } if (apath != uri) free(apath); @@ -662,6 +658,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) { @@ -1412,6 +1421,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); @@ -1872,22 +1884,6 @@ destroywin(GtkWidget* w, Client *c) gtk_main_quit(); } -gchar * -parseuri(const gchar *uri) { - guint i; - - for (i = 0; i < LENGTH(searchengines); i++) { - if (searchengines[i].token == NULL || searchengines[i].uri == NULL || - *(uri + strlen(searchengines[i].token)) != ' ') - continue; - if (g_str_has_prefix(uri, searchengines[i].token)) - return g_strdup_printf(searchengines[i].uri, - uri + strlen(searchengines[i].token) + 1); - } - - return g_strdup_printf("http://%s", uri); -} - void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) {