diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 88f8f7995..289fd7b41 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1602,6 +1602,23 @@ tabs.min_width: This setting does not apply to pinned tabs, unless `tabs.pinned.shrink` is False. +tabs.max_width: + default: -1 + type: + name: Int + minval: -1 + maxval: maxint + desc: >- + Maximum width (in pixels) of tabs (-1 for no maximum). + + This setting only applies when tabs are horizontal. + + This setting does not apply to pinned tabs, unless `tabs.pinned.shrink` is + False. + + This setting may not apply properly if max_width is smaller than the + minimum size of tab contents, or smaller than tabs.min_width. + tabs.width.indicator: renamed: tabs.indicator.width diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 154c93bfd..a2de308da 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -610,6 +610,9 @@ class TabBar(QTabBar): # Request as much space as possible so we fill the tabbar, let # Qt shrink us down width = self.width() + max_width = config.cache['tabs.max_width'] + if max_width > 0: + width = min(max_width, width) # If we don't have enough space, we return the minimum size width = max(width, minimum_size.width()) diff --git a/tests/unit/mainwindow/test_tabwidget.py b/tests/unit/mainwindow/test_tabwidget.py index d16d31e01..d29c61c0f 100644 --- a/tests/unit/mainwindow/test_tabwidget.py +++ b/tests/unit/mainwindow/test_tabwidget.py @@ -38,6 +38,7 @@ class TestTabWidget: qtbot.addWidget(w) monkeypatch.setattr(tabwidget.objects, 'backend', usertypes.Backend.QtWebKit) + monkeypatch.setattr(w.tabBar(), 'width', w.width) return w @pytest.fixture @@ -108,7 +109,7 @@ class TestTabWidget: for i in range(num_tabs): if i in pinned_num and shrink_pinned and not vertical: - assert (first_size.width() < + assert (first_size.width() > widget.tabBar().tabSizeHint(i).width()) assert (first_size_min.width() < widget.tabBar().minimumTabSizeHint(i).width()) @@ -128,6 +129,22 @@ class TestTabWidget: benchmark(widget.update_tab_titles) + def test_tab_min_width(self, widget, fake_web_tab, config_stub): + """Ensure by default, all tab sizes are the same.""" + widget.addTab(fake_web_tab(), 'foobar') + normal_size = widget.tabBar().minimumTabSizeHint(0).width() + normal_size += 100 + config_stub.val.tabs.min_width = normal_size + assert widget.tabBar().minimumTabSizeHint(0).width() == normal_size + + def test_tab_max_width(self, widget, fake_web_tab, config_stub): + """Ensure by default, all tab sizes are the same.""" + widget.addTab(fake_web_tab(), 'foobar') + normal_size = widget.tabBar().tabSizeHint(0).width() + normal_size -= 10 + config_stub.val.tabs.max_width = normal_size + assert widget.tabBar().tabSizeHint(0).width() == normal_size + @pytest.mark.parametrize("num_tabs", [4, 10]) def test_add_remove_tab_benchmark(self, benchmark, browser, qtbot, fake_web_tab, num_tabs):