From dd927ded6ba3b03d9450c8e375b25651f67f90bf Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 20 Oct 2017 08:25:43 +0200 Subject: [PATCH] Only update tab/window title on scroll if needed This way, if {scroll_pos} is not in the window/tab title template, we don't redraw anything unnecessarily. See #2233 --- qutebrowser/mainwindow/tabbedbrowser.py | 19 ++++++++++++----- qutebrowser/mainwindow/tabwidget.py | 28 ++++++++++++++++--------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 0571d7e34..a280df650 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -173,8 +173,18 @@ class TabbedBrowser(tabwidget.TabWidget): widgets.append(widget) return widgets - def _update_window_title(self): - """Change the window title to match the current tab.""" + def _update_window_title(self, field=None): + """Change the window title to match the current tab. + + Args: + idx: The tab index to update. + field: A field name which was updated. If given, the title + is only set if the given field is in the template. + """ + title_format = config.val.window.title_format + if field is not None and ('{' + field + '}') not in title_format: + return + idx = self.currentIndex() if idx == -1: # (e.g. last tab removed) @@ -183,7 +193,6 @@ class TabbedBrowser(tabwidget.TabWidget): fields = self.get_tab_fields(idx) fields['id'] = self._win_id - title_format = config.val.window.title_format title = title_format.format(**fields) self.window().setWindowTitle(title) @@ -696,8 +705,8 @@ class TabbedBrowser(tabwidget.TabWidget): log.webview.debug("Not updating scroll position because index is " "-1") return - self._update_window_title() - self._update_tab_title(idx) + self._update_window_title('scroll_pos') + self._update_tab_title(idx, 'scroll_pos') def _on_renderer_process_terminated(self, tab, status, code): """Show an error when a renderer process terminated.""" diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 56cb922f8..03c9929e0 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -121,21 +121,29 @@ class TabWidget(QTabWidget): """Get the tab title user data.""" return self.tabBar().page_title(idx) - def _update_tab_title(self, idx): - """Update the tab text for the given tab.""" + def _update_tab_title(self, idx, field=None): + """Update the tab text for the given tab. + + Args: + idx: The tab index to update. + field: A field name which was updated. If given, the title + is only set if the given field is in the template. + """ tab = self.widget(idx) + if tab.data.pinned: + fmt = config.val.tabs.title.format_pinned + else: + fmt = config.val.tabs.title.format + + if (field is not None and + (fmt is None or ('{' + field + '}') not in fmt)): + return + fields = self.get_tab_fields(idx) fields['title'] = fields['title'].replace('&', '&&') fields['index'] = idx + 1 - fmt = config.val.tabs.title.format - fmt_pinned = config.val.tabs.title.format_pinned - - if tab.data.pinned: - title = '' if fmt_pinned is None else fmt_pinned.format(**fields) - else: - title = '' if fmt is None else fmt.format(**fields) - + title = '' if fmt is None else fmt.format(**fields) self.tabBar().setTabText(idx, title) def get_tab_fields(self, idx):