surf

A surf web browser [kocotian build]
git clone git://git.kocotian.pl/surf.git
Log | Files | Refs | README | LICENSE

commit 532e6326e4b2ab0bfd43f5e8df13d3f7c3204b3f
parent db5387501d22c18a6d122d40e5cea566bda390ae
Author: kocotian <kocotian@kocotian.pl>
Date:   Tue, 22 Dec 2020 17:23:06 +0100

searching, config upgrades

Diffstat:
Mconfig.def.h | 18++++++++++++++----
Mpatches/surf-git-20170323-webkit2-searchengines.diff | 0
Msurf.c | 37++++++++++++++++++++++++++++++++++++-
3 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -13,6 +13,15 @@ static char **plugindirs = (char*[]){ NULL }; +static SearchEngine searchengines[] = { + /* token, uri */ + { "ddg", "https://duckduckgo.com/?q=%s" }, +}; + +static char *reservednames[] = { + "localhost", +}; + /* enable to open GO prompt on startup */ static int startgo = 0; @@ -35,12 +44,12 @@ static Parameter defconfig[ParameterLast] = { [DNSPrefetch] = { { .i = 0 }, }, [Ephemeral] = { { .i = 0 }, }, [FileURLsCrossAccess] = { { .i = 0 }, }, - [FontSize] = { { .i = 12 }, }, + [FontSize] = { { .i = 15 }, }, [FrameFlattening] = { { .i = 0 }, }, [Geolocation] = { { .i = 0 }, }, - [HideBackground] = { { .i = 0 }, }, + [HideBackground] = { { .i = 1 }, }, [Inspector] = { { .i = 0 }, }, - [Java] = { { .i = 1 }, }, + [Java] = { { .i = 0 }, }, [JavaScript] = { { .i = 1 }, }, [KioskMode] = { { .i = 0 }, }, [LoadImages] = { { .i = 1 }, }, @@ -51,7 +60,7 @@ static Parameter defconfig[ParameterLast] = { [ScrollBars] = { { .i = 1 }, }, [ShowIndicators] = { { .i = 1 }, }, [SiteQuirks] = { { .i = 1 }, }, - [SmoothScrolling] = { { .i = 0 }, }, + [SmoothScrolling] = { { .i = 1 }, }, [SpellChecking] = { { .i = 0 }, }, [SpellLanguages] = { { .v = ((char *[]){ "en_US", NULL }) }, }, [StrictTLS] = { { .i = 1 }, }, @@ -124,6 +133,7 @@ p, winid, NULL } } */ static SiteSpecific styles[] = { /* regexp file in $styledir */ + { ".*suckless.org", "suckless.css" }, { ".*", "default.css" }, }; diff --git a/patches/surf-git-20170323-webkit2-searchengines.diff b/patches/surf-git-20170323-webkit2-searchengines.diff diff --git a/surf.c b/surf.c @@ -132,6 +132,11 @@ typedef struct { } Button; typedef struct { + char *token; + char *uri; +} SearchEngine; + +typedef struct { const char *uri; Parameter config[ParameterLast]; regex_t re; @@ -219,6 +224,7 @@ 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); @@ -582,7 +588,7 @@ loaduri(Client *c, const Arg *a) url = g_strdup_printf("file://%s", path); free(path); } else { - url = g_strdup_printf("http://%s", uri); + url = parseuri(uri); } if (apath != uri) free(apath); @@ -1814,6 +1820,35 @@ destroywin(GtkWidget* w, Client *c) gtk_main_quit(); } +gchar * +parseuri(const gchar *uri) { + guint i, havedot, havespace, reserved; + havedot = havespace = reserved = 0; + + 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); + } + + for (i = 0; i < strlen(uri); ++i) + if (uri[i] == '.') havedot = 1; + else if (uri[i] == ' ') havespace = 1; + + for (i = 0; i < LENGTH(reservednames); ++i) + if (!strcmp(reservednames[i], uri)) + reserved = 1; + + if (!reserved && (!havedot || havespace)) + return g_strdup_printf(searchengines[0].uri, + uri); + + return g_strdup_printf("http://%s", uri); +} + void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) {