Hi,
Currently when using a window manager where focus follows mouse, making a
search usually requires you to reach for the mouse. One way to avoid this
would be to allow using search engine(s) directly from the address bar.
Searches would have to be differentiated somehow from URLs. Dillo already
has a customizable list of engines in preferences, so one natural solution
would be to interpret url strings which start with the name of a search
engine as searches to be performed using it, so that e.g. 'wikipedia
slartibartfast', 'google foo' and 'weather oulu' do what you would expect.
Below is a quick patch I've used to do this for a while, should anyone
else find this feature useful.
diff -r 91fdbc0feb68 src/uicmd.cc
--- a/src/uicmd.cc Sun Jun 16 21:23:19 2013 +0200
+++ b/src/uicmd.cc Mon Jun 17 15:00:05 2013 +0300
@@ -70,6 +70,7 @@
*/
static BrowserWindow *UIcmd_tab_new(CustTabs *tabs, UI *old_ui, int focus);
static void close_tab_btn_cb (Fl_Widget *w, void *cb_data);
+static char *UIcmd_make_search_str(const char *str);
//----------------------------------------------------------------------------
@@ -649,6 +650,27 @@
}
/*
+ * Return a search string of the suffix if str is prefixed by the first word of a search engine name
+ */
+static char *UIcmd_find_search_str(const char *str)
+{
+ int end = dList_length(prefs.search_urls);
+ int p = 0;
+ char *url = NULL;
+ while (p < end && !url) {
+ char *search = (char *)dList_nth_data(prefs.search_urls,p);
+ int len = strcspn(search, " ");
+ int res = strncasecmp(str, search, len);
+ if (res == 0 && (str[len] == 0 || str[len] == ' ')) {
+ prefs.search_url_idx = p;
+ url = UIcmd_make_search_str(str + len);
+ }
+ p++;
+ }
+ return url;
+}
+
+/*
* Open a new URL in the given browser window.
*
* our custom "file:" URIs are normalized here too.
@@ -656,10 +678,14 @@
void a_UIcmd_open_urlstr(void *vbw, const char *urlstr)
{
char *new_urlstr;
+ char *search_urlstr = NULL;
DilloUrl *url;
int ch;
BrowserWindow *bw = (BrowserWindow*)vbw;
+ if ((search_urlstr = UIcmd_find_search_str(urlstr))) {
+ urlstr = search_urlstr;
+ }
if (urlstr && *urlstr) {
/* Filter URL string */
new_urlstr = a_Url_string_strip_delimiters(urlstr);
@@ -680,6 +706,8 @@
url = a_Url_new(new_urlstr, NULL);
}
dFree(new_urlstr);
+ if (search_urlstr)
+ dFree(search_urlstr);
if (url) {
a_UIcmd_open_url(bw, url);
--
Aki Helin