From 076ed43ec0fc7283f2e080d6c86a81500084a204 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 18 Sep 2014 18:15:37 +0200 Subject: [PATCH] Add auto-hide option for tabs. --- qutebrowser/config/configdata.py | 4 ++++ qutebrowser/widgets/tabwidget.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index d5f87a6b5..080fd59a8 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -389,6 +389,10 @@ DATA = collections.OrderedDict([ SettingValue(typ.LastClose(), 'ignore'), "Behaviour when the last tab is closed."), + ('auto-hide', + SettingValue(typ.Bool(), 'false'), + "Hide the tabbar if only one tab is open."), + ('wrap', SettingValue(typ.Bool(), 'true'), "Whether to wrap when changing tabs."), diff --git a/qutebrowser/widgets/tabwidget.py b/qutebrowser/widgets/tabwidget.py index 9301d9fbe..c3a613b87 100644 --- a/qutebrowser/widgets/tabwidget.py +++ b/qutebrowser/widgets/tabwidget.py @@ -138,6 +138,12 @@ class TabBar(QTabBar): p = self.palette() p.setColor(QPalette.Window, config.get('colors', 'tab.bg.bar')) self.setPalette(p) + elif section == 'tabs' and option == 'auto-hide': + hide = config.get('tabs', 'auto-hide') + if hide and self.count() == 1: + self.hide() + elif not hide: + self.show() def mousePressEvent(self, e): """Override mousePressEvent to close tabs if configured.""" @@ -240,6 +246,18 @@ class TabBar(QTabBar): continue p.drawControl(QStyle.CE_TabBarTab, tab) + def tabInserted(self, idx): + """Show the tabbar if configured to hide and >1 tab is open.""" + if self.count() > 1 and config.get('tabs', 'auto-hide'): + self.show() + super().tabInserted(idx) + + def tabRemoved(self, idx): + """Hide the tabbar if configured when only one tab is open.""" + if self.count() <= 1 and config.get('tabs', 'auto-hide'): + self.hide() + super().tabRemoved(idx) + class TabBarStyle(QCommonStyle):