[PATCH v2] middle click on nav buttons to open in new tab

Hi, Here is an updated version of the patch which addresses most of Rodrigos comments. Not sure how much more I can improve on it, but open to suggestions. Regards, Alex diff -upr a/doc/user_help.in.html b/doc/user_help.in.html --- a/doc/user_help.in.html Sun Apr 27 18:56:44 2025 +++ b/doc/user_help.in.html Wed Apr 30 16:47:28 2025 @@ -349,6 +349,9 @@ pressed while left-clicking a link. The same applies t form. A new tab can also be opened from the <code>File</code> menu or using the shortcut <code>Ctrl+T</code>. <p> +To open the previous page in a new tab, middle-click the back button. To open +the next page in a new tab, middle-click the forward button. +<p> Press <code>Shift</code> while opening a page in a new tab to focus the tab. If you want this behaviour to be the default, set the following option in the <a href="#dillorc">dillorc</a> configuration file: diff -upr a/src/nav.c b/src/nav.c --- a/src/nav.c Sun Apr 27 18:56:44 2025 +++ b/src/nav.c Wed Apr 30 16:49:55 2025 @@ -447,6 +447,19 @@ void a_Nav_back(BrowserWindow *bw) } /* + * Send the browser back to previous page in new tab + */ +void a_Nav_back_nt(BrowserWindow *bw) +{ + int idx = a_Nav_stack_ptr(bw); + + if (--idx >= 0){ + a_UIcmd_set_msg(bw, ""); + a_UIcmd_open_url_nt(bw, a_History_get_url(NAV_UIDX(bw, idx)), -1); + } +} + +/* * Send the browser to next page in the history list */ void a_Nav_forw(BrowserWindow *bw) @@ -457,6 +470,19 @@ void a_Nav_forw(BrowserWindow *bw) if (++idx < a_Nav_stack_size(bw)) { a_UIcmd_set_msg(bw, ""); Nav_open_url(bw, a_History_get_url(NAV_UIDX(bw,idx)), NULL, +1); + } +} + +/* + * Send the browser to next page in the history list in new tab + */ +void a_Nav_forw_nt(BrowserWindow *bw) +{ + int idx = a_Nav_stack_ptr(bw); + + if (++idx < a_Nav_stack_size(bw)) { + a_UIcmd_set_msg(bw, ""); + a_UIcmd_open_url_nt(bw, a_History_get_url(NAV_UIDX(bw, idx)), +1); } } diff -upr a/src/nav.h b/src/nav.h --- a/src/nav.h Sun Apr 27 18:56:44 2025 +++ b/src/nav.h Wed Apr 30 16:49:55 2025 @@ -18,7 +18,9 @@ void a_Nav_push(BrowserWindow *bw, const DilloUrl *url const DilloUrl *requester); void a_Nav_repush(BrowserWindow *bw); void a_Nav_back(BrowserWindow *bw); +void a_Nav_back_nt(BrowserWindow *bw); void a_Nav_forw(BrowserWindow *bw); +void a_Nav_forw_nt(BrowserWindow *bw); void a_Nav_home(BrowserWindow *bw); void a_Nav_reload(BrowserWindow *bw); void a_Nav_jump(BrowserWindow *bw, int offset, int new_bw); diff -upr a/src/ui.cc b/src/ui.cc --- a/src/ui.cc Sun Apr 27 18:56:44 2025 +++ b/src/ui.cc Wed Apr 30 16:49:55 2025 @@ -312,6 +312,8 @@ static void b1_cb(Fl_Widget *wid, void *cb_data) case UI_BACK: if (b == FL_LEFT_MOUSE) { a_UIcmd_back(a_UIcmd_get_bw_by_widget(wid)); + } else if (b == FL_MIDDLE_MOUSE) { + a_UIcmd_back_nt(a_UIcmd_get_bw_by_widget(wid)); } else if (b == FL_RIGHT_MOUSE) { a_UIcmd_back_popup(a_UIcmd_get_bw_by_widget(wid), wid->x(), wid->y() + wid->h()); @@ -320,6 +322,8 @@ static void b1_cb(Fl_Widget *wid, void *cb_data) case UI_FORW: if (b == FL_LEFT_MOUSE) { a_UIcmd_forw(a_UIcmd_get_bw_by_widget(wid)); + } else if (b == FL_MIDDLE_MOUSE) { + a_UIcmd_forw_nt(a_UIcmd_get_bw_by_widget(wid)); } else if (b == FL_RIGHT_MOUSE) { a_UIcmd_forw_popup(a_UIcmd_get_bw_by_widget(wid), wid->x(), wid->y() + wid->h()); diff -upr a/src/uicmd.cc b/src/uicmd.cc --- a/src/uicmd.cc Sun Apr 27 18:56:44 2025 +++ b/src/uicmd.cc Wed Apr 30 16:49:55 2025 @@ -868,6 +868,14 @@ void a_UIcmd_back(void *vbw) } /* + * Send the browser back to previous page in a new tab + */ +void a_UIcmd_back_nt(void *vbw) +{ + a_Nav_back_nt((BrowserWindow*)vbw); +} + +/* * Popup the navigation menu of the Back button */ void a_UIcmd_back_popup(void *vbw, int x, int y) @@ -881,6 +889,14 @@ void a_UIcmd_back_popup(void *vbw, int x, int y) void a_UIcmd_forw(void *vbw) { a_Nav_forw((BrowserWindow*)vbw); +} + +/* + * Send the browser to next page in the history list in new tab + */ +void a_UIcmd_forw_nt(void *vbw) +{ + a_Nav_forw_nt((BrowserWindow*)vbw); } /* diff -upr a/src/uicmd.hh b/src/uicmd.hh --- a/src/uicmd.hh Sun Apr 27 18:56:44 2025 +++ b/src/uicmd.hh Wed Apr 30 16:49:55 2025 @@ -29,8 +29,10 @@ void a_UIcmd_open_url(BrowserWindow *bw, const DilloUr void a_UIcmd_open_url_nw(BrowserWindow *bw, const DilloUrl *url); void a_UIcmd_open_url_nt(void *vbw, const DilloUrl *url, int focus); void a_UIcmd_back(void *vbw); +void a_UIcmd_back_nt(void *vbw); void a_UIcmd_back_popup(void *vbw, int x, int y); void a_UIcmd_forw(void *vbw); +void a_UIcmd_forw_nt(void *vbw); void a_UIcmd_forw_popup(void *vbw, int x, int y); void a_UIcmd_home(void *vbw); void a_UIcmd_zoom_in(void *vbw); diff -upr a/doc/user_help.in.html b/doc/user_help.in.html --- a/doc/user_help.in.html Sun Apr 27 18:56:44 2025 +++ b/doc/user_help.in.html Wed Apr 30 16:47:28 2025 @@ -349,6 +349,9 @@ pressed while left-clicking a link. The same applies t form. A new tab can also be opened from the <code>File</code> menu or using the shortcut <code>Ctrl+T</code>. <p> +To open the previous page in a new tab, middle-click the back button. To open +the next page in a new tab, middle-click the forward button. +<p> Press <code>Shift</code> while opening a page in a new tab to focus the tab. If you want this behaviour to be the default, set the following option in the <a href="#dillorc">dillorc</a> configuration file: diff -upr a/src/nav.c b/src/nav.c --- a/src/nav.c Sun Apr 27 18:56:44 2025 +++ b/src/nav.c Wed Apr 30 16:49:55 2025 @@ -447,6 +447,19 @@ void a_Nav_back(BrowserWindow *bw) } /* + * Send the browser back to previous page in new tab + */ +void a_Nav_back_nt(BrowserWindow *bw) +{ + int idx = a_Nav_stack_ptr(bw); + + if (--idx >= 0){ + a_UIcmd_set_msg(bw, ""); + a_UIcmd_open_url_nt(bw, a_History_get_url(NAV_UIDX(bw, idx)), -1); + } +} + +/* * Send the browser to next page in the history list */ void a_Nav_forw(BrowserWindow *bw) @@ -457,6 +470,19 @@ void a_Nav_forw(BrowserWindow *bw) if (++idx < a_Nav_stack_size(bw)) { a_UIcmd_set_msg(bw, ""); Nav_open_url(bw, a_History_get_url(NAV_UIDX(bw,idx)), NULL, +1); + } +} + +/* + * Send the browser to next page in the history list in new tab + */ +void a_Nav_forw_nt(BrowserWindow *bw) +{ + int idx = a_Nav_stack_ptr(bw); + + if (++idx < a_Nav_stack_size(bw)) { + a_UIcmd_set_msg(bw, ""); + a_UIcmd_open_url_nt(bw, a_History_get_url(NAV_UIDX(bw, idx)), +1); } } diff -upr a/src/nav.h b/src/nav.h --- a/src/nav.h Sun Apr 27 18:56:44 2025 +++ b/src/nav.h Wed Apr 30 16:49:55 2025 @@ -18,7 +18,9 @@ void a_Nav_push(BrowserWindow *bw, const DilloUrl *url const DilloUrl *requester); void a_Nav_repush(BrowserWindow *bw); void a_Nav_back(BrowserWindow *bw); +void a_Nav_back_nt(BrowserWindow *bw); void a_Nav_forw(BrowserWindow *bw); +void a_Nav_forw_nt(BrowserWindow *bw); void a_Nav_home(BrowserWindow *bw); void a_Nav_reload(BrowserWindow *bw); void a_Nav_jump(BrowserWindow *bw, int offset, int new_bw); diff -upr a/src/ui.cc b/src/ui.cc --- a/src/ui.cc Sun Apr 27 18:56:44 2025 +++ b/src/ui.cc Wed Apr 30 16:49:55 2025 @@ -312,6 +312,8 @@ static void b1_cb(Fl_Widget *wid, void *cb_data) case UI_BACK: if (b == FL_LEFT_MOUSE) { a_UIcmd_back(a_UIcmd_get_bw_by_widget(wid)); + } else if (b == FL_MIDDLE_MOUSE) { + a_UIcmd_back_nt(a_UIcmd_get_bw_by_widget(wid)); } else if (b == FL_RIGHT_MOUSE) { a_UIcmd_back_popup(a_UIcmd_get_bw_by_widget(wid), wid->x(), wid->y() + wid->h()); @@ -320,6 +322,8 @@ static void b1_cb(Fl_Widget *wid, void *cb_data) case UI_FORW: if (b == FL_LEFT_MOUSE) { a_UIcmd_forw(a_UIcmd_get_bw_by_widget(wid)); + } else if (b == FL_MIDDLE_MOUSE) { + a_UIcmd_forw_nt(a_UIcmd_get_bw_by_widget(wid)); } else if (b == FL_RIGHT_MOUSE) { a_UIcmd_forw_popup(a_UIcmd_get_bw_by_widget(wid), wid->x(), wid->y() + wid->h()); diff -upr a/src/uicmd.cc b/src/uicmd.cc --- a/src/uicmd.cc Sun Apr 27 18:56:44 2025 +++ b/src/uicmd.cc Wed Apr 30 16:49:55 2025 @@ -868,6 +868,14 @@ void a_UIcmd_back(void *vbw) } /* + * Send the browser back to previous page in a new tab + */ +void a_UIcmd_back_nt(void *vbw) +{ + a_Nav_back_nt((BrowserWindow*)vbw); +} + +/* * Popup the navigation menu of the Back button */ void a_UIcmd_back_popup(void *vbw, int x, int y) @@ -881,6 +889,14 @@ void a_UIcmd_back_popup(void *vbw, int x, int y) void a_UIcmd_forw(void *vbw) { a_Nav_forw((BrowserWindow*)vbw); +} + +/* + * Send the browser to next page in the history list in new tab + */ +void a_UIcmd_forw_nt(void *vbw) +{ + a_Nav_forw_nt((BrowserWindow*)vbw); } /* diff -upr a/src/uicmd.hh b/src/uicmd.hh --- a/src/uicmd.hh Sun Apr 27 18:56:44 2025 +++ b/src/uicmd.hh Wed Apr 30 16:49:55 2025 @@ -29,8 +29,10 @@ void a_UIcmd_open_url(BrowserWindow *bw, const DilloUr void a_UIcmd_open_url_nw(BrowserWindow *bw, const DilloUrl *url); void a_UIcmd_open_url_nt(void *vbw, const DilloUrl *url, int focus); void a_UIcmd_back(void *vbw); +void a_UIcmd_back_nt(void *vbw); void a_UIcmd_back_popup(void *vbw, int x, int y); void a_UIcmd_forw(void *vbw); +void a_UIcmd_forw_nt(void *vbw); void a_UIcmd_forw_popup(void *vbw, int x, int y); void a_UIcmd_home(void *vbw); void a_UIcmd_zoom_in(void *vbw);

Hi, On Wed, Apr 30, 2025 at 05:01:28PM +0000, a1ex@dismail.de wrote:
Hi,
Here is an updated version of the patch which addresses most of Rodrigos comments. Not sure how much more I can improve on it, but open to suggestions.
Thanks, it looks good. I reworded the documentation and moved it to the history section. See: https://github.com/dillo-browser/dillo/pull/387 When the tests pass we can merge it. Best, Rodrigo.

Hi, On Wed, Apr 30, 2025 at 08:37:33PM +0200, Rodrigo Arias wrote:
https://github.com/dillo-browser/dillo/pull/387
When the tests pass we can merge it.
Merged: To github.com:dillo-browser/dillo.git e6364911..19559f53 master -> master Best, Rodrigo.
participants (2)
-
a1ex@dismail.de
-
Rodrigo Arias