X-Git-Url: https://git.danieliu.xyz/?p=surf.git;a=blobdiff_plain;f=surf.c;h=a9da587e47397b1455c52bfde1991272e1234eb0;hp=9d2dacb8e8a7da84cdd12881d189186d72b03011;hb=1007143bda871936e93925a6942c587de2f8939f;hpb=c6f48298df2ff2c4a3c7bf2948bbc5fad7628ebc diff --git a/surf.c b/surf.c index 9d2dacb..a9da587 100644 --- 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, AtomSearch, AtomGo, AtomUri, AtomLast }; +enum { AtomFind, AtomGo, AtomUri, AtomLast }; enum { OnDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT, @@ -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,7 +238,6 @@ 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); @@ -327,7 +333,6 @@ 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); @@ -561,7 +566,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); @@ -579,19 +584,6 @@ 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) { @@ -1326,9 +1318,6 @@ 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); @@ -1783,6 +1772,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) {