aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2025-08-04 21:46:18 +0200
committerRodrigo Arias Mallo <rodarima@gmail.com>2025-08-04 22:23:21 +0200
commit8429930aecec8f5714c9e956171002fbb9c4eba3 (patch)
treec5d0992fc22fb90b2dbebc3875a803408ecc1188
parent607e4acefeec5776dfff63090a79baef15c6c336 (diff)
Focus the N-th tab with Alt-<number>
Allows jumping directly to a given tab. It encourages a low number of tabs opened, otherwise it will exceed the 1 to 10 range.
-rw-r--r--ChangeLog1
-rw-r--r--doc/user_help.in.html4
-rw-r--r--src/keys.cc10
-rw-r--r--src/keys.hh12
-rw-r--r--src/keysrc12
-rw-r--r--src/ui.cc4
-rw-r--r--src/uicmd.cc21
-rw-r--r--src/uicmd.hh1
8 files changed, 64 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index aa5a07cd..b4c36ba4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,7 @@ dillo-3.3.0 [Unreleased]
- Control + left click opens links in new tab (emulates mouse middle button).
- Ctrl+C copies selected text into the clipboard so Ctrl+V works as expected.
- Enable IPv6 support by default if supported by the platform.
+ - Focus the N-th tab with the Alt+<number> shortcut.
Patches: Rodrigo Arias Mallo
+- Middle click on back or forward button opens page in new tab.
Patches: Alex
diff --git a/doc/user_help.in.html b/doc/user_help.in.html
index 50a2b28d..aca3fa60 100644
--- a/doc/user_help.in.html
+++ b/doc/user_help.in.html
@@ -389,6 +389,10 @@ bookmarks page set the following line in <a href="#dillorc">dillorc</a>:
<pre>
new_tab_page="dpi:/bm/"
</pre>
+<p>
+You can quickly focus the N-th tab by pressing <code>Alt</code> and the tab
+number, for example <code>Alt+3</code> will focus the third tab. Using
+<code>Alt+0</code> focuses the tenth tab, as they start counting at 1.
<h3 id="bookmarks">Bookmarks</h3>
<p>
diff --git a/src/keys.cc b/src/keys.cc
index 2a97a160..d94e5918 100644
--- a/src/keys.cc
+++ b/src/keys.cc
@@ -144,6 +144,16 @@ static const KeyBinding_t default_keys[] = {
{ "zoom-in" , KEYS_ZOOM_IN , FL_CTRL , '=' /* US + */ },
{ "zoom-out" , KEYS_ZOOM_OUT , FL_CTRL , '-' },
{ "zoom-reset" , KEYS_ZOOM_RESET , FL_CTRL , '0' },
+ { "focus-tab1" , KEYS_FOCUS_TAB1 , FL_ALT , '1' },
+ { "focus-tab2" , KEYS_FOCUS_TAB2 , FL_ALT , '2' },
+ { "focus-tab3" , KEYS_FOCUS_TAB3 , FL_ALT , '3' },
+ { "focus-tab4" , KEYS_FOCUS_TAB4 , FL_ALT , '4' },
+ { "focus-tab5" , KEYS_FOCUS_TAB5 , FL_ALT , '5' },
+ { "focus-tab6" , KEYS_FOCUS_TAB6 , FL_ALT , '6' },
+ { "focus-tab7" , KEYS_FOCUS_TAB7 , FL_ALT , '7' },
+ { "focus-tab8" , KEYS_FOCUS_TAB8 , FL_ALT , '8' },
+ { "focus-tab9" , KEYS_FOCUS_TAB9 , FL_ALT , '9' },
+ { "focus-tab10" , KEYS_FOCUS_TAB10 , FL_ALT , '0' },
};
static Dlist *bindings;
diff --git a/src/keys.hh b/src/keys.hh
index 72b62d18..6a2c82c7 100644
--- a/src/keys.hh
+++ b/src/keys.hh
@@ -52,7 +52,17 @@ typedef enum {
KEYS_COPY,
KEYS_ZOOM_IN,
KEYS_ZOOM_OUT,
- KEYS_ZOOM_RESET
+ KEYS_ZOOM_RESET,
+ KEYS_FOCUS_TAB1,
+ KEYS_FOCUS_TAB2,
+ KEYS_FOCUS_TAB3,
+ KEYS_FOCUS_TAB4,
+ KEYS_FOCUS_TAB5,
+ KEYS_FOCUS_TAB6,
+ KEYS_FOCUS_TAB7,
+ KEYS_FOCUS_TAB8,
+ KEYS_FOCUS_TAB9,
+ KEYS_FOCUS_TAB10
} KeysCommand_t;
class Keys {
diff --git a/src/keysrc b/src/keysrc
index 2d467fa2..a825f79c 100644
--- a/src/keysrc
+++ b/src/keysrc
@@ -95,6 +95,18 @@
# "zoom-reset" resets the zoom to 100%.
#<ctrl>0 = zoom-reset
+# "focus-tab<N>" focus the N-th tab (starting in 1).
+#<alt>1 = focus-tab1
+#<alt>2 = focus-tab2
+#<alt>3 = focus-tab3
+#<alt>4 = focus-tab4
+#<alt>5 = focus-tab5
+#<alt>6 = focus-tab6
+#<alt>7 = focus-tab7
+#<alt>8 = focus-tab8
+#<alt>9 = focus-tab9
+#<alt>0 = focus-tab10
+
#--------------------------------------------------------------------
# MOTION COMMANDS
#--------------------------------------------------------------------
diff --git a/src/ui.cc b/src/ui.cc
index 30e0a2d5..9a01cdd5 100644
--- a/src/ui.cc
+++ b/src/ui.cc
@@ -794,6 +794,10 @@ int UI::handle(int event)
const DilloUrl *url = a_History_get_url(NAV_TOP_UIDX(bw));
a_UIcmd_view_page_source(bw, url);
ret = 1;
+ } else if (cmd >= KEYS_FOCUS_TAB1 && cmd <= KEYS_FOCUS_TAB10) {
+ int index = cmd - KEYS_FOCUS_TAB1; /* zero-based index */
+ a_UIcmd_focus_tab(a_UIcmd_get_bw_by_widget(this), index);
+ ret = 1;
}
} else if (event == FL_RELEASE) {
if (Fl::event_button() == FL_MIDDLE_MOUSE &&
diff --git a/src/uicmd.cc b/src/uicmd.cc
index a46fd7c5..957bedd7 100644
--- a/src/uicmd.cc
+++ b/src/uicmd.cc
@@ -189,6 +189,7 @@ public:
Fl_Wizard *wizard(void) { return Wizard; }
int num_tabs() { return (Pack ? Pack->children() : 0); }
void switch_tab(CustTabButton *cbtn);
+ void switch_tab(int index);
void prev_tab(void);
void next_tab(void);
void set_tab_label(UI *ui, const char *title);
@@ -487,6 +488,15 @@ void CustTabs::next_tab()
}
/**
+ * Make index tab the active one, starting from 0.
+ */
+void CustTabs::switch_tab(int index)
+{
+ if (index >= 0 && index < num_tabs())
+ switch_tab((CustTabButton*)Pack->child(index));
+}
+
+/**
* Set this UI's tab button label.
*/
void CustTabs::set_tab_label(UI *ui, const char *label)
@@ -1684,3 +1694,14 @@ void a_UIcmd_focus_location(void *vbw)
BW2UI(bw)->focus_location();
}
+/*
+ * Focus the tab at index, starting from 0.
+ */
+void a_UIcmd_focus_tab(void *vbw, int index)
+{
+ BrowserWindow *bw = (BrowserWindow*)vbw;
+ UI *ui = BW2UI(bw);
+ CustTabs *tabs = ui->tabs();
+ if (tabs)
+ tabs->switch_tab(index);
+}
diff --git a/src/uicmd.hh b/src/uicmd.hh
index 581eac30..7ef676e9 100644
--- a/src/uicmd.hh
+++ b/src/uicmd.hh
@@ -74,6 +74,7 @@ void a_UIcmd_view_page_bugs(void *vbw);
void a_UIcmd_bugmeter_popup(void *vbw);
int *a_UIcmd_get_history(BrowserWindow *bw, int direction);
void a_UIcmd_nav_jump(BrowserWindow *bw, int offset, int new_bw);
+void a_UIcmd_focus_tab(void *vbw, int index);
void a_UIcmd_close_bw(void *vbw);
void a_UIcmd_close_all_bw(void *p);