From 45dea54e3c2cacbd887ce4e0a006d92afd740e53 Mon Sep 17 00:00:00 2001 From: Tobias Patzl Date: Mon, 25 May 2015 15:23:14 +0200 Subject: [PATCH 1/4] Add setting to disable mousewheel tab switching. See #374. --- doc/help/settings.asciidoc | 12 ++++++++++++ qutebrowser/config/configdata.py | 4 ++++ qutebrowser/mainwindow/tabwidget.py | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 46539c3b7..d3c571aa3 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -111,6 +111,7 @@ |<>|Spacing between tab edge and indicator. |<>|Whether to open windows instead of tabs. |<>|The format to use for the tab title. The following placeholders are defined: +|<>|Switch between tabs using the mouse wheel. |============== .Quick reference for section ``storage'' @@ -1031,6 +1032,17 @@ The format to use for the tab title. The following placeholders are defined: Default: +pass:[{index}: {title}]+ +[[tabs-mousewheel-tab-switching]] +=== mousewheel-tab-switching +Switch between tabs using the mouse wheel. + +Valid values: + + * +true+ + * +false+ + +Default: +pass:[true]+ + == storage Settings related to cache and storage. diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index cb3a47be7..02b8c6008 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -522,6 +522,10 @@ def data(readonly=False): "* `{index}`: The index of this tab.\n" "* `{id}`: The internal tab ID of this tab."), + ('mousewheel-tab-switching', + SettingValue(typ.Bool(), 'true'), + "Switch between tabs using the mouse wheel."), + readonly=readonly )), diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index df44ebbba..1ad97370e 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -480,6 +480,17 @@ class TabBar(QTabBar): new_idx = super().insertTab(idx, icon, '') self.set_page_title(new_idx, text) + def wheelEvent(self, event): + """Override wheelEvent to make the action configurable.""" + if config.get('tabs', 'mousewheel-tab-switching'): + super().wheelEvent(event) + else: + tabbed_browser = objreg.get('tabbed-browser', scope='window', + window=self._win_id) + focused_tab = tabbed_browser.currentWidget() + if focused_tab is not None: + focused_tab.wheelEvent(event) + class TabBarStyle(QCommonStyle): From 61519e63839b81ee1532c8021709534f6f49e9f3 Mon Sep 17 00:00:00 2001 From: Tobias Patzl Date: Mon, 25 May 2015 20:21:37 +0200 Subject: [PATCH 2/4] move part of the logic to `TabbedBrowser` --- qutebrowser/mainwindow/tabbedbrowser.py | 9 +++++++++ qutebrowser/mainwindow/tabwidget.py | 14 ++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index c465c8ca4..7b3477018 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -577,3 +577,12 @@ class TabbedBrowser(tabwidget.TabWidget): """ super().resizeEvent(e) self.resized.emit(self.geometry()) + + def wheelEvent(self, e): + """Override wheelEvent of QWidget to forward it to the focused tab. + + Args: + e: The QWheelEvent + """ + if self._now_focused is not None: + self._now_focused.wheelEvent(e) diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 1ad97370e..bbbfdf045 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -480,16 +480,18 @@ class TabBar(QTabBar): new_idx = super().insertTab(idx, icon, '') self.set_page_title(new_idx, text) - def wheelEvent(self, event): - """Override wheelEvent to make the action configurable.""" + def wheelEvent(self, e): + """Override wheelEvent to make the action configurable. + + Args: + e: The QWheelEvent + """ if config.get('tabs', 'mousewheel-tab-switching'): - super().wheelEvent(event) + super().wheelEvent(e) else: tabbed_browser = objreg.get('tabbed-browser', scope='window', window=self._win_id) - focused_tab = tabbed_browser.currentWidget() - if focused_tab is not None: - focused_tab.wheelEvent(event) + tabbed_browser.wheelEvent(e) class TabBarStyle(QCommonStyle): From b858b6ac755ffc6633a24a1a85c7902ce78c1edc Mon Sep 17 00:00:00 2001 From: Tobias Patzl Date: Tue, 26 May 2015 10:24:32 +0200 Subject: [PATCH 3/4] call `e.ignore()` when the event is not handled --- qutebrowser/mainwindow/tabbedbrowser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 7b3477018..ba5a5c725 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -586,3 +586,5 @@ class TabbedBrowser(tabwidget.TabWidget): """ if self._now_focused is not None: self._now_focused.wheelEvent(e) + else: + e.ignore() From 6b98c48985fd9ef4c3c6b7095b60bdd69358dd20 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 26 May 2015 10:30:21 +0200 Subject: [PATCH 4/4] Regenerate authors. --- README.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/README.asciidoc b/README.asciidoc index 8742f11cb..ad7a95ff2 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -150,6 +150,7 @@ Contributors, sorted by the number of commits in descending order: * Error 800 * Brian Jackson * sbinix +* Tobias Patzl * Johannes Altmanninger * Samir Benmendil * Regina Hug