X-Git-Url: https://git.danieliu.xyz/?p=surf.git;a=blobdiff_plain;f=surf.c;h=4520daa044a35c8b4f7458736ebef03cb0df4946;hp=aad863eab6585507f3f46e3dd8024e5667c8aaec;hb=b1e5693d5b520552c2f683f5b4585a83fb2d4c81;hpb=56729247de9ae123cc08ed1e45097622340388b6 diff --git a/surf.c b/surf.c index aad863e..4520daa 100644 --- a/surf.c +++ b/surf.c @@ -128,6 +128,12 @@ typedef struct { unsigned int stopevent; } Button; + +typedef struct { + char *token; + char *uri; +} SearchEngine; + typedef struct { const char *uri; Parameter config[ParameterLast]; @@ -214,6 +220,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); @@ -231,6 +238,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 playexternal(Client *c, const Arg *a); /* Buttons */ static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h); @@ -559,7 +567,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); @@ -1765,6 +1773,22 @@ 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) { @@ -1971,6 +1995,15 @@ clickexternplayer(Client *c, const Arg *a, WebKitHitTestResult *h) spawn(c, &arg); } +void +playexternal(Client *c, const Arg *a) +{ + Arg arg; + + arg = (Arg)VIDEOPLAY(geturi(c)); + spawn(c, &arg); +} + int main(int argc, char *argv[]) {