[PATCH] User defined new tab page
Hi list, Here is a patch to add a new tab page to dillo. You can define any url in dillorc preference 'new_tab_page', and it will be automatically opened in new tabs. Setting the value "about:blank" will retain the default blank page behavior. I tried to make it work with an empty value of "", but for some reason dillo prepends 'http:' to the value. Hopefully this won't be a problem, because now the about:blank is pre-selected and you can just start typing over it. If there is a better way to do this, I'm open to suggestions. Regards, Alex --- dillorc Thu Apr 11 11:11:01 2024 +++ dillorc Thu Apr 11 11:14:18 2024 @@ -154,6 +154,11 @@ # home="file:/home/jcid/HomePage/Home.html" #home="https://dillo-browser.github.io/" +# Set the new tab page. +# new_tab_page="dpi:/bm/" +# new_tab_page="https://example.com/" #new_tab_page="about:blank" + # Set the URLs used by the web search dialog. # "%s" is replaced with the search keywords separated by '+'. # Format: search_url="[prefix ][<label> ]<url>" --- src/prefs.c Thu Apr 11 11:18:24 2024 +++ src/prefs.c Thu Apr 11 11:21:16 2024 @@ -14,6 +14,7 @@ #define PREFS_START_PAGE "about:splash" #define PREFS_HOME "https://dillo-browser.github.io/" +#define PREFS_NEW_TAB_PAGE "about:blank" #define PREFS_FONT_SERIF "DejaVu Serif" #define PREFS_FONT_SANS_SERIF "DejaVu Sans" #define PREFS_FONT_CURSIVE "URW Chancery L" @@ -109,6 +110,7 @@ prefs.show_ui_tooltip = TRUE; prefs.small_icons = FALSE; prefs.start_page = a_Url_new(PREFS_START_PAGE, NULL); + prefs.new_tab_page = a_Url_new(PREFS_NEW_TAB_PAGE, NULL); prefs.theme = dStrdup(PREFS_THEME); prefs.ui_button_highlight_color = -1; prefs.ui_fg_color = -1; @@ -143,6 +145,7 @@ dFree(prefs.font_sans_serif); dFree(prefs.font_serif); a_Url_free(prefs.home); + a_Url_free(prefs.new_tab_page); dFree(prefs.http_language); a_Url_free(prefs.http_proxy); dFree(prefs.http_proxyuser); --- src/prefs.h Thu Apr 11 11:23:35 2024 +++ src/prefs.h Thu Apr 11 11:24:35 2024 @@ -48,6 +48,7 @@ char *no_proxy; DilloUrl *start_page; DilloUrl *home; + DilloUrl *new_tab_page; bool_t allow_white_bg; int32_t white_bg_replacement; int32_t bg_color; --- src/prefsparser.cc Thu Apr 11 11:26:31 2024 +++ src/prefsparser.cc Thu Apr 11 11:28:12 2024 @@ -171,6 +171,7 @@ { "fullwindow_start", &prefs.fullwindow_start, PREFS_BOOL, 0 }, { "geometry", NULL, PREFS_GEOMETRY, 0 }, { "home", &prefs.home, PREFS_URL, 0 }, + { "new_tab_page", &prefs.new_tab_page, PREFS_URL, 0 }, { "http_language", &prefs.http_language, PREFS_STRING, 0 }, { "http_max_conns", &prefs.http_max_conns, PREFS_INT32, 0 }, { "http_persistent_conns", &prefs.http_persistent_conns, PREFS_BOOL, 0 }, --- src/uicmd.cc Thu Apr 11 11:31:18 2024 +++ src/uicmd.cc Thu Apr 11 12:06:13 2024 @@ -778,6 +778,7 @@ a_UIcmd_set_location_text(new_bw, URL_STR(url)); BW2UI(new_bw)->focus_main(); } else { + a_UIcmd_open_url((BrowserWindow*)new_bw, prefs.new_tab_page); BW2UI(new_bw)->focus_location(); a_UIcmd_set_buttons_sens(new_bw); }
Try again, last message was mangled: --- dillorc Thu Apr 11 11:11:01 2024 +++ dillorc Thu Apr 11 11:14:18 2024 @@ -154,6 +154,11 @@ # home="file:/home/jcid/HomePage/Home.html" #home="https://dillo-browser.github.io/" +# Set the new tab page. +# new_tab_page="dpi:/bm/" +# new_tab_page="https://example.com/" +#new_tab_page="about:blank" + # Set the URLs used by the web search dialog. # "%s" is replaced with the search keywords separated by '+'. # Format: search_url="[prefix ][<label> ]<url>" --- src/prefs.c Thu Apr 11 11:18:24 2024 +++ src/prefs.c Thu Apr 11 11:21:16 2024 @@ -14,6 +14,7 @@ #define PREFS_START_PAGE "about:splash" #define PREFS_HOME "https://dillo-browser.github.io/" +#define PREFS_NEW_TAB_PAGE "about:blank" #define PREFS_FONT_SERIF "DejaVu Serif" #define PREFS_FONT_SANS_SERIF "DejaVu Sans" #define PREFS_FONT_CURSIVE "URW Chancery L" @@ -109,6 +110,7 @@ prefs.show_ui_tooltip = TRUE; prefs.small_icons = FALSE; prefs.start_page = a_Url_new(PREFS_START_PAGE, NULL); + prefs.new_tab_page = a_Url_new(PREFS_NEW_TAB_PAGE, NULL); prefs.theme = dStrdup(PREFS_THEME); prefs.ui_button_highlight_color = -1; prefs.ui_fg_color = -1; @@ -143,6 +145,7 @@ dFree(prefs.font_sans_serif); dFree(prefs.font_serif); a_Url_free(prefs.home); + a_Url_free(prefs.new_tab_page); dFree(prefs.http_language); a_Url_free(prefs.http_proxy); dFree(prefs.http_proxyuser); --- src/prefs.h Thu Apr 11 11:23:35 2024 +++ src/prefs.h Thu Apr 11 11:24:35 2024 @@ -48,6 +48,7 @@ char *no_proxy; DilloUrl *start_page; DilloUrl *home; + DilloUrl *new_tab_page; bool_t allow_white_bg; int32_t white_bg_replacement; int32_t bg_color; --- src/prefsparser.cc Thu Apr 11 11:26:31 2024 +++ src/prefsparser.cc Thu Apr 11 11:28:12 2024 @@ -171,6 +171,7 @@ { "fullwindow_start", &prefs.fullwindow_start, PREFS_BOOL, 0 }, { "geometry", NULL, PREFS_GEOMETRY, 0 }, { "home", &prefs.home, PREFS_URL, 0 }, + { "new_tab_page", &prefs.new_tab_page, PREFS_URL, 0 }, { "http_language", &prefs.http_language, PREFS_STRING, 0 }, { "http_max_conns", &prefs.http_max_conns, PREFS_INT32, 0 }, { "http_persistent_conns", &prefs.http_persistent_conns, PREFS_BOOL, 0 }, --- src/uicmd.cc Thu Apr 11 11:31:18 2024 +++ src/uicmd.cc Thu Apr 11 12:06:13 2024 @@ -778,6 +778,7 @@ a_UIcmd_set_location_text(new_bw, URL_STR(url)); BW2UI(new_bw)->focus_main(); } else { + a_UIcmd_open_url((BrowserWindow*)new_bw, prefs.new_tab_page); BW2UI(new_bw)->focus_location(); a_UIcmd_set_buttons_sens(new_bw); }
Try again, last message was mangled:
Please use "git send-email" to send patches, so they can be applied with "git am". Follow this guide to set it up: https://git-send-email.io/ Rodrigo.
Here is a patch to add a new tab page to dillo. You can define any url in dillorc preference 'new_tab_page', and it will be automatically opened in new tabs. Setting the value "about:blank" will retain the default blank page behavior. I tried to make it work with an empty value of "", but for some reason dillo prepends 'http:' to the value.
I would be nice to have an exception for "" so it is kept as-is.
Hopefully this won't be a problem, because now the about:blank is pre-selected and you can just start typing over it.
It only works well with about:blank. As soon as you load another page (like dpi:/bm/) it deselects the location bar. Rodrigo.
On Thu, 11 Apr 2024 13:26:50 +0200 Rodrigo Arias <rodarima@gmail.com> wrote:
Here is a patch to add a new tab page to dillo. You can define any url in dillorc preference 'new_tab_page', and it will be automatically opened in new tabs. Setting the value "about:blank" will retain the default blank page behavior. I tried to make it work with an empty value of "", but for some reason dillo prepends 'http:' to the value.
I would be nice to have an exception for "" so it is kept as-is.
I'm looking at lines 401-411 in url.c, and almost have it working as you suggest. My code is undoubtedly ugly and incorrect, so I might need some help with this one. Will keep trying.
Hopefully this won't be a problem, because now the about:blank is pre-selected and you can just start typing over it.
It only works well with about:blank. As soon as you load another page (like dpi:/bm/) it deselects the location bar.
Right, the pre-selection doesn't seem to work with other urls. I still haven't figured out how to fix that, but am guessing that as soon as content starts to load, it deselects the text. I think the feature is still useful given that caveat, but surely there must be some solution. Regards, Alex
I'm looking at lines 401-411 in url.c, and almost have it working as you suggest. My code is undoubtedly ugly and incorrect, so I might need some help with this one. Will keep trying.
The problem is that the url "" is converted to "http:/" when parsing the value from the preferences. We may leave the value "about:blank" by default (and forbid ""), but then, when opening a new tab, if the new_tab_url matches "about:blank", we set it to NULL to leave the location empty, which follows the current behavior. Maybe, something like this? + if (!url && strcmp(URL_STR(prefs.new_tab_page), "about:blank") != 0) + url = prefs.new_tab_page; So we keep url to NULL when opening "about:blank".
Right, the pre-selection doesn't seem to work with other urls. I still haven't figured out how to fix that, but am guessing that as soon as content starts to load, it deselects the text. I think the feature is still useful given that caveat, but surely there must be some solution.
The selection is lost because of this call that sets the location value: https://github.com/dillo-browser/dillo/blob/c7d5e1e071955b1009b114146014960b... I'm thinking if we really want to focus on the location bar when not opening "about:blank" as you may want to load a search engine and focus on the search input instead. I think for now this is not needed, as long as we can keep the current behavior intact by default. We can add another option later to always focus the location bar when is not an empty page. Thanks, Rodrigo.
We may leave the value "about:blank" by default (and forbid ""), but then, when opening a new tab, if the new_tab_url matches "about:blank", we set it to NULL to leave the location empty, which follows the current behavior. Maybe, something like this?
+ if (!url && strcmp(URL_STR(prefs.new_tab_page), "about:blank") != 0) + url = prefs.new_tab_page;
That does seem like the most elegant solution for now. Thanks! Alex
On Thu, Apr 11, 2024 at 05:36:07PM +0200, a1ex@dismail.de wrote:
We may leave the value "about:blank" by default (and forbid ""), but then, when opening a new tab, if the new_tab_url matches "about:blank", we set it to NULL to leave the location empty, which follows the current behavior. Maybe, something like this?
+ if (!url && strcmp(URL_STR(prefs.new_tab_page), "about:blank") != 0) + url = prefs.new_tab_page;
That does seem like the most elegant solution for now. Thanks!
Related PR: https://github.com/dillo-browser/dillo/pull/147 Rodrigo.
Hi, On Thu, Apr 11, 2024 at 05:36:07PM +0200, a1ex@dismail.de wrote:
We may leave the value "about:blank" by default (and forbid ""), but then, when opening a new tab, if the new_tab_url matches "about:blank", we set it to NULL to leave the location empty, which follows the current behavior. Maybe, something like this?
+ if (!url && strcmp(URL_STR(prefs.new_tab_page), "about:blank") != 0) + url = prefs.new_tab_page;
That does seem like the most elegant solution for now. Thanks!
Merged in https://github.com/dillo-browser/dillo/pull/188 Empty URLs are used when parsing something like href="", so we cannot return an invalid URL in a_URL_new(), otherwise that causes a segfault in other parts (see #190). So for now, I'm only making it invalid if the base URL is NULL, which covers the case when you set new_tab_page="", causing the newly open tab to just open a blank tab instead of "http:/". Rodrigo.
Hopefully this won't be a problem, because now the about:blank is pre-selected and you can just start typing over it.
It only works well with about:blank. As soon as you load another page (like dpi:/bm/) it deselects the location bar.
Maybe there is a way to do something like this to retake the selection after the page has finished loading (or earlier?) from ui.cc: 139 // Make text selected when already focused. 140 position(size(), 0); ... 836 // Make text selected when already focused. 837 Location->position(Location->size(), 0); Sorry if I'm stating the obvious, just thinking aloud :) Alex
participants (2)
-
a1ex@dismail.de
-
Rodrigo Arias