summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoofar <toofar@spalge.com>2023-12-22 18:58:50 +1300
committertoofar <toofar@spalge.com>2024-01-06 20:53:27 +1300
commit8aa88b83e8b63a81958882d9d6a2abff63a5cc76 (patch)
treec4138cb16e028ebc9855061ef3577dcf5b6295cd
parentdcee69f050ff5206eb68bcef9f2412ec3cbb152c (diff)
downloadqutebrowser-8aa88b83e8b63a81958882d9d6a2abff63a5cc76.tar.gz
qutebrowser-8aa88b83e8b63a81958882d9d6a2abff63a5cc76.zip
Avoid tab title updates while shutting down.
TreeTabWidget.get_tab_fields() was getting called with indexes that didn't match what it had in its internal data structure on shutdown and was printing errors. With this change tab titles no longer get updated during shutdown, avoiding those errors. Unfortunately we couldn't connect to the `shutting_down` signal on the parent object because that is only emitted after the tabs are removed, and it seems it needs to stay that way for the sake of the window close undo functionality. So I plumbed that parent object through to a member variable, hopefully mypy is happy with that. For some reason `self.parent()` in that later on function was returning a MainWindow instead of a TabbedBrowser? Weird. That does beg the question of why the nodes aren't getting removed from the tree when they are getting removed from the widget. Should `TreeTabbedBrowser._remove_tab()` be doing things in a different order? That says "node will already be removed from tree", so where are they getting removed? Or is that meaning widget instead of tree? TODO: get more certainty on alternate logic fixes
-rw-r--r--qutebrowser/mainwindow/tabwidget.py4
-rw-r--r--qutebrowser/mainwindow/treetabwidget.py29
2 files changed, 14 insertions, 19 deletions
diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py
index 4dfdb541b..2ac7cb6d4 100644
--- a/qutebrowser/mainwindow/tabwidget.py
+++ b/qutebrowser/mainwindow/tabwidget.py
@@ -54,6 +54,7 @@ class TabWidget(QTabWidget):
def __init__(self, win_id, parent=None):
super().__init__(parent)
+ self._tabbed_browser = parent
bar = TabBar(win_id, self)
self.setStyle(TabBarStyle())
self.setTabBar(bar)
@@ -140,6 +141,9 @@ class TabWidget(QTabWidget):
if self._tab_title_update_disabled:
return
+ if self._tabbed_browser.is_shutting_down:
+ return
+
assert idx != -1
tab = self._tab_by_idx(idx)
assert tab is not None
diff --git a/qutebrowser/mainwindow/treetabwidget.py b/qutebrowser/mainwindow/treetabwidget.py
index 83a409b2a..8534a6283 100644
--- a/qutebrowser/mainwindow/treetabwidget.py
+++ b/qutebrowser/mainwindow/treetabwidget.py
@@ -39,25 +39,16 @@ class TreeTabWidget(TabWidget):
rendered_tree = self.tree_root.render()
- # We can be called when the count of tabs in the widget is different
- # to the size of the rendered tree. This is known to happen when
- # hiding a tree group with multiple tabs in it. render() will reflect
- # the final state right away but we get called for every removal or
- # insertion from the tab widget while update_tree_tab_visibility() is
- # traversing through the tree group to update the widget.
- # There may be other cases when this happens that we would be
- # swallowing here. To avoid that, since we get called via
- # update_tab_titles() possibly it would be cleanest to add an
- # attribute to TabWidget (or a context manager) to disabled tab title
- # updates and set that while calling
- # update_tree_tab_{visibility,positions} in tree_tab_update().
- miscount = len(rendered_tree) - 1 - self.count()
- if miscount < 0:
- log.misc.error(f"Less nodes in tree than widget. Are we collapsing tabs? {idx=} {miscount=} {fields['current_url']=}")
- return fields
- elif miscount > 0:
- log.misc.error(f"More nodes in tree than widget. Are we revealing tabs? {idx=} {miscount=} {fields['current_url']=}")
- return fields
+ # We are getting called with an index into the tab bar. If we have a
+ # different amount of nodes in the tree than the tab bar that
+ # indicates a logic error.
+ difference = len(rendered_tree) - 1 - self.count()
+ if difference != 0:
+ tabs = [str(self.widget(idx)) for idx in range(self.count())]
+ assert difference == 0, (
+ "Different amount of nodes in tree than widget. "
+ f"difference={difference} tree={rendered_tree[1:]} tabs={tabs}"
+ )
# we remove the first two chars because every tab is child of tree
# root and that gets rendered as well