diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 4462e56e2..1ead1e363 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -227,6 +227,10 @@ class CommandDispatcher: tabbar = self._tabbed_browser.tabBar() selection_override = self._get_selection_override(left, right, opposite) + + if tab.data.pinned: + tabbar.pinned -= 1 + if selection_override is None: self._tabbed_browser.close_tab(tab) else: diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index b42ff0f3f..c12b88952 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -99,9 +99,16 @@ class TabWidget(QTabWidget): pinned: Pinned tab state. """ bar = self.tabBar() - bar.set_tab_data(idx, 'pinned',pinned) + bar.set_tab_data(idx, 'pinned', pinned) bar.update(bar.tabRect(idx)) + if pinned: + bar.pinned += 1 + else: + bar.pinned -= 1 + + bar.refresh() + def set_page_title(self, idx, title): """Set the tab title user data.""" self.tabBar().set_tab_data(idx, 'page-title', title) @@ -139,10 +146,6 @@ class TabWidget(QTabWidget): fields['title_sep'] = ' - ' if page_title else '' fields['perc_raw'] = tab.progress() - #TODO: Move this to a proper place - if tab.data.pinned: - self.set_tab_pinned(idx, tab.data.pinned) - if tab.load_status() == usertypes.LoadStatus.loading: fields['perc'] = '[{}%] '.format(tab.progress()) else: @@ -298,6 +301,7 @@ class TabBar(QTabBar): self._auto_hide_timer.timeout.connect(self._tabhide) self.setAutoFillBackground(True) self.set_colors() + self.pinned = 0 config_obj.changed.connect(self.set_colors) QTimer.singleShot(0, self._tabhide) config_obj.changed.connect(self.on_tab_colors_changed) @@ -479,14 +483,16 @@ class TabBar(QTabBar): return size # If we *do* have enough space, tabs should occupy the whole window - # width. - #looks like this generates high cpu usage - #need to register the number of pin tabs in advance - #nb_of_pins = len([None for item in range(self.count()) - # if objreg.get('tab', scope='tab', - # window=self._win_id, tab=item).pin is True]) - #width = (self.width() + 40*nb_of_pins) / self.count() - width = self.width() / self.count() + # width. Also taken in consideration the reduced space necessary for + # the pinned tabs. + #TODO: During shutdown the self.count goes down, but the self.pinned not + #this generates some odd bahavior. + #To avoid this we compare self.count against self.pinned. + if self.pinned > 0 and self.count() > self.pinned: + width = (self.width() - 40*self.pinned) / (self.count() - self.pinned) + else: + width = self.width() / self.count() + ## If width is not divisible by count, add a pixel to some tabs so ## that there is no ugly leftover space. if index < self.width() % self.count(): diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py index f6c6d97b2..31335f33b 100644 --- a/qutebrowser/misc/sessions.py +++ b/qutebrowser/misc/sessions.py @@ -381,6 +381,8 @@ class SessionManager(QObject): self._load_tab(new_tab, tab) if tab.get('active', False): tab_to_focus = i + if new_tab.data.pinned: + tabbed_browser.set_tab_pinned(i, new_tab.data.pinned) if tab_to_focus is not None: tabbed_browser.setCurrentIndex(tab_to_focus) if win.get('active', False):