[wiki] [sites] [surf][searchengines] Add about: support || Ivan Tham

From: <git_AT_suckless.org>
Date: Wed, 27 Jan 2016 07:38:11 +0100

commit 6fe7331432deae3c0dbfb875e67bfa403fe4c718
Author: Ivan Tham <pickfire_AT_riseup.net>
Date: Wed Jan 27 14:37:51 2016 +0800

    [surf][searchengines] Add about: support

diff --git a/surf.suckless.org/patches/searchengines.md b/surf.suckless.org/patches/searchengines.md
index 05af28a..3b309dc 100644
--- a/surf.suckless.org/patches/searchengines.md
+++ b/surf.suckless.org/patches/searchengines.md
_AT_@ -32,6 +32,7 @@ Download
 * [surf-0.5-searchengines.diff](surf-0.5-searchengines.diff) (1611) (20101028)
 * [surf-0.6-searchengines.diff](surf-0.6-searchengines.diff) (20130514)
 * [surf-0.7-searchengines.diff](surf-0.7-searchengines.diff) (20151219)
+* [surf-git-20160127-searchengines.diff](surf-git-20160127-searchengines.diff)
 * [surf-0.7-webkit2-searchengines.diff](surf-0.7-webkit2-searchengines.diff) (20160108)
 
 Author
diff --git a/surf.suckless.org/patches/surf-git-20160127-searchengines.diff b/surf.suckless.org/patches/surf-git-20160127-searchengines.diff
new file mode 100644
index 0000000..9e525b0
--- /dev/null
+++ b/surf.suckless.org/patches/surf-git-20160127-searchengines.diff
_AT_@ -0,0 +1,74 @@
+diff --git a/config.def.h b/config.def.h
+index 93a3d49..df96d15 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -75,6 +75,13 @@ static SiteStyle styles[] = {
+ { ".*", "default.css" },
+ };
+
++/* search engines */
++static SearchEngine searchengines[] = {
++ { "g", "http://www.google.de/search?q=%s" },
++ { "leo", "http://dict.leo.org/ende?search=%s" },
++ { "ddg", "https://duckduckgo.com/?q=%s" },
++};
++
+ #define MODKEY GDK_CONTROL_MASK
+
+ /* hotkeys */
+diff --git a/surf.c b/surf.c
+index 23c49bd..579848d 100644
+--- a/surf.c
++++ b/surf.c
+_AT_@ -92,6 +92,11 @@ typedef struct {
+ G_DEFINE_TYPE(CookieJar, cookiejar, SOUP_TYPE_COOKIE_JAR_TEXT)
+
+ typedef struct {
++ char *token;
++ char *uri;
++} SearchEngine;
++
++typedef struct {
+ char *regex;
+ char *style;
+ regex_t re;
+_AT_@ -179,6 +184,7 @@ static void loaduri(Client *c, const Arg *arg);
+ static void navigate(Client *c, const Arg *arg);
+ static Client *newclient(void);
+ static void newwindow(Client *c, const Arg *arg, gboolean noembed);
++static gchar *parseuri(const gchar *uri);
+ static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
+ static gboolean contextmenu(WebKitWebView *view, GtkWidget *menu,
+ WebKitHitTestResult *target, gboolean keyboard,
+_AT_@ -840,8 +846,7 @@ loaduri(Client *c, const Arg *arg)
+ u = g_strdup_printf("file://%s", rp);
+ free(rp);
+ } else {
+- u = g_strrstr(uri, "://") || g_str_has_prefix(uri, "about:") ? g_strdup(uri)
+- : g_strdup_printf("http://%s", uri);
++ u = parseuri(uri);
+ }
+
+ setatom(c, AtomUri, uri);
+_AT_@ -1173,6 +1178,21 @@ menuactivate(GtkMenuItem *item, Client *c)
+ }
+ }
+
++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_strrstr(uri, "://") || g_str_has_prefix(uri, "about:") ? g_strdup(uri)
++ : g_strdup_printf("http://%s", uri);
++}
++
+ void
+ pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
+ {
Received on Wed Jan 27 2016 - 07:38:11 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 27 2016 - 07:48:14 CET